summaryrefslogtreecommitdiffstats
path: root/api/channel.go
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2015-10-07 11:39:45 -0400
committerJoramWilander <jwawilander@gmail.com>2015-10-07 11:39:45 -0400
commit1421e1ec4aa09c0e7094643d342d095cdd91d506 (patch)
tree80eac658b063f64c019dd71eaa6ac4bbb062d91e /api/channel.go
parentdfaef4bd7227391e21890c720f9668acb3a64c28 (diff)
downloadchat-1421e1ec4aa09c0e7094643d342d095cdd91d506.tar.gz
chat-1421e1ec4aa09c0e7094643d342d095cdd91d506.tar.bz2
chat-1421e1ec4aa09c0e7094643d342d095cdd91d506.zip
Fix user_added websocket event and update websocket channel access cache on add/remove member.
Diffstat (limited to 'api/channel.go')
-rw-r--r--api/channel.go39
1 files changed, 23 insertions, 16 deletions
diff --git a/api/channel.go b/api/channel.go
index 5e13fa18a..0d22d7c00 100644
--- a/api/channel.go
+++ b/api/channel.go
@@ -472,6 +472,8 @@ func leaveChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
+ UpdateChannelAccessCacheAndForget(c.Session.TeamId, c.Session.UserId, channel.Id)
+
post := &model.Post{ChannelId: channel.Id, Message: fmt.Sprintf(
`%v has left the channel.`,
user.Username), Type: model.POST_JOIN_LEAVE}
@@ -706,20 +708,21 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- post := &model.Post{ChannelId: id, Message: fmt.Sprintf(
- `%v added to the channel by %v`,
- nUser.Username, oUser.Username), Type: model.POST_JOIN_LEAVE}
- if _, err := CreatePost(c, post, false); err != nil {
- l4g.Error("Failed to post add message %v", err)
- c.Err = model.NewAppError("addChannelMember", "Failed to add member to channel", "")
- return
- }
-
c.LogAudit("name=" + channel.Name + " user_id=" + userId)
- message := model.NewMessage(c.Session.TeamId, "", userId, model.ACTION_USER_ADDED)
+ go func() {
+ post := &model.Post{ChannelId: id, Message: fmt.Sprintf(
+ `%v added to the channel by %v`,
+ nUser.Username, oUser.Username), Type: model.POST_JOIN_LEAVE}
+ if _, err := CreatePost(c, post, false); err != nil {
+ l4g.Error("Failed to post add member to channel message, err=%v", err)
+ }
- PublishAndForget(message)
+ UpdateChannelAccessCache(c.Session.TeamId, userId, channel.Id)
+ message := model.NewMessage(c.Session.TeamId, channel.Id, userId, model.ACTION_USER_ADDED)
+
+ PublishAndForget(message)
+ }()
<-Srv.Store.Channel().UpdateLastViewedAt(id, oUser.Id)
w.Write([]byte(cm.ToJson()))
@@ -773,13 +776,17 @@ func removeChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- message := model.NewMessage(c.Session.TeamId, "", userId, model.ACTION_USER_REMOVED)
- message.Add("channel_id", id)
- message.Add("remover", c.Session.UserId)
- PublishAndForget(message)
-
c.LogAudit("name=" + channel.Name + " user_id=" + userId)
+ go func() {
+ UpdateChannelAccessCache(c.Session.TeamId, userId, id)
+
+ message := model.NewMessage(c.Session.TeamId, "", userId, model.ACTION_USER_REMOVED)
+ message.Add("channel_id", id)
+ message.Add("remover", c.Session.UserId)
+ PublishAndForget(message)
+ }()
+
result := make(map[string]string)
result["channel_id"] = channel.Id
result["removed_user_id"] = userId