diff options
Diffstat (limited to 'store/sqlstore')
-rw-r--r-- | store/sqlstore/user_store.go | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/store/sqlstore/user_store.go b/store/sqlstore/user_store.go index 04e0c994c..5e84af930 100644 --- a/store/sqlstore/user_store.go +++ b/store/sqlstore/user_store.go @@ -412,7 +412,18 @@ func (us SqlUserStore) GetProfilesInChannel(channelId string, offset int, limit return store.Do(func(result *store.StoreResult) { var users []*model.User - query := "SELECT Users.* FROM Users, ChannelMembers WHERE ChannelMembers.ChannelId = :ChannelId AND Users.Id = ChannelMembers.UserId ORDER BY Users.Username ASC LIMIT :Limit OFFSET :Offset" + query := ` + SELECT + Users.* + FROM + Users, ChannelMembers + WHERE + ChannelMembers.ChannelId = :ChannelId + AND Users.Id = ChannelMembers.UserId + ORDER BY + Users.Username ASC + LIMIT :Limit OFFSET :Offset + ` if _, err := us.GetReplica().Select(&users, query, map[string]interface{}{"ChannelId": channelId, "Offset": offset, "Limit": limit}); err != nil { result.Err = model.NewAppError("SqlUserStore.GetProfilesInChannel", "store.sql_user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) @@ -427,6 +438,42 @@ func (us SqlUserStore) GetProfilesInChannel(channelId string, offset int, limit }) } +func (us SqlUserStore) GetProfilesInChannelByStatus(channelId string, offset int, limit int) store.StoreChannel { + return store.Do(func(result *store.StoreResult) { + var users []*model.User + + query := ` + SELECT + Users.* + FROM Users + INNER JOIN ChannelMembers ON Users.Id = ChannelMembers.UserId + LEFT JOIN Status ON Users.Id = Status.UserId + WHERE + ChannelMembers.ChannelId = :ChannelId + ORDER BY + CASE Status + WHEN 'online' THEN 1 + WHEN 'away' THEN 2 + WHEN 'dnd' THEN 3 + ELSE 4 + END, + Users.Username ASC + LIMIT :Limit OFFSET :Offset + ` + + if _, err := us.GetReplica().Select(&users, query, map[string]interface{}{"ChannelId": channelId, "Offset": offset, "Limit": limit}); err != nil { + result.Err = model.NewAppError("SqlUserStore.GetProfilesInChannelByStatus", "store.sql_user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError) + } else { + + for _, u := range users { + u.Sanitize(map[string]bool{}) + } + + result.Data = users + } + }) +} + func (us SqlUserStore) GetAllProfilesInChannel(channelId string, allowFromCache bool) store.StoreChannel { return store.Do(func(result *store.StoreResult) { if allowFromCache { |