Skip to content
Snippets Groups Projects
Verified Commit 24cae68c authored by aguestuser's avatar aguestuser
Browse files

[329] don't send responses to PRIVATE "commands"

* we do notifications instead (those can include attachments)
* also: add an integration test to make sure we're not doing this!
parent 7677f0a1
Branches
No related tags found
No related merge requests found
...@@ -77,7 +77,10 @@ const handleHotlineMessage = async ({ commandResult, dispatchable }) => { ...@@ -77,7 +77,10 @@ const handleHotlineMessage = async ({ commandResult, dispatchable }) => {
const handleCommandResult = async ({ commandResult, dispatchable }) => { const handleCommandResult = async ({ commandResult, dispatchable }) => {
const { command, message, notifications, status } = commandResult const { command, message, notifications, status } = commandResult
if (command !== commands.REPLY) await respond({ ...dispatchable, message, command, status }) // We don't respond to REPLY or PRIVATE commands b/c their senders receive notifications instead.
// Rationale: these commands are more like relayable messages than they are actual commands.
if (![commands.REPLY, commands.PRIVATE].includes(command))
await respond({ ...dispatchable, message, command, status })
if (status === statuses.SUCCESS) await sendNotifications(dispatchable.channel, notifications) if (status === statuses.SUCCESS) await sendNotifications(dispatchable.channel, notifications)
await wait(setExpiryInterval) // to ensure welcome notification arrives first await wait(setExpiryInterval) // to ensure welcome notification arrives first
await setExpiryTimeForNewUsers({ commandResult, dispatchable }) await setExpiryTimeForNewUsers({ commandResult, dispatchable })
......
...@@ -280,4 +280,47 @@ describe('dispatcher service', () => { ...@@ -280,4 +280,47 @@ describe('dispatcher service', () => {
]) ])
}) })
}) })
describe('dispatching a PRIVATE message', () => {
beforeEach(async () => {
await createChannelWithMembers()
readSock.emit(
'data',
JSON.stringify({
type: 'message',
data: {
username: channel.phoneNumber,
source: { number: admins[0].memberPhoneNumber },
dataMessage: {
timestamp: new Date().toISOString(),
body: 'PRIVATE There was a wall. It did not look important.',
expiresInSeconds: channel.messageExpiryTime,
attachments: [],
},
},
}),
)
await wait(2 * socketDelay)
})
it('relays the private message to all admins', () => {
const messages = flatten(map(writeStub.getCalls(), 'args'))
expect(messages).to.have.deep.members([
{
type: 'send',
username: channel.phoneNumber,
recipientAddress: { number: admins[0].memberPhoneNumber },
messageBody: `[PRIVATE]\nThere was a wall. It did not look important.`,
attachments: [],
},
{
type: 'send',
username: channel.phoneNumber,
recipientAddress: { number: admins[1].memberPhoneNumber },
messageBody: `[PRIVATE]\nThere was a wall. It did not look important.`,
attachments: [],
},
])
})
})
}) })
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment