aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-18 18:07:35 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-18 18:07:35 +0100
commit85d2c215bb882a027c86db0f5ce4b93b96ceb915 (patch)
tree09f13276301dfcb1066ef945b04c9fd44ebaf7fd
parentb96f8a20169f2fb399fc756df4a72e14d82cf7fa (diff)
downloadeasybridge-85d2c215bb882a027c86db0f5ce4b93b96ceb915.tar.gz
easybridge-85d2c215bb882a027c86db0f5ce4b93b96ceb915.zip
Don't always rejoin; propagate user nicknames
-rw-r--r--connector/mattermost/mattermost.go29
1 files changed, 22 insertions, 7 deletions
diff --git a/connector/mattermost/mattermost.go b/connector/mattermost/mattermost.go
index 41f956b..7c776d8 100644
--- a/connector/mattermost/mattermost.go
+++ b/connector/mattermost/mattermost.go
@@ -27,7 +27,9 @@ type Mattermost struct {
conn *matterclient.MMClient
handlerStopChan chan bool
- usermap map[string]string // map username to user id
+ usermap map[string]string // map username to mm user id
+ sentjoinedmap map[string]bool // map username/room name to bool
+ userdisplaynamemap map[UserID]string // map username to last displayname
}
@@ -264,6 +266,8 @@ func (mm *Mattermost) Close() {
func (mm *Mattermost) handleConnected() {
mm.handlerStopChan = make(chan bool)
mm.usermap = make(map[string]string)
+ mm.sentjoinedmap = make(map[string]bool)
+ mm.userdisplaynamemap = make(map[UserID]string)
go mm.handleLoop(mm.conn.MessageChan, mm.handlerStopChan)
fmt.Printf("Connected to mattermost\n")
@@ -323,6 +327,14 @@ func (mm *Mattermost) handlePosted(msg *model.WebSocketEvent) error {
}
userId := UserID(fmt.Sprintf("%s@%s", user.Username, mm.server))
+ if lastdn, ok := mm.userdisplaynamemap[userId]; !ok || lastdn != user.Nickname {
+ log.Warnf("Update displayname %s %s", userId, user.Nickname)
+ mm.handler.UserInfoUpdated(userId, &UserInfo{
+ DisplayName: user.Nickname,
+ })
+ mm.userdisplaynamemap[userId] = user.Nickname
+ }
+
// Build message event
msg_ev := &Event{
Author: userId,
@@ -348,12 +360,15 @@ func (mm *Mattermost) handlePosted(msg *model.WebSocketEvent) error {
return fmt.Errorf("Invalid channel id")
}
- // TODO don't join everytime
- mm.handler.Event(&Event{
- Author: userId,
- Room: roomId,
- Type: EVENT_JOIN,
- })
+ cache_key := fmt.Sprintf("%s / %s", userId, roomId)
+ if _, ok := mm.sentjoinedmap[cache_key]; !ok {
+ mm.handler.Event(&Event{
+ Author: userId,
+ Room: roomId,
+ Type: EVENT_JOIN,
+ })
+ mm.sentjoinedmap[cache_key] = true
+ }
if post.Type == "system_header_change" {
new_header := post.Props["new_header"].(string)