aboutsummaryrefslogtreecommitdiff
path: root/connector/mattermost
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-21 19:36:16 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-21 19:36:45 +0100
commita14bacc9c13309593c6eab2d19b70bcd315d193d (patch)
tree4d2cee5b2d34b5539c86d9b30a369285e7fd0aaf /connector/mattermost
parentb0644c3a17dfd1a55f4ed5f4f91fcc84e74359ed (diff)
downloadeasybridge-a14bacc9c13309593c6eab2d19b70bcd315d193d.tar.gz
easybridge-a14bacc9c13309593c6eab2d19b70bcd315d193d.zip
Keep in cache the Id of the last seen post for backlogging purposes
Diffstat (limited to 'connector/mattermost')
-rw-r--r--connector/mattermost/mattermost.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/connector/mattermost/mattermost.go b/connector/mattermost/mattermost.go
index 117286b..ab612ba 100644
--- a/connector/mattermost/mattermost.go
+++ b/connector/mattermost/mattermost.go
@@ -337,6 +337,7 @@ func (mm *Mattermost) handleConnected() {
mm.handler.RoomInfoUpdated(id, UserID(""), room_info)
// Update member list
+ // TODO (when this will be slow, i.e. hundreds of members): do only a diff
members, resp := mm.conn.Client.GetChannelMembers(ch.Id, 0, 1000, "")
if resp.Error == nil {
for _, mem := range *members {
@@ -356,8 +357,14 @@ func (mm *Mattermost) handleConnected() {
}
// Read backlog
- // TODO: remember what was the last seen post in this channel
- backlog, resp := mm.conn.Client.GetPostsForChannel(ch.Id, 0, 1000, "")
+ var backlog *model.PostList
+ last_seen_post := mm.handler.CacheGet(fmt.Sprintf("last_seen_%s", ch.Id))
+ if last_seen_post != "" {
+ backlog, resp = mm.conn.Client.GetPostsAfter(ch.Id, last_seen_post, 0, 1000, "")
+ // TODO: if there are more than 1000, loop around
+ } else {
+ backlog, resp = mm.conn.Client.GetPostsForChannel(ch.Id, 0, 1000, "")
+ }
if resp.Error == nil {
for i := 0; i < len(backlog.Order); i++ {
post_id := backlog.Order[len(backlog.Order)-i-1]
@@ -519,6 +526,7 @@ func (mm *Mattermost) handlePost(channel_name string, post *model.Post, only_mes
} else if post.Type == "" || post.Type == "me" {
msg_ev.Room = roomId
mm.handler.Event(msg_ev)
+ mm.handler.CachePut(fmt.Sprintf("last_seen_%s", post.ChannelId), post.Id)
} else {
return fmt.Errorf("Unhandled post type: %s", post.Type)
}