Remove read items from list

This commit is contained in:
Peter Stuifzand 2018-04-10 20:30:24 +02:00
parent ac2e238e0a
commit e24c01e781
2 changed files with 28 additions and 26 deletions

View File

@ -332,7 +332,7 @@ func (b *memoryBackend) ProcessContent(channel, fetchURL, contentType string, bo
} }
for _, item := range items { for _, item := range items {
item.Read = b.checkRead(channel, item.ID) item.Read = false
b.channelAddItem(channel, item) b.channelAddItem(channel, item)
} }

View File

@ -18,7 +18,6 @@
package main package main
import ( import (
"encoding/hex"
"encoding/json" "encoding/json"
"fmt" "fmt"
"log" "log"
@ -428,7 +427,7 @@ func (b *memoryBackend) TimelineGet(after, before, channel string) microsub.Time
log.Println(err) log.Println(err)
continue continue
} }
item.Read = b.checkRead(channel, item.ID) item.Read = false
items = append(items, item) items = append(items, item)
} }
paging := microsub.Pagination{ paging := microsub.Pagination{
@ -451,30 +450,30 @@ func reverseSlice(s interface{}) {
} }
} }
func (b *memoryBackend) checkRead(channel string, uid string) bool { // func (b *memoryBackend) checkRead(channel string, uid string) bool {
conn := pool.Get() // conn := pool.Get()
defer conn.Close() // defer conn.Close()
args := redis.Args{}.Add(fmt.Sprintf("timeline:%s:read", channel)).Add("item:" + uid) // args := redis.Args{}.Add(fmt.Sprintf("timeline:%s:read", channel)).Add("item:" + uid)
member, err := redis.Bool(conn.Do("SISMEMBER", args...)) // member, err := redis.Bool(conn.Do("SISMEMBER", args...))
if err != nil { // if err != nil {
log.Printf("Checking read for channel %s item %s has failed\n", channel, uid) // log.Printf("Checking read for channel %s item %s has failed\n", channel, uid)
} // }
return member // return member
} // }
func (b *memoryBackend) wasRead(channel string, item map[string]interface{}) bool { // func (b *memoryBackend) wasRead(channel string, item map[string]interface{}) bool {
if uid, e := item["uid"]; e { // if uid, e := item["uid"]; e {
uid = hex.EncodeToString([]byte(uid.(string))) // uid = hex.EncodeToString([]byte(uid.(string)))
return b.checkRead(channel, uid.(string)) // return b.checkRead(channel, uid.(string))
} // }
if uid, e := item["url"]; e { // if uid, e := item["url"]; e {
uid = hex.EncodeToString([]byte(uid.(string))) // uid = hex.EncodeToString([]byte(uid.(string)))
return b.checkRead(channel, uid.(string)) // return b.checkRead(channel, uid.(string))
} // }
return false // return false
} // }
func (b *memoryBackend) FollowGetList(uid string) []microsub.Feed { func (b *memoryBackend) FollowGetList(uid string) []microsub.Feed {
return b.Feeds[uid] return b.Feeds[uid]
@ -628,9 +627,12 @@ func (b *memoryBackend) MarkRead(channel string, uids []string) {
itemUIDs = append(itemUIDs, "item:"+uid) itemUIDs = append(itemUIDs, "item:"+uid)
} }
args := redis.Args{}.Add(fmt.Sprintf("timeline:%s:read", channel)).AddFlat(itemUIDs) channelKey := fmt.Sprintf("zchannel:%s:posts", channel)
if _, err := conn.Do("SADD", args...); err != nil { args := redis.Args{}.Add(channelKey).AddFlat(itemUIDs)
if _, err := conn.Do("ZREM", args...); err != nil {
log.Printf("Marking read for channel %s has failed\n", channel) log.Printf("Marking read for channel %s has failed\n", channel)
} }
log.Printf("Marking read success for %s %v\n", channel, itemUIDs) log.Printf("Marking read success for %s %v\n", channel, itemUIDs)
} }