2024-07-31 15:36:00 +02:00
|
|
|
from django.db import transaction
|
|
|
|
|
2022-09-22 11:56:58 +02:00
|
|
|
from zerver.actions.user_settings import do_change_user_setting
|
2022-09-16 18:05:17 +02:00
|
|
|
from zerver.lib.user_status import update_user_status
|
2023-10-17 12:56:39 +02:00
|
|
|
from zerver.lib.users import get_user_ids_who_can_access_user
|
|
|
|
from zerver.models import UserProfile
|
2024-07-31 15:36:00 +02:00
|
|
|
from zerver.tornado.django_api import send_event_on_commit
|
2022-09-16 18:05:17 +02:00
|
|
|
|
|
|
|
|
2024-07-31 15:36:00 +02:00
|
|
|
@transaction.atomic(savepoint=False)
|
2022-09-16 18:05:17 +02:00
|
|
|
def do_update_user_status(
|
|
|
|
user_profile: UserProfile,
|
2024-07-12 02:30:23 +02:00
|
|
|
away: bool | None,
|
|
|
|
status_text: str | None,
|
2022-09-16 18:05:17 +02:00
|
|
|
client_id: int,
|
2024-07-12 02:30:23 +02:00
|
|
|
emoji_name: str | None,
|
|
|
|
emoji_code: str | None,
|
|
|
|
reaction_type: str | None,
|
2022-09-16 18:05:17 +02:00
|
|
|
) -> None:
|
2022-09-22 11:56:58 +02:00
|
|
|
# Deprecated way for clients to access the user's `presence_enabled`
|
2022-09-22 12:21:00 +02:00
|
|
|
# setting, with away != presence_enabled. Can be removed when clients
|
|
|
|
# migrate "away" (also referred to as "unavailable") feature to directly
|
|
|
|
# use and update the user's presence_enabled setting.
|
2022-09-22 11:56:58 +02:00
|
|
|
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)
|
|
|
|
|
2022-09-16 18:05:17 +02:00
|
|
|
realm = user_profile.realm
|
|
|
|
|
|
|
|
update_user_status(
|
|
|
|
user_profile_id=user_profile.id,
|
|
|
|
status_text=status_text,
|
|
|
|
client_id=client_id,
|
|
|
|
emoji_name=emoji_name,
|
|
|
|
emoji_code=emoji_code,
|
|
|
|
reaction_type=reaction_type,
|
|
|
|
)
|
|
|
|
|
|
|
|
event = dict(
|
|
|
|
type="user_status",
|
|
|
|
user_id=user_profile.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
if away is not None:
|
|
|
|
event["away"] = away
|
|
|
|
|
|
|
|
if status_text is not None:
|
|
|
|
event["status_text"] = status_text
|
|
|
|
|
|
|
|
if emoji_name is not None:
|
|
|
|
event["emoji_name"] = emoji_name
|
|
|
|
event["emoji_code"] = emoji_code
|
|
|
|
event["reaction_type"] = reaction_type
|
2024-07-31 15:36:00 +02:00
|
|
|
send_event_on_commit(realm, event, get_user_ids_who_can_access_user(user_profile))
|