MM-33544 is_following prop in getPosts API methods (#17093)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c0971970e9
Коммит
0cc72342de
@@ -33,6 +33,7 @@ type SqlPostStore struct {
|
||||
|
||||
type postWithExtra struct {
|
||||
ThreadReplyCount int64
|
||||
IsFollowing bool
|
||||
ThreadParticipants model.StringArray
|
||||
model.Post
|
||||
}
|
||||
@@ -425,7 +426,7 @@ func (s *SqlPostStore) GetFlaggedPostsForChannel(userId, channelId string, offse
|
||||
|
||||
return pl, nil
|
||||
}
|
||||
func (s *SqlPostStore) getPostWithCollapsedThreads(id string, extended bool) (*model.PostList, error) {
|
||||
func (s *SqlPostStore) getPostWithCollapsedThreads(id, userID string, extended bool) (*model.PostList, error) {
|
||||
if id == "" {
|
||||
return nil, store.NewErrInvalidInput("Post", "id", id)
|
||||
}
|
||||
@@ -434,13 +435,19 @@ func (s *SqlPostStore) getPostWithCollapsedThreads(id string, extended bool) (*m
|
||||
for _, c := range postSliceColumns() {
|
||||
columns = append(columns, "Posts."+c)
|
||||
}
|
||||
columns = append(columns, "COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount", "COALESCE(Threads.LastReplyAt, 0) as LastReplyAt", "COALESCE(Threads.Participants, '[]') as ThreadParticipants")
|
||||
columns = append(columns,
|
||||
"COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount",
|
||||
"COALESCE(Threads.LastReplyAt, 0) as LastReplyAt",
|
||||
"COALESCE(Threads.Participants, '[]') as ThreadParticipants",
|
||||
"COALESCE(ThreadMemberships.Following, false) as IsFollowing",
|
||||
)
|
||||
var post postWithExtra
|
||||
|
||||
postFetchQuery, args, _ := s.getQueryBuilder().
|
||||
Select(columns...).
|
||||
From("Posts").
|
||||
LeftJoin("Threads ON Threads.PostId = Id").
|
||||
LeftJoin("ThreadMemberships ON ThreadMemberships.PostId = Id AND ThreadMemberships.UserId = ?", userID).
|
||||
Where(sq.Eq{"DeleteAt": 0}).
|
||||
Where(sq.Eq{"Id": id}).ToSql()
|
||||
|
||||
@@ -455,9 +462,9 @@ func (s *SqlPostStore) getPostWithCollapsedThreads(id string, extended bool) (*m
|
||||
return s.prepareThreadedResponse([]*postWithExtra{&post}, extended, false)
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) Get(ctx context.Context, id string, skipFetchThreads, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, error) {
|
||||
func (s *SqlPostStore) Get(ctx context.Context, id string, skipFetchThreads, collapsedThreads, collapsedThreadsExtended bool, userID string) (*model.PostList, error) {
|
||||
if collapsedThreads {
|
||||
return s.getPostWithCollapsedThreads(id, collapsedThreadsExtended)
|
||||
return s.getPostWithCollapsedThreads(id, userID, collapsedThreadsExtended)
|
||||
}
|
||||
pl := model.NewPostList()
|
||||
|
||||
@@ -689,6 +696,7 @@ func (s *SqlPostStore) prepareThreadedResponse(posts []*postWithExtra, extended,
|
||||
}
|
||||
processPost := func(p *postWithExtra) error {
|
||||
p.Post.ReplyCount = p.ThreadReplyCount
|
||||
p.Post.IsFollowing = p.IsFollowing
|
||||
for _, th := range p.ThreadParticipants {
|
||||
var participant *model.User
|
||||
for _, u := range users {
|
||||
@@ -728,7 +736,12 @@ func (s *SqlPostStore) getPostsCollapsedThreads(options model.GetPostsOptions) (
|
||||
for _, c := range postSliceColumns() {
|
||||
columns = append(columns, "Posts."+c)
|
||||
}
|
||||
columns = append(columns, "COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount", "COALESCE(Threads.LastReplyAt, 0) as LastReplyAt", "COALESCE(Threads.Participants, '[]') as ThreadParticipants")
|
||||
columns = append(columns,
|
||||
"COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount",
|
||||
"COALESCE(Threads.LastReplyAt, 0) as LastReplyAt",
|
||||
"COALESCE(Threads.Participants, '[]') as ThreadParticipants",
|
||||
"COALESCE(ThreadMemberships.Following, false) as IsFollowing",
|
||||
)
|
||||
var posts []*postWithExtra
|
||||
offset := options.PerPage * options.Page
|
||||
|
||||
@@ -736,6 +749,7 @@ func (s *SqlPostStore) getPostsCollapsedThreads(options model.GetPostsOptions) (
|
||||
Select(columns...).
|
||||
From("Posts").
|
||||
LeftJoin("Threads ON Threads.PostId = Id").
|
||||
LeftJoin("ThreadMemberships ON ThreadMemberships.PostId = Id AND ThreadMemberships.UserId = ?", options.UserId).
|
||||
Where(sq.Eq{"DeleteAt": 0}).
|
||||
Where(sq.Eq{"Posts.ChannelId": options.ChannelId}).
|
||||
Where(sq.Eq{"RootId": ""}).
|
||||
@@ -808,13 +822,19 @@ func (s *SqlPostStore) getPostsSinceCollapsedThreads(options model.GetPostsSince
|
||||
for _, c := range postSliceColumns() {
|
||||
columns = append(columns, "Posts."+c)
|
||||
}
|
||||
columns = append(columns, "COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount", "COALESCE(Threads.LastReplyAt, 0) as LastReplyAt", "COALESCE(Threads.Participants, '[]') as ThreadParticipants")
|
||||
columns = append(columns,
|
||||
"COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount",
|
||||
"COALESCE(Threads.LastReplyAt, 0) as LastReplyAt",
|
||||
"COALESCE(Threads.Participants, '[]') as ThreadParticipants",
|
||||
"COALESCE(ThreadMemberships.Following, false) as IsFollowing",
|
||||
)
|
||||
var posts []*postWithExtra
|
||||
|
||||
postFetchQuery, args, _ := s.getQueryBuilder().
|
||||
Select(columns...).
|
||||
From("Posts").
|
||||
LeftJoin("Threads ON Threads.PostId = Id").
|
||||
LeftJoin("ThreadMemberships ON ThreadMemberships.PostId = Id AND ThreadMemberships.UserId = ?", options.UserId).
|
||||
Where(sq.Eq{"DeleteAt": 0}).
|
||||
Where(sq.Eq{"Posts.ChannelId": options.ChannelId}).
|
||||
Where(sq.Gt{"UpdateAt": options.Time}).
|
||||
@@ -944,7 +964,12 @@ func (s *SqlPostStore) getPostsAround(before bool, options model.GetPostsOptions
|
||||
}
|
||||
columns := []string{"p.*"}
|
||||
if options.CollapsedThreads {
|
||||
columns = append(columns, "COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount", "COALESCE(Threads.LastReplyAt, 0) as LastReplyAt", "COALESCE(Threads.Participants, '[]') as ThreadParticipants")
|
||||
columns = append(columns,
|
||||
"COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount",
|
||||
"COALESCE(Threads.LastReplyAt, 0) as LastReplyAt",
|
||||
"COALESCE(Threads.Participants, '[]') as ThreadParticipants",
|
||||
"COALESCE(ThreadMemberships.Following, false) as IsFollowing",
|
||||
)
|
||||
}
|
||||
query := s.getQueryBuilder().Select(columns...)
|
||||
replyCountSubQuery := s.getQueryBuilder().Select("COUNT(Posts.Id)").From("Posts").Where(sq.Expr("Posts.RootId = (CASE WHEN p.RootId = '' THEN p.Id ELSE p.RootId END) AND Posts.DeleteAt = 0"))
|
||||
@@ -956,7 +981,7 @@ func (s *SqlPostStore) getPostsAround(before bool, options model.GetPostsOptions
|
||||
}
|
||||
if options.CollapsedThreads {
|
||||
conditions = append(conditions, sq.Eq{"RootId": ""})
|
||||
query = query.LeftJoin("Threads ON Threads.PostId = p.Id")
|
||||
query = query.LeftJoin("Threads ON Threads.PostId = p.Id").LeftJoin("ThreadMemberships ON ThreadMemberships.PostId = p.Id AND ThreadMemberships.UserId=?", options.UserId)
|
||||
} else {
|
||||
query = query.Column(sq.Alias(replyCountSubQuery, "ReplyCount"))
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user