Update profile sharing when added to group

This commit is contained in:
trevor-signal 2025-08-25 10:26:49 -04:00 committed by GitHub
commit 435dc2acf7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 38 deletions

View file

@ -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

View file

@ -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<void> {
const ourConversationId =
window.ConversationController.getOurConversationId();

View file

@ -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);
}