diff --git a/ts/test-mock/messaging/unknown_contact_test.ts b/ts/test-mock/messaging/unknown_contact_test.ts index db02cd0d2853..42fca2b97d9e 100644 --- a/ts/test-mock/messaging/unknown_contact_test.ts +++ b/ts/test-mock/messaging/unknown_contact_test.ts @@ -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(); + }); }); diff --git a/ts/textsecure/MessageReceiver.ts b/ts/textsecure/MessageReceiver.ts index 64bb7e813972..92167f5131eb 100644 --- a/ts/textsecure/MessageReceiver.ts +++ b/ts/textsecure/MessageReceiver.ts @@ -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(