mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-05-08 08:58:38 +01:00
Support device name change sync message
This commit is contained in:
@@ -315,6 +315,7 @@ export default class AccountManager extends EventTarget {
|
||||
|
||||
if (base64) {
|
||||
await this.server.updateDeviceName(base64);
|
||||
await window.textsecure.storage.user.setDeviceNameEncrypted();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -113,6 +113,7 @@ import {
|
||||
DecryptionErrorEvent,
|
||||
DeleteForMeSyncEvent,
|
||||
DeliveryEvent,
|
||||
DeviceNameChangeSyncEvent,
|
||||
EmptyEvent,
|
||||
EnvelopeQueuedEvent,
|
||||
EnvelopeUnsealedEvent,
|
||||
@@ -701,6 +702,11 @@ export default class MessageReceiver
|
||||
handler: (ev: DeleteForMeSyncEvent) => void
|
||||
): void;
|
||||
|
||||
public override addEventListener(
|
||||
name: 'deviceNameChangeSync',
|
||||
handler: (ev: DeviceNameChangeSyncEvent) => void
|
||||
): void;
|
||||
|
||||
public override addEventListener(name: string, handler: EventHandler): void {
|
||||
return super.addEventListener(name, handler);
|
||||
}
|
||||
@@ -3191,6 +3197,12 @@ export default class MessageReceiver
|
||||
if (syncMessage.deleteForMe) {
|
||||
return this.handleDeleteForMeSync(envelope, syncMessage.deleteForMe);
|
||||
}
|
||||
if (syncMessage.deviceNameChange) {
|
||||
return this.handleDeviceNameChangeSync(
|
||||
envelope,
|
||||
syncMessage.deviceNameChange
|
||||
);
|
||||
}
|
||||
|
||||
this.removeFromCache(envelope);
|
||||
const envelopeId = getEnvelopeId(envelope);
|
||||
@@ -3817,6 +3829,39 @@ export default class MessageReceiver
|
||||
log.info('handleDeleteForMeSync: finished');
|
||||
}
|
||||
|
||||
private async handleDeviceNameChangeSync(
|
||||
envelope: ProcessedEnvelope,
|
||||
deviceNameChange: Proto.SyncMessage.IDeviceNameChange
|
||||
): Promise<void> {
|
||||
const logId = `MessageReceiver.handleDeviceNameChangeSync: ${getEnvelopeId(envelope)}`;
|
||||
log.info(logId);
|
||||
|
||||
logUnexpectedUrgentValue(envelope, 'deviceNameChangeSync');
|
||||
|
||||
const { deviceId } = deviceNameChange;
|
||||
const localDeviceId = parseIntOrThrow(
|
||||
this.storage.user.getDeviceId(),
|
||||
'MessageReceiver.handleDeviceNameChangeSync: localDeviceId'
|
||||
);
|
||||
|
||||
if (deviceId == null) {
|
||||
log.warn(logId, 'deviceId was falsey');
|
||||
this.removeFromCache(envelope);
|
||||
return;
|
||||
}
|
||||
|
||||
if (deviceId !== localDeviceId) {
|
||||
log.info(logId, 'meant for other device:', deviceId);
|
||||
this.removeFromCache(envelope);
|
||||
return;
|
||||
}
|
||||
|
||||
const deviceNameChangeEvent = new DeviceNameChangeSyncEvent(
|
||||
this.removeFromCache.bind(this, envelope)
|
||||
);
|
||||
await this.dispatchAndWait(logId, deviceNameChangeEvent);
|
||||
}
|
||||
|
||||
private async handleContacts(
|
||||
envelope: ProcessedEnvelope,
|
||||
contactSyncProto: Proto.SyncMessage.IContacts
|
||||
|
||||
+24
-9
@@ -862,6 +862,19 @@ export type GetAccountForUsernameResultType = z.infer<
|
||||
typeof getAccountForUsernameResultZod
|
||||
>;
|
||||
|
||||
const getDevicesResultZod = z.object({
|
||||
devices: z.array(
|
||||
z.object({
|
||||
id: z.number(),
|
||||
name: z.string().nullish(), // primary devices may not have a name
|
||||
lastSeen: z.number().nullish(),
|
||||
created: z.number().nullish(),
|
||||
})
|
||||
),
|
||||
});
|
||||
|
||||
export type GetDevicesResultType = z.infer<typeof getDevicesResultZod>;
|
||||
|
||||
export type GetIceServersResultType = Readonly<{
|
||||
relays?: ReadonlyArray<IceServerGroupType>;
|
||||
}>;
|
||||
@@ -874,15 +887,6 @@ export type IceServerGroupType = Readonly<{
|
||||
hostname?: string;
|
||||
}>;
|
||||
|
||||
export type GetDevicesResultType = ReadonlyArray<
|
||||
Readonly<{
|
||||
id: number;
|
||||
name: string;
|
||||
lastSeen: number;
|
||||
created: number;
|
||||
}>
|
||||
>;
|
||||
|
||||
export type GetSenderCertificateResultType = Readonly<{ certificate: string }>;
|
||||
|
||||
export type MakeProxiedRequestResultType =
|
||||
@@ -1376,6 +1380,7 @@ export type WebAPIType = {
|
||||
getAccountForUsername: (
|
||||
options: GetAccountForUsernameOptionsType
|
||||
) => Promise<GetAccountForUsernameResultType>;
|
||||
getDevices: () => Promise<GetDevicesResultType>;
|
||||
getProfileUnauth: (
|
||||
serviceId: ServiceIdString,
|
||||
options: ProfileFetchUnauthRequestOptions
|
||||
@@ -1847,6 +1852,7 @@ export function initialize({
|
||||
getBackupUploadForm,
|
||||
getBadgeImageFile,
|
||||
getConfig,
|
||||
getDevices,
|
||||
getGroup,
|
||||
getGroupAvatar,
|
||||
getGroupCredentials,
|
||||
@@ -2935,6 +2941,15 @@ export function initialize({
|
||||
});
|
||||
}
|
||||
|
||||
async function getDevices() {
|
||||
const result = await _ajax({
|
||||
call: 'devices',
|
||||
httpType: 'GET',
|
||||
responseType: 'json',
|
||||
});
|
||||
return parseUnknown(getDevicesResultZod, result);
|
||||
}
|
||||
|
||||
async function updateDeviceName(deviceName: string) {
|
||||
await _ajax({
|
||||
call: 'updateDeviceName',
|
||||
|
||||
@@ -493,6 +493,12 @@ export class CallLinkUpdateSyncEvent extends ConfirmableEvent {
|
||||
}
|
||||
}
|
||||
|
||||
export class DeviceNameChangeSyncEvent extends ConfirmableEvent {
|
||||
constructor(confirm: ConfirmCallback) {
|
||||
super('deviceNameChangeSync', confirm);
|
||||
}
|
||||
}
|
||||
|
||||
const messageToDeleteSchema = z.union([
|
||||
z.object({
|
||||
type: z.literal('aci').readonly(),
|
||||
|
||||
@@ -153,6 +153,10 @@ export class User {
|
||||
return this.storage.get('device_name');
|
||||
}
|
||||
|
||||
public async setDeviceName(name: string): Promise<void> {
|
||||
return this.storage.put('device_name', name);
|
||||
}
|
||||
|
||||
public async setDeviceNameEncrypted(): Promise<void> {
|
||||
return this.storage.put('deviceNameEncrypted', true);
|
||||
}
|
||||
@@ -175,9 +179,7 @@ export class User {
|
||||
this.storage.put('uuid_id', `${aci}.${deviceId}`),
|
||||
this.storage.put('password', password),
|
||||
this.setPni(pni),
|
||||
deviceName
|
||||
? this.storage.put('device_name', deviceName)
|
||||
: Promise.resolve(),
|
||||
deviceName ? this.setDeviceName(deviceName) : Promise.resolve(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user