summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/channel.go16
-rw-r--r--app/diagnostics.go1
-rw-r--r--app/post.go6
-rw-r--r--app/web_conn.go8
-rw-r--r--config/config.json1
-rw-r--r--model/config.go6
-rw-r--r--model/websocket_message.go1
-rw-r--r--utils/config.go1
-rw-r--r--webapp/actions/websocket_actions.jsx13
9 files changed, 50 insertions, 3 deletions
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
diff --git a/config/config.json b/config/config.json
index 928468ed0..2424da69e 100644
--- a/config/config.json
+++ b/config/config.json
@@ -45,6 +45,7 @@
"EnablePostSearch": true,
"EnableUserTypingMessages": true,
"EnableUserStatuses": true,
+ "EnablChannelViewedMessages": true,
"ClusterLogTimeoutMilliseconds": 2000
},
"ElasticSearchSettings": {
diff --git a/model/config.go b/model/config.go
index 90b3bd6c8..6d62aab91 100644
--- a/model/config.go
+++ b/model/config.go
@@ -158,6 +158,7 @@ type ServiceSettings struct {
TimeBetweenUserTypingUpdatesMilliseconds *int64
EnablePostSearch *bool
EnableUserTypingMessages *bool
+ EnablChannelViewedMessages *bool
EnableUserStatuses *bool
ClusterLogTimeoutMilliseconds *int
}
@@ -1300,6 +1301,11 @@ func (o *Config) SetDefaults() {
*o.ServiceSettings.EnableUserTypingMessages = true
}
+ if o.ServiceSettings.EnablChannelViewedMessages == nil {
+ o.ServiceSettings.EnablChannelViewedMessages = new(bool)
+ *o.ServiceSettings.EnablChannelViewedMessages = true
+ }
+
if o.ServiceSettings.EnableUserStatuses == nil {
o.ServiceSettings.EnableUserStatuses = new(bool)
*o.ServiceSettings.EnableUserStatuses = true
diff --git a/model/websocket_message.go b/model/websocket_message.go
index deeab2396..3206a2a8d 100644
--- a/model/websocket_message.go
+++ b/model/websocket_message.go
@@ -37,6 +37,7 @@ const (
WEBSOCKET_EVENT_REACTION_REMOVED = "reaction_removed"
WEBSOCKET_EVENT_RESPONSE = "response"
WEBSOCKET_EVENT_EMOJI_ADDED = "emoji_added"
+ WEBSOCKET_EVENT_CHANNEL_VIEWED = "channel_viewed"
)
type WebSocketMessage interface {
diff --git a/utils/config.go b/utils/config.go
index 8b096b6ea..4136a6515 100644
--- a/utils/config.go
+++ b/utils/config.go
@@ -473,6 +473,7 @@ func getClientConfig(c *model.Config) map[string]string {
props["MaxNotificationsPerChannel"] = strconv.FormatInt(*c.TeamSettings.MaxNotificationsPerChannel, 10)
props["TimeBetweenUserTypingUpdatesMilliseconds"] = strconv.FormatInt(*c.ServiceSettings.TimeBetweenUserTypingUpdatesMilliseconds, 10)
props["EnableUserTypingMessages"] = strconv.FormatBool(*c.ServiceSettings.EnableUserTypingMessages)
+ props["EnablChannelViewedMessages"] = strconv.FormatBool(*c.ServiceSettings.EnablChannelViewedMessages)
props["DiagnosticId"] = CfgDiagnosticId
props["DiagnosticsEnabled"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics)
diff --git a/webapp/actions/websocket_actions.jsx b/webapp/actions/websocket_actions.jsx
index 2af9a5d96..9d53ead6b 100644
--- a/webapp/actions/websocket_actions.jsx
+++ b/webapp/actions/websocket_actions.jsx
@@ -225,6 +225,10 @@ function handleEvent(msg) {
handleAddEmoji(msg);
break;
+ case SocketEvents.CHANNEL_VIEWED:
+ handleChannelViewedEvent(msg);
+ break;
+
default:
}
}
@@ -433,3 +437,12 @@ function handleReactionRemovedEvent(msg) {
data: reaction
});
}
+
+function handleChannelViewedEvent(msg) {
+// Useful for when multiple devices have the app open to different channels
+ if (ChannelStore.getCurrentId() !== msg.data.channel_id &&
+ UserStore.getCurrentId() === msg.broadcast.user_id) {
+ // Mark previous and next channel as read
+ ChannelStore.resetCounts([msg.data.channel_id]);
+ }
+}