diff --git a/ts/groups.ts b/ts/groups.ts index 4e87f7cb29de..bb7b28c5e5c0 100644 --- a/ts/groups.ts +++ b/ts/groups.ts @@ -5146,10 +5146,19 @@ async function applyGroupChange({ } // Capture who added us - if (ourAci && sourceServiceId && addedUuid === ourAci) { + if (addedUuid === ourAci && pendingAdminApprovalMembers[ourAci]) { + result.addedBy = ourAci; + } else if (addedUuid === ourAci && sourceServiceId) { result.addedBy = sourceServiceId; } + if (pendingAdminApprovalMembers[addedUuid]) { + log.warn( + `applyGroupChange/${logId}: Removing newly-added member from pendingAdminApprovalMembers.` + ); + delete pendingAdminApprovalMembers[addedUuid]; + } + if (added.profileKey) { newProfileKeys.push({ profileKey: added.profileKey, @@ -5291,6 +5300,7 @@ async function applyGroupChange({ log.warn( `applyGroupChange/${logId}: Attempt to promote pendingMember failed; was not in pendingMembers.` ); + return; } if (members[aci]) { @@ -5518,6 +5528,7 @@ async function applyGroupChange({ log.warn( `applyGroupChange/${logId}: Attempt to promote pendingAdminApproval failed; was not in pendingAdminApprovalMembers.` ); + return; } if (pendingMembers[userId]) { delete pendingAdminApprovalMembers[userId]; @@ -5533,6 +5544,11 @@ async function applyGroupChange({ return; } + // If we had requested to join, and are approved, we added ourselves + if (userId === ourAci) { + result.addedBy = ourAci; + } + members[userId] = { aci: userId, joinedAtVersion: version, @@ -5840,7 +5856,9 @@ async function applyGroupState({ result.left = false; // Capture who added us if we were previously not in group - if ( + if (pendingAdminApprovalMembers[ourAci] && !wasPreviouslyAMember) { + result.addedBy = sourceServiceId; + } else if ( sourceServiceId && !wasPreviouslyAMember && isNumber(member.joinedAtVersion) && diff --git a/ts/groups/joinViaLink.ts b/ts/groups/joinViaLink.ts index 2e2aa0bff351..8a753cbf751f 100644 --- a/ts/groups/joinViaLink.ts +++ b/ts/groups/joinViaLink.ts @@ -356,6 +356,7 @@ export async function joinViaLink(value: string): Promise { tempConversation.set({ // We want to keep this conversation around, since the join succeeded isTemporary: undefined, + profileSharing: true, }); await DataWriter.updateConversation(tempConversation.attributes); } diff --git a/ts/util/avatarUtils.ts b/ts/util/avatarUtils.ts index 9094b6a2cd85..6b889a00cfaa 100644 --- a/ts/util/avatarUtils.ts +++ b/ts/util/avatarUtils.ts @@ -62,7 +62,7 @@ export function getRawAvatarPath( export function getLocalProfileAvatarUrl( conversationAttrs: ConversationAttributesType ): string | undefined { - const avatar = conversationAttrs.profileAvatar; + const avatar = conversationAttrs.profileAvatar || conversationAttrs.avatar; return avatar?.path ? getLocalAttachmentUrl(avatar) : undefined; } diff --git a/ts/util/isConversationAccepted.ts b/ts/util/isConversationAccepted.ts index 61cd8ac6c2b6..433cd95b0d68 100644 --- a/ts/util/isConversationAccepted.ts +++ b/ts/util/isConversationAccepted.ts @@ -35,12 +35,26 @@ export function isConversationAccepted( return true; } - const { sentMessageCount } = conversationAttrs; + const { + sentMessageCount, + messageCount, + messageCountBeforeMessageRequests, + pendingAdminApprovalV2, + profileSharing, + } = conversationAttrs; + + const ourAci = window.storage.user.getAci(); + const hasRequestedToJoin = + Boolean(ourAci) && + (pendingAdminApprovalV2 || []).some(item => item.aci === ourAci); + if (hasRequestedToJoin) { + return true; + } const hasSentMessages = (sentMessageCount || 0) > 0; const hasMessagesBeforeMessageRequests = - (conversationAttrs.messageCountBeforeMessageRequests || 0) > 0; - const hasNoMessages = (conversationAttrs.messageCount || 0) === 0; + (messageCountBeforeMessageRequests || 0) > 0; + const hasNoMessages = (messageCount || 0) === 0; // We don't want to show the message request UI in an empty conversation. const isEmptyPrivateConvo = @@ -50,7 +64,7 @@ export function isConversationAccepted( const isEmptyWhitelistedGroup = hasNoMessages && !isDirectConversation(conversationAttrs) && - Boolean(conversationAttrs.profileSharing); + Boolean(profileSharing); return ( isFromOrAddedByTrustedContact(conversationAttrs) ||