summaryrefslogtreecommitdiffstats
path: root/matterclient/matterclient.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-07-03 22:35:44 +0200
committerWim <wim@42.be>2018-07-03 22:35:44 +0200
commit89aa114192ceb42c34a945a0e8c8205166f8f970 (patch)
treec08415eb899fd7447cb55fae6fcb968b2b5d2e7f /matterclient/matterclient.go
parented062e0ce54724714285ce840c2b59ae805e568c (diff)
downloadmatterbridge-msglm-89aa114192ceb42c34a945a0e8c8205166f8f970.tar.gz
matterbridge-msglm-89aa114192ceb42c34a945a0e8c8205166f8f970.tar.bz2
matterbridge-msglm-89aa114192ceb42c34a945a0e8c8205166f8f970.zip
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
Diffstat (limited to 'matterclient/matterclient.go')
-rw-r--r--matterclient/matterclient.go23
1 files changed, 23 insertions, 0 deletions
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 {