Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion taskuary/outbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,15 @@ def reply_to_message(store, msg: dict, body: str, to: list = None, cc: list = No
connector_id = _source_connector_id(store, 'imessage', chat)
return send_text(store, chat, body, connector_id) if connector_id else send_text(store, chat, body)
if ch == 'discord':
from . import chatformat
from .devtools import discord_send
chat = str(msg.get('ConversationId') or '').split(':', 1)[-1] # 'discord:<channel_id>'
if not chat: raise RuntimeError('this chat message has no channel id to answer in')
connector_id = _source_connector_id(store, 'discord', chat)
return discord_send(store, chat, body, connector_id) if connector_id else discord_send(store, chat, body)
pieces = chatformat.split(body, 1900)
sent = [discord_send(store, chat, piece, connector_id) if connector_id else
discord_send(store, chat, piece) for piece in pieces]
return sent[0]
if ch in CHAT_SERVERS:
from . import chatservers
chat = str(msg.get('ConversationId') or '').split(':', 1)[-1] # '<type>:<room id>'
Expand Down
24 changes: 24 additions & 0 deletions tests/test_reply_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@ def test_case_and_blank_are_handled(self):
self.assertFalse(outbound.can_reply(s, None))


class DiscordReplyTests(unittest.TestCase):
def test_long_reply_is_sent_in_order_without_loss(self):
s = MemoryStore()
body = 'x' * 5000
msg = {'Channel': 'discord', 'ConversationId': 'discord:555', 'ExternalId': 'discord:1'}

with mock.patch('taskuary.devtools.discord_send', return_value={'channel': 'discord'}) as send:
outbound.reply_to_message(s, msg, body)

pieces = [call.args[2] for call in send.call_args_list]
self.assertEqual(len(pieces), 3)
self.assertTrue(all(len(piece) <= 2000 for piece in pieces))
self.assertEqual(''.join(pieces), body)

def test_short_reply_is_sent_once_unchanged(self):
s = MemoryStore()
msg = {'Channel': 'discord', 'ConversationId': 'discord:555', 'ExternalId': 'discord:1'}

with mock.patch('taskuary.devtools.discord_send', return_value={'channel': 'discord'}) as send:
outbound.reply_to_message(s, msg, 'On it.')

send.assert_called_once_with(s, '555', 'On it.')


class FinishTests(unittest.TestCase):
"""coder.finish is the truth, and the UI promises exactly what it did: a channel that cannot carry the
reply still gets its draft (the always-draft rule, PW-237) - Send is hidden and the reason said."""
Expand Down