2018-12-17 16:19:18 +01:00
|
|
|
from django.utils.timezone import now as timezone_now
|
|
|
|
|
|
|
|
from zerver.models import (
|
|
|
|
UserStatus,
|
|
|
|
)
|
|
|
|
|
|
|
|
from typing import Set
|
|
|
|
|
|
|
|
def get_away_user_ids(realm_id: int) -> Set[int]:
|
|
|
|
user_ids = UserStatus.objects.filter(
|
|
|
|
status=UserStatus.AWAY,
|
|
|
|
user_profile__realm_id=realm_id,
|
|
|
|
user_profile__is_active=True,
|
|
|
|
).values_list('user_profile_id', flat=True)
|
|
|
|
|
|
|
|
return set(user_ids)
|
|
|
|
|
2019-01-21 18:19:59 +01:00
|
|
|
def update_user_status(user_profile_id: int,
|
|
|
|
status: int,
|
|
|
|
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 18:19:59 +01:00
|
|
|
defaults['status'] = status
|
|
|
|
|
|
|
|
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,
|
|
|
|
)
|