MM-35392 Load thread unreads for other teams on app load (#17944)
* Add ability to include thread unreads in team unreads api response * Do not include GMs/DMs in team unreads for threads * Fix bad merge
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
04ef406bd6
Коммит
a0cc420e2a
@@ -420,8 +420,9 @@ func getTeamsUnreadForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// optional team id to be excluded from the result
|
// optional team id to be excluded from the result
|
||||||
teamId := r.URL.Query().Get("exclude_team")
|
teamId := r.URL.Query().Get("exclude_team")
|
||||||
|
includeCollapsedThreads := r.URL.Query().Get("include_collapsed_threads") == "true"
|
||||||
|
|
||||||
unreadTeamsList, err := c.App.GetTeamsUnreadForUser(teamId, c.Params.UserId)
|
unreadTeamsList, err := c.App.GetTeamsUnreadForUser(teamId, c.Params.UserId, includeCollapsedThreads)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -2651,22 +2651,22 @@ func TestGetMyTeamsUnread(t *testing.T) {
|
|||||||
user := th.BasicUser
|
user := th.BasicUser
|
||||||
Client.Login(user.Email, user.Password)
|
Client.Login(user.Email, user.Password)
|
||||||
|
|
||||||
teams, resp := Client.GetTeamsUnreadForUser(user.Id, "")
|
teams, resp := Client.GetTeamsUnreadForUser(user.Id, "", true)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
require.NotEqual(t, len(teams), 0, "should have results")
|
require.NotEqual(t, len(teams), 0, "should have results")
|
||||||
|
|
||||||
teams, resp = Client.GetTeamsUnreadForUser(user.Id, th.BasicTeam.Id)
|
teams, resp = Client.GetTeamsUnreadForUser(user.Id, th.BasicTeam.Id, true)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
require.Empty(t, teams, "should not have results")
|
require.Empty(t, teams, "should not have results")
|
||||||
|
|
||||||
_, resp = Client.GetTeamsUnreadForUser("fail", "")
|
_, resp = Client.GetTeamsUnreadForUser("fail", "", true)
|
||||||
CheckBadRequestStatus(t, resp)
|
CheckBadRequestStatus(t, resp)
|
||||||
|
|
||||||
_, resp = Client.GetTeamsUnreadForUser(model.NewId(), "")
|
_, resp = Client.GetTeamsUnreadForUser(model.NewId(), "", true)
|
||||||
CheckForbiddenStatus(t, resp)
|
CheckForbiddenStatus(t, resp)
|
||||||
|
|
||||||
Client.Logout()
|
Client.Logout()
|
||||||
_, resp = Client.GetTeamsUnreadForUser(user.Id, "")
|
_, resp = Client.GetTeamsUnreadForUser(user.Id, "", true)
|
||||||
CheckUnauthorizedStatus(t, resp)
|
CheckUnauthorizedStatus(t, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5551,7 +5551,7 @@ func TestGetThreadsForUser(t *testing.T) {
|
|||||||
|
|
||||||
require.Nil(t, resp.Error)
|
require.Nil(t, resp.Error)
|
||||||
require.Len(t, uss.Threads, 10)
|
require.Len(t, uss.Threads, 10)
|
||||||
require.Equal(t, uss.Threads[0].PostId, rootIdBefore)
|
require.Equal(t, rootIdBefore, uss.Threads[0].PostId)
|
||||||
|
|
||||||
uss2, resp2 := th.Client.GetUserThreads(th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
|
uss2, resp2 := th.Client.GetUserThreads(th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
|
||||||
Deleted: false,
|
Deleted: false,
|
||||||
@@ -5561,7 +5561,7 @@ func TestGetThreadsForUser(t *testing.T) {
|
|||||||
require.Nil(t, resp2.Error)
|
require.Nil(t, resp2.Error)
|
||||||
require.Len(t, uss2.Threads, 10)
|
require.Len(t, uss2.Threads, 10)
|
||||||
|
|
||||||
require.Equal(t, uss2.Threads[0].PostId, rootIdAfter)
|
require.Equal(t, rootIdAfter, uss2.Threads[0].PostId)
|
||||||
|
|
||||||
uss3, resp3 := th.Client.GetUserThreads(th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
|
uss3, resp3 := th.Client.GetUserThreads(th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{
|
||||||
Deleted: false,
|
Deleted: false,
|
||||||
|
|||||||
@@ -762,7 +762,7 @@ type AppIface interface {
|
|||||||
GetTeamsForScheme(scheme *model.Scheme, offset int, limit int) ([]*model.Team, *model.AppError)
|
GetTeamsForScheme(scheme *model.Scheme, offset int, limit int) ([]*model.Team, *model.AppError)
|
||||||
GetTeamsForSchemePage(scheme *model.Scheme, page int, perPage int) ([]*model.Team, *model.AppError)
|
GetTeamsForSchemePage(scheme *model.Scheme, page int, perPage int) ([]*model.Team, *model.AppError)
|
||||||
GetTeamsForUser(userID string) ([]*model.Team, *model.AppError)
|
GetTeamsForUser(userID string) ([]*model.Team, *model.AppError)
|
||||||
GetTeamsUnreadForUser(excludeTeamId string, userID string) ([]*model.TeamUnread, *model.AppError)
|
GetTeamsUnreadForUser(excludeTeamId string, userID string, includeCollapsedThreads bool) ([]*model.TeamUnread, *model.AppError)
|
||||||
GetTermsOfService(id string) (*model.TermsOfService, *model.AppError)
|
GetTermsOfService(id string) (*model.TermsOfService, *model.AppError)
|
||||||
GetThreadForUser(teamID string, threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, *model.AppError)
|
GetThreadForUser(teamID string, threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, *model.AppError)
|
||||||
GetThreadMembershipForUser(userId, threadId string) (*model.ThreadMembership, *model.AppError)
|
GetThreadMembershipForUser(userId, threadId string) (*model.ThreadMembership, *model.AppError)
|
||||||
|
|||||||
@@ -9250,7 +9250,7 @@ func (a *OpenTracingAppLayer) GetTeamsForUser(userID string) ([]*model.Team, *mo
|
|||||||
return resultVar0, resultVar1
|
return resultVar0, resultVar1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *OpenTracingAppLayer) GetTeamsUnreadForUser(excludeTeamId string, userID string) ([]*model.TeamUnread, *model.AppError) {
|
func (a *OpenTracingAppLayer) GetTeamsUnreadForUser(excludeTeamId string, userID string, includeCollapsedThreads bool) ([]*model.TeamUnread, *model.AppError) {
|
||||||
origCtx := a.ctx
|
origCtx := a.ctx
|
||||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetTeamsUnreadForUser")
|
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetTeamsUnreadForUser")
|
||||||
|
|
||||||
@@ -9262,7 +9262,7 @@ func (a *OpenTracingAppLayer) GetTeamsUnreadForUser(excludeTeamId string, userID
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
resultVar0, resultVar1 := a.app.GetTeamsUnreadForUser(excludeTeamId, userID)
|
resultVar0, resultVar1 := a.app.GetTeamsUnreadForUser(excludeTeamId, userID, includeCollapsedThreads)
|
||||||
|
|
||||||
if resultVar1 != nil {
|
if resultVar1 != nil {
|
||||||
span.LogFields(spanlog.Error(resultVar1))
|
span.LogFields(spanlog.Error(resultVar1))
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ func (api *PluginAPI) GetTeamByName(name string) (*model.Team, *model.AppError)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetTeamsUnreadForUser(userID string) ([]*model.TeamUnread, *model.AppError) {
|
func (api *PluginAPI) GetTeamsUnreadForUser(userID string) ([]*model.TeamUnread, *model.AppError) {
|
||||||
return api.app.GetTeamsUnreadForUser("", userID)
|
return api.app.GetTeamsUnreadForUser("", userID, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) UpdateTeam(team *model.Team) (*model.Team, *model.AppError) {
|
func (api *PluginAPI) UpdateTeam(team *model.Team) (*model.Team, *model.AppError) {
|
||||||
|
|||||||
28
app/team.go
28
app/team.go
@@ -1654,7 +1654,7 @@ func (a *App) FindTeamByName(name string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetTeamsUnreadForUser(excludeTeamId string, userID string) ([]*model.TeamUnread, *model.AppError) {
|
func (a *App) GetTeamsUnreadForUser(excludeTeamId string, userID string, includeCollapsedThreads bool) ([]*model.TeamUnread, *model.AppError) {
|
||||||
data, err := a.Srv().Store.Team().GetChannelUnreadsForAllTeams(excludeTeamId, userID)
|
data, err := a.Srv().Store.Team().GetChannelUnreadsForAllTeams(excludeTeamId, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("GetTeamsUnreadForUser", "app.team.get_unread.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("GetTeamsUnreadForUser", "app.team.get_unread.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
@@ -1681,17 +1681,29 @@ func (a *App) GetTeamsUnreadForUser(excludeTeamId string, userID string) ([]*mod
|
|||||||
membersMap[id] = unreads(data[i], mu)
|
membersMap[id] = unreads(data[i], mu)
|
||||||
} else {
|
} else {
|
||||||
membersMap[id] = unreads(data[i], &model.TeamUnread{
|
membersMap[id] = unreads(data[i], &model.TeamUnread{
|
||||||
MsgCount: 0,
|
MsgCount: 0,
|
||||||
MentionCount: 0,
|
MentionCount: 0,
|
||||||
MentionCountRoot: 0,
|
MentionCountRoot: 0,
|
||||||
MsgCountRoot: 0,
|
MsgCountRoot: 0,
|
||||||
TeamId: id,
|
ThreadCount: 0,
|
||||||
|
ThreadMentionCount: 0,
|
||||||
|
TeamId: id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, val := range membersMap {
|
includeCollapsedThreads = includeCollapsedThreads && *a.Config().ServiceSettings.CollapsedThreads != model.COLLAPSED_THREADS_DISABLED
|
||||||
members = append(members, val)
|
|
||||||
|
for _, member := range membersMap {
|
||||||
|
if includeCollapsedThreads {
|
||||||
|
data, err := a.Srv().Store.Thread().GetThreadsForUser(userID, member.TeamId, model.GetUserThreadsOpts{TotalsOnly: true, TeamOnly: true})
|
||||||
|
if err != nil {
|
||||||
|
return nil, model.NewAppError("GetTeamsUnreadForUser", "app.team.get_unread.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
member.ThreadCount = data.TotalUnreadThreads
|
||||||
|
member.ThreadMentionCount = data.TotalUnreadMentions
|
||||||
|
}
|
||||||
|
members = append(members, member)
|
||||||
}
|
}
|
||||||
|
|
||||||
return members, nil
|
return members, nil
|
||||||
|
|||||||
@@ -1445,14 +1445,20 @@ func (c *Client4) AttachDeviceId(deviceId string) (bool, *Response) {
|
|||||||
|
|
||||||
// GetTeamsUnreadForUser will return an array with TeamUnread objects that contain the amount
|
// GetTeamsUnreadForUser will return an array with TeamUnread objects that contain the amount
|
||||||
// of unread messages and mentions the current user has for the teams it belongs to.
|
// of unread messages and mentions the current user has for the teams it belongs to.
|
||||||
// An optional team ID can be set to exclude that team from the results. Must be authenticated.
|
// An optional team ID can be set to exclude that team from the results.
|
||||||
func (c *Client4) GetTeamsUnreadForUser(userId, teamIdToExclude string) ([]*TeamUnread, *Response) {
|
// An optional boolean can be set to include collapsed thread unreads. Must be authenticated.
|
||||||
var optional string
|
func (c *Client4) GetTeamsUnreadForUser(userId, teamIdToExclude string, includeCollapsedThreads bool) ([]*TeamUnread, *Response) {
|
||||||
|
query := url.Values{}
|
||||||
|
|
||||||
if teamIdToExclude != "" {
|
if teamIdToExclude != "" {
|
||||||
optional += fmt.Sprintf("?exclude_team=%s", url.QueryEscape(teamIdToExclude))
|
query.Set("exclude_team", teamIdToExclude)
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := c.DoApiGet(c.GetUserRoute(userId)+"/teams/unread"+optional, "")
|
if includeCollapsedThreads {
|
||||||
|
query.Set("include_collapsed_threads", "true")
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := c.DoApiGet(c.GetUserRoute(userId)+"/teams/unread?"+query.Encode(), "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, BuildErrorResponse(r, err)
|
return nil, BuildErrorResponse(r, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,11 +31,13 @@ type TeamMember struct {
|
|||||||
|
|
||||||
//msgp:ignore TeamUnread
|
//msgp:ignore TeamUnread
|
||||||
type TeamUnread struct {
|
type TeamUnread struct {
|
||||||
TeamId string `json:"team_id"`
|
TeamId string `json:"team_id"`
|
||||||
MsgCount int64 `json:"msg_count"`
|
MsgCount int64 `json:"msg_count"`
|
||||||
MentionCount int64 `json:"mention_count"`
|
MentionCount int64 `json:"mention_count"`
|
||||||
MentionCountRoot int64 `json:"mention_count_root"`
|
MentionCountRoot int64 `json:"mention_count_root"`
|
||||||
MsgCountRoot int64 `json:"msg_count_root"`
|
MsgCountRoot int64 `json:"msg_count_root"`
|
||||||
|
ThreadCount int64 `json:"thread_count"`
|
||||||
|
ThreadMentionCount int64 `json:"thread_mention_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//msgp:ignore TeamMemberForExport
|
//msgp:ignore TeamMemberForExport
|
||||||
|
|||||||
@@ -54,6 +54,12 @@ type GetUserThreadsOpts struct {
|
|||||||
|
|
||||||
// Unread will make sure that only threads with unread replies are returned
|
// Unread will make sure that only threads with unread replies are returned
|
||||||
Unread bool
|
Unread bool
|
||||||
|
|
||||||
|
// TotalsOnly will not fetch any threads and just fetch the total counts
|
||||||
|
TotalsOnly bool
|
||||||
|
|
||||||
|
// TeamOnly will only fetch threads and unreads for the specified team and excludes DMs/GMs
|
||||||
|
TeamOnly bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ThreadResponse) ToJson() string {
|
func (o *ThreadResponse) ToJson() string {
|
||||||
|
|||||||
@@ -131,10 +131,20 @@ func (s *SqlThreadStore) GetThreadsForUser(userId, teamId string, opts model.Get
|
|||||||
}
|
}
|
||||||
|
|
||||||
fetchConditions := sq.And{
|
fetchConditions := sq.And{
|
||||||
sq.Or{sq.Eq{"Channels.TeamId": teamId}, sq.Eq{"Channels.TeamId": ""}},
|
|
||||||
sq.Eq{"ThreadMemberships.UserId": userId},
|
sq.Eq{"ThreadMemberships.UserId": userId},
|
||||||
sq.Eq{"ThreadMemberships.Following": true},
|
sq.Eq{"ThreadMemberships.Following": true},
|
||||||
}
|
}
|
||||||
|
if opts.TeamOnly {
|
||||||
|
fetchConditions = sq.And{
|
||||||
|
sq.Eq{"Channels.TeamId": teamId},
|
||||||
|
fetchConditions,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fetchConditions = sq.And{
|
||||||
|
sq.Or{sq.Eq{"Channels.TeamId": teamId}, sq.Eq{"Channels.TeamId": ""}},
|
||||||
|
fetchConditions,
|
||||||
|
}
|
||||||
|
}
|
||||||
if !opts.Deleted {
|
if !opts.Deleted {
|
||||||
fetchConditions = sq.And{
|
fetchConditions = sq.And{
|
||||||
fetchConditions,
|
fetchConditions,
|
||||||
@@ -150,7 +160,11 @@ func (s *SqlThreadStore) GetThreadsForUser(userId, teamId string, opts model.Get
|
|||||||
totalUnreadThreadsChan := make(chan store.StoreResult, 1)
|
totalUnreadThreadsChan := make(chan store.StoreResult, 1)
|
||||||
totalCountChan := make(chan store.StoreResult, 1)
|
totalCountChan := make(chan store.StoreResult, 1)
|
||||||
totalUnreadMentionsChan := make(chan store.StoreResult, 1)
|
totalUnreadMentionsChan := make(chan store.StoreResult, 1)
|
||||||
threadsChan := make(chan store.StoreResult, 1)
|
var threadsChan chan store.StoreResult
|
||||||
|
if !opts.TotalsOnly {
|
||||||
|
threadsChan = make(chan store.StoreResult, 1)
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
repliesQuery, repliesQueryArgs, _ := s.getQueryBuilder().
|
repliesQuery, repliesQueryArgs, _ := s.getQueryBuilder().
|
||||||
Select("COUNT(DISTINCT(Posts.RootId))").
|
Select("COUNT(DISTINCT(Posts.RootId))").
|
||||||
@@ -195,71 +209,68 @@ func (s *SqlThreadStore) GetThreadsForUser(userId, teamId string, opts model.Get
|
|||||||
totalUnreadMentionsChan <- store.StoreResult{Data: totalUnreadMentions, NErr: err}
|
totalUnreadMentionsChan <- store.StoreResult{Data: totalUnreadMentions, NErr: err}
|
||||||
close(totalUnreadMentionsChan)
|
close(totalUnreadMentionsChan)
|
||||||
}()
|
}()
|
||||||
go func() {
|
|
||||||
newFetchConditions := fetchConditions
|
|
||||||
if opts.Since > 0 {
|
|
||||||
newFetchConditions = sq.And{newFetchConditions, sq.GtOrEq{"ThreadMemberships.LastUpdated": opts.Since}}
|
|
||||||
}
|
|
||||||
order := "DESC"
|
|
||||||
if opts.Before != "" {
|
|
||||||
newFetchConditions = sq.And{
|
|
||||||
newFetchConditions,
|
|
||||||
sq.Expr(`LastReplyAt < (SELECT LastReplyAt FROM Threads WHERE PostId = ?)`, opts.Before),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if opts.After != "" {
|
|
||||||
order = "ASC"
|
|
||||||
newFetchConditions = sq.And{
|
|
||||||
newFetchConditions,
|
|
||||||
sq.Expr(`LastReplyAt > (SELECT LastReplyAt FROM Threads WHERE PostId = ?)`, opts.After),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if opts.Unread {
|
|
||||||
newFetchConditions = sq.And{newFetchConditions, sq.Expr("ThreadMemberships.LastViewed < Threads.LastReplyAt")}
|
|
||||||
}
|
|
||||||
|
|
||||||
unreadRepliesFetchConditions := sq.And{
|
if !opts.TotalsOnly {
|
||||||
sq.Expr("Posts.RootId = ThreadMemberships.PostId"),
|
go func() {
|
||||||
sq.Expr("Posts.CreateAt > ThreadMemberships.LastViewed"),
|
newFetchConditions := fetchConditions
|
||||||
}
|
if opts.Since > 0 {
|
||||||
if !opts.Deleted {
|
newFetchConditions = sq.And{newFetchConditions, sq.GtOrEq{"ThreadMemberships.LastUpdated": opts.Since}}
|
||||||
unreadRepliesFetchConditions = sq.And{
|
}
|
||||||
unreadRepliesFetchConditions,
|
order := "DESC"
|
||||||
sq.Expr("Posts.DeleteAt = 0"),
|
if opts.Before != "" {
|
||||||
|
newFetchConditions = sq.And{
|
||||||
|
newFetchConditions,
|
||||||
|
sq.Expr(`LastReplyAt < (SELECT LastReplyAt FROM Threads WHERE PostId = ?)`, opts.Before),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if opts.After != "" {
|
||||||
|
order = "ASC"
|
||||||
|
newFetchConditions = sq.And{
|
||||||
|
newFetchConditions,
|
||||||
|
sq.Expr(`LastReplyAt > (SELECT LastReplyAt FROM Threads WHERE PostId = ?)`, opts.After),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if opts.Unread {
|
||||||
|
newFetchConditions = sq.And{newFetchConditions, sq.Expr("ThreadMemberships.LastViewed < Threads.LastReplyAt")}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
unreadRepliesQuery, _ := sq.
|
unreadRepliesFetchConditions := sq.And{
|
||||||
Select("COUNT(Posts.Id)").
|
sq.Expr("Posts.RootId = ThreadMemberships.PostId"),
|
||||||
From("Posts").
|
sq.Expr("Posts.CreateAt > ThreadMemberships.LastViewed"),
|
||||||
Where(unreadRepliesFetchConditions).
|
}
|
||||||
MustSql()
|
if !opts.Deleted {
|
||||||
|
unreadRepliesFetchConditions = sq.And{
|
||||||
|
unreadRepliesFetchConditions,
|
||||||
|
sq.Expr("Posts.DeleteAt = 0"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var threads []*JoinedThread
|
unreadRepliesQuery, _ := sq.
|
||||||
query, args, _ := s.getQueryBuilder().
|
Select("COUNT(Posts.Id)").
|
||||||
Select(`Threads.*,
|
From("Posts").
|
||||||
|
Where(unreadRepliesFetchConditions).
|
||||||
|
MustSql()
|
||||||
|
|
||||||
|
var threads []*JoinedThread
|
||||||
|
query, args, _ := s.getQueryBuilder().
|
||||||
|
Select(`Threads.*,
|
||||||
` + postSliceCoalesceQuery() + `,
|
` + postSliceCoalesceQuery() + `,
|
||||||
ThreadMemberships.LastViewed as LastViewedAt,
|
ThreadMemberships.LastViewed as LastViewedAt,
|
||||||
ThreadMemberships.UnreadMentions as UnreadMentions`).
|
ThreadMemberships.UnreadMentions as UnreadMentions`).
|
||||||
From("Threads").
|
From("Threads").
|
||||||
Column(sq.Alias(sq.Expr(unreadRepliesQuery), "UnreadReplies")).
|
Column(sq.Alias(sq.Expr(unreadRepliesQuery), "UnreadReplies")).
|
||||||
LeftJoin("Posts ON Posts.Id = Threads.PostId").
|
LeftJoin("Posts ON Posts.Id = Threads.PostId").
|
||||||
LeftJoin("Channels ON Posts.ChannelId = Channels.Id").
|
LeftJoin("Channels ON Posts.ChannelId = Channels.Id").
|
||||||
LeftJoin("ThreadMemberships ON ThreadMemberships.PostId = Threads.PostId").
|
LeftJoin("ThreadMemberships ON ThreadMemberships.PostId = Threads.PostId").
|
||||||
Where(newFetchConditions).
|
Where(newFetchConditions).
|
||||||
OrderBy("Threads.LastReplyAt " + order).
|
OrderBy("Threads.LastReplyAt " + order).
|
||||||
Limit(pageSize).ToSql()
|
Limit(pageSize).ToSql()
|
||||||
|
|
||||||
_, err := s.GetReplica().Select(&threads, query, args...)
|
_, err := s.GetReplica().Select(&threads, query, args...)
|
||||||
threadsChan <- store.StoreResult{Data: threads, NErr: err}
|
threadsChan <- store.StoreResult{Data: threads, NErr: err}
|
||||||
close(threadsChan)
|
close(threadsChan)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
threadsResult := <-threadsChan
|
|
||||||
if threadsResult.NErr != nil {
|
|
||||||
return nil, threadsResult.NErr
|
|
||||||
}
|
}
|
||||||
threads := threadsResult.Data.([]*JoinedThread)
|
|
||||||
|
|
||||||
totalUnreadMentionsResult := <-totalUnreadMentionsChan
|
totalUnreadMentionsResult := <-totalUnreadMentionsChan
|
||||||
if totalUnreadMentionsResult.NErr != nil {
|
if totalUnreadMentionsResult.NErr != nil {
|
||||||
@@ -281,26 +292,6 @@ func (s *SqlThreadStore) GetThreadsForUser(userId, teamId string, opts model.Get
|
|||||||
|
|
||||||
var userIds []string
|
var userIds []string
|
||||||
userIdMap := map[string]bool{}
|
userIdMap := map[string]bool{}
|
||||||
for _, thread := range threads {
|
|
||||||
for _, participantId := range thread.Participants {
|
|
||||||
if _, ok := userIdMap[participantId]; !ok {
|
|
||||||
userIdMap[participantId] = true
|
|
||||||
userIds = append(userIds, participantId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var users []*model.User
|
|
||||||
if opts.Extended {
|
|
||||||
var err error
|
|
||||||
users, err = s.User().GetProfileByIds(context.Background(), userIds, &store.UserGetByIdsOpts{}, true)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrapf(err, "failed to get threads for user id=%s", userId)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for _, userId := range userIds {
|
|
||||||
users = append(users, &model.User{Id: userId})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result := &model.Threads{
|
result := &model.Threads{
|
||||||
Total: totalCount,
|
Total: totalCount,
|
||||||
@@ -309,31 +300,59 @@ func (s *SqlThreadStore) GetThreadsForUser(userId, teamId string, opts model.Get
|
|||||||
TotalUnreadThreads: totalUnreadThreads,
|
TotalUnreadThreads: totalUnreadThreads,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, thread := range threads {
|
if !opts.TotalsOnly {
|
||||||
var participants []*model.User
|
threadsResult := <-threadsChan
|
||||||
for _, participantId := range thread.Participants {
|
if threadsResult.NErr != nil {
|
||||||
var participant *model.User
|
return nil, threadsResult.NErr
|
||||||
for _, u := range users {
|
}
|
||||||
if u.Id == participantId {
|
threads := threadsResult.Data.([]*JoinedThread)
|
||||||
participant = u
|
for _, thread := range threads {
|
||||||
break
|
for _, participantId := range thread.Participants {
|
||||||
|
if _, ok := userIdMap[participantId]; !ok {
|
||||||
|
userIdMap[participantId] = true
|
||||||
|
userIds = append(userIds, participantId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if participant == nil {
|
|
||||||
return nil, errors.New("cannot find thread participant with id=" + participantId)
|
|
||||||
}
|
|
||||||
participants = append(participants, participant)
|
|
||||||
}
|
}
|
||||||
result.Threads = append(result.Threads, &model.ThreadResponse{
|
var users []*model.User
|
||||||
PostId: thread.PostId,
|
if opts.Extended {
|
||||||
ReplyCount: thread.ReplyCount,
|
var err error
|
||||||
LastReplyAt: thread.LastReplyAt,
|
users, err = s.User().GetProfileByIds(context.Background(), userIds, &store.UserGetByIdsOpts{}, true)
|
||||||
LastViewedAt: thread.LastViewedAt,
|
if err != nil {
|
||||||
UnreadReplies: thread.UnreadReplies,
|
return nil, errors.Wrapf(err, "failed to get threads for user id=%s", userId)
|
||||||
UnreadMentions: thread.UnreadMentions,
|
}
|
||||||
Participants: participants,
|
} else {
|
||||||
Post: thread.Post.ToNilIfInvalid(),
|
for _, userId := range userIds {
|
||||||
})
|
users = append(users, &model.User{Id: userId})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, thread := range threads {
|
||||||
|
var participants []*model.User
|
||||||
|
for _, participantId := range thread.Participants {
|
||||||
|
var participant *model.User
|
||||||
|
for _, u := range users {
|
||||||
|
if u.Id == participantId {
|
||||||
|
participant = u
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if participant == nil {
|
||||||
|
return nil, errors.New("cannot find thread participant with id=" + participantId)
|
||||||
|
}
|
||||||
|
participants = append(participants, participant)
|
||||||
|
}
|
||||||
|
result.Threads = append(result.Threads, &model.ThreadResponse{
|
||||||
|
PostId: thread.PostId,
|
||||||
|
ReplyCount: thread.ReplyCount,
|
||||||
|
LastReplyAt: thread.LastReplyAt,
|
||||||
|
LastViewedAt: thread.LastViewedAt,
|
||||||
|
UnreadReplies: thread.UnreadReplies,
|
||||||
|
UnreadMentions: thread.UnreadMentions,
|
||||||
|
Participants: participants,
|
||||||
|
Post: thread.Post.ToNilIfInvalid(),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user