Mark category as read (#24003)
* Mark category as read * Fix lint and test * Fix tests * Fix test and remove wrong aria * Address server issues and add mark as read for unreads * Missing changes * Fix tests * fix tests * Add confirmation popup to mark as read category * Always use viewMultipleChannels and other fixes * Remove unneeded code * Fix test * Address feedback * Address feedback * Fix tests * Fix test * Fix tests * Update aria-haspopup depending on the number of channels to mark as viewed --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c1c07ba1bb
Коммит
e9b3afecc2
@@ -2970,57 +2970,32 @@ func (a *App) SearchChannelsUserNotIn(c request.CTX, teamID string, userID strin
|
||||
}
|
||||
|
||||
func (a *App) MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID string, currentSessionId string, collapsedThreadsSupported, isCRTEnabled bool) (map[string]int64, *model.AppError) {
|
||||
// I start looking for channels with notifications before I mark it as read, to clear the push notifications if needed
|
||||
channelsToClearPushNotifications := []string{}
|
||||
if a.canSendPushNotifications() {
|
||||
for _, channelID := range channelIDs {
|
||||
channel, errCh := a.Srv().Store().Channel().Get(channelID, true)
|
||||
if errCh != nil {
|
||||
c.Logger().Warn("Failed to get channel", mlog.Err(errCh))
|
||||
continue
|
||||
}
|
||||
var err error
|
||||
|
||||
member, err := a.Srv().Store().Channel().GetMember(context.Background(), channelID, userID)
|
||||
if err != nil {
|
||||
c.Logger().Warn("Failed to get membership", mlog.Err(err))
|
||||
continue
|
||||
}
|
||||
|
||||
notify := member.NotifyProps[model.PushNotifyProp]
|
||||
if notify == model.ChannelNotifyDefault {
|
||||
user, err := a.GetUser(userID)
|
||||
if err != nil {
|
||||
c.Logger().Warn("Failed to get user", mlog.String("user_id", userID), mlog.Err(err))
|
||||
continue
|
||||
}
|
||||
notify = user.NotifyProps[model.PushNotifyProp]
|
||||
}
|
||||
if notify == model.UserNotifyAll {
|
||||
if count, err := a.Srv().Store().User().GetAnyUnreadPostCountForChannel(userID, channelID); err == nil {
|
||||
if count > 0 {
|
||||
channelsToClearPushNotifications = append(channelsToClearPushNotifications, channelID)
|
||||
}
|
||||
}
|
||||
} else if notify == model.UserNotifyMention || channel.Type == model.ChannelTypeDirect {
|
||||
if count, err := a.Srv().Store().User().GetUnreadCountForChannel(userID, channelID); err == nil {
|
||||
if count > 0 {
|
||||
channelsToClearPushNotifications = append(channelsToClearPushNotifications, channelID)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
user, err := a.Srv().Store().User().Get(c.Context(), userID)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("MarkChannelsAsViewed", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
// We use channelsToView to later only update those, or early return if no channel is to be read
|
||||
channelsToView, channelsToClearPushNotifications, times, err := a.Srv().Store().Channel().GetChannelsWithUnreadsAndWithMentions(c.Context(), channelIDs, userID, user.NotifyProps)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("MarkChannelsAsViewed", "app.channel.get_channels_with_unreads_and_with_mentions.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
if len(channelsToView) == 0 {
|
||||
return times, nil
|
||||
}
|
||||
|
||||
var err error
|
||||
updateThreads := *a.Config().ServiceSettings.ThreadAutoFollow && (!collapsedThreadsSupported || !isCRTEnabled)
|
||||
if updateThreads {
|
||||
err = a.Srv().Store().Thread().MarkAllAsReadByChannels(userID, channelIDs)
|
||||
err = a.Srv().Store().Thread().MarkAllAsReadByChannels(userID, channelsToView)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("MarkChannelsAsViewed", "app.channel.update_last_viewed_at.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return nil, model.NewAppError("MarkChannelsAsViewed", "app.thread.mark_all_as_read_by_channels.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
times, err := a.Srv().Store().Channel().UpdateLastViewedAt(channelIDs, userID)
|
||||
_, err = a.Srv().Store().Channel().UpdateLastViewedAt(channelsToView, userID)
|
||||
if err != nil {
|
||||
var invErr *store.ErrInvalidInput
|
||||
switch {
|
||||
@@ -3032,19 +3007,18 @@ func (a *App) MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID st
|
||||
}
|
||||
|
||||
if *a.Config().ServiceSettings.EnableChannelViewedMessages {
|
||||
for _, channelID := range channelIDs {
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventChannelViewed, "", "", userID, nil, "")
|
||||
message.Add("channel_id", channelID)
|
||||
a.Publish(message)
|
||||
}
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventMultipleChannelsViewed, "", "", userID, nil, "")
|
||||
message.Add("channel_times", times)
|
||||
a.Publish(message)
|
||||
}
|
||||
|
||||
for _, channelID := range channelsToClearPushNotifications {
|
||||
a.clearPushNotification(currentSessionId, userID, channelID, "")
|
||||
}
|
||||
|
||||
if updateThreads && isCRTEnabled {
|
||||
timestamp := model.GetMillis()
|
||||
for _, channelID := range channelIDs {
|
||||
for _, channelID := range channelsToView {
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventThreadReadChanged, "", channelID, userID, nil, "")
|
||||
message.Add("timestamp", timestamp)
|
||||
a.Publish(message)
|
||||
|
||||
Ссылка в новой задаче
Block a user