Usernames: Create/update/delete in profile editor
This commit is contained in:
parent
a9cb621eb6
commit
3190f95fac
38 changed files with 923 additions and 89 deletions
38
ts/services/writeUsername.ts
Normal file
38
ts/services/writeUsername.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import dataInterface from '../sql/Client';
|
||||
import { handleMessageSend } from '../util/handleMessageSend';
|
||||
|
||||
export async function writeUsername({
|
||||
username,
|
||||
previousUsername,
|
||||
}: {
|
||||
username: string | undefined;
|
||||
previousUsername: string | undefined;
|
||||
}): Promise<void> {
|
||||
const me = window.ConversationController.getOurConversationOrThrow();
|
||||
await me.getProfiles();
|
||||
|
||||
if (me.get('username') !== previousUsername) {
|
||||
throw new Error('Username has changed on another device');
|
||||
}
|
||||
|
||||
if (username) {
|
||||
await window.textsecure.messaging.putUsername(username);
|
||||
} else {
|
||||
await window.textsecure.messaging.deleteUsername();
|
||||
}
|
||||
|
||||
// Update backbone, update DB, then tell linked devices about profile update
|
||||
me.set({
|
||||
username,
|
||||
});
|
||||
|
||||
dataInterface.updateConversation(me.attributes);
|
||||
|
||||
await handleMessageSend(
|
||||
window.textsecure.messaging.sendFetchLocalProfileSyncMessage(),
|
||||
{ messageIds: [], sendType: 'otherSync' }
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue