aboutsummaryrefslogtreecommitdiff
path: root/connector/mattermost
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-21 19:28:00 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-21 19:28:00 +0100
commitb0644c3a17dfd1a55f4ed5f4f91fcc84e74359ed (patch)
tree9a0e45bde1ad4b30e116ab58c6db1241f5e1c9df /connector/mattermost
parente1b838d30493effbcd8a23fe43e2b131c745b722 (diff)
downloadeasybridge-b0644c3a17dfd1a55f4ed5f4f91fcc84e74359ed.tar.gz
easybridge-b0644c3a17dfd1a55f4ed5f4f91fcc84e74359ed.zip
Basic backlogging
Diffstat (limited to 'connector/mattermost')
-rw-r--r--connector/mattermost/mattermost.go31
1 files changed, 27 insertions, 4 deletions
diff --git a/connector/mattermost/mattermost.go b/connector/mattermost/mattermost.go
index 6282831..117286b 100644
--- a/connector/mattermost/mattermost.go
+++ b/connector/mattermost/mattermost.go
@@ -354,6 +354,22 @@ func (mm *Mattermost) handleConnected() {
} else {
log.Warnf("Could not get channel members: %s", resp.Error)
}
+
+ // Read backlog
+ // TODO: remember what was the last seen post in this channel
+ 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]
+ post := backlog.Posts[post_id]
+ post_time := time.Unix(post.CreateAt/1000, 0)
+ post.Message = fmt.Sprintf("[%s] %s",
+ post_time.Format("2006-01-02 15:04:05 MST"), post.Message)
+ mm.handlePost(ch.Name, post, true)
+ }
+ } else {
+ log.Warnf("Could not get channel backlog: %s", resp.Error)
+ }
}
}
@@ -425,6 +441,10 @@ func (mm *Mattermost) handlePosted(msg *model.WebSocketEvent) error {
return err
}
+ return mm.handlePost(channel_name, &post, false)
+}
+
+func (mm *Mattermost) handlePost(channel_name string, post *model.Post, only_messages bool) error {
// Skip self messages
if post.UserId == mm.conn.User.Id {
return nil
@@ -440,6 +460,7 @@ func (mm *Mattermost) handlePosted(msg *model.WebSocketEvent) error {
// Build message event
msg_ev := &Event{
+ Id: post.Id,
Author: userId,
Text: post.Message,
Type: EVENT_MESSAGE,
@@ -489,10 +510,12 @@ func (mm *Mattermost) handlePosted(msg *model.WebSocketEvent) error {
mm.ensureJoined(user, roomId)
if post.Type == "system_header_change" {
- new_header := post.Props["new_header"].(string)
- mm.handler.RoomInfoUpdated(roomId, userId, &RoomInfo{
- Topic: new_header,
- })
+ if !only_messages {
+ new_header := post.Props["new_header"].(string)
+ mm.handler.RoomInfoUpdated(roomId, userId, &RoomInfo{
+ Topic: new_header,
+ })
+ }
} else if post.Type == "" || post.Type == "me" {
msg_ev.Room = roomId
mm.handler.Event(msg_ev)