user-status: Update presence_enabled with changes to user status away.

When a user toggles a status update for `away=True|False`, we now update
their `presence_enabled` setting to match (`away!=presence_enabled`).

First step of making user status `away` updates a deprecated way to
access presence_enabled for clients supporting older servers, and
checkpoint commit before migrating users with a current UserStatus
of `status=AWAY` to have their `presence_enabled` set to `False`.

Note that when user status `away` is updated, we now send 4 events:
user_status, user_settings, presence, and update_global_notifications.

Also, this means that these updates change the UserPresence.status
value, which impacts the test for importing and exporting user
information.

Part of transitioning from 'unavailable' user status feature to
'invisible mode' user presence feature.
This commit is contained in:
Lauryn Menard
2022-09-22 11:56:58 +02:00
committed by Tim Abbott
parent 3428fe86d6
commit 843eb4e4fc
4 changed files with 62 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
from typing import Optional
from zerver.actions.user_settings import do_change_user_setting
from zerver.lib.user_status import update_user_status
from zerver.models import UserProfile, UserStatus, active_user_ids
from zerver.tornado.django_api import send_event
@@ -14,6 +15,13 @@ def do_update_user_status(
emoji_code: Optional[str],
reaction_type: Optional[str],
) -> None:
# Deprecated way for clients to access the user's `presence_enabled`
# setting, with away != presence_enabled.
if away is not None:
user_setting = "presence_enabled"
value = not away
do_change_user_setting(user_profile, user_setting, value, acting_user=user_profile)
if away is None:
status = None
elif away: