mirror of https://github.com/zulip/zulip.git
user_status: Fix bug with resetting away status.
The fix is pretty simple here--if the client doesn't send an away status, then don't change it. I improved the tests to cover this case. Fixes #17071
This commit is contained in:
parent
5da304d902
commit
36b1794c1d
|
@ -4183,7 +4183,9 @@ def do_update_user_status(user_profile: UserProfile,
|
||||||
away: Optional[bool],
|
away: Optional[bool],
|
||||||
status_text: Optional[str],
|
status_text: Optional[str],
|
||||||
client_id: int) -> None:
|
client_id: int) -> None:
|
||||||
if away:
|
if away is None:
|
||||||
|
status = None
|
||||||
|
elif away:
|
||||||
status = UserStatus.AWAY
|
status = UserStatus.AWAY
|
||||||
else:
|
else:
|
||||||
status = UserStatus.NORMAL
|
status = UserStatus.NORMAL
|
||||||
|
|
|
@ -230,3 +230,40 @@ class UserStatusTest(ZulipTestCase):
|
||||||
get_user_info_dict(realm_id=realm_id),
|
get_user_info_dict(realm_id=realm_id),
|
||||||
{},
|
{},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Turn on "away" status again.
|
||||||
|
payload = dict(away=orjson.dumps(True).decode())
|
||||||
|
|
||||||
|
event_info = EventInfo()
|
||||||
|
with capture_event(event_info):
|
||||||
|
result = self.client_post('/json/users/me/status', payload)
|
||||||
|
self.assert_json_success(result)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
event_info.payload,
|
||||||
|
dict(type='user_status', user_id=hamlet.id, away=True),
|
||||||
|
)
|
||||||
|
|
||||||
|
away_user_ids = get_away_user_ids(realm_id=realm_id)
|
||||||
|
self.assertEqual(away_user_ids, {hamlet.id})
|
||||||
|
|
||||||
|
# And set status text while away.
|
||||||
|
payload = dict(status_text=' at the beach ')
|
||||||
|
|
||||||
|
event_info = EventInfo()
|
||||||
|
with capture_event(event_info):
|
||||||
|
result = self.client_post('/json/users/me/status', payload)
|
||||||
|
self.assert_json_success(result)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
event_info.payload,
|
||||||
|
dict(type='user_status', user_id=hamlet.id, status_text='at the beach'),
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
user_info(hamlet),
|
||||||
|
dict(status_text='at the beach', away=True),
|
||||||
|
)
|
||||||
|
|
||||||
|
away_user_ids = get_away_user_ids(realm_id=realm_id)
|
||||||
|
self.assertEqual(away_user_ids, {hamlet.id})
|
||||||
|
|
Loading…
Reference in New Issue