mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
Add message.topic_name() helper function.
This little helper will facilitate adding a new Topic table in the future.
This commit is contained in:
@@ -2445,7 +2445,7 @@ def do_update_message(user_profile, message_id, subject, propagate_mode, content
|
|||||||
check_attachment_reference_change(prev_content, message)
|
check_attachment_reference_change(prev_content, message)
|
||||||
|
|
||||||
if subject is not None:
|
if subject is not None:
|
||||||
orig_subject = message.subject
|
orig_subject = message.topic_name()
|
||||||
subject = truncate_topic(subject)
|
subject = truncate_topic(subject)
|
||||||
event["orig_subject"] = orig_subject
|
event["orig_subject"] = orig_subject
|
||||||
event["propagate_mode"] = propagate_mode
|
event["propagate_mode"] = propagate_mode
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ def build_message_list(user_profile, messages):
|
|||||||
header_html = u"<a style='color: #ffffff;' href='%s'>%s</a>" % (html_link, header)
|
header_html = u"<a style='color: #ffffff;' href='%s'>%s</a>" % (html_link, header)
|
||||||
else:
|
else:
|
||||||
assert isinstance(disp_recipient, text_type)
|
assert isinstance(disp_recipient, text_type)
|
||||||
header = u"%s > %s" % (disp_recipient, message.subject)
|
header = u"%s > %s" % (disp_recipient, message.topic_name())
|
||||||
stream_link = stream_narrow_url(disp_recipient)
|
stream_link = stream_narrow_url(disp_recipient)
|
||||||
topic_link = topic_narrow_url(disp_recipient, message.subject)
|
topic_link = topic_narrow_url(disp_recipient, message.subject)
|
||||||
header_html = u"<a href='%s'>%s</a> > <a href='%s'>%s</a>" % (
|
header_html = u"<a href='%s'>%s</a> > <a href='%s'>%s</a>" % (
|
||||||
@@ -300,7 +300,7 @@ def handle_missedmessage_emails(user_profile_id, missed_email_events):
|
|||||||
|
|
||||||
messages_by_recipient_subject = defaultdict(list) # type: Dict[Tuple[int, text_type], List[Message]]
|
messages_by_recipient_subject = defaultdict(list) # type: Dict[Tuple[int, text_type], List[Message]]
|
||||||
for msg in messages:
|
for msg in messages:
|
||||||
messages_by_recipient_subject[(msg.recipient_id, msg.subject)].append(msg)
|
messages_by_recipient_subject[(msg.recipient_id, msg.topic_name())].append(msg)
|
||||||
|
|
||||||
message_count_by_recipient_subject = {
|
message_count_by_recipient_subject = {
|
||||||
recipient_subject: len(msgs)
|
recipient_subject: len(msgs)
|
||||||
|
|||||||
@@ -780,6 +780,13 @@ class Message(ModelReprMixin, models.Model):
|
|||||||
has_image = models.BooleanField(default=False, db_index=True) # type: bool
|
has_image = models.BooleanField(default=False, db_index=True) # type: bool
|
||||||
has_link = models.BooleanField(default=False, db_index=True) # type: bool
|
has_link = models.BooleanField(default=False, db_index=True) # type: bool
|
||||||
|
|
||||||
|
def topic_name(self):
|
||||||
|
# type: () -> text_type
|
||||||
|
"""
|
||||||
|
Please start using this helper to facilitate an
|
||||||
|
eventual switch over to a separate topic table.
|
||||||
|
"""
|
||||||
|
return self.subject
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
# type: () -> text_type
|
# type: () -> text_type
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class TestStreamEmailMessagesSuccess(AuthedTestCase):
|
|||||||
|
|
||||||
self.assertEqual(message.content, "TestStreamEmailMessages Body")
|
self.assertEqual(message.content, "TestStreamEmailMessages Body")
|
||||||
self.assertEqual(get_display_recipient(message.recipient), stream.name)
|
self.assertEqual(get_display_recipient(message.recipient), stream.name)
|
||||||
self.assertEqual(message.subject, incoming_valid_message['Subject'])
|
self.assertEqual(message.topic_name(), incoming_valid_message['Subject'])
|
||||||
|
|
||||||
class TestStreamEmailMessagesEmptyBody(AuthedTestCase):
|
class TestStreamEmailMessagesEmptyBody(AuthedTestCase):
|
||||||
def test_receive_stream_email_messages_empty_body(self):
|
def test_receive_stream_email_messages_empty_body(self):
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class WebhookTestCase(AuthedTestCase):
|
|||||||
def do_test_subject(self, msg, expected_subject):
|
def do_test_subject(self, msg, expected_subject):
|
||||||
# type: (Message, Optional[text_type]) -> None
|
# type: (Message, Optional[text_type]) -> None
|
||||||
if expected_subject is not None:
|
if expected_subject is not None:
|
||||||
self.assertEqual(msg.subject, expected_subject)
|
self.assertEqual(msg.topic_name(), expected_subject)
|
||||||
|
|
||||||
def do_test_message(self, msg, expected_message):
|
def do_test_message(self, msg, expected_message):
|
||||||
# type: (Message, Optional[text_type]) -> None
|
# type: (Message, Optional[text_type]) -> None
|
||||||
@@ -96,7 +96,7 @@ class JiraHookTests(WebhookTestCase):
|
|||||||
self.get_body('created'),
|
self.get_body('created'),
|
||||||
stream_name="jira_custom",
|
stream_name="jira_custom",
|
||||||
content_type="application/json")
|
content_type="application/json")
|
||||||
self.assertEqual(msg.subject, "BUG-15: New bug with hook")
|
self.assertEqual(msg.topic_name(), "BUG-15: New bug with hook")
|
||||||
self.assertEqual(msg.content, """Leo Franchi **created** [BUG-15](http://lfranchi.com:8080/browse/BUG-15) priority Major, assigned to @**no one**:
|
self.assertEqual(msg.content, """Leo Franchi **created** [BUG-15](http://lfranchi.com:8080/browse/BUG-15) priority Major, assigned to @**no one**:
|
||||||
|
|
||||||
> New bug with hook""")
|
> New bug with hook""")
|
||||||
|
|||||||
@@ -631,7 +631,7 @@ class MessagePOSTTest(AuthedTestCase):
|
|||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
|
|
||||||
sent_message = self.get_last_message()
|
sent_message = self.get_last_message()
|
||||||
self.assertEquals(sent_message.subject,
|
self.assertEquals(sent_message.topic_name(),
|
||||||
"A" * (MAX_SUBJECT_LENGTH - 3) + "...")
|
"A" * (MAX_SUBJECT_LENGTH - 3) + "...")
|
||||||
|
|
||||||
def test_send_forged_message_as_not_superuser(self):
|
def test_send_forged_message_as_not_superuser(self):
|
||||||
@@ -725,7 +725,7 @@ class EditMessageTest(AuthedTestCase):
|
|||||||
uncached = msg.to_dict_uncached_helper(False)
|
uncached = msg.to_dict_uncached_helper(False)
|
||||||
self.assertEqual(cached, uncached)
|
self.assertEqual(cached, uncached)
|
||||||
if subject:
|
if subject:
|
||||||
self.assertEqual(msg.subject, subject)
|
self.assertEqual(msg.topic_name(), subject)
|
||||||
if content:
|
if content:
|
||||||
self.assertEqual(msg.content, content)
|
self.assertEqual(msg.content, content)
|
||||||
return msg
|
return msg
|
||||||
|
|||||||
Reference in New Issue
Block a user