From 15e3dc46cf485f6833e1d6a669a23abe43869ade Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 9 Mar 2020 18:12:25 +0100 Subject: Mattermost user search --- connector/mattermost/mattermost.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'connector/mattermost') diff --git a/connector/mattermost/mattermost.go b/connector/mattermost/mattermost.go index 4490f2a..ea8377c 100644 --- a/connector/mattermost/mattermost.go +++ b/connector/mattermost/mattermost.go @@ -254,8 +254,19 @@ func (mm *Mattermost) Leave(roomId RoomID) { } func (mm *Mattermost) SearchForUsers(query string) ([]UserSearchResult, error) { - // TODO - return nil, fmt.Errorf("Not implemented") + query = strings.ToLower(query) + ret := []UserSearchResult{} + for _, user := range mm.conn.Users { + if strings.Contains(strings.ToLower(user.Username), query) || + strings.Contains(strings.ToLower(user.Nickname), query) || + strings.Contains(strings.ToLower(user.GetDisplayName(model.SHOW_NICKNAME_FULLNAME)), query) { + ret = append(ret, UserSearchResult{ + ID: UserID(fmt.Sprintf("%s@%s", user.Username, mm.server)), + DisplayName: user.GetDisplayName(model.SHOW_NICKNAME_FULLNAME), + }) + } + } + return ret, nil } func (mm *Mattermost) Send(event *Event) (string, error) { -- cgit v1.2.3