github.com/rajatvaryani/mattermost-server@v5.11.1+incompatible/model/channel_mentions.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package model
     5  
     6  import (
     7  	"regexp"
     8  	"strings"
     9  )
    10  
    11  var channelMentionRegexp = regexp.MustCompile(`\B~[a-zA-Z0-9\-_]+`)
    12  
    13  func ChannelMentions(message string) []string {
    14  	var names []string
    15  
    16  	if strings.Contains(message, "~") {
    17  		alreadyMentioned := make(map[string]bool)
    18  		for _, match := range channelMentionRegexp.FindAllString(message, -1) {
    19  			name := match[1:]
    20  			if !alreadyMentioned[name] {
    21  				names = append(names, name)
    22  				alreadyMentioned[name] = true
    23  			}
    24  		}
    25  	}
    26  
    27  	return names
    28  }