MM-30304 - Handle collapsed threads in page apis (#17064)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f2e27a39da
Коммит
4aa6c863c3
28
app/post.go
28
app/post.go
@@ -876,8 +876,8 @@ func (a *App) GetPostsAroundPost(before bool, options model.GetPostsOptions) (*m
|
||||
return postList, nil
|
||||
}
|
||||
|
||||
func (a *App) GetPostAfterTime(channelID string, time int64) (*model.Post, *model.AppError) {
|
||||
post, err := a.Srv().Store.Post().GetPostAfterTime(channelID, time)
|
||||
func (a *App) GetPostAfterTime(channelID string, time int64, collapsedThreads bool) (*model.Post, *model.AppError) {
|
||||
post, err := a.Srv().Store.Post().GetPostAfterTime(channelID, time, collapsedThreads)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetPostAfterTime", "app.post.get_post_after_time.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
@@ -885,8 +885,8 @@ func (a *App) GetPostAfterTime(channelID string, time int64) (*model.Post, *mode
|
||||
return post, nil
|
||||
}
|
||||
|
||||
func (a *App) GetPostIdAfterTime(channelID string, time int64) (string, *model.AppError) {
|
||||
postID, err := a.Srv().Store.Post().GetPostIdAfterTime(channelID, time)
|
||||
func (a *App) GetPostIdAfterTime(channelID string, time int64, collapsedThreads bool) (string, *model.AppError) {
|
||||
postID, err := a.Srv().Store.Post().GetPostIdAfterTime(channelID, time, collapsedThreads)
|
||||
if err != nil {
|
||||
return "", model.NewAppError("GetPostIdAfterTime", "app.post.get_post_id_around.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
@@ -894,8 +894,8 @@ func (a *App) GetPostIdAfterTime(channelID string, time int64) (string, *model.A
|
||||
return postID, nil
|
||||
}
|
||||
|
||||
func (a *App) GetPostIdBeforeTime(channelID string, time int64) (string, *model.AppError) {
|
||||
postID, err := a.Srv().Store.Post().GetPostIdBeforeTime(channelID, time)
|
||||
func (a *App) GetPostIdBeforeTime(channelID string, time int64, collapsedThreads bool) (string, *model.AppError) {
|
||||
postID, err := a.Srv().Store.Post().GetPostIdBeforeTime(channelID, time, collapsedThreads)
|
||||
if err != nil {
|
||||
return "", model.NewAppError("GetPostIdBeforeTime", "app.post.get_post_id_around.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
@@ -903,11 +903,11 @@ func (a *App) GetPostIdBeforeTime(channelID string, time int64) (string, *model.
|
||||
return postID, nil
|
||||
}
|
||||
|
||||
func (a *App) GetNextPostIdFromPostList(postList *model.PostList) string {
|
||||
func (a *App) GetNextPostIdFromPostList(postList *model.PostList, collapsedThreads bool) string {
|
||||
if len(postList.Order) > 0 {
|
||||
firstPostId := postList.Order[0]
|
||||
firstPost := postList.Posts[firstPostId]
|
||||
nextPostId, err := a.GetPostIdAfterTime(firstPost.ChannelId, firstPost.CreateAt)
|
||||
nextPostId, err := a.GetPostIdAfterTime(firstPost.ChannelId, firstPost.CreateAt, collapsedThreads)
|
||||
if err != nil {
|
||||
mlog.Warn("GetNextPostIdFromPostList: failed in getting next post", mlog.Err(err))
|
||||
}
|
||||
@@ -918,11 +918,11 @@ func (a *App) GetNextPostIdFromPostList(postList *model.PostList) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (a *App) GetPrevPostIdFromPostList(postList *model.PostList) string {
|
||||
func (a *App) GetPrevPostIdFromPostList(postList *model.PostList, collapsedThreads bool) string {
|
||||
if len(postList.Order) > 0 {
|
||||
lastPostId := postList.Order[len(postList.Order)-1]
|
||||
lastPost := postList.Posts[lastPostId]
|
||||
previousPostId, err := a.GetPostIdBeforeTime(lastPost.ChannelId, lastPost.CreateAt)
|
||||
previousPostId, err := a.GetPostIdBeforeTime(lastPost.ChannelId, lastPost.CreateAt, collapsedThreads)
|
||||
if err != nil {
|
||||
mlog.Warn("GetPrevPostIdFromPostList: failed in getting previous post", mlog.Err(err))
|
||||
}
|
||||
@@ -936,7 +936,7 @@ func (a *App) GetPrevPostIdFromPostList(postList *model.PostList) string {
|
||||
// AddCursorIdsForPostList adds NextPostId and PrevPostId as cursor to the PostList.
|
||||
// The conditional blocks ensure that it sets those cursor IDs immediately as afterPost, beforePost or empty,
|
||||
// and only query to database whenever necessary.
|
||||
func (a *App) AddCursorIdsForPostList(originalList *model.PostList, afterPost, beforePost string, since int64, page, perPage int) {
|
||||
func (a *App) AddCursorIdsForPostList(originalList *model.PostList, afterPost, beforePost string, since int64, page, perPage int, collapsedThreads bool) {
|
||||
prevPostIdSet := false
|
||||
prevPostId := ""
|
||||
nextPostIdSet := false
|
||||
@@ -966,11 +966,11 @@ func (a *App) AddCursorIdsForPostList(originalList *model.PostList, afterPost, b
|
||||
}
|
||||
|
||||
if !nextPostIdSet {
|
||||
nextPostId = a.GetNextPostIdFromPostList(originalList)
|
||||
nextPostId = a.GetNextPostIdFromPostList(originalList, collapsedThreads)
|
||||
}
|
||||
|
||||
if !prevPostIdSet {
|
||||
prevPostId = a.GetPrevPostIdFromPostList(originalList)
|
||||
prevPostId = a.GetPrevPostIdFromPostList(originalList, collapsedThreads)
|
||||
}
|
||||
|
||||
originalList.NextPostId = nextPostId
|
||||
@@ -985,7 +985,7 @@ func (a *App) GetPostsForChannelAroundLastUnread(channelID, userID string, limit
|
||||
return model.NewPostList(), nil
|
||||
}
|
||||
|
||||
lastUnreadPostId, err := a.GetPostIdAfterTime(channelID, member.LastViewedAt)
|
||||
lastUnreadPostId, err := a.GetPostIdAfterTime(channelID, member.LastViewedAt, collapsedThreads)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if lastUnreadPostId == "" {
|
||||
|
||||
Ссылка в новой задаче
Block a user