Skip to content

Commit

Permalink
Fix MessageRequestResponse sync processing
Browse files Browse the repository at this point in the history
  • Loading branch information
automated-signal authored Feb 14, 2024
1 parent 7c9364b commit fe015f4
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 10 deletions.
66 changes: 66 additions & 0 deletions ts/test-mock/messaging/unknown_contact_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
24 changes: 14 additions & 10 deletions ts/textsecure/MessageReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit fe015f4

Please sign in to comment.