add_new_user_history: Add missing historical flags.

This commit adds the missing historical flag to recent
messages added in a new user's feed.

Reason:
* User didn't receive when they were sent, so semantically
the 'historical' flag should be present.
* It helps to avoid the "You (un)subscribed to.." bookend
while reading older messages.
The bookend appears whenever the historical flag flips
between adjacent messages. Earlier, the bookend was visible
between 'recent messages' and 'older messages'. This makes
sure that the bookend is visible only at the moment new
message is sent by the user after account creation.
This commit is contained in:
Prakhar Pratyush
2024-06-21 19:06:58 +05:30
committed by Tim Abbott
parent f5a0755f16
commit 485a8a1421
2 changed files with 14 additions and 5 deletions

View File

@@ -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)

View File

@@ -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:
"""