From b9886fe6a0a157b1d9d95afab0d888ef1033c773 Mon Sep 17 00:00:00 2001 From: aguestuser <aguestuser@riseup.net> Date: Fri, 20 Dec 2019 19:37:48 -0500 Subject: [PATCH] [131][WIP] deconfuse messages TODO: translations, testing! --- app/services/dispatcher/messenger.js | 33 +++++++++---------- .../dispatcher/strings/messages/EN.js | 16 ++++++--- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/app/services/dispatcher/messenger.js b/app/services/dispatcher/messenger.js index 4e0698e..94478ab 100644 --- a/app/services/dispatcher/messenger.js +++ b/app/services/dispatcher/messenger.js @@ -18,13 +18,13 @@ const { const messageTypes = { BROADCAST_MESSAGE: 'BROADCAST_MESSAGE', - BROADCAST_RESPONSE: 'BROADCAST_RESPONSE', + HOTLINE_MESSAGE: 'HOTLINE_MESSAGE', COMMAND_RESULT: 'COMMAND_RESULT', NEW_ADMIN_WELCOME: 'NEW_ADMIN_WELCOME', SIGNUP_MESSAGE: 'SIGNUP_MESSAGE', } -const { BROADCAST_MESSAGE, BROADCAST_RESPONSE, COMMAND_RESULT, SIGNUP_MESSAGE } = messageTypes +const { BROADCAST_MESSAGE, HOTLINE_MESSAGE, COMMAND_RESULT, SIGNUP_MESSAGE } = messageTypes const { ADMIN } = memberTypes @@ -38,8 +38,8 @@ const dispatch = async ({ commandResult, dispatchable }) => { switch (messageType) { case BROADCAST_MESSAGE: return broadcast(dispatchable) - case BROADCAST_RESPONSE: - return handleBroadcastResponse(dispatchable) + case HOTLINE_MESSAGE: + return handleHotlineMessage(dispatchable) case COMMAND_RESULT: return handleCommandResult({ commandResult, dispatchable }) case SIGNUP_MESSAGE: @@ -54,7 +54,7 @@ const parseMessageType = (commandResult, { sender, channel }) => { if (commandResult.status === statuses.NOOP) { if (sender.type === ADMIN) return BROADCAST_MESSAGE if (channel.phoneNumber === signupPhoneNumber) return SIGNUP_MESSAGE - return BROADCAST_RESPONSE + return HOTLINE_MESSAGE } return COMMAND_RESULT } @@ -78,20 +78,17 @@ const handleSignupMessage = async ({ sock, channel, sender, sdMessage }) => { }) } -const handleBroadcastResponse = dispatchable => { +const handleHotlineMessage = dispatchable => { const { channel: { responsesEnabled }, - sender: { language }, + sender: { language, type }, } = dispatchable - - if (!responsesEnabled) { - return respond({ - ...dispatchable, - message: messagesIn(language).notifications.unauthorized, - status: statuses.UNAUTHORIZED, - }) - } - return relayBroadcastResponse(dispatchable) + const disabledMessage = messagesIn(language).notifications.hotlineMessagesDisabled( + type === memberTypes.SUBSCRIBER, + ) + return responsesEnabled + ? relayBroadcastResponse(dispatchable) + : respond({ ...dispatchable, status: statuses.UNAUTHORIZED, message: disabledMessage }) } const handleCommandResult = async ({ commandResult, dispatchable }) => { @@ -145,7 +142,7 @@ const relayBroadcastResponse = async ({ db, sock, channel, sender, sdMessage }) const { language } = sender const recipients = channelRepository.getAdminPhoneNumbers(channel) const notification = messagesIn(language).notifications.broadcastResponseSent(channel) - const outMessage = format({ channel, sdMessage, messageType: BROADCAST_RESPONSE, language }) + const outMessage = format({ channel, sdMessage, messageType: HOTLINE_MESSAGE, language }) return signal .broadcastMessage(sock, recipients, outMessage) .then(() => countBroacast({ db, channel })) @@ -184,7 +181,7 @@ const resolvePrefix = (channel, messageType, command, language) => { // INFO & HELP messages provide their own prefixes return '' } - if (messageType === BROADCAST_RESPONSE) { + if (messageType === HOTLINE_MESSAGE) { // subscriber responses get a special header so they don't look like broadcast messages from admins // we clone message to preserve attachments return `[${prefixes.broadcastResponse}]\n` diff --git a/app/services/dispatcher/strings/messages/EN.js b/app/services/dispatcher/strings/messages/EN.js index ad46c72..0839f02 100644 --- a/app/services/dispatcher/strings/messages/EN.js +++ b/app/services/dispatcher/strings/messages/EN.js @@ -5,9 +5,10 @@ const { } = require('../../../../db/repositories/channel') const systemName = 'the signalboost system administrator' -const unauthorized = 'Whoops! You are not authorized to do that on this channel.' +const unauthorized = + 'Your message could not be processed because you are not subscribed to this channel. Send HELLO to subscribe.' const invalidNumber = phoneNumber => - `Whoops! "${phoneNumber}" is not a valid phone number. Phone numbers must include country codes prefixed by a '+'.` + `"${phoneNumber}" is not a valid phone number. Phone numbers must include country codes prefixed by a '+'.` const support = `---------------------------- HOW IT WORKS @@ -36,9 +37,11 @@ const notifications = { adminAdded: (commandIssuer, addedAdmin) => `New Admin ${addedAdmin} added by ${commandIssuer}`, broadcastResponseSent: channel => - `Your message was forwarded to the admins of [${channel.name}]. + `Your message was anonymously forwarded to the admins of [${ + channel.name + }]. Please include your phone number if you want admins to respond to you. -Send HELP to see commands I understand! :)`, +You can also send HELP to list valid commands.`, deauthorization: adminPhoneNumber => ` ${adminPhoneNumber} has been removed from this channel because their safety number changed. @@ -55,6 +58,11 @@ Until then, they will be unable to send messages to or read messages from this c noop: "Whoops! That's not a command!", unauthorized: "Whoops! I don't understand that.\n Send HELP to see commands I understand!", + hotlineMessagesDisabled: isSubscriber => + isSubscriber + ? 'Sorry, incoming messages are not enabled on this channel. Send HELP to list valid commands.' + : 'Sorry, incoming messages are not enabled on this channel. Send HELLO to subscribe.', + welcome: (addingAdmin, channelPhoneNumber) => ` You were just made an admin of this Signalboost channel by ${addingAdmin}. Welcome! -- GitLab