Skip to content

Commit

Permalink
sdk: send toDevice messages to deviceId='*'
Browse files Browse the repository at this point in the history
So since #2579, we are sending messages only to specific
deviceId='RAIDEN', but the commit which made raiden-py log in with that
deviceId came only after their v1.2.0 release. We've checked with the
matrix team, and the target deviceIds for toDevice messages are checked
at request time, so it should be safe to send to `*` instead, which will
reach all connected clients and make it compatible with PC 1.2+
  • Loading branch information
andrevmatos authored and weilbith committed Mar 22, 2021
1 parent 6d51019 commit 0493a3d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions raiden-ts/src/transport/epics/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
import type { RaidenAction } from '../../actions';
import type { RaidenConfig } from '../../config';
import { intervalFromConfig } from '../../config';
import { Capabilities, RAIDEN_DEVICE_ID } from '../../constants';
import { Capabilities } from '../../constants';
import { messageReceived, messageSend, messageServiceSend } from '../../messages/actions';
import type { Delivered, Message } from '../../messages/types';
import { MessageType, Processed, SecretRequest, SecretReveal } from '../../messages/types';
Expand Down Expand Up @@ -113,7 +113,7 @@ function flushQueueToDevice(
// several messages can be batched in a single body, as long as they share same msgtype
const body = peerQueue.map((action) => getMessageBody(action.payload.message)).join('\n');
const content = { msgtype: getMsgType(peerQueue[0]), body };
payload[peerId] = { [RAIDEN_DEVICE_ID]: content };
payload[peerId] = { ['*']: content };
}

let retries = -1;
Expand Down
12 changes: 6 additions & 6 deletions raiden-ts/tests/unit/epics/transport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { MatrixClient } from 'matrix-js-sdk';
import { first, pluck } from 'rxjs/operators';

import { raidenConfigUpdate, raidenShutdown } from '@/actions';
import { Capabilities, RAIDEN_DEVICE_ID } from '@/constants';
import { Capabilities } from '@/constants';
import { messageReceived, messageSend, messageServiceSend } from '@/messages/actions';
import type { Delivered, Processed } from '@/messages/types';
import { MessageType } from '@/messages/types';
Expand Down Expand Up @@ -647,7 +647,7 @@ describe('matrixMessageSendEpic', () => {
expect(matrix.sendToDevice).toHaveBeenCalledWith(
'm.room.message',
expect.objectContaining({
[partnerMatrix.getUserId()!]: { [RAIDEN_DEVICE_ID]: { body: message, msgtype: 'm.text' } },
[partnerMatrix.getUserId()!]: { ['*']: { body: message, msgtype: 'm.text' } },
}),
);
});
Expand Down Expand Up @@ -685,7 +685,7 @@ describe('matrixMessageSendEpic', () => {
expect(matrix.sendToDevice).toHaveBeenCalledTimes(2);
expect(matrix.sendToDevice).toHaveBeenCalledWith('m.room.message', {
[partnerMatrix.getUserId()!]: {
[RAIDEN_DEVICE_ID]: { body: expect.stringMatching('"Processed"'), msgtype: 'm.text' },
['*']: { body: expect.stringMatching('"Processed"'), msgtype: 'm.text' },
},
});
});
Expand Down Expand Up @@ -732,16 +732,16 @@ describe('matrixMessageSendEpic', () => {
// first message got sent immediately
expect(mockedSendToDevice).toHaveBeenNthCalledWith(1, 'm.room.message', {
[p1Matrix.getUserId()!]: {
[RAIDEN_DEVICE_ID]: { body: messages[0], msgtype: 'm.text' },
['*']: { body: messages[0], msgtype: 'm.text' },
},
});
// second message to first recipient, plus batched messages to 2nd recipient, in a single call
expect(mockedSendToDevice).toHaveBeenNthCalledWith(2, 'm.room.message', {
[p1Matrix.getUserId()!]: {
[RAIDEN_DEVICE_ID]: { body: messages[1], msgtype: 'm.text' },
['*']: { body: messages[1], msgtype: 'm.text' },
},
[p2Matrix.getUserId()!]: {
[RAIDEN_DEVICE_ID]: { body: messages.slice(2).join('\n'), msgtype: 'm.text' },
['*']: { body: messages.slice(2).join('\n'), msgtype: 'm.text' },
},
});
});
Expand Down

0 comments on commit 0493a3d

Please sign in to comment.