Fix user_added websocket event and update websocket channel access cache on add/remove member.

Этот коммит содержится в:
JoramWilander
2015-10-07 11:39:45 -04:00
родитель dfaef4bd72
Коммит 1421e1ec4a
4 изменённых файлов: 33 добавлений и 22 удалений

Просмотреть файл

@@ -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

Просмотреть файл

@@ -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)
}()
}

Просмотреть файл

@@ -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 {

Просмотреть файл

@@ -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;
}