diff options
author | Wim <wim@42.be> | 2023-08-05 20:43:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-05 20:43:19 +0200 |
commit | 56e7bd01ca09ad52b0c4f48f146a20a4f1b78696 (patch) | |
tree | b1355645342667209263cbd355dc0b4254f1e8fe /vendor/github.com/mattermost/mattermost-server/v5/model/mention_map.go | |
parent | 9459495484d6e06a3d46de64fccd8d06f7ccc72c (diff) | |
download | matterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.tar.gz matterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.tar.bz2 matterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.zip |
Diffstat (limited to 'vendor/github.com/mattermost/mattermost-server/v5/model/mention_map.go')
-rw-r--r-- | vendor/github.com/mattermost/mattermost-server/v5/model/mention_map.go | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/vendor/github.com/mattermost/mattermost-server/v5/model/mention_map.go b/vendor/github.com/mattermost/mattermost-server/v5/model/mention_map.go deleted file mode 100644 index 2f3444dd..00000000 --- a/vendor/github.com/mattermost/mattermost-server/v5/model/mention_map.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See LICENSE.txt for license information. - -package model - -import ( - "fmt" - "net/url" -) - -type UserMentionMap map[string]string -type ChannelMentionMap map[string]string - -const ( - userMentionsKey = "user_mentions" - userMentionsIdsKey = "user_mentions_ids" - channelMentionsKey = "channel_mentions" - channelMentionsIdsKey = "channel_mentions_ids" -) - -func UserMentionMapFromURLValues(values url.Values) (UserMentionMap, error) { - return mentionsFromURLValues(values, userMentionsKey, userMentionsIdsKey) -} - -func (m UserMentionMap) ToURLValues() url.Values { - return mentionsToURLValues(m, userMentionsKey, userMentionsIdsKey) -} - -func ChannelMentionMapFromURLValues(values url.Values) (ChannelMentionMap, error) { - return mentionsFromURLValues(values, channelMentionsKey, channelMentionsIdsKey) -} - -func (m ChannelMentionMap) ToURLValues() url.Values { - return mentionsToURLValues(m, channelMentionsKey, channelMentionsIdsKey) -} - -func mentionsFromURLValues(values url.Values, mentionKey, idKey string) (map[string]string, error) { - mentions, mentionsOk := values[mentionKey] - ids, idsOk := values[idKey] - - if !mentionsOk && !idsOk { - return map[string]string{}, nil - } - - if !mentionsOk { - return nil, fmt.Errorf("%s key not found", mentionKey) - } - - if !idsOk { - return nil, fmt.Errorf("%s key not found", idKey) - } - - if len(mentions) != len(ids) { - return nil, fmt.Errorf("keys %s and %s have different length", mentionKey, idKey) - } - - mentionsMap := make(map[string]string) - for i, mention := range mentions { - id := ids[i] - - if oldId, ok := mentionsMap[mention]; ok && oldId != id { - return nil, fmt.Errorf("key %s has two different values: %s and %s", mention, oldId, id) - } - - mentionsMap[mention] = id - } - - return mentionsMap, nil -} - -func mentionsToURLValues(mentions map[string]string, mentionKey, idKey string) url.Values { - values := url.Values{} - - for mention, id := range mentions { - values.Add(mentionKey, mention) - values.Add(idKey, id) - } - - return values -} |