Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
mention: Refactor 'extract_mention_text' to return dataclass.
Prakhar Pratyushd78bdc092f2f
diff --git a/zerver/lib/mention.py b/zerver/lib/mention.pyindex 0d03d27a7f2..b76fa61aebd 100644--- a/zerver/lib/mention.py+++ b/zerver/lib/mention.py@@ -43,6 +43,12 @@ class UserFilter:raise AssertionError("totally empty filter makes no sense")+@dataclass+class MentionText:+ text: Optional[str]+ is_wildcard: bool++class MentionBackend:def __init__(self, realm_id: int) -> None:self.realm_id = realm_id@@ -139,11 +145,11 @@ def user_mention_matches_wildcard(mention: str) -> bool:return mention in wildcards-def extract_mention_text(m: Match[str]) -> Tuple[Optional[str], bool]:+def extract_mention_text(m: Match[str]) -> MentionText:text = m.group("match")if text in wildcards:- return None, True- return text, False+ return MentionText(text=None, is_wildcard=True)+ return MentionText(text=text, is_wildcard=False)def possible_mentions(content: str) -> Tuple[Set[str], bool]:@@ -151,10 +157,11 @@ def possible_mentions(content: str) -> Tuple[Set[str], bool]:texts = set()message_has_wildcards = Falsefor m in MENTIONS_RE.finditer(content):- text, is_wildcard = extract_mention_text(m)+ mention_text = extract_mention_text(m)+ text = mention_text.textif text:texts.add(text)- if is_wildcard:+ if mention_text.is_wildcard:message_has_wildcards = Truereturn texts, message_has_wildcards