Compare commits

...

3 Commits

Author SHA1 Message Date
aa22931786 Fix actual include code 2018-07-16 22:34:25 +02:00
f2d9d450d0 Remember include_regex 2018-07-16 22:26:04 +02:00
023209c5d5 Add matching of includeRegex 2018-07-16 22:24:50 +02:00
4 changed files with 56 additions and 16 deletions

View File

@ -373,11 +373,30 @@ func (b *memoryBackend) Fetch3(channel, fetchURL string) (*http.Response, error)
return Fetch2(fetchURL)
}
func (b *memoryBackend) channelAddItem(conn redis.Conn, channel string, item microsub.Item) error {
zchannelKey := fmt.Sprintf("zchannel:%s:posts", channel)
func (b *memoryBackend) channelAddItemWithMatcher(conn redis.Conn, channel string, item microsub.Item) error {
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 && includeRegex.MatchString(item.Content.Text) {
log.Printf("Included %#v\n", item)
included = true
}
var excludeRegex regexp.Regexp
testExcludeRegex := false
if includeRegex.MatchString(item.Name) {
log.Printf("Included %#v\n", item)
included = true
}
}
if included {
b.channelAddItem(conn, channelKey, item)
}
}
}
if setting, e := b.Settings[channel]; e {
if setting.ExcludeRegex != "" {
@ -385,12 +404,6 @@ func (b *memoryBackend) channelAddItem(conn redis.Conn, channel string, item mic
if err != nil {
log.Printf("error in regexp: %q\n", excludeRegex)
} else {
testExcludeRegex = true
}
}
}
if testExcludeRegex {
if item.Content != nil && excludeRegex.MatchString(item.Content.Text) {
log.Printf("Excluded %#v\n", item)
return nil
@ -401,6 +414,14 @@ func (b *memoryBackend) channelAddItem(conn redis.Conn, channel string, item mic
return nil
}
}
}
}
return b.channelAddItem(conn, channel, item)
}
func (b *memoryBackend) channelAddItem(conn redis.Conn, channel string, item microsub.Item) error {
zchannelKey := fmt.Sprintf("zchannel:%s:posts", channel)
if item.Published == "" {
item.Published = time.Now().Format(time.RFC3339)

View File

@ -569,6 +569,18 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.Backend.Settings[uid] = setting
}
includeRegex := r.FormValue("include_regex")
if setting, e := h.Backend.Settings[uid]; e {
setting.IncludeRegex = includeRegex
h.Backend.Settings[uid] = setting
} else {
setting = channelSetting{
IncludeRegex: includeRegex,
}
h.Backend.Settings[uid] = setting
}
h.Backend.Debug()
http.Redirect(w, r, "/settings", 302)

View File

@ -48,6 +48,7 @@ type memoryBackend struct {
type channelSetting struct {
ExcludeRegex string
IncludeRegex string
}
type Debug interface {

View File

@ -57,10 +57,16 @@
<input type="hidden" name="uid" value="{{ .CurrentChannel.UID }}" />
<div class="field">
<div class="control">
<label class="label">Exclude regex</label>
<label class="label">Blocking Regex</label>
<input type="text" class="input" name="exclude_regex" value="{{ .CurrentSetting.ExcludeRegex }}" placeholder="enter regex to block" />
</div>
</div>
<div class="field">
<div class="control">
<label class="label">Tracking Regex</label>
<input type="text" class="input" name="include_regex" value="{{ .CurrentSetting.IncludeRegex }}" placeholder="enter regex to track items" />
</div>
</div>
<div class="field">
<button type="submit" class="button is-primary">Save</button>
</div>