user status: Restructure code.

We now have single function that handle both away
and not-away.

This refactoring sets us up to piggyback "info" more
easily onto status updates.

The only thing that changes here is that we don't
delete database rows any more when users revoke
their away status.  Instead we just set the status
to NORMAL.
This commit is contained in:
Steve Howell
2019-01-21 17:19:59 +00:00
committed by Tim Abbott
parent 7e904c3a1a
commit ac861f2b7d
5 changed files with 57 additions and 57 deletions

View File

@@ -15,22 +15,20 @@ def get_away_user_ids(realm_id: int) -> Set[int]:
return set(user_ids)
def set_away_status(user_profile_id: int,
client_id: int) -> None:
def update_user_status(user_profile_id: int,
status: int,
client_id: int) -> None:
timestamp = timezone_now()
status = UserStatus.AWAY
defaults = dict(
client_id=client_id,
timestamp=timestamp,
)
defaults['status'] = status
UserStatus.objects.update_or_create(
user_profile_id=user_profile_id,
defaults=dict(
client_id=client_id,
timestamp=timestamp,
status=status,
),
defaults=defaults,
)
def revoke_away_status(user_profile_id: int) -> None:
UserStatus.objects.filter(
user_profile_id=user_profile_id,
).delete()