Reactions: Skip notifications about self reactions (#1753)

This commit is contained in:
Alexander Zinchuk 2022-03-09 01:02:57 +01:00
parent 790f2b613a
commit 59ea096c7b
3 changed files with 5 additions and 3 deletions

View File

@ -491,7 +491,7 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
}
// Only notify about added reactions, not removed ones
const shouldNotify = checkIfReactionAdded(currentReactions, reactions);
const shouldNotify = checkIfReactionAdded(currentReactions, reactions, global.currentUserId);
global = updateChatMessage(global, chatId, id, { reactions: update.reactions });

View File

@ -5,4 +5,4 @@ export * from './messageSummary';
export * from './messageMedia';
export * from './localSearch';
export * from './payments';
export { getMessageRecentReaction } from './reactions';
export * from './reactions';

View File

@ -4,9 +4,11 @@ export function getMessageRecentReaction(message: Partial<ApiMessage>) {
return message.isOutgoing ? message.reactions?.recentReactions?.[0] : undefined;
}
export function checkIfReactionAdded(oldReactions?: ApiReactions, newReactions?: ApiReactions) {
export function checkIfReactionAdded(oldReactions?: ApiReactions, newReactions?: ApiReactions, currentUserId?: string) {
if (!oldReactions || !oldReactions.recentReactions) return true;
if (!newReactions || !newReactions.recentReactions) return false;
// Skip reactions from yourself
if (newReactions.recentReactions.every(reaction => reaction.userId === currentUserId)) return false;
const oldReactionsMap = oldReactions.results.reduce<Record<string, number>>((acc, reaction) => {
acc[reaction.reaction] = reaction.count;
return acc;