Send FETCH_LATEST.LOCAL_PROFILE on capability flip
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
parent
9c5fe0fc70
commit
df91fcce51
3 changed files with 53 additions and 0 deletions
|
@ -9,7 +9,9 @@ import type { ConversationModel } from '../models/conversations';
|
||||||
import type {
|
import type {
|
||||||
GetProfileOptionsType,
|
GetProfileOptionsType,
|
||||||
GetProfileUnauthOptionsType,
|
GetProfileUnauthOptionsType,
|
||||||
|
CapabilitiesType,
|
||||||
} from '../textsecure/WebAPI';
|
} from '../textsecure/WebAPI';
|
||||||
|
import MessageSender from '../textsecure/SendMessage';
|
||||||
import type { ServiceIdString } from '../types/ServiceId';
|
import type { ServiceIdString } from '../types/ServiceId';
|
||||||
import { DataWriter } from '../sql/Client';
|
import { DataWriter } from '../sql/Client';
|
||||||
import * as log from '../logging/log';
|
import * as log from '../logging/log';
|
||||||
|
@ -30,6 +32,7 @@ import { parseBadgesFromServer } from '../badges/parseBadgesFromServer';
|
||||||
import { strictAssert } from '../util/assert';
|
import { strictAssert } from '../util/assert';
|
||||||
import { drop } from '../util/drop';
|
import { drop } from '../util/drop';
|
||||||
import { findRetryAfterTimeFromError } from '../jobs/helpers/findRetryAfterTimeFromError';
|
import { findRetryAfterTimeFromError } from '../jobs/helpers/findRetryAfterTimeFromError';
|
||||||
|
import { singleProtoJobQueue } from '../jobs/singleProtoJobQueue';
|
||||||
import { SEALED_SENDER } from '../types/SealedSender';
|
import { SEALED_SENDER } from '../types/SealedSender';
|
||||||
import { HTTPError } from '../textsecure/Errors';
|
import { HTTPError } from '../textsecure/Errors';
|
||||||
import { Address } from '../types/Address';
|
import { Address } from '../types/Address';
|
||||||
|
@ -59,6 +62,11 @@ type JobType = {
|
||||||
// - Enforce a maximum profile fetch frequency
|
// - Enforce a maximum profile fetch frequency
|
||||||
// - Don't even attempt jobs when offline
|
// - Don't even attempt jobs when offline
|
||||||
|
|
||||||
|
const OBSERVED_CAPABILITY_KEYS = Object.keys({
|
||||||
|
deleteSync: true,
|
||||||
|
versionedExpirationTimer: true,
|
||||||
|
} satisfies CapabilitiesType) as ReadonlyArray<keyof CapabilitiesType>;
|
||||||
|
|
||||||
export class ProfileService {
|
export class ProfileService {
|
||||||
private jobQueue: PQueue;
|
private jobQueue: PQueue;
|
||||||
|
|
||||||
|
@ -453,12 +461,48 @@ async function doGetProfile(c: ConversationModel): Promise<void> {
|
||||||
await window.storage.put('paymentAddress', profile.paymentAddress);
|
await window.storage.put('paymentAddress', profile.paymentAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pastCapabilities = c.get('capabilities');
|
||||||
if (profile.capabilities) {
|
if (profile.capabilities) {
|
||||||
c.set({ capabilities: profile.capabilities });
|
c.set({ capabilities: profile.capabilities });
|
||||||
} else {
|
} else {
|
||||||
c.unset('capabilities');
|
c.unset('capabilities');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isMe(c.attributes)) {
|
||||||
|
const newCapabilities = c.get('capabilities');
|
||||||
|
|
||||||
|
let hasChanged = false;
|
||||||
|
const observedCapabilities = {
|
||||||
|
...window.storage.get('observedCapabilities'),
|
||||||
|
};
|
||||||
|
const newKeys = new Array<string>();
|
||||||
|
for (const key of OBSERVED_CAPABILITY_KEYS) {
|
||||||
|
// Already reported
|
||||||
|
if (observedCapabilities[key]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newCapabilities?.[key]) {
|
||||||
|
if (!pastCapabilities?.[key]) {
|
||||||
|
hasChanged = true;
|
||||||
|
newKeys.push(key);
|
||||||
|
}
|
||||||
|
observedCapabilities[key] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await window.storage.put('observedCapabilities', observedCapabilities);
|
||||||
|
if (hasChanged) {
|
||||||
|
log.info(
|
||||||
|
'getProfile: detected a capability flip, sending fetch profile',
|
||||||
|
newKeys
|
||||||
|
);
|
||||||
|
await singleProtoJobQueue.add(
|
||||||
|
MessageSender.getFetchLocalProfileSyncMessage()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const badges = parseBadgesFromServer(profile.badges, updatesUrl);
|
const badges = parseBadgesFromServer(profile.badges, updatesUrl);
|
||||||
if (badges.length) {
|
if (badges.length) {
|
||||||
await window.reduxActions.badges.updateOrCreate(badges);
|
await window.reduxActions.badges.updateOrCreate(badges);
|
||||||
|
|
|
@ -738,6 +738,8 @@ export type WebAPIConnectType = {
|
||||||
connect: (options: WebAPIConnectOptionsType) => WebAPIType;
|
connect: (options: WebAPIConnectOptionsType) => WebAPIType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// When updating this make sure to update `observedCapabilities` type in
|
||||||
|
// ts/types/Storage.d.ts
|
||||||
export type CapabilitiesType = {
|
export type CapabilitiesType = {
|
||||||
deleteSync: boolean;
|
deleteSync: boolean;
|
||||||
versionedExpirationTimer: boolean;
|
versionedExpirationTimer: boolean;
|
||||||
|
|
7
ts/types/Storage.d.ts
vendored
7
ts/types/Storage.d.ts
vendored
|
@ -175,6 +175,13 @@ export type StorageAccessType = {
|
||||||
serverId: Uint8Array;
|
serverId: Uint8Array;
|
||||||
};
|
};
|
||||||
needOrphanedAttachmentCheck: boolean;
|
needOrphanedAttachmentCheck: boolean;
|
||||||
|
observedCapabilities: {
|
||||||
|
deleteSync?: true;
|
||||||
|
versionedExpirationTimer?: true;
|
||||||
|
|
||||||
|
// Note: Upon capability deprecation - change the value type to `never` and
|
||||||
|
// remove it in `ts/background.ts`
|
||||||
|
};
|
||||||
|
|
||||||
// Deprecated
|
// Deprecated
|
||||||
'challenge:retry-message-ids': never;
|
'challenge:retry-message-ids': never;
|
||||||
|
|
Loading…
Add table
Reference in a new issue