From 435dc2acf7b6dd89c0fd133b18bf6ee4e88d9435 Mon Sep 17 00:00:00 2001 From: trevor-signal <131492920+trevor-signal@users.noreply.github.com> Date: Mon, 25 Aug 2025 10:26:49 -0400 Subject: [PATCH] Update profile sharing when added to group --- ts/groups.ts | 12 +++++++++- ts/models/conversations.ts | 23 ------------------- ts/util/isConversationAccepted.ts | 38 +++++++++++++++++++------------ 3 files changed, 35 insertions(+), 38 deletions(-) diff --git a/ts/groups.ts b/ts/groups.ts index 3cfaf320828..476d3951fdc 100644 --- a/ts/groups.ts +++ b/ts/groups.ts @@ -105,7 +105,10 @@ import { generateMessageId } from './util/generateMessageId'; import { postSaveUpdates } from './util/cleanup'; import { MessageModel } from './models/messages'; import { areWePending } from './util/groupMembershipUtils'; -import { isConversationAccepted } from './util/isConversationAccepted'; +import { + isConversationAccepted, + isTrustedContact, +} from './util/isConversationAccepted'; const log = createLogger('groups'); @@ -3277,6 +3280,13 @@ async function updateGroup( // Return early to discard group changes resulting from unwanted group add return; } + + if (adder && isTrustedContact(adder?.attributes)) { + conversation.enableProfileSharing({ + reason: 'addedToGroupByTrustedContact', + viaStorageServiceSync: false, + }); + } } // We update group membership last to ensure that all notifications are in place before diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index f93ccd5238c..49e09d030f0 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -4185,29 +4185,6 @@ export class ConversationModel { return attributes; } - // Is this someone who is a contact, or are we sharing our profile with them? - // Or is the person who added us to this group a contact or are we sharing profile - // with them? - isFromOrAddedByTrustedContact(): boolean { - if (isDirectConversation(this.attributes)) { - return Boolean(this.get('name')) || Boolean(this.get('profileSharing')); - } - - const addedBy = this.get('addedBy'); - if (!addedBy) { - return false; - } - - const conv = window.ConversationController.get(addedBy); - if (!conv) { - return false; - } - - return Boolean( - isMe(conv.attributes) || conv.get('name') || conv.get('profileSharing') - ); - } - async maybeClearUsername(): Promise { const ourConversationId = window.ConversationController.getOurConversationId(); diff --git a/ts/util/isConversationAccepted.ts b/ts/util/isConversationAccepted.ts index 433cd95b0d6..e513a5c7bf7 100644 --- a/ts/util/isConversationAccepted.ts +++ b/ts/util/isConversationAccepted.ts @@ -5,11 +5,14 @@ import type { ConversationAttributesType } from '../model-types.d'; import { SignalService as Proto } from '../protobuf'; import { isDirectConversation, isMe } from './whatTypeOfConversation'; import { isInSystemContacts } from './isInSystemContacts'; +import { createLogger } from '../logging/log'; export type IsConversationAcceptedOptionsType = { ignoreEmptyConvo: boolean; }; +const log = createLogger('isConversationAccepted'); + /** * Determine if this conversation should be considered "accepted" in terms * of message requests @@ -77,17 +80,28 @@ export function isConversationAccepted( ); } -// Is this someone who is a contact, or are we sharing our profile with them? -// Or is the person who added us to this group a contact or are we sharing profile -// with them? +// Is this someone me, a system contact, or are we sharing our profile with them? +export function isTrustedContact( + conversationAttrs: ConversationAttributesType +): boolean { + if (!isDirectConversation(conversationAttrs)) { + log.error('isTrustedContact should only be called for direct convos'); + return false; + } + + return ( + isMe(conversationAttrs) || + isInSystemContacts(conversationAttrs) || + Boolean(conversationAttrs.profileSharing) + ); +} + +// Is this person (or the person who added us to this group) a trusted contact? function isFromOrAddedByTrustedContact( conversationAttrs: ConversationAttributesType ): boolean { if (isDirectConversation(conversationAttrs)) { - return ( - isInSystemContacts(conversationAttrs) || - Boolean(conversationAttrs.profileSharing) - ); + return isTrustedContact(conversationAttrs); } const { addedBy } = conversationAttrs; @@ -95,14 +109,10 @@ function isFromOrAddedByTrustedContact( return false; } - const conversation = window.ConversationController.get(addedBy); - if (!conversation) { + const addedByContact = window.ConversationController.get(addedBy); + if (!addedByContact) { return false; } - return Boolean( - isMe(conversation.attributes) || - conversation.get('name') || - conversation.get('profileSharing') - ); + return isTrustedContact(addedByContact.attributes); }