From 89aa114192ceb42c34a945a0e8c8205166f8f970 Mon Sep 17 00:00:00 2001 From: Wim Date: Tue, 3 Jul 2018 22:35:44 +0200 Subject: 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 --- matterclient/matterclient.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'matterclient') diff --git a/matterclient/matterclient.go b/matterclient/matterclient.go index e62ae428..951d6317 100644 --- a/matterclient/matterclient.go +++ b/matterclient/matterclient.go @@ -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 { -- cgit v1.2.3