mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 21:13:36 +00:00
messages: Add an is_channel_message flag.
This commit is contained in:
committed by
Tim Abbott
parent
e365ac6d11
commit
47d55c4b6f
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
20
zerver/migrations/0690_message_is_channel_message.py
Normal file
20
zerver/migrations/0690_message_is_channel_message.py
Normal file
@@ -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),
|
||||
),
|
||||
]
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user