mirror of
https://github.com/zulip/zulip.git
synced 2025-10-30 03:23:50 +00:00
presence: Extract lib/presence.py.
This will make more sense when we pull some code out of the model.
This commit is contained in:
@@ -4989,15 +4989,6 @@ def filter_presence_idle_user_ids(user_ids: Set[int]) -> List[int]:
|
||||
idle_user_ids = user_ids - active_user_ids
|
||||
return sorted(list(idle_user_ids))
|
||||
|
||||
def get_status_dict(requesting_user_profile: UserProfile,
|
||||
slim_presence: bool) -> Dict[str, Dict[str, Dict[str, Any]]]:
|
||||
|
||||
if requesting_user_profile.realm.presence_disabled:
|
||||
# Return an empty dict if presence is disabled in this realm
|
||||
return defaultdict(dict)
|
||||
|
||||
return UserPresence.get_status_dict_by_realm(requesting_user_profile.realm_id, slim_presence)
|
||||
|
||||
def do_send_confirmation_email(invitee: PreregistrationUser,
|
||||
referrer: UserProfile) -> str:
|
||||
"""
|
||||
|
||||
@@ -27,6 +27,7 @@ from zerver.lib.message import (
|
||||
remove_message_id_from_unread_mgs,
|
||||
)
|
||||
from zerver.lib.narrow import check_supported_events_narrow_filter, read_stop_words
|
||||
from zerver.lib.presence import get_status_dict
|
||||
from zerver.lib.push_notifications import push_notifications_enabled
|
||||
from zerver.lib.soft_deactivation import reactivate_user_if_soft_deactivated
|
||||
from zerver.lib.realm_icon import realm_icon_url
|
||||
@@ -39,7 +40,7 @@ from zerver.lib.actions import (
|
||||
do_get_streams,
|
||||
get_default_streams_for_realm,
|
||||
gather_subscriptions_helper,
|
||||
get_status_dict, streams_to_dicts_sorted,
|
||||
streams_to_dicts_sorted,
|
||||
default_stream_groups_to_dicts_sorted,
|
||||
get_owned_bot_dicts,
|
||||
get_available_notification_sounds,
|
||||
|
||||
19
zerver/lib/presence.py
Normal file
19
zerver/lib/presence.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from collections import defaultdict
|
||||
import time
|
||||
from typing import Any, Dict
|
||||
from zerver.models import UserProfile, UserPresence
|
||||
|
||||
def get_status_dict(requesting_user_profile: UserProfile,
|
||||
slim_presence: bool) -> Dict[str, Dict[str, Dict[str, Any]]]:
|
||||
|
||||
if requesting_user_profile.realm.presence_disabled:
|
||||
# Return an empty dict if presence is disabled in this realm
|
||||
return defaultdict(dict)
|
||||
|
||||
return UserPresence.get_status_dict_by_realm(requesting_user_profile.realm_id, slim_presence)
|
||||
|
||||
def get_presence_response(requesting_user_profile: UserProfile,
|
||||
slim_presence: bool) -> Dict[str, Any]:
|
||||
server_timestamp = time.time()
|
||||
presences = get_status_dict(requesting_user_profile, slim_presence)
|
||||
return dict(presences=presences, server_timestamp=server_timestamp)
|
||||
@@ -1,5 +1,4 @@
|
||||
import datetime
|
||||
import time
|
||||
|
||||
from django.conf import settings
|
||||
from typing import Any, Dict, Optional
|
||||
@@ -11,9 +10,9 @@ from django.utils.translation import ugettext as _
|
||||
from zerver.decorator import human_users_only
|
||||
from zerver.lib.actions import (
|
||||
do_update_user_status,
|
||||
get_status_dict,
|
||||
update_user_presence,
|
||||
)
|
||||
from zerver.lib.presence import get_presence_response
|
||||
from zerver.lib.request import has_request_variables, REQ, JsonableError
|
||||
from zerver.lib.response import json_success, json_error
|
||||
from zerver.lib.timestamp import datetime_to_timestamp
|
||||
@@ -21,12 +20,6 @@ from zerver.lib.validator import check_bool, check_capped_string
|
||||
from zerver.models import UserActivity, UserPresence, UserProfile, \
|
||||
get_active_user_by_delivery_email
|
||||
|
||||
def get_presence_response(requesting_user_profile: UserProfile,
|
||||
slim_presence: bool) -> Dict[str, Any]:
|
||||
server_timestamp = time.time()
|
||||
presences = get_status_dict(requesting_user_profile, slim_presence)
|
||||
return dict(presences=presences, server_timestamp=server_timestamp)
|
||||
|
||||
def get_presence_backend(request: HttpRequest, user_profile: UserProfile,
|
||||
email: str) -> HttpResponse:
|
||||
# This isn't used by the webapp; it's available for API use by
|
||||
|
||||
Reference in New Issue
Block a user