Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

messages: Add an is_channel_message flag.

Alex Vandiver47d55c4b6f4a
diff --git a/zerver/actions/message_send.py b/zerver/actions/message_send.py
index d598e231770..722b6f3211e 100644
--- a/zerver/actions/message_send.py
+++ b/zerver/actions/message_send.py
@@ -1803,6 +1803,9 @@ def check_message(
message.realm = realm
if addressee.is_stream():
message.set_topic_name(topic_name)
+ message.is_channel_message = True
+ else:
+ message.is_channel_message = False
if forged and forged_timestamp is not None:
# Forged messages come with a timestamp
message.date_sent = timestamp_to_datetime(forged_timestamp)
diff --git a/zerver/data_import/import_util.py b/zerver/data_import/import_util.py
index e4f18b5a78e..4801928c185 100644
--- a/zerver/data_import/import_util.py
+++ b/zerver/data_import/import_util.py
@@ -495,6 +495,7 @@ def build_message(
user_id: int,
recipient_id: int,
realm_id: int,
+ is_channel_message: bool,
has_image: bool = False,
has_link: bool = False,
has_attachment: bool = True,
@@ -506,6 +507,7 @@ def build_message(
id=message_id,
content=content,
rendered_content=rendered_content,
+ is_channel_message=is_channel_message,
has_image=has_image,
has_attachment=has_attachment,
has_link=has_link,
diff --git a/zerver/data_import/mattermost.py b/zerver/data_import/mattermost.py
index 530e966f1ca..04dcd9554e8 100644
--- a/zerver/data_import/mattermost.py
+++ b/zerver/data_import/mattermost.py
@@ -497,6 +497,7 @@ def process_raw_message_batch(
rendered_content=rendered_content,
topic_name=topic_name,
user_id=sender_user_id,
+ is_channel_message=not is_pm_data,
has_image=has_image,
has_link=has_link,
has_attachment=has_attachment,
diff --git a/zerver/data_import/rocketchat.py b/zerver/data_import/rocketchat.py
index dc3a91154e7..44fba297fba 100644
--- a/zerver/data_import/rocketchat.py
+++ b/zerver/data_import/rocketchat.py
@@ -517,6 +517,7 @@ def process_raw_message_batch(
has_attachment = False
has_image = False
has_link = raw_message["has_link"]
+ is_channel_message = raw_message["is_channel_message"]
if "file" in raw_message:
has_attachment = True
@@ -547,6 +548,7 @@ def process_raw_message_batch(
rendered_content=rendered_content,
topic_name=topic_name,
user_id=sender_user_id,
+ is_channel_message=is_channel_message,
has_image=has_image,
has_link=has_link,
has_attachment=has_attachment,
@@ -676,6 +678,7 @@ def process_messages(
if is_pm_data:
# Message is in a 1:1 or group direct message.
rc_channel_id = message["rid"]
+ message_dict["is_channel_message"] = False
if rc_channel_id in direct_message_group_id_to_direct_message_group_map:
direct_message_group_id = direct_message_group_id_mapper.get(rc_channel_id)
message_dict["recipient_id"] = direct_message_group_id_to_recipient_id[
@@ -695,11 +698,13 @@ def process_messages(
message_dict["recipient_id"] = user_id_to_recipient_id[zulip_member_id]
elif message["rid"] in dsc_id_to_dsc_map:
# Message is in a discussion
+ message_dict["is_channel_message"] = True
dsc_channel = dsc_id_to_dsc_map[message["rid"]]
parent_channel_id = dsc_channel["prid"]
stream_id = stream_id_mapper.get(parent_channel_id)
message_dict["recipient_id"] = stream_id_to_recipient_id[stream_id]
else:
+ message_dict["is_channel_message"] = True
stream_id = stream_id_mapper.get(message["rid"])
message_dict["recipient_id"] = stream_id_to_recipient_id[stream_id]
diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.py
index 082e5697c85..e275a3b7461 100644
--- a/zerver/data_import/slack.py
+++ b/zerver/data_import/slack.py
@@ -1028,6 +1028,7 @@ def channel_message_to_zerver_message(
user_id=slack_user_id_to_zulip_user_id[slack_user_id],
recipient_id=recipient_id,
realm_id=realm_id,
+ is_channel_message=not is_private,
has_image=has_image,
has_link=has_link,
has_attachment=has_attachment,
diff --git a/zerver/migrations/0690_message_is_channel_message.py b/zerver/migrations/0690_message_is_channel_message.py
new file mode 100644
index 00000000000..34c430b4222
--- /dev/null
+++ b/zerver/migrations/0690_message_is_channel_message.py
@@ -0,0 +1,20 @@
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("zerver", "0689_mark_navigation_tour_video_as_read"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="archivedmessage",
+ name="is_channel_message",
+ field=models.BooleanField(db_index=True, default=True, null=True),
+ ),
+ migrations.AddField(
+ model_name="message",
+ name="is_channel_message",
+ field=models.BooleanField(db_index=True, default=True, null=True),
+ ),
+ ]
diff --git a/zerver/models/messages.py b/zerver/models/messages.py
index a19e0ad9cc1..8a09e352a4f 100644
--- a/zerver/models/messages.py
+++ b/zerver/models/messages.py
@@ -97,6 +97,8 @@ class AbstractMessage(models.Model):
has_image = models.BooleanField(default=False, db_index=True)
# Whether the message contains a link.
has_link = models.BooleanField(default=False, db_index=True)
+ # If the message is a channel message (as opposed to a DM or group-DM)
+ is_channel_message = models.BooleanField(default=True, null=True, db_index=True)
class Meta:
abstract = True
diff --git a/zerver/tests/test_message_send.py b/zerver/tests/test_message_send.py
index fa852b8548d..f2a800540b9 100644
--- a/zerver/tests/test_message_send.py
+++ b/zerver/tests/test_message_send.py
@@ -1818,6 +1818,18 @@ class StreamMessagesTest(ZulipTestCase):
).flags.is_private.is_set
)
+ def test_is_channel_message(self) -> None:
+ user_profile = self.example_user("iago")
+ self.subscribe(user_profile, "Denmark")
+
+ self.send_stream_message(self.example_user("hamlet"), "Denmark", content="test")
+ message = most_recent_message(user_profile)
+ self.assertTrue(message.is_channel_message)
+
+ self.send_personal_message(self.example_user("hamlet"), user_profile, content="test")
+ message = most_recent_message(user_profile)
+ self.assertFalse(message.is_channel_message)
+
def _send_stream_message(self, user: UserProfile, stream_name: str, content: str) -> set[int]:
with self.capture_send_event_calls(expected_num_events=1) as events:
self.send_stream_message(