Don't always rejoin; propagate user nicknames
This commit is contained in:
parent
b96f8a2016
commit
85d2c215bb
|
@ -27,7 +27,9 @@ type Mattermost struct {
|
||||||
conn *matterclient.MMClient
|
conn *matterclient.MMClient
|
||||||
handlerStopChan chan bool
|
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() {
|
func (mm *Mattermost) handleConnected() {
|
||||||
mm.handlerStopChan = make(chan bool)
|
mm.handlerStopChan = make(chan bool)
|
||||||
mm.usermap = make(map[string]string)
|
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)
|
go mm.handleLoop(mm.conn.MessageChan, mm.handlerStopChan)
|
||||||
|
|
||||||
fmt.Printf("Connected to mattermost\n")
|
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))
|
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
|
// Build message event
|
||||||
msg_ev := &Event{
|
msg_ev := &Event{
|
||||||
Author: userId,
|
Author: userId,
|
||||||
|
@ -348,12 +360,15 @@ func (mm *Mattermost) handlePosted(msg *model.WebSocketEvent) error {
|
||||||
return fmt.Errorf("Invalid channel id")
|
return fmt.Errorf("Invalid channel id")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO don't join everytime
|
cache_key := fmt.Sprintf("%s / %s", userId, roomId)
|
||||||
mm.handler.Event(&Event{
|
if _, ok := mm.sentjoinedmap[cache_key]; !ok {
|
||||||
Author: userId,
|
mm.handler.Event(&Event{
|
||||||
Room: roomId,
|
Author: userId,
|
||||||
Type: EVENT_JOIN,
|
Room: roomId,
|
||||||
})
|
Type: EVENT_JOIN,
|
||||||
|
})
|
||||||
|
mm.sentjoinedmap[cache_key] = true
|
||||||
|
}
|
||||||
|
|
||||||
if post.Type == "system_header_change" {
|
if post.Type == "system_header_change" {
|
||||||
new_header := post.Props["new_header"].(string)
|
new_header := post.Props["new_header"].(string)
|
||||||
|
|
Loading…
Reference in a new issue