From eb7561e05bb797a0f925ac69079040016926eef5 Mon Sep 17 00:00:00 2001 From: Corey Hulen Date: Thu, 29 Jun 2017 07:51:15 -0700 Subject: PLT-6610 sending websocket event for last channel viewed (#6787) --- app/channel.go | 16 +++++++++++++++- app/diagnostics.go | 1 + app/post.go | 6 ++++++ app/web_conn.go | 8 ++++++-- 4 files changed, 28 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/channel.go b/app/channel.go index c9f89eb1a..5dafa1f76 100644 --- a/app/channel.go +++ b/app/channel.go @@ -266,7 +266,7 @@ func createGroupChannel(userIds []string, creatorId string) (*model.Channel, *mo } if len(users) != len(userIds) { - return nil, model.NewAppError("CreateGroupChannel", "api.channel.create_group.bad_user.app_error", nil, "user_ids=" + model.ArrayToJson(userIds), http.StatusBadRequest) + return nil, model.NewAppError("CreateGroupChannel", "api.channel.create_group.bad_user.app_error", nil, "user_ids="+model.ArrayToJson(userIds), http.StatusBadRequest) } group := &model.Channel{ @@ -1091,6 +1091,14 @@ func UpdateChannelLastViewedAt(channelIds []string, userId string) *model.AppErr return result.Err } + if *utils.Cfg.ServiceSettings.EnablChannelViewedMessages { + for _, channelId := range channelIds { + message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_VIEWED, "", "", userId, nil) + message.Add("channel_id", channelId) + go Publish(message) + } + } + return nil } @@ -1150,6 +1158,12 @@ func ViewChannel(view *model.ChannelView, userId string, clearPushNotifications return result.Err } + if *utils.Cfg.ServiceSettings.EnablChannelViewedMessages { + message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_VIEWED, "", "", userId, nil) + message.Add("channel_id", view.ChannelId) + go Publish(message) + } + return nil } diff --git a/app/diagnostics.go b/app/diagnostics.go index 14e207997..65d67742e 100644 --- a/app/diagnostics.go +++ b/app/diagnostics.go @@ -188,6 +188,7 @@ func trackConfig() { "allow_edit_post": *utils.Cfg.ServiceSettings.AllowEditPost, "post_edit_time_limit": *utils.Cfg.ServiceSettings.PostEditTimeLimit, "enable_user_typing_messages": *utils.Cfg.ServiceSettings.EnableUserTypingMessages, + "enable_channel_viewed_messages": *utils.Cfg.ServiceSettings.EnablChannelViewedMessages, "time_between_user_typing_updates_milliseconds": *utils.Cfg.ServiceSettings.TimeBetweenUserTypingUpdatesMilliseconds, "cluster_log_timeout_milliseconds": *utils.Cfg.ServiceSettings.ClusterLogTimeoutMilliseconds, }) diff --git a/app/post.go b/app/post.go index 01581c748..841048cbc 100644 --- a/app/post.go +++ b/app/post.go @@ -48,6 +48,12 @@ func CreatePostAsUser(post *model.Post) (*model.Post, *model.AppError) { if result := <-Srv.Store.Channel().UpdateLastViewedAt([]string{post.ChannelId}, post.UserId); result.Err != nil { l4g.Error(utils.T("api.post.create_post.last_viewed.error"), post.ChannelId, post.UserId, result.Err) } + + if *utils.Cfg.ServiceSettings.EnablChannelViewedMessages { + message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_VIEWED, "", "", post.UserId, nil) + message.Add("channel_id", post.ChannelId) + go Publish(message) + } } return rp, nil diff --git a/app/web_conn.go b/app/web_conn.go index 1ebed9fa5..1cab36a2a 100644 --- a/app/web_conn.go +++ b/app/web_conn.go @@ -226,8 +226,12 @@ func (webCon *WebConn) ShouldSendEvent(msg *model.WebSocketEvent) bool { } // If the event is destined to a specific user - if len(msg.Broadcast.UserId) > 0 && webCon.UserId != msg.Broadcast.UserId { - return false + if len(msg.Broadcast.UserId) > 0 { + if webCon.UserId == msg.Broadcast.UserId { + return true + } else { + return false + } } // if the user is omitted don't send the message -- cgit v1.2.3-1-g7c22