summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--api/channel.go39
-rw-r--r--api/web_hub.go10
-rw-r--r--model/message.go4
-rw-r--r--web/react/components/sidebar.jsx2
4 files changed, 33 insertions, 22 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
diff --git a/api/web_hub.go b/api/web_hub.go
index 44d405283..15528c612 100644
--- a/api/web_hub.go
+++ b/api/web_hub.go
@@ -30,11 +30,15 @@ func PublishAndForget(message *model.Message) {
}()
}
+func UpdateChannelAccessCache(teamId, userId, channelId string) {
+ if nh, ok := hub.teamHubs[teamId]; ok {
+ nh.UpdateChannelAccessCache(userId, channelId)
+ }
+}
+
func UpdateChannelAccessCacheAndForget(teamId, userId, channelId string) {
go func() {
- if nh, ok := hub.teamHubs[teamId]; ok {
- nh.UpdateChannelAccessCache(userId, channelId)
- }
+ UpdateChannelAccessCache(teamId, userId, channelId)
}()
}
diff --git a/model/message.go b/model/message.go
index ec4817b2a..8598bea0e 100644
--- a/model/message.go
+++ b/model/message.go
@@ -31,8 +31,8 @@ func (m *Message) Add(key string, value string) {
m.Props[key] = value
}
-func NewMessage(teamId string, channekId string, userId string, action string) *Message {
- return &Message{TeamId: teamId, ChannelId: channekId, UserId: userId, Action: action, Props: make(map[string]string)}
+func NewMessage(teamId string, channelId string, userId string, action string) *Message {
+ return &Message{TeamId: teamId, ChannelId: channelId, UserId: userId, Action: action, Props: make(map[string]string)}
}
func (o *Message) ToJson() string {
diff --git a/web/react/components/sidebar.jsx b/web/react/components/sidebar.jsx
index b696f4b53..88eaed335 100644
--- a/web/react/components/sidebar.jsx
+++ b/web/react/components/sidebar.jsx
@@ -205,7 +205,7 @@ export default class Sidebar extends React.Component {
const user = UserStore.getCurrentUser();
const member = ChannelStore.getMember(msg.channel_id);
- var notifyLevel = member.notify_props.desktop;
+ var notifyLevel = member && member.notify_props ? member.notify_props.desktop : 'default';
if (notifyLevel === 'default') {
notifyLevel = user.notify_props.desktop;
}