mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 19:06:09 +00:00
user_status: Use strings as dict keys.
JSON keys must be strings, and orjson enforces this. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
a329b538d2
commit
fe5c524890
@@ -804,28 +804,28 @@ def apply_event(state: Dict[str, Any],
|
|||||||
state['realm_user_groups'] = [ug for ug in state['realm_user_groups']
|
state['realm_user_groups'] = [ug for ug in state['realm_user_groups']
|
||||||
if ug['id'] != event['group_id']]
|
if ug['id'] != event['group_id']]
|
||||||
elif event['type'] == 'user_status':
|
elif event['type'] == 'user_status':
|
||||||
user_id = event['user_id']
|
user_id_str = str(event['user_id'])
|
||||||
user_status = state['user_status']
|
user_status = state['user_status']
|
||||||
away = event.get('away')
|
away = event.get('away')
|
||||||
status_text = event.get('status_text')
|
status_text = event.get('status_text')
|
||||||
|
|
||||||
if user_id not in user_status:
|
if user_id_str not in user_status:
|
||||||
user_status[user_id] = dict()
|
user_status[user_id_str] = dict()
|
||||||
|
|
||||||
if away is not None:
|
if away is not None:
|
||||||
if away:
|
if away:
|
||||||
user_status[user_id]['away'] = True
|
user_status[user_id_str]['away'] = True
|
||||||
else:
|
else:
|
||||||
user_status[user_id].pop('away', None)
|
user_status[user_id_str].pop('away', None)
|
||||||
|
|
||||||
if status_text is not None:
|
if status_text is not None:
|
||||||
if status_text == '':
|
if status_text == '':
|
||||||
user_status[user_id].pop('status_text', None)
|
user_status[user_id_str].pop('status_text', None)
|
||||||
else:
|
else:
|
||||||
user_status[user_id]['status_text'] = status_text
|
user_status[user_id_str]['status_text'] = status_text
|
||||||
|
|
||||||
if not user_status[user_id]:
|
if not user_status[user_id_str]:
|
||||||
user_status.pop(user_id, None)
|
user_status.pop(user_id_str, None)
|
||||||
|
|
||||||
state['user_status'] = user_status
|
state['user_status'] = user_status
|
||||||
elif event['type'] == 'has_zoom_token':
|
elif event['type'] == 'has_zoom_token':
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from django.utils.timezone import now as timezone_now
|
|||||||
from zerver.models import UserStatus
|
from zerver.models import UserStatus
|
||||||
|
|
||||||
|
|
||||||
def get_user_info_dict(realm_id: int) -> Dict[int, Dict[str, Any]]:
|
def get_user_info_dict(realm_id: int) -> Dict[str, Dict[str, Any]]:
|
||||||
rows = UserStatus.objects.filter(
|
rows = UserStatus.objects.filter(
|
||||||
user_profile__realm_id=realm_id,
|
user_profile__realm_id=realm_id,
|
||||||
user_profile__is_active=True,
|
user_profile__is_active=True,
|
||||||
@@ -19,7 +19,7 @@ def get_user_info_dict(realm_id: int) -> Dict[int, Dict[str, Any]]:
|
|||||||
'status_text',
|
'status_text',
|
||||||
)
|
)
|
||||||
|
|
||||||
user_dict: Dict[int, Dict[str, Any]] = dict()
|
user_dict: Dict[str, Dict[str, Any]] = dict()
|
||||||
for row in rows:
|
for row in rows:
|
||||||
away = row['status'] == UserStatus.AWAY
|
away = row['status'] == UserStatus.AWAY
|
||||||
status_text = row['status_text']
|
status_text = row['status_text']
|
||||||
@@ -31,7 +31,7 @@ def get_user_info_dict(realm_id: int) -> Dict[int, Dict[str, Any]]:
|
|||||||
if status_text:
|
if status_text:
|
||||||
dct['status_text'] = status_text
|
dct['status_text'] = status_text
|
||||||
|
|
||||||
user_dict[user_id] = dct
|
user_dict[str(user_id)] = dct
|
||||||
|
|
||||||
return user_dict
|
return user_dict
|
||||||
|
|
||||||
|
|||||||
@@ -12,14 +12,14 @@ def get_away_user_ids(realm_id: int) -> Set[int]:
|
|||||||
user_dict = get_user_info_dict(realm_id)
|
user_dict = get_user_info_dict(realm_id)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
user_id
|
int(user_id)
|
||||||
for user_id in user_dict
|
for user_id in user_dict
|
||||||
if user_dict[user_id].get('away')
|
if user_dict[user_id].get('away')
|
||||||
}
|
}
|
||||||
|
|
||||||
def user_info(user: UserProfile) -> Dict[str, Any]:
|
def user_info(user: UserProfile) -> Dict[str, Any]:
|
||||||
user_dict = get_user_info_dict(user.realm_id)
|
user_dict = get_user_info_dict(user.realm_id)
|
||||||
return user_dict.get(user.id, dict())
|
return user_dict.get(str(user.id), dict())
|
||||||
|
|
||||||
class UserStatusTest(ZulipTestCase):
|
class UserStatusTest(ZulipTestCase):
|
||||||
def test_basics(self) -> None:
|
def test_basics(self) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user