From c77b24a2d42373ecc004d41376173d6cb5f6512b Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 6 May 2021 17:56:02 +1000 Subject: [PATCH] fix avatar loading for opengroupv2 --- .github/workflows/release.yml | 3 +++ ts/receiver/configMessage.ts | 6 +++--- ts/receiver/dataMessage.ts | 20 ++++++++++++++++++-- ts/receiver/queuedJob.ts | 10 +++++----- ts/receiver/receiver.ts | 4 ++-- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e7fdfd45b..3b09093d1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,6 +5,9 @@ on: push: branches: - master + pull_request: + branches: + - master jobs: build: diff --git a/ts/receiver/configMessage.ts b/ts/receiver/configMessage.ts index 009acc5a6..0cb4801d6 100644 --- a/ts/receiver/configMessage.ts +++ b/ts/receiver/configMessage.ts @@ -9,7 +9,7 @@ import { toHex } from '../session/utils/String'; import { configurationMessageReceived, trigger } from '../shims/events'; import { removeFromCache } from './cache'; import { handleNewClosedGroup } from './closedGroups'; -import { updateProfile } from './dataMessage'; +import { updateProfileOneAtATime } from './dataMessage'; import { EnvelopePlus } from './types'; async function handleOurProfileUpdate( @@ -39,7 +39,7 @@ async function handleOurProfileUpdate( displayName, profilePicture, }; - await updateProfile(ourConversation, lokiProfile, profileKey); + await updateProfileOneAtATime(ourConversation, lokiProfile, profileKey); UserUtils.setLastProfileUpdateTimestamp(_.toNumber(sentAt)); // do not trigger a signin by linking if the display name is empty if (displayName) { @@ -121,7 +121,7 @@ async function handleGroupsAndContactsFromConfigMessage( // updateProfile will do a commit for us contactConvo.set('active_at', _.toNumber(envelope.timestamp)); - await updateProfile(contactConvo, profile, c.profileKey); + await updateProfileOneAtATime(contactConvo, profile, c.profileKey); } catch (e) { window?.log?.warn('failed to handle a new closed group from configuration message'); } diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index b43d4932f..63e45080f 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -16,8 +16,24 @@ import { MessageModelType } from '../models/messageType'; import { getMessageBySender, getMessageBySenderAndServerId } from '../../ts/data/data'; import { ConversationModel, ConversationTypeEnum } from '../models/conversation'; import { DeliveryReceiptMessage } from '../session/messages/outgoing/controlMessage/receipt/DeliveryReceiptMessage'; +import { allowOnlyOneAtATime } from '../session/utils/Promise'; -export async function updateProfile( +export async function updateProfileOneAtATime( + conversation: ConversationModel, + profile: SignalService.DataMessage.ILokiProfile, + profileKey: any +) { + if (!conversation?.id) { + window.log.warn('Cannot update profile with empty convoid'); + return; + } + const oneAtaTimeStr = `updateProfileOneAtATime:${conversation.id}`; + return allowOnlyOneAtATime(oneAtaTimeStr, async () => { + return updateProfile(conversation, profile, profileKey); + }); +} + +async function updateProfile( conversation: ConversationModel, profile: SignalService.DataMessage.ILokiProfile, profileKey: any @@ -285,7 +301,7 @@ export async function handleDataMessage( // Check if we need to update any profile names if (!isMe && senderConversation && message.profile) { - await updateProfile(senderConversation, message.profile, message.profileKey); + await updateProfileOneAtATime(senderConversation, message.profile, message.profileKey); } if (isMessageEmpty(message)) { window.log.warn(`Message ${getEnvelopeId(envelope)} ignored; it was empty`); diff --git a/ts/receiver/queuedJob.ts b/ts/receiver/queuedJob.ts index 3d1751720..b77cd68a5 100644 --- a/ts/receiver/queuedJob.ts +++ b/ts/receiver/queuedJob.ts @@ -11,7 +11,7 @@ import { MessageModel } from '../models/message'; import { MessageController } from '../session/messages'; import { getMessageById, getMessagesBySentAt } from '../../ts/data/data'; import { actions as conversationActions } from '../state/ducks/conversations'; -import { updateProfile } from './dataMessage'; +import { updateProfileOneAtATime } from './dataMessage'; import Long from 'long'; async function handleGroups( @@ -299,7 +299,6 @@ async function handleRegularMessage( const { upgradeMessageSchema } = window.Signal.Migrations; const type = message.get('type'); - await copyFromQuotedMessage(message, initialMessage.quote); // `upgradeMessageSchema` only seems to add `schemaVersion: 10` to the message @@ -371,14 +370,15 @@ async function handleRegularMessage( source, ConversationTypeEnum.PRIVATE ); + // Check if we need to update any profile names // the only profile we don't update with what is coming here is ours, // as our profile is shared accross our devices with a ConfigurationMessage - if (type === 'incoming' && dataMessage.profile) { - await updateProfile( + if (type === 'incoming' && dataMessage.profile && dataMessage.profile && dataMessage.profileKey) { + void updateProfileOneAtATime( sendingDeviceConversation, dataMessage.profile, - dataMessage.profile?.profileKey + dataMessage.profileKey ); } diff --git a/ts/receiver/receiver.ts b/ts/receiver/receiver.ts index de1cfa378..b4590e6dc 100644 --- a/ts/receiver/receiver.ts +++ b/ts/receiver/receiver.ts @@ -19,7 +19,7 @@ import { handleMessageEvent, isMessageDuplicate, MessageCreationData, - updateProfile, + updateProfileOneAtATime, } from './dataMessage'; import { getEnvelopeId } from './common'; @@ -283,7 +283,7 @@ export async function handlePublicMessage(messageData: any) { source, ConversationTypeEnum.PRIVATE ); - await updateProfile(conversation, profile, profileKey); + await updateProfileOneAtATime(conversation, profile, profileKey); } const isPublicVisibleMessage = group && group.id && !!group.id.match(openGroupPrefixRegex);