Compare commits

..

No commits in common. "118b072f3842562d424961381ca8b266d01ce028" and "93a91a49664e7aa6c1811b940d2e2d5e4adfb071" have entirely different histories.

View File

@ -653,13 +653,18 @@ func (b *memoryBackend) channelAddItemWithMatcher(conn redis.Conn, channel strin
var updatedChannels []string
for channelKey, setting := range b.Settings {
if setting.IncludeRegex != "" {
re, err := regexp.Compile(setting.IncludeRegex)
included := false
includeRegex, err := regexp.Compile(setting.IncludeRegex)
if err != nil {
log.Printf("error in regexp: %q, %s\n", setting.IncludeRegex, err)
return 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 = included || includeRegex.MatchString(item.Name)
}
if matchItem(item, re) {
if included {
log.Printf("Included %#v\n", item)
b.channelAddItem(conn, channelKey, item)
updatedChannels = append(updatedChannels, channelKey)
@ -678,11 +683,21 @@ func (b *memoryBackend) channelAddItemWithMatcher(conn redis.Conn, channel strin
excludeRegex, err := regexp.Compile(setting.ExcludeRegex)
if err != nil {
log.Printf("error in regexp: %q\n", excludeRegex)
return nil
}
if matchItem(item, excludeRegex) {
log.Printf("Excluded %#v\n", item)
return nil
} else {
if item.Content != nil {
if excludeRegex.MatchString(item.Content.Text) {
log.Printf("Excluded %#v\n", item)
return nil
}
if excludeRegex.MatchString(item.Content.HTML) {
log.Printf("Excluded %#v\n", item)
return nil
}
}
if excludeRegex.MatchString(item.Name) {
log.Printf("Excluded %#v\n", item)
return nil
}
}
}
}
@ -690,32 +705,6 @@ func (b *memoryBackend) channelAddItemWithMatcher(conn redis.Conn, channel strin
return b.channelAddItem(conn, channel, item)
}
func matchItem(item microsub.Item, re *regexp.Regexp) bool {
if matchItemText(item, re) {
return true
}
for _, v := range item.Refs {
if matchItemText(v, re) {
return true
}
}
return false
}
func matchItemText(item microsub.Item, re *regexp.Regexp) bool {
if item.Content != nil {
if re.MatchString(item.Content.Text) {
return true
}
if re.MatchString(item.Content.HTML) {
return true
}
}
return re.MatchString(item.Name)
}
func (b *memoryBackend) channelAddItem(conn redis.Conn, channel string, item microsub.Item) error {
zchannelKey := fmt.Sprintf("zchannel:%s:posts", channel)