Integrate message requests with storage service

This commit is contained in:
Josh Perez 2020-07-22 12:47:59 -04:00 committed by Scott Nonnenberg
parent 9433a1de99
commit 0f8a60acc3
3 changed files with 47 additions and 35 deletions

View file

@ -955,7 +955,9 @@
fromContact || fromContact ||
hasSentMessages || hasSentMessages ||
hasMessagesBeforeMessageRequests || hasMessagesBeforeMessageRequests ||
hasNoMessages // an empty conversation is the scenario where we need to rely on
// whether the profile has already been shared or not
(hasNoMessages && this.get('profileSharing'))
); );
}, },

1
ts/model-types.d.ts vendored
View file

@ -75,6 +75,7 @@ declare class ConversationModelType extends Backbone.Model<
id: string; id: string;
cachedProps: ConversationType; cachedProps: ConversationType;
initialPromise: Promise<any>; initialPromise: Promise<any>;
messageRequestEnum: typeof SyncMessageClass.MessageRequestResponse.Type;
addCallHistory(details: CallHistoryDetailsType): void; addCallHistory(details: CallHistoryDetailsType): void;
applyMessageRequestResponse( applyMessageRequestResponse(

View file

@ -89,6 +89,35 @@ async function fetchManifest(manifestVersion: string) {
} }
} }
type MessageRequestCapableRecord = ContactRecordClass | GroupV1RecordClass;
function applyMessageRequestState(
record: MessageRequestCapableRecord,
conversation: ConversationModelType
): void {
if (record.blocked) {
conversation.applyMessageRequestResponse(
conversation.messageRequestEnum.BLOCK,
{ fromSync: true }
);
} else if (record.whitelisted) {
// unblocking is also handled by this function which is why the next
// condition is part of the else-if and not separate
conversation.applyMessageRequestResponse(
conversation.messageRequestEnum.ACCEPT,
{ fromSync: true }
);
} else if (!record.blocked) {
// if the condition above failed the state could still be blocked=false
// in which case we should unblock the conversation
conversation.unblock();
}
if (!record.whitelisted) {
conversation.disableProfileSharing();
}
}
async function mergeGroupV1Record( async function mergeGroupV1Record(
storageID: string, storageID: string,
groupV1Record: GroupV1RecordClass groupV1Record: GroupV1RecordClass
@ -112,6 +141,8 @@ async function mergeGroupV1Record(
storageID, storageID,
}); });
applyMessageRequestState(groupV1Record, conversation);
window.Signal.Data.updateConversation(conversation.attributes); window.Signal.Data.updateConversation(conversation.attributes);
window.log.info(`storageService.mergeGroupV1Record: merged ${storageID}`); window.log.info(`storageService.mergeGroupV1Record: merged ${storageID}`);
@ -121,20 +152,22 @@ async function mergeContactRecord(
storageID: string, storageID: string,
contactRecord: ContactRecordClass contactRecord: ContactRecordClass
): Promise<void> { ): Promise<void> {
window.log.info(`storageService.mergeContactRecord: merging ${storageID}`);
window.normalizeUuids( window.normalizeUuids(
contactRecord, contactRecord,
['serviceUuid'], ['serviceUuid'],
'storageService.mergeContactRecord' 'storageService.mergeContactRecord'
); );
if (!contactRecord.serviceE164) { const e164 = contactRecord.serviceE164 || undefined;
window.log.info( const uuid = contactRecord.serviceUuid || undefined;
`storageService.mergeContactRecord: no E164 for ${storageID}, uuid: ${contactRecord.serviceUuid}. Dropping record`
);
return;
}
const id = contactRecord.serviceE164 || contactRecord.serviceUuid; const id = window.ConversationController.ensureContactIds({
e164,
uuid,
highTrust: true,
});
if (!id) { if (!id) {
window.log.info( window.log.info(
@ -143,19 +176,11 @@ async function mergeContactRecord(
return; return;
} }
window.log.info(`storageService.mergeContactRecord: merging ${storageID}`);
const conversation = await window.ConversationController.getOrCreateAndWait( const conversation = await window.ConversationController.getOrCreateAndWait(
id, id,
'private' 'private'
); );
if (contactRecord.blocked === true) {
window.storage.addBlockedNumber(conversation.id);
} else if (contactRecord.blocked === false) {
window.storage.removeBlockedNumber(conversation.id);
}
const verified = contactRecord.identityState const verified = contactRecord.identityState
? fromRecordVerified(contactRecord.identityState) ? fromRecordVerified(contactRecord.identityState)
: window.textsecure.storage.protocol.VerifiedStatus.DEFAULT; : window.textsecure.storage.protocol.VerifiedStatus.DEFAULT;
@ -167,28 +192,11 @@ async function mergeContactRecord(
? arrayBufferToBase64(contactRecord.profileKey.toArrayBuffer()) ? arrayBufferToBase64(contactRecord.profileKey.toArrayBuffer())
: null, : null,
profileName: contactRecord.givenName, profileName: contactRecord.givenName,
profileSharing: Boolean(contactRecord.whitelisted),
storageID, storageID,
verified, verified,
}); });
if ( applyMessageRequestState(contactRecord, conversation);
contactRecord.serviceUuid &&
(!conversation.get('uuid') ||
conversation.get('uuid') !== contactRecord.serviceUuid)
) {
window.log.info(
`storageService.mergeContactRecord: updating UUID ${storageID}`
);
conversation.set({ uuid: contactRecord.serviceUuid });
}
if (contactRecord.serviceE164 && !conversation.get('e164')) {
window.log.info(
`storageService.mergeContactRecord: updating E164 ${storageID}`
);
conversation.set({ e164: contactRecord.serviceE164 });
}
const identityKey = await window.textsecure.storage.protocol.loadIdentityKey( const identityKey = await window.textsecure.storage.protocol.loadIdentityKey(
conversation.id conversation.id
@ -307,6 +315,7 @@ async function processManifest(
.getConversations() .getConversations()
.map((conversation: ConversationModelType) => conversation.get('storageID')) .map((conversation: ConversationModelType) => conversation.get('storageID'))
.filter(Boolean); .filter(Boolean);
window.log.info( window.log.info(
`storageService.processManifest localKeys.length ${localKeys.length}` `storageService.processManifest localKeys.length ${localKeys.length}`
); );
@ -402,7 +411,7 @@ async function processManifest(
} }
export async function runStorageServiceSyncJob() { export async function runStorageServiceSyncJob() {
const localManifestVersion = '0'; // window.storage.get('manifestVersion') || 0; const localManifestVersion = window.storage.get('manifestVersion') || 0;
let manifest; let manifest;
try { try {