2019-01-21 19:06:03 +01:00
|
|
|
from django.db.models import Q
|
2018-12-17 16:19:18 +01:00
|
|
|
from django.utils.timezone import now as timezone_now
|
|
|
|
|
|
|
|
from zerver.models import (
|
|
|
|
UserStatus,
|
|
|
|
)
|
|
|
|
|
2019-01-21 19:06:03 +01:00
|
|
|
from typing import Any, Dict, Optional
|
2018-12-17 16:19:18 +01:00
|
|
|
|
2019-01-21 19:06:03 +01:00
|
|
|
def get_user_info_dict(realm_id: int) -> Dict[int, Dict[str, Any]]:
|
|
|
|
rows = UserStatus.objects.filter(
|
2018-12-17 16:19:18 +01:00
|
|
|
user_profile__realm_id=realm_id,
|
|
|
|
user_profile__is_active=True,
|
2019-01-21 19:06:03 +01:00
|
|
|
).exclude(
|
|
|
|
Q(status=UserStatus.NORMAL) &
|
|
|
|
Q(status_text='')
|
|
|
|
).values(
|
|
|
|
'user_profile_id',
|
|
|
|
'status',
|
|
|
|
'status_text',
|
|
|
|
)
|
|
|
|
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
user_dict: Dict[int, Dict[str, Any]] = dict()
|
2019-01-21 19:06:03 +01:00
|
|
|
for row in rows:
|
|
|
|
away = row['status'] == UserStatus.AWAY
|
|
|
|
status_text = row['status_text']
|
|
|
|
user_id = row['user_profile_id']
|
|
|
|
|
|
|
|
dct = dict()
|
|
|
|
if away:
|
|
|
|
dct['away'] = away
|
|
|
|
if status_text:
|
|
|
|
dct['status_text'] = status_text
|
2018-12-17 16:19:18 +01:00
|
|
|
|
2019-01-21 19:06:03 +01:00
|
|
|
user_dict[user_id] = dct
|
|
|
|
|
|
|
|
return user_dict
|
2018-12-17 16:19:18 +01:00
|
|
|
|
2019-01-21 18:19:59 +01:00
|
|
|
def update_user_status(user_profile_id: int,
|
2019-01-21 19:06:03 +01:00
|
|
|
status: Optional[int],
|
|
|
|
status_text: Optional[str],
|
2019-01-21 18:19:59 +01:00
|
|
|
client_id: int) -> None:
|
2018-12-17 16:19:18 +01:00
|
|
|
|
|
|
|
timestamp = timezone_now()
|
|
|
|
|
2019-01-21 18:19:59 +01:00
|
|
|
defaults = dict(
|
|
|
|
client_id=client_id,
|
|
|
|
timestamp=timestamp,
|
2018-12-17 16:19:18 +01:00
|
|
|
)
|
|
|
|
|
2019-01-21 19:06:03 +01:00
|
|
|
if status is not None:
|
|
|
|
defaults['status'] = status
|
|
|
|
|
|
|
|
if status_text is not None:
|
|
|
|
defaults['status_text'] = status_text
|
2019-01-21 18:19:59 +01:00
|
|
|
|
|
|
|
UserStatus.objects.update_or_create(
|
2018-12-17 16:19:18 +01:00
|
|
|
user_profile_id=user_profile_id,
|
2019-01-21 18:19:59 +01:00
|
|
|
defaults=defaults,
|
|
|
|
)
|