Fix user_added websocket event and update websocket channel access cache on add/remove member.
Этот коммит содержится в:
@@ -472,6 +472,8 @@ func leaveChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateChannelAccessCacheAndForget(c.Session.TeamId, c.Session.UserId, channel.Id)
|
||||||
|
|
||||||
post := &model.Post{ChannelId: channel.Id, Message: fmt.Sprintf(
|
post := &model.Post{ChannelId: channel.Id, Message: fmt.Sprintf(
|
||||||
`%v has left the channel.`,
|
`%v has left the channel.`,
|
||||||
user.Username), Type: model.POST_JOIN_LEAVE}
|
user.Username), Type: model.POST_JOIN_LEAVE}
|
||||||
@@ -706,20 +708,21 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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)
|
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)
|
<-Srv.Store.Channel().UpdateLastViewedAt(id, oUser.Id)
|
||||||
w.Write([]byte(cm.ToJson()))
|
w.Write([]byte(cm.ToJson()))
|
||||||
@@ -773,13 +776,17 @@ func removeChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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)
|
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 := make(map[string]string)
|
||||||
result["channel_id"] = channel.Id
|
result["channel_id"] = channel.Id
|
||||||
result["removed_user_id"] = userId
|
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) {
|
func UpdateChannelAccessCacheAndForget(teamId, userId, channelId string) {
|
||||||
go func() {
|
go func() {
|
||||||
if nh, ok := hub.teamHubs[teamId]; ok {
|
UpdateChannelAccessCache(teamId, userId, channelId)
|
||||||
nh.UpdateChannelAccessCache(userId, channelId)
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ func (m *Message) Add(key string, value string) {
|
|||||||
m.Props[key] = value
|
m.Props[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMessage(teamId string, channekId string, userId string, action string) *Message {
|
func NewMessage(teamId string, channelId string, userId string, action string) *Message {
|
||||||
return &Message{TeamId: teamId, ChannelId: channekId, UserId: userId, Action: action, Props: make(map[string]string)}
|
return &Message{TeamId: teamId, ChannelId: channelId, UserId: userId, Action: action, Props: make(map[string]string)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Message) ToJson() string {
|
func (o *Message) ToJson() string {
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ export default class Sidebar extends React.Component {
|
|||||||
const user = UserStore.getCurrentUser();
|
const user = UserStore.getCurrentUser();
|
||||||
const member = ChannelStore.getMember(msg.channel_id);
|
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') {
|
if (notifyLevel === 'default') {
|
||||||
notifyLevel = user.notify_props.desktop;
|
notifyLevel = user.notify_props.desktop;
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user