5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-12-24 03:25:40 +00:00

Add GetNickname and UpdateUser functions

When we get an user_updated event from mattermost we also actually update
the user, so the nicknames/usernames are also updated
This commit is contained in:
Wim 2018-07-03 22:35:44 +02:00
parent ed062e0ce5
commit 89aa114192

View File

@ -310,6 +310,11 @@ func (m *MMClient) parseMessage(rmsg *Message) {
switch rmsg.Raw.Event {
case model.WEBSOCKET_EVENT_POSTED, model.WEBSOCKET_EVENT_POST_EDITED, model.WEBSOCKET_EVENT_POST_DELETED:
m.parseActionPost(rmsg)
case "user_updated":
user := rmsg.Raw.Data["user"].(map[string]interface{})
if _, ok := user["id"].(string); ok {
m.UpdateUser(user["id"].(string))
}
/*
case model.ACTION_USER_REMOVED:
m.handleWsActionUserRemoved(&rmsg)
@ -750,6 +755,16 @@ func (m *MMClient) GetUser(userId string) *model.User {
return m.Users[userId]
}
func (m *MMClient) UpdateUser(userId string) {
m.Lock()
defer m.Unlock()
res, resp := m.Client.GetUser(userId, "")
if resp.Error != nil {
return
}
m.Users[userId] = res
}
func (m *MMClient) GetUserName(userId string) string {
user := m.GetUser(userId)
if user != nil {
@ -758,6 +773,14 @@ func (m *MMClient) GetUserName(userId string) string {
return ""
}
func (m *MMClient) GetNickName(userId string) string {
user := m.GetUser(userId)
if user != nil {
return user.Nickname
}
return ""
}
func (m *MMClient) GetStatus(userId string) string {
res, resp := m.Client.GetUserStatus(userId, "")
if resp.Error != nil {