diff options
author | Jesús Espino <jespinog@gmail.com> | 2018-09-27 16:15:41 +0200 |
---|---|---|
committer | Carlos Tadeu Panato Junior <ctadeu@gmail.com> | 2018-09-27 16:15:41 +0200 |
commit | 49e0473753c2e4e2e02e30c17a7793657b71363f (patch) | |
tree | 944fe36b0a1982705b2fa98da466867285d00652 /app | |
parent | 89852d04c064588f24c6122caf18b8e656399f94 (diff) | |
download | chat-49e0473753c2e4e2e02e30c17a7793657b71363f.tar.gz chat-49e0473753c2e4e2e02e30c17a7793657b71363f.tar.bz2 chat-49e0473753c2e4e2e02e30c17a7793657b71363f.zip |
MM-11567: Autocomplete search in: for DMs and GMs (#9430)
* MM-11567: Autocomplete search in: for DMs and GMs
* Adding unit tests
* Allowing to search Direct Messages in the autocompletion
* Fix it in TE
Diffstat (limited to 'app')
-rw-r--r-- | app/post.go | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/app/post.go b/app/post.go index fc941a68f..da6f7ac2b 100644 --- a/app/post.go +++ b/app/post.go @@ -616,6 +616,43 @@ func (a *App) DeletePostFiles(post *model.Post) { } } +func (a *App) parseAndFetchChannelIdByNameFromInFilter(channelName, userId, teamId string, includeDeleted bool) (*model.Channel, error) { + if strings.HasPrefix(channelName, "@") && strings.Contains(channelName, ",") { + var userIds []string + users, err := a.GetUsersByUsernames(strings.Split(channelName[1:], ","), false) + if err != nil { + return nil, err + } + for _, user := range users { + userIds = append(userIds, user.Id) + } + + channel, err := a.GetGroupChannel(userIds) + if err != nil { + return nil, err + } + return channel, nil + } + + if strings.HasPrefix(channelName, "@") && !strings.Contains(channelName, ",") { + user, err := a.GetUserByUsername(channelName[1:]) + if err != nil { + return nil, err + } + channel, err := a.GetDirectChannel(userId, user.Id) + if err != nil { + return nil, err + } + return channel, nil + } + + channel, err := a.GetChannelByName(channelName, teamId, includeDeleted) + if err != nil { + return nil, err + } + return channel, nil +} + func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOrSearch bool, includeDeletedChannels bool, timeZoneOffset int, page, perPage int) (*model.PostSearchResults, *model.AppError) { paramsList := model.ParseSearchParams(terms, timeZoneOffset) includeDeleted := includeDeletedChannels && *a.Config().TeamSettings.ExperimentalViewArchivedChannels @@ -630,11 +667,12 @@ func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOr if params.Terms != "*" { // Convert channel names to channel IDs for idx, channelName := range params.InChannels { - if channel, err := a.GetChannelByName(channelName, teamId, includeDeleted); err != nil { + channel, err := a.parseAndFetchChannelIdByNameFromInFilter(channelName, userId, teamId, includeDeletedChannels) + if err != nil { mlog.Error(fmt.Sprint(err)) - } else { - params.InChannels[idx] = channel.Id + continue } + params.InChannels[idx] = channel.Id } // Convert usernames to user IDs @@ -695,6 +733,16 @@ func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOr params.OrTerms = isOrSearch // don't allow users to search for everything if params.Terms != "*" { + for idx, channelName := range params.InChannels { + if strings.HasPrefix(channelName, "@") { + channel, err := a.parseAndFetchChannelIdByNameFromInFilter(channelName, userId, teamId, includeDeletedChannels) + if err != nil { + mlog.Error(fmt.Sprint(err)) + continue + } + params.InChannels[idx] = channel.Name + } + } channels = append(channels, a.Srv.Store.Post().Search(teamId, userId, params)) } } |