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.

add_new_user_history: Add missing historical flags.

Prakhar Pratyush485a8a142118
diff --git a/zerver/actions/create_user.py b/zerver/actions/create_user.py
index ce2214507f1..8187ca817eb 100644
--- a/zerver/actions/create_user.py
+++ b/zerver/actions/create_user.py
@@ -217,9 +217,11 @@ def add_new_user_history(user_profile: UserProfile, streams: Iterable[Stream]) -
# Create UserMessage rows for the backfill.
ums_to_create = []
for message_id in backfill_message_ids:
- um = UserMessage(user_profile=user_profile, message_id=message_id)
+ um = UserMessage(
+ user_profile=user_profile, message_id=message_id, flags=UserMessage.flags.historical
+ )
if message_id in older_message_ids:
- um.flags = UserMessage.flags.read
+ um.flags |= UserMessage.flags.read
ums_to_create.append(um)
UserMessage.objects.bulk_create(ums_to_create)
diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py
index 40ab6f504a9..dd21f77d730 100644
--- a/zerver/tests/test_signup.py
+++ b/zerver/tests/test_signup.py
@@ -266,7 +266,7 @@ class AddNewUserHistoryTest(ZulipTestCase):
self.assertTrue(
UserMessage.objects.filter(user_profile=user_profile, message_id=message_id).exists()
)
- # The race message is in the user's history and marked unread.
+ # The race message is in the user's history, marked unread & NOT historical.
self.assertTrue(
UserMessage.objects.filter(
user_profile=user_profile, message_id=race_message_id
@@ -277,9 +277,14 @@ class AddNewUserHistoryTest(ZulipTestCase):
user_profile=user_profile, message_id=race_message_id
).flags.read.is_set
)
+ self.assertFalse(
+ UserMessage.objects.get(
+ user_profile=user_profile, message_id=race_message_id
+ ).flags.historical.is_set
+ )
# Verify that the MAX_NUM_RECENT_UNREAD_MESSAGES latest messages
- # that weren't the race message are marked as unread.
+ # that weren't the race message are marked as unread & historical.
latest_messages = (
UserMessage.objects.filter(
user_profile=user_profile,
@@ -291,8 +296,9 @@ class AddNewUserHistoryTest(ZulipTestCase):
self.assert_length(latest_messages, 2)
for msg in latest_messages:
self.assertFalse(msg.flags.read.is_set)
+ self.assertTrue(msg.flags.historical.is_set)
- # Verify that older messages are correctly marked as read.
+ # Verify that older messages are correctly marked as read & historical.
older_messages = (
UserMessage.objects.filter(
user_profile=user_profile,
@@ -306,6 +312,7 @@ class AddNewUserHistoryTest(ZulipTestCase):
self.assertGreater(len(older_messages), 0)
for msg in older_messages:
self.assertTrue(msg.flags.read.is_set)
+ self.assertTrue(msg.flags.historical.is_set)
def test_auto_subbed_to_personals(self) -> None:
"""