From 8360c178c71a91848d6e3d4f5c8d0a7a533aa1dd Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Sat, 18 Aug 2018 20:50:10 +0200 Subject: [PATCH] Also look at referenced items for included text --- cmd/eksterd/memory.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/eksterd/memory.go b/cmd/eksterd/memory.go index 3dcf7ad..89bf1dd 100644 --- a/cmd/eksterd/memory.go +++ b/cmd/eksterd/memory.go @@ -654,14 +654,16 @@ func (b *memoryBackend) channelAddItemWithMatcher(conn redis.Conn, channel strin for channelKey, setting := range b.Settings { if setting.IncludeRegex != "" { included := false + includeRegex, err := regexp.Compile(setting.IncludeRegex) if err != nil { log.Printf("error in regexp: %q\n", includeRegex) } else { - if item.Content != nil { - included = includeRegex.MatchString(item.Content.Text) || includeRegex.MatchString(item.Content.HTML) + included = matchItemText(item, includeRegex) + + for _, v := range item.Refs { + included = included || matchItemText(v, includeRegex) } - included = included || includeRegex.MatchString(item.Name) } if included { @@ -705,6 +707,14 @@ func (b *memoryBackend) channelAddItemWithMatcher(conn redis.Conn, channel strin return b.channelAddItem(conn, channel, item) } +func matchItemText(item microsub.Item, includeRegex *regexp.Regexp) bool { + var included bool + if item.Content != nil { + included = includeRegex.MatchString(item.Content.Text) || includeRegex.MatchString(item.Content.HTML) + } + return included || includeRegex.MatchString(item.Name) +} + func (b *memoryBackend) channelAddItem(conn redis.Conn, channel string, item microsub.Item) error { zchannelKey := fmt.Sprintf("zchannel:%s:posts", channel)