From bf7badd2e153245e21b70f48b2730d0a0ba91b8e Mon Sep 17 00:00:00 2001 From: William Grant Date: Wed, 24 Aug 2022 16:03:06 +1000 Subject: [PATCH] fix: include you property in open group reaction updates --- ts/types/Reaction.ts | 6 +++--- ts/util/reactions.ts | 30 ++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/ts/types/Reaction.ts b/ts/types/Reaction.ts index 488045a61..22dbad543 100644 --- a/ts/types/Reaction.ts +++ b/ts/types/Reaction.ts @@ -124,20 +124,20 @@ export type ReactionList = Record< count: number; index: number; // relies on reactsIndex in the message model senders: Record; // + you?: boolean; // whether you are in the senders because sometimes we dont have the full list of senders yet. } >; // used when rendering reactions to guarantee sorted order using the index export type SortedReactionList = Array< - [string, { count: number; index: number; senders: Record }] + [string, { count: number; index: number; senders: Record; you?: boolean }] >; export interface OpenGroupReaction { index: number; count: number; - first: number; - reactors: Array; you: boolean; + reactors: Array; } export type OpenGroupReactionList = Record; diff --git a/ts/util/reactions.ts b/ts/util/reactions.ts index 36ebb7344..f558af080 100644 --- a/ts/util/reactions.ts +++ b/ts/util/reactions.ts @@ -2,7 +2,10 @@ import { isEmpty } from 'lodash'; import { Data } from '../data/data'; import { MessageModel } from '../models/message'; import { SignalService } from '../protobuf'; -import { getUsBlindedInThatServer } from '../session/apis/open_group_api/sogsv3/knownBlindedkeys'; +import { + getUsBlindedInThatServer, + isUsAnySogsFromCache, +} from '../session/apis/open_group_api/sogsv3/knownBlindedkeys'; import { UserUtils } from '../session/utils'; import { Action, OpenGroupReactionList, ReactionList, RecentReactions } from '../types/Reaction'; @@ -219,11 +222,34 @@ export const handleOpenGroupMessageReactions = async ( const reacts: ReactionList = {}; Object.keys(reactions).forEach(key => { const emoji = decodeURI(key); + const you = reactions[key].you || false; + + if (you) { + if (reactions[key].reactors && reactions[key].reactors.length > 0) { + const reactorsWithoutMe = reactions[key].reactors.filter( + reactor => !isUsAnySogsFromCache(reactor) + ); + + const conversationModel = originalMessage?.getConversation(); + if (conversationModel) { + const me = + getUsBlindedInThatServer(conversationModel) || UserUtils.getOurPubKeyStrFromCache(); + reactions[key].reactors = [me, ...reactorsWithoutMe]; + } + } + } + const senders: Record = {}; reactions[key].reactors.forEach(reactor => { senders[reactor] = String(serverId); }); - reacts[emoji] = { count: reactions[key].count, index: reactions[key].index, senders }; + + reacts[emoji] = { + count: reactions[key].count, + index: reactions[key].index, + senders, + you, + }; }); originalMessage.set({