def update_active_status_backend( request: HttpRequest, user_profile: UserProfile, status: str = REQ(), ping_only: bool = REQ(validator=check_bool, default=False), new_user_input: bool = REQ(validator=check_bool, default=False), slim_presence: bool = REQ(validator=check_bool, default=False), ) -> HttpResponse: status_val = UserPresence.status_from_string(status) if status_val is None: raise JsonableError(_("Invalid status: {}").format(status)) elif user_profile.presence_enabled: update_user_presence(user_profile, request.client, timezone_now(), status_val, new_user_input) if ping_only: ret: Dict[str, Any] = {} else: ret = get_presence_response(user_profile, slim_presence) if user_profile.realm.is_zephyr_mirror_realm: # In zephyr mirroring realms, users can't see the presence of other # users, but each user **is** interested in whether their mirror bot # (running as their user) has been active. try: activity = UserActivity.objects.get(user_profile=user_profile, query="get_events", client__name="zephyr_mirror") ret["zephyr_mirror_active"] = activity.last_visit > timezone_now( ) - datetime.timedelta(minutes=5) except UserActivity.DoesNotExist: ret["zephyr_mirror_active"] = False return json_success(ret)
def update_active_status_backend(request, user_profile, status=REQ(), new_user_input=REQ(validator=check_bool, default=False)): # type: (HttpRequest, UserProfile, str, bool) -> HttpResponse status_val = UserPresence.status_from_string(status) if status_val is None: raise JsonableError(_("Invalid status: %s") % (status,)) else: update_user_presence(user_profile, request.client, timezone.now(), status_val, new_user_input) ret = get_status_list(user_profile) if user_profile.realm.is_zephyr_mirror_realm: # In zephyr mirroring realms, users can't see the presence of other # users, but each user **is** interested in whether their mirror bot # (running as their user) has been active. try: activity = UserActivity.objects.get(user_profile = user_profile, query="get_events_backend", client__name="zephyr_mirror") ret['zephyr_mirror_active'] = \ (activity.last_visit > timezone.now() - datetime.timedelta(minutes=5)) except UserActivity.DoesNotExist: ret['zephyr_mirror_active'] = False return json_success(ret)
def update_active_status_backend(request, user_profile, status=REQ(), ping_only=REQ(validator=check_bool, default=False), new_user_input=REQ(validator=check_bool, default=False)): # type: (HttpRequest, UserProfile, str, bool, bool) -> HttpResponse status_val = UserPresence.status_from_string(status) if status_val is None: raise JsonableError(_("Invalid status: %s") % (status,)) else: update_user_presence(user_profile, request.client, timezone.now(), status_val, new_user_input) if ping_only: ret = {} # type: Dict[str, Any] else: ret = get_status_list(user_profile) if user_profile.realm.is_zephyr_mirror_realm: # In zephyr mirroring realms, users can't see the presence of other # users, but each user **is** interested in whether their mirror bot # (running as their user) has been active. try: activity = UserActivity.objects.get(user_profile = user_profile, query="get_events_backend", client__name="zephyr_mirror") ret['zephyr_mirror_active'] = \ (activity.last_visit > timezone.now() - datetime.timedelta(minutes=5)) except UserActivity.DoesNotExist: ret['zephyr_mirror_active'] = False return json_success(ret)
def update_active_status_backend(request, user_profile, status=REQ(), new_user_input=REQ(validator=check_bool, default=False)): # type: (HttpRequest, UserProfile, str, bool) -> HttpResponse status_val = UserPresence.status_from_string(status) if status_val is None: raise JsonableError(_("Invalid presence status: %s") % (status,)) else: update_user_presence(user_profile, request.client, now(), status_val, new_user_input) ret = get_status_list(user_profile) if user_profile.realm.is_zephyr_mirror_realm: # Presence is disabled in zephyr mirroring realms try: activity = UserActivity.objects.get(user_profile = user_profile, query="get_events_backend", client__name="zephyr_mirror") ret['zephyr_mirror_active'] = \ (activity.last_visit.replace(tzinfo=None) > datetime.datetime.utcnow() - datetime.timedelta(minutes=5)) except UserActivity.DoesNotExist: ret['zephyr_mirror_active'] = False return json_success(ret)