mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	This adds the data model and bugdown support for the new UserGroup mention feature. Before it'll be fully operational, we'll still need: * A backend API for making these. * A UI for interacting with that API. * Typeahead on the frontend. * CSS to make them look pretty and see who's in them.
		
			
				
	
	
		
			43 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
 | 
						|
from typing import Optional, Set, Text
 | 
						|
 | 
						|
import re
 | 
						|
 | 
						|
# Match multi-word string between @** ** or match any one-word
 | 
						|
# sequences after @
 | 
						|
find_mentions = r'(?<![^\s\'\"\(,:<])@(\*\*[^\*]+\*\*|all|everyone)'
 | 
						|
user_group_mentions = r'(?<![^\s\'\"\(,:<])@(\*[^\*]+\*)'
 | 
						|
 | 
						|
wildcards = ['all', 'everyone']
 | 
						|
 | 
						|
def user_mention_matches_wildcard(mention):
 | 
						|
    # type: (Text) -> bool
 | 
						|
    return mention in wildcards
 | 
						|
 | 
						|
def extract_name(s):
 | 
						|
    # type: (Text) -> Optional[Text]
 | 
						|
    if s.startswith("**") and s.endswith("**"):
 | 
						|
        name = s[2:-2]
 | 
						|
        if name in wildcards:
 | 
						|
            return None
 | 
						|
        return name
 | 
						|
 | 
						|
    # We don't care about @all or @everyone
 | 
						|
    return None
 | 
						|
 | 
						|
def possible_mentions(content):
 | 
						|
    # type: (Text) -> Set[Text]
 | 
						|
    matches = re.findall(find_mentions, content)
 | 
						|
    names_with_none = (extract_name(match) for match in matches)
 | 
						|
    names = {name for name in names_with_none if name}
 | 
						|
    return names
 | 
						|
 | 
						|
def extract_user_group(matched_text):
 | 
						|
    # type: (Text) -> Text
 | 
						|
    return matched_text[1:-1]
 | 
						|
 | 
						|
def possible_user_group_mentions(content):
 | 
						|
    # type: (Text) -> Set[Text]
 | 
						|
    matches = re.findall(user_group_mentions, content)
 | 
						|
    return {extract_user_group(match) for match in matches}
 |