mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
* Add read receipt store for burn on read message types * update mocks * fix invalidation target * have consistent case on index creation * Add temporary posts table * add mock * add transaction support * reflect review comments * wip: Add reveal endpoint * user check error id instead * wip: Add ws events and cleanup for burn on read posts * add burn endpoint for explicitly burning messages * add translations * Added logic to associate files of BoR post with the post * Added test * fixes * disable pinning posts and review comments * MM-66594 - Burn on read UI integration (#34647) * MM-66244 - add BoR visual components to message editor * MM-66246 - BoR visual indicator for sender and receiver * MM-66607 - bor - add timer countdown and autodeletion * add the system console max time to live config * use the max expire at and create global scheduler to register bor messages * use seconds for BoR config values in BE * implement the read by text shown in the tooltip logic * unestack the posts from same receiver and BoR and fix styling * avoid opening reply RHS * remove unused dispatchers * persis the BoR label in the drafts * move expiration value to metadata * adjust unit tests to metadata insted of props * code clean up and some performance improvements; add period grace for deletion too * adjust migration serie number * hide bor messages when config is off * performance improvements on post component and code clean up * keep bor existing post functionality if config is disabled * Add read receipt store for burn on read message types * Add temporary posts table * add transaction support * reflect review comments * wip: Add reveal endpoint * user check error id instead * wip: Add ws events and cleanup for burn on read posts * avoid reacting to unrevealed bor messages * adjust migration number * Add read receipt store for burn on read message types * have consistent case on index creation * Add temporary posts table * add mock * add transaction support * reflect review comments * wip: Add reveal endpoint * user check error id instead * wip: Add ws events and cleanup for burn on read posts * add burn endpoint for explicitly burning messages * adjust post reveal and type with backend changes * use real config values, adjust icon usage and style * adjust the delete from from sender and receiver * improve self deleting logic by placing in badge, use burn endpoint * adjust websocket events handling for the read by sender label information * adjust styling for concealed and error state * update burn-on-read post event handling for improved recipient tracking and multi-device sync * replace burn_on_read with type in database migrations and model * remove burn_on_read metadata from PostMetadata and related structures * Added logic to associate files of BoR post with the post * Added test * adjust migration name and fix linter * Add read receipt store for burn on read message types * update mocks * have consistent case on index creation * Add temporary posts table * add mock * add transaction support * reflect review comments * wip: Add reveal endpoint * user check error id instead * wip: Add ws events and cleanup for burn on read posts * add burn endpoint for explicitly burning messages * Added logic to associate files of BoR post with the post * Added test * disable pinning posts and review comments * show attachment on bor reveal * remove unused translation * Enhance burn-on-read post handling and refine previous post ID retrieval logic * adjust the returning chunk to work with bor messages * read temp post from master db * read from master * show the copy link button to the sender * revert unnecessary check * restore correct json tag * remove unused error handling and clarify burn-on-read comment * improve type safety and use proper selectors * eliminate code duplication in deletion handler * optimize performance and add documentation * delete bor message for sender once all receivers reveal it * add burn on read to scheduled posts * add feature enable check * use master to avoid all read recipients race condition --------- Co-authored-by: Mattermost Build <[email protected]> Co-authored-by: Ibrahim Serdar Acikgoz <[email protected]> Co-authored-by: Harshil Sharma <[email protected]> * squash migrations into single file * add configuration for the scheduler * don't run messagehasbeenposted hook * remove parallel tests on burn on read * add clean up for closing opened modals from previous tests * simplify delete menu item rendering * add cleanup step to close open modals after each test to prevent pollution * streamline delete button visibility logic for Burn on Read posts * improve reliability of closing post menu and modals by using body ESC key --------- Co-authored-by: Harshil Sharma <[email protected]> Co-authored-by: Pablo Vélez <[email protected]> Co-authored-by: Mattermost Build <[email protected]>
216 lines
7.6 KiB
Go
216 lines
7.6 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package app
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/mattermost/mattermost/server/public/model"
|
|
"github.com/mattermost/mattermost/server/public/plugin"
|
|
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
|
"github.com/mattermost/mattermost/server/public/shared/request"
|
|
"github.com/mattermost/mattermost/server/v8/channels/store"
|
|
)
|
|
|
|
func (a *App) SaveReactionForPost(rctx request.CTX, reaction *model.Reaction) (*model.Reaction, *model.AppError) {
|
|
post, err := a.GetSinglePost(rctx, reaction.PostId, false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if post.Type == model.PostTypeBurnOnRead && post.UserId != reaction.UserId {
|
|
receipt, err := a.Srv().Store().ReadReceipt().Get(rctx, post.Id, reaction.UserId)
|
|
if err != nil && !store.IsErrNotFound(err) {
|
|
return nil, model.NewAppError("SaveReactionForPost", "app.reaction.save.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
|
}
|
|
if receipt == nil || receipt.ExpireAt < model.GetMillis() {
|
|
return nil, model.NewAppError("SaveReactionForPost", "api.reaction.save.burn_on_read.app_error", nil, "", http.StatusForbidden)
|
|
}
|
|
}
|
|
|
|
// Check whether this is a valid emoji
|
|
if _, ok := model.GetSystemEmojiId(reaction.EmojiName); !ok {
|
|
if _, emojiErr := a.GetEmojiByName(rctx, reaction.EmojiName); emojiErr != nil {
|
|
return nil, emojiErr
|
|
}
|
|
}
|
|
|
|
existing, dErr := a.Srv().Store().Reaction().ExistsOnPost(reaction.PostId, reaction.EmojiName)
|
|
if dErr != nil {
|
|
return nil, model.NewAppError("SaveReactionForPost", "app.reaction.save.save.app_error", nil, "", http.StatusInternalServerError).Wrap(dErr)
|
|
}
|
|
|
|
// If it exists already, we don't need to check for the limit
|
|
if !existing {
|
|
count, dErr := a.Srv().Store().Reaction().GetUniqueCountForPost(reaction.PostId)
|
|
if dErr != nil {
|
|
return nil, model.NewAppError("SaveReactionForPost", "app.reaction.save.save.app_error", nil, "", http.StatusInternalServerError).Wrap(dErr)
|
|
}
|
|
|
|
if count >= *a.Config().ServiceSettings.UniqueEmojiReactionLimitPerPost {
|
|
return nil, model.NewAppError("SaveReactionForPost", "app.reaction.save.save.too_many_reactions", nil, "", http.StatusBadRequest)
|
|
}
|
|
}
|
|
|
|
channel, err := a.GetChannel(rctx, post.ChannelId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
restrictDM, appErr := a.CheckIfChannelIsRestrictedDM(rctx, channel)
|
|
if appErr != nil {
|
|
return nil, appErr
|
|
}
|
|
|
|
if restrictDM {
|
|
err := model.NewAppError("SaveReactionForPost", "api.reaction.save.restricted_dm.error", nil, "", http.StatusBadRequest)
|
|
return nil, err
|
|
}
|
|
|
|
if channel.DeleteAt > 0 {
|
|
return nil, model.NewAppError("SaveReactionForPost", "api.reaction.save.archived_channel.app_error", nil, "", http.StatusForbidden)
|
|
}
|
|
// Pre-populating the channelID to save a DB call in store.
|
|
reaction.ChannelId = post.ChannelId
|
|
reaction, nErr := a.Srv().Store().Reaction().Save(reaction)
|
|
if nErr != nil {
|
|
var appErr *model.AppError
|
|
switch {
|
|
case errors.As(nErr, &appErr):
|
|
return nil, appErr
|
|
default:
|
|
return nil, model.NewAppError("SaveReactionForPost", "app.reaction.save.save.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
|
}
|
|
}
|
|
|
|
if post.RootId == "" {
|
|
if appErr := a.ResolvePersistentNotification(rctx, post, reaction.UserId); appErr != nil {
|
|
a.CountNotificationReason(model.NotificationStatusError, model.NotificationTypeAll, model.NotificationReasonResolvePersistentNotificationError, model.NotificationNoPlatform)
|
|
a.Log().LogM(mlog.MlvlNotificationError, "Error resolving persistent notification",
|
|
mlog.String("sender_id", reaction.UserId),
|
|
mlog.String("post_id", post.RootId),
|
|
mlog.String("status", model.NotificationStatusError),
|
|
mlog.String("reason", model.NotificationReasonResolvePersistentNotificationError),
|
|
mlog.Err(appErr),
|
|
)
|
|
return nil, appErr
|
|
}
|
|
}
|
|
|
|
// The post is always modified since the UpdateAt always changes
|
|
a.Srv().Store().Post().InvalidateLastPostTimeCache(channel.Id)
|
|
|
|
pluginContext := pluginContext(rctx)
|
|
a.Srv().Go(func() {
|
|
a.ch.RunMultiHook(func(hooks plugin.Hooks, _ *model.Manifest) bool {
|
|
hooks.ReactionHasBeenAdded(pluginContext, reaction)
|
|
return true
|
|
}, plugin.ReactionHasBeenAddedID)
|
|
})
|
|
|
|
a.sendReactionEvent(rctx, model.WebsocketEventReactionAdded, reaction, post)
|
|
|
|
return reaction, nil
|
|
}
|
|
|
|
func (a *App) GetReactionsForPost(postID string) ([]*model.Reaction, *model.AppError) {
|
|
reactions, err := a.Srv().Store().Reaction().GetForPost(postID, true)
|
|
if err != nil {
|
|
return nil, model.NewAppError("GetReactionsForPost", "app.reaction.get_for_post.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
|
}
|
|
return reactions, nil
|
|
}
|
|
|
|
func (a *App) GetBulkReactionsForPosts(postIDs []string) (map[string][]*model.Reaction, *model.AppError) {
|
|
reactions := make(map[string][]*model.Reaction)
|
|
|
|
allReactions, err := a.Srv().Store().Reaction().BulkGetForPosts(postIDs)
|
|
if err != nil {
|
|
return nil, model.NewAppError("GetBulkReactionsForPosts", "app.reaction.bulk_get_for_post_ids.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
|
}
|
|
|
|
for _, reaction := range allReactions {
|
|
reactionsForPost := reactions[reaction.PostId]
|
|
reactionsForPost = append(reactionsForPost, reaction)
|
|
|
|
reactions[reaction.PostId] = reactionsForPost
|
|
}
|
|
|
|
reactions = populateEmptyReactions(postIDs, reactions)
|
|
return reactions, nil
|
|
}
|
|
|
|
func populateEmptyReactions(postIDs []string, reactions map[string][]*model.Reaction) map[string][]*model.Reaction {
|
|
for _, postID := range postIDs {
|
|
if _, present := reactions[postID]; !present {
|
|
reactions[postID] = []*model.Reaction{}
|
|
}
|
|
}
|
|
return reactions
|
|
}
|
|
|
|
func (a *App) DeleteReactionForPost(rctx request.CTX, reaction *model.Reaction) *model.AppError {
|
|
post, err := a.GetSinglePost(rctx, reaction.PostId, false)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
channel, err := a.GetChannel(rctx, post.ChannelId)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
restrictDM, appErr := a.CheckIfChannelIsRestrictedDM(rctx, channel)
|
|
if appErr != nil {
|
|
return err
|
|
}
|
|
|
|
if restrictDM {
|
|
err := model.NewAppError("DeleteReactionForPost", "api.reaction.delete.restricted_dm.error", nil, "", http.StatusBadRequest)
|
|
return err
|
|
}
|
|
|
|
if channel.DeleteAt > 0 {
|
|
return model.NewAppError("DeleteReactionForPost", "api.reaction.delete.archived_channel.app_error", nil, "", http.StatusForbidden)
|
|
}
|
|
|
|
if _, err := a.Srv().Store().Reaction().Delete(reaction); err != nil {
|
|
return model.NewAppError("DeleteReactionForPost", "app.reaction.delete_all_with_emoji_name.get_reactions.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
|
}
|
|
|
|
// The post is always modified since the UpdateAt always changes
|
|
a.Srv().Store().Post().InvalidateLastPostTimeCache(channel.Id)
|
|
|
|
pluginContext := pluginContext(rctx)
|
|
a.Srv().Go(func() {
|
|
a.ch.RunMultiHook(func(hooks plugin.Hooks, _ *model.Manifest) bool {
|
|
hooks.ReactionHasBeenRemoved(pluginContext, reaction)
|
|
return true
|
|
}, plugin.ReactionHasBeenRemovedID)
|
|
})
|
|
|
|
a.sendReactionEvent(rctx, model.WebsocketEventReactionRemoved, reaction, post)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (a *App) sendReactionEvent(rctx request.CTX, event model.WebsocketEventType, reaction *model.Reaction, post *model.Post) {
|
|
// send out that a reaction has been added/removed
|
|
message := model.NewWebSocketEvent(event, "", post.ChannelId, "", nil, "")
|
|
reactionJSON, err := json.Marshal(reaction)
|
|
if err != nil {
|
|
rctx.Logger().Warn("Failed to encode reaction to JSON", mlog.Err(err))
|
|
}
|
|
message.Add("reaction", string(reactionJSON))
|
|
|
|
// For burn-on-read posts, filter recipients based on read receipts
|
|
if post.Type == model.PostTypeBurnOnRead {
|
|
useBurnOnReadReactionHook(message, post.UserId, post.Id)
|
|
}
|
|
|
|
a.Publish(message)
|
|
}
|