Fix MessageRequestResponse sync processing

This commit is contained in:
Fedor Indutny 2024-02-14 12:19:08 -08:00 committed by GitHub
parent 94f02dcc88
commit 943518dc3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 80 additions and 10 deletions

View file

@ -74,4 +74,70 @@ describe('unknown contacts', function (this: Mocha.Suite) {
0
);
});
it('blocks incoming calls from unknown contacts & shows message request', async () => {
const { desktop } = bootstrap;
debug('sending calling offer message');
await unknownContact.sendRaw(desktop, {
callingMessage: {
offer: {
callId: new Long(Math.floor(Math.random() * 1e10)),
type: Proto.CallingMessage.Offer.Type.OFFER_AUDIO_CALL,
opaque: new Uint8Array(0),
},
},
});
debug('opening conversation');
const leftPane = page.locator('#LeftPane');
const conversationListItem = leftPane.getByRole('button', {
name: 'Chat with Unknown contact',
});
await conversationListItem.getByText('Message Request').click();
const conversationStack = page.locator('.Inbox__conversation-stack');
await conversationStack.getByText('Missed voice call').waitFor();
debug('accepting message request');
await page.getByText('message you and share your name').waitFor();
await page.getByRole('button', { name: 'Accept' }).click();
assert.strictEqual(
await page.getByText('message you and share your name').count(),
0
);
});
it('syncs message request state', async () => {
const { phone, desktop } = bootstrap;
debug('sending regular text message');
await unknownContact.sendText(desktop, 'hello');
debug('opening conversation');
const leftPane = page.locator('#LeftPane');
const conversationListItem = leftPane.getByRole('button', {
name: 'Chat with Unknown contact',
});
await conversationListItem.getByText('Message Request').click();
debug('sending message request sync');
await phone.sendRaw(desktop, {
syncMessage: {
messageRequestResponse: {
type: Proto.SyncMessage.MessageRequestResponse.Type.ACCEPT,
threadAci: unknownContact.device.aci,
},
},
});
debug('verifying that compose is now visible');
const composeArea = page.locator(
'.composition-area-wrapper, .Inbox__conversation .ConversationView'
);
const input = composeArea.locator('[data-testid=CompositionInput]');
await input.waitFor();
});
});

View file

@ -2899,10 +2899,12 @@ export default class MessageReceiver
const { groupId, timestamp, action } = typingMessage;
let groupV2IdString: string | undefined;
if (groupId && groupId.byteLength === GROUPV2_ID_LENGTH) {
groupV2IdString = Bytes.toBase64(groupId);
} else {
log.error('handleTypingMessage: Received invalid groupId value');
if (groupId?.byteLength) {
if (groupId.byteLength === GROUPV2_ID_LENGTH) {
groupV2IdString = Bytes.toBase64(groupId);
} else {
log.error('handleTypingMessage: Received invalid groupId value');
}
}
this.dispatchEvent(
@ -3241,12 +3243,14 @@ export default class MessageReceiver
const { groupId } = sync;
let groupV2IdString: string | undefined;
if (groupId && groupId.byteLength === GROUPV2_ID_LENGTH) {
groupV2IdString = Bytes.toBase64(groupId);
} else {
this.removeFromCache(envelope);
log.error('Received message request with invalid groupId');
return undefined;
if (groupId?.byteLength) {
if (groupId.byteLength === GROUPV2_ID_LENGTH) {
groupV2IdString = Bytes.toBase64(groupId);
} else {
this.removeFromCache(envelope);
log.error('Received message request with invalid groupId');
return undefined;
}
}
const ev = new MessageRequestResponseEvent(