fix: include you property in open group reaction updates

pull/2445/head
William Grant 3 years ago
parent 218456f7fd
commit bf7badd2e1

@ -124,20 +124,20 @@ export type ReactionList = Record<
count: number;
index: number; // relies on reactsIndex in the message model
senders: Record<string, string>; // <sender pubkey, messageHash or serverId>
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, string> }]
[string, { count: number; index: number; senders: Record<string, string>; you?: boolean }]
>;
export interface OpenGroupReaction {
index: number;
count: number;
first: number;
reactors: Array<string>;
you: boolean;
reactors: Array<string>;
}
export type OpenGroupReactionList = Record<string, OpenGroupReaction>;

@ -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<string, string> = {};
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({

Loading…
Cancel
Save