mirror of https://github.com/zulip/zulip.git
bugdown: Add mention_data.get_user_by_id().
This will allow us to do the lookups required to support the upcoming `@**name|id**` syntax.
This commit is contained in:
parent
8a61ac3500
commit
920ef2b7f7
|
@ -1811,8 +1811,8 @@ class MentionData:
|
|||
def __init__(self, realm_id: int, content: str) -> None:
|
||||
full_names = possible_mentions(content)
|
||||
self.full_name_info = get_full_name_info(realm_id, full_names)
|
||||
self.user_ids = {
|
||||
row['id']
|
||||
self.user_id_info = {
|
||||
row['id']: row
|
||||
for row in self.full_name_info.values()
|
||||
}
|
||||
|
||||
|
@ -1829,6 +1829,9 @@ class MentionData:
|
|||
def get_user(self, name: str) -> Optional[FullNameInfo]:
|
||||
return self.full_name_info.get(name.lower(), None)
|
||||
|
||||
def get_user_by_id(self, id: str) -> Optional[FullNameInfo]:
|
||||
return self.user_id_info.get(int(id), None)
|
||||
|
||||
def get_user_ids(self) -> Set[int]:
|
||||
"""
|
||||
Returns the user IDs that might have been mentioned by this
|
||||
|
@ -1836,7 +1839,7 @@ class MentionData:
|
|||
the message and does not know about escaping/code blocks, this
|
||||
will overestimate the list of user ids.
|
||||
"""
|
||||
return self.user_ids
|
||||
return set(self.user_id_info.keys())
|
||||
|
||||
def get_user_group(self, name: str) -> Optional[UserGroup]:
|
||||
return self.user_group_name_info.get(name.lower(), None)
|
||||
|
|
|
@ -215,6 +215,11 @@ class BugdownMiscTest(ZulipTestCase):
|
|||
content = '@**King Hamlet** @**Cordelia lear**'
|
||||
mention_data = bugdown.MentionData(realm.id, content)
|
||||
self.assertEqual(mention_data.get_user_ids(), {hamlet.id, cordelia.id})
|
||||
self.assertEqual(mention_data.get_user_by_id(hamlet.id), dict(
|
||||
email=hamlet.email,
|
||||
full_name=hamlet.full_name,
|
||||
id=hamlet.id
|
||||
))
|
||||
|
||||
user = mention_data.get_user('king hamLET')
|
||||
assert(user is not None)
|
||||
|
|
Loading…
Reference in New Issue