Process username changes in storage service

This commit is contained in:
Fedor Indutny 2023-02-02 10:03:51 -08:00 committed by GitHub
parent 71c97e9580
commit 1381e8df5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 252 additions and 53 deletions

View file

@ -33,6 +33,7 @@ import {
getSafeLongFromTimestamp,
getTimestampFromLong,
} from '../util/timestampLongUtils';
import { canHaveUsername } from '../util/getTitle';
import {
get as getUniversalExpireTimer,
set as setUniversalExpireTimer,
@ -156,6 +157,11 @@ export async function toContactRecord(
if (e164) {
contactRecord.serviceE164 = e164;
}
const username = conversation.get('username');
const ourID = window.ConversationController.getOurConversationId();
if (username && canHaveUsername(conversation.attributes, ourID)) {
contactRecord.username = username;
}
const pni = conversation.get('pni');
if (pni && RemoteConfig.isEnabled('desktop.pnp')) {
contactRecord.pni = pni;
@ -978,6 +984,10 @@ export async function mergeContactRecord(
};
}
await conversation.updateUsername(dropNull(contactRecord.username), {
shouldSave: false,
});
let needsProfileFetch = false;
if (contactRecord.profileKey && contactRecord.profileKey.length > 0) {
needsProfileFetch = await conversation.setProfileKey(