Get posts for a channel has_next attribute fix (#26901)
* Get posts for a channel has_next attribute fix * HasNext attribute test changes * tests fix --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
468813c04f
Коммит
4999c4a9c6
@@ -1774,6 +1774,8 @@ func TestGetPostsForChannel(t *testing.T) {
|
||||
require.Equal(t, post2.Id, posts.Order[2], "wrong order")
|
||||
require.Equal(t, post1.Id, posts.Order[3], "wrong order")
|
||||
|
||||
require.Nil(t, posts.HasNext, "HasNext should not be returned")
|
||||
|
||||
posts, resp, _ = c.GetPostsForChannel(context.Background(), th.BasicChannel.Id, 0, 3, resp.Etag, false, false)
|
||||
CheckEtag(t, posts, resp)
|
||||
|
||||
|
||||
@@ -677,7 +677,7 @@ func (s *SqlPostStore) getPostWithCollapsedThreads(id, userID string, opts model
|
||||
list.AddPost(p)
|
||||
list.AddOrder(p.Id)
|
||||
}
|
||||
list.HasNext = hasNext
|
||||
list.HasNext = &hasNext
|
||||
|
||||
return list, nil
|
||||
}
|
||||
@@ -828,7 +828,7 @@ func (s *SqlPostStore) Get(ctx context.Context, id string, opts model.GetPostsOp
|
||||
pl.AddPost(p)
|
||||
pl.AddOrder(p.Id)
|
||||
}
|
||||
pl.HasNext = hasNext
|
||||
pl.HasNext = &hasNext
|
||||
}
|
||||
return pl, nil
|
||||
}
|
||||
|
||||
@@ -776,7 +776,7 @@ func testPostStoreGetForThread(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, r1.Order, 3) // including the root post
|
||||
require.Len(t, r1.Posts, 3)
|
||||
assert.True(t, r1.HasNext)
|
||||
assert.True(t, *r1.HasNext)
|
||||
|
||||
lastPostID := r1.Order[len(r1.Order)-1]
|
||||
lastPostCreateAt := r1.Posts[lastPostID].CreateAt
|
||||
@@ -793,7 +793,7 @@ func testPostStoreGetForThread(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
require.Len(t, r1.Order, 3) // including the root post
|
||||
require.Len(t, r1.Posts, 3)
|
||||
assert.GreaterOrEqual(t, r1.Posts[r1.Order[len(r1.Order)-1]].CreateAt, lastPostCreateAt)
|
||||
assert.False(t, r1.HasNext)
|
||||
assert.False(t, *r1.HasNext)
|
||||
|
||||
// Going from bottom to top now.
|
||||
firstPostCreateAt := r1.Posts[r1.Order[1]].CreateAt
|
||||
@@ -809,7 +809,7 @@ func testPostStoreGetForThread(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
require.Len(t, r1.Order, 3) // including the root post
|
||||
require.Len(t, r1.Posts, 3)
|
||||
assert.LessOrEqual(t, r1.Posts[r1.Order[1]].CreateAt, firstPostCreateAt)
|
||||
assert.False(t, r1.HasNext)
|
||||
assert.False(t, *r1.HasNext)
|
||||
|
||||
// Only with CreateAt
|
||||
opts = model.GetPostsOptions{
|
||||
@@ -826,7 +826,7 @@ func testPostStoreGetForThread(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
require.Len(t, r1.Order, 2) // including the root post
|
||||
require.Len(t, r1.Posts, 2)
|
||||
assert.LessOrEqual(t, r1.Posts[r1.Order[1]].CreateAt, m1.CreateAt)
|
||||
assert.True(t, r1.HasNext)
|
||||
assert.True(t, *r1.HasNext)
|
||||
|
||||
// Non-CRT mode
|
||||
opts = model.GetPostsOptions{
|
||||
@@ -839,7 +839,7 @@ func testPostStoreGetForThread(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, r1.Order, 2) // including the root post
|
||||
require.Len(t, r1.Posts, 2)
|
||||
assert.True(t, r1.HasNext)
|
||||
assert.True(t, *r1.HasNext)
|
||||
|
||||
lastPostID = r1.Order[len(r1.Order)-1]
|
||||
lastPostCreateAt = r1.Posts[lastPostID].CreateAt
|
||||
@@ -861,7 +861,7 @@ func testPostStoreGetForThread(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
require.Len(t, r1.Order, 4) // including the root post
|
||||
require.Len(t, r1.Posts, 4)
|
||||
assert.GreaterOrEqual(t, r1.Posts[r1.Order[len(r1.Order)-1]].CreateAt, lastPostCreateAt)
|
||||
assert.False(t, r1.HasNext)
|
||||
assert.False(t, *r1.HasNext)
|
||||
|
||||
// Going from bottom to top now.
|
||||
firstPostCreateAt = r1.Posts[r1.Order[1]].CreateAt
|
||||
@@ -878,7 +878,7 @@ func testPostStoreGetForThread(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
require.Len(t, r1.Order, 2) // including the root post
|
||||
require.Len(t, r1.Posts, 2)
|
||||
assert.LessOrEqual(t, r1.Posts[r1.Order[1]].CreateAt, firstPostCreateAt)
|
||||
assert.False(t, r1.HasNext)
|
||||
assert.False(t, *r1.HasNext)
|
||||
|
||||
// Only with CreateAt
|
||||
opts = model.GetPostsOptions{
|
||||
@@ -893,7 +893,7 @@ func testPostStoreGetForThread(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
require.Len(t, r1.Order, 2) // including the root post
|
||||
require.Len(t, r1.Posts, 2)
|
||||
assert.GreaterOrEqual(t, r1.Posts[r1.Order[1]].CreateAt, m1.CreateAt)
|
||||
assert.True(t, r1.HasNext)
|
||||
assert.True(t, *r1.HasNext)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ type PostList struct {
|
||||
NextPostId string `json:"next_post_id"`
|
||||
PrevPostId string `json:"prev_post_id"`
|
||||
// HasNext indicates whether there are more items to be fetched or not.
|
||||
HasNext bool `json:"has_next"`
|
||||
HasNext *bool `json:"has_next,omitempty"`
|
||||
// If there are inaccessible posts, FirstInaccessiblePostTime is the time of the latest inaccessible post
|
||||
FirstInaccessiblePostTime int64 `json:"first_inaccessible_post_time"`
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user