soft_deactivation: Change `<` to `<=` in add_missing_messages.

We should still short-circuit the iteration in
`add_missing_messages` if the unsubscription was the last
thing to happen to the user before unsubscription and
soft deactivation.
This commit is contained in:
Ben Reeves 2018-04-15 17:05:14 -04:00 committed by Tim Abbott
parent d4e5777296
commit fdfbd45208
2 changed files with 9 additions and 14 deletions

View File

@ -119,7 +119,7 @@ def add_missing_messages(user_profile: UserProfile) -> None:
for sub in all_stream_subs: for sub in all_stream_subs:
stream_subscription_logs = all_stream_subscription_logs[sub['recipient__type_id']] stream_subscription_logs = all_stream_subscription_logs[sub['recipient__type_id']]
if (stream_subscription_logs[-1].event_type == 'subscription_deactivated' and if (stream_subscription_logs[-1].event_type == 'subscription_deactivated' and
stream_subscription_logs[-1].event_last_message_id < user_profile.last_active_message_id): stream_subscription_logs[-1].event_last_message_id <= user_profile.last_active_message_id):
# We are going to short circuit this iteration as its no use # We are going to short circuit this iteration as its no use
# iterating since user unsubscribed before soft-deactivation # iterating since user unsubscribed before soft-deactivation
continue continue

View File

@ -2811,18 +2811,13 @@ class SoftDeactivationMessageTest(ZulipTestCase):
do_soft_activate_users([long_term_idle_user]) do_soft_activate_users([long_term_idle_user])
self.subscribe(long_term_idle_user, stream_name) self.subscribe(long_term_idle_user, stream_name)
self.unsubscribe(long_term_idle_user, stream_name) # Send a real message to update last_active_message_id
send_fake_message('Test Message 9', stream)
# Send a (not fake) message to another stream that the user is
# subscribed to so that their last_active_message_id field will
# be greater than the event_last_message_id of the unsubscription.
other_stream_name = 'Verona'
self.subscribe(long_term_idle_user, other_stream_name)
sent_message_id = self.send_stream_message( sent_message_id = self.send_stream_message(
sender.email, other_stream_name, 'Test Message 10') sender.email, stream_name, 'Test Message 9')
self.unsubscribe(long_term_idle_user, stream_name)
# Soft deactivate and send another message to the unsubscribed stream. # Soft deactivate and send another message to the unsubscribed stream.
do_soft_deactivate_users([long_term_idle_user]) do_soft_deactivate_users([long_term_idle_user])
send_fake_message('Test Message 11', stream) send_fake_message('Test Message 10', stream)
idle_user_msg_list = get_user_messages(long_term_idle_user) idle_user_msg_list = get_user_messages(long_term_idle_user)
idle_user_msg_count = len(idle_user_msg_list) idle_user_msg_count = len(idle_user_msg_list)
@ -2844,13 +2839,13 @@ class SoftDeactivationMessageTest(ZulipTestCase):
private_stream = self.make_stream('Core', invite_only=True) private_stream = self.make_stream('Core', invite_only=True)
self.subscribe(self.example_user("iago"), stream_name) self.subscribe(self.example_user("iago"), stream_name)
sent_message_list = [] sent_message_list = []
send_fake_message('Test Message 12', private_stream) send_fake_message('Test Message 11', private_stream)
self.subscribe(self.example_user("hamlet"), stream_name) self.subscribe(self.example_user("hamlet"), stream_name)
sent_message_list.append(send_fake_message('Test Message 13', private_stream)) sent_message_list.append(send_fake_message('Test Message 12', private_stream))
self.unsubscribe(long_term_idle_user, stream_name) self.unsubscribe(long_term_idle_user, stream_name)
send_fake_message('Test Message 14', private_stream) send_fake_message('Test Message 13', private_stream)
self.subscribe(long_term_idle_user, stream_name) self.subscribe(long_term_idle_user, stream_name)
sent_message_list.append(send_fake_message('Test Message 15', private_stream)) sent_message_list.append(send_fake_message('Test Message 14', private_stream))
sent_message_list.reverse() sent_message_list.reverse()
idle_user_msg_list = get_user_messages(long_term_idle_user) idle_user_msg_list = get_user_messages(long_term_idle_user)
idle_user_msg_count = len(idle_user_msg_list) idle_user_msg_count = len(idle_user_msg_list)