diff --git a/zerver/lib/message.py b/zerver/lib/message.py index f88ee10107..06fb39cf7b 100644 --- a/zerver/lib/message.py +++ b/zerver/lib/message.py @@ -189,6 +189,9 @@ class MessageDict(object): avatar_url = avatar_url, client = sending_client_name) + if obj['type'] == 'stream': + obj['stream_id'] = recipient_type_id + obj['subject_links'] = bugdown.subject_links(sender_realm_id, subject) if last_edit_time != None: diff --git a/zerver/tests/test_messages.py b/zerver/tests/test_messages.py index 7ea65f34d6..27eb357d99 100644 --- a/zerver/tests/test_messages.py +++ b/zerver/tests/test_messages.py @@ -441,6 +441,20 @@ class StreamMessagesTest(ZulipTestCase): self.assert_max_length(queries, 8) + def test_stream_message_dict(self): + # type: () -> None + user_profile = get_user_profile_by_email("iago@zulip.com") + self.subscribe_to_stream(user_profile.email, "Denmark") + self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM, + content="whatever", subject="my topic") + message = most_recent_message(user_profile) + row = Message.get_raw_db_rows([message.id])[0] + dct = MessageDict.build_dict_from_raw_db_row(row, apply_markdown=True) + self.assertEqual(dct['display_recipient'], 'Denmark') + + stream = get_stream('Denmark', user_profile.realm) + self.assertEqual(dct['stream_id'], stream.id) + def test_stream_message_unicode(self): # type: () -> None user_profile = get_user_profile_by_email("iago@zulip.com")