PLT-6610 sending websocket event for last channel viewed (#6787)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
bf81fea9f8
Коммит
eb7561e05b
@@ -1091,6 +1091,14 @@ func UpdateChannelLastViewedAt(channelIds []string, userId string) *model.AppErr
|
|||||||
return result.Err
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1150,6 +1158,12 @@ func ViewChannel(view *model.ChannelView, userId string, clearPushNotifications
|
|||||||
return result.Err
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -188,6 +188,7 @@ func trackConfig() {
|
|||||||
"allow_edit_post": *utils.Cfg.ServiceSettings.AllowEditPost,
|
"allow_edit_post": *utils.Cfg.ServiceSettings.AllowEditPost,
|
||||||
"post_edit_time_limit": *utils.Cfg.ServiceSettings.PostEditTimeLimit,
|
"post_edit_time_limit": *utils.Cfg.ServiceSettings.PostEditTimeLimit,
|
||||||
"enable_user_typing_messages": *utils.Cfg.ServiceSettings.EnableUserTypingMessages,
|
"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,
|
"time_between_user_typing_updates_milliseconds": *utils.Cfg.ServiceSettings.TimeBetweenUserTypingUpdatesMilliseconds,
|
||||||
"cluster_log_timeout_milliseconds": *utils.Cfg.ServiceSettings.ClusterLogTimeoutMilliseconds,
|
"cluster_log_timeout_milliseconds": *utils.Cfg.ServiceSettings.ClusterLogTimeoutMilliseconds,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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 {
|
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)
|
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
|
return rp, nil
|
||||||
|
|||||||
@@ -226,9 +226,13 @@ func (webCon *WebConn) ShouldSendEvent(msg *model.WebSocketEvent) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the event is destined to a specific user
|
// If the event is destined to a specific user
|
||||||
if len(msg.Broadcast.UserId) > 0 && webCon.UserId != msg.Broadcast.UserId {
|
if len(msg.Broadcast.UserId) > 0 {
|
||||||
|
if webCon.UserId == msg.Broadcast.UserId {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if the user is omitted don't send the message
|
// if the user is omitted don't send the message
|
||||||
if len(msg.Broadcast.OmitUsers) > 0 {
|
if len(msg.Broadcast.OmitUsers) > 0 {
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
"EnablePostSearch": true,
|
"EnablePostSearch": true,
|
||||||
"EnableUserTypingMessages": true,
|
"EnableUserTypingMessages": true,
|
||||||
"EnableUserStatuses": true,
|
"EnableUserStatuses": true,
|
||||||
|
"EnablChannelViewedMessages": true,
|
||||||
"ClusterLogTimeoutMilliseconds": 2000
|
"ClusterLogTimeoutMilliseconds": 2000
|
||||||
},
|
},
|
||||||
"ElasticSearchSettings": {
|
"ElasticSearchSettings": {
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ type ServiceSettings struct {
|
|||||||
TimeBetweenUserTypingUpdatesMilliseconds *int64
|
TimeBetweenUserTypingUpdatesMilliseconds *int64
|
||||||
EnablePostSearch *bool
|
EnablePostSearch *bool
|
||||||
EnableUserTypingMessages *bool
|
EnableUserTypingMessages *bool
|
||||||
|
EnablChannelViewedMessages *bool
|
||||||
EnableUserStatuses *bool
|
EnableUserStatuses *bool
|
||||||
ClusterLogTimeoutMilliseconds *int
|
ClusterLogTimeoutMilliseconds *int
|
||||||
}
|
}
|
||||||
@@ -1300,6 +1301,11 @@ func (o *Config) SetDefaults() {
|
|||||||
*o.ServiceSettings.EnableUserTypingMessages = true
|
*o.ServiceSettings.EnableUserTypingMessages = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if o.ServiceSettings.EnablChannelViewedMessages == nil {
|
||||||
|
o.ServiceSettings.EnablChannelViewedMessages = new(bool)
|
||||||
|
*o.ServiceSettings.EnablChannelViewedMessages = true
|
||||||
|
}
|
||||||
|
|
||||||
if o.ServiceSettings.EnableUserStatuses == nil {
|
if o.ServiceSettings.EnableUserStatuses == nil {
|
||||||
o.ServiceSettings.EnableUserStatuses = new(bool)
|
o.ServiceSettings.EnableUserStatuses = new(bool)
|
||||||
*o.ServiceSettings.EnableUserStatuses = true
|
*o.ServiceSettings.EnableUserStatuses = true
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ const (
|
|||||||
WEBSOCKET_EVENT_REACTION_REMOVED = "reaction_removed"
|
WEBSOCKET_EVENT_REACTION_REMOVED = "reaction_removed"
|
||||||
WEBSOCKET_EVENT_RESPONSE = "response"
|
WEBSOCKET_EVENT_RESPONSE = "response"
|
||||||
WEBSOCKET_EVENT_EMOJI_ADDED = "emoji_added"
|
WEBSOCKET_EVENT_EMOJI_ADDED = "emoji_added"
|
||||||
|
WEBSOCKET_EVENT_CHANNEL_VIEWED = "channel_viewed"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WebSocketMessage interface {
|
type WebSocketMessage interface {
|
||||||
|
|||||||
@@ -473,6 +473,7 @@ func getClientConfig(c *model.Config) map[string]string {
|
|||||||
props["MaxNotificationsPerChannel"] = strconv.FormatInt(*c.TeamSettings.MaxNotificationsPerChannel, 10)
|
props["MaxNotificationsPerChannel"] = strconv.FormatInt(*c.TeamSettings.MaxNotificationsPerChannel, 10)
|
||||||
props["TimeBetweenUserTypingUpdatesMilliseconds"] = strconv.FormatInt(*c.ServiceSettings.TimeBetweenUserTypingUpdatesMilliseconds, 10)
|
props["TimeBetweenUserTypingUpdatesMilliseconds"] = strconv.FormatInt(*c.ServiceSettings.TimeBetweenUserTypingUpdatesMilliseconds, 10)
|
||||||
props["EnableUserTypingMessages"] = strconv.FormatBool(*c.ServiceSettings.EnableUserTypingMessages)
|
props["EnableUserTypingMessages"] = strconv.FormatBool(*c.ServiceSettings.EnableUserTypingMessages)
|
||||||
|
props["EnablChannelViewedMessages"] = strconv.FormatBool(*c.ServiceSettings.EnablChannelViewedMessages)
|
||||||
|
|
||||||
props["DiagnosticId"] = CfgDiagnosticId
|
props["DiagnosticId"] = CfgDiagnosticId
|
||||||
props["DiagnosticsEnabled"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics)
|
props["DiagnosticsEnabled"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics)
|
||||||
|
|||||||
@@ -225,6 +225,10 @@ function handleEvent(msg) {
|
|||||||
handleAddEmoji(msg);
|
handleAddEmoji(msg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SocketEvents.CHANNEL_VIEWED:
|
||||||
|
handleChannelViewedEvent(msg);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -433,3 +437,12 @@ function handleReactionRemovedEvent(msg) {
|
|||||||
data: reaction
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user