Skip to content

Commit

Permalink
Get posts for a channel has_next attribute fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryakoste committed Apr 27, 2024
1 parent a6aa92d commit d2ac27c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions server/channels/store/sqlstore/post_store.go
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
16 changes: 8 additions & 8 deletions server/channels/store/storetest/post_store.go
Expand Up @@ -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)
require.Nil(t, r1.HasNext)

lastPostID := r1.Order[len(r1.Order)-1]
lastPostCreateAt := r1.Posts[lastPostID].CreateAt
Expand All @@ -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)
require.Nil(t, r1.HasNext)

// Going from bottom to top now.
firstPostCreateAt := r1.Posts[r1.Order[1]].CreateAt
Expand All @@ -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)
require.Nil(t, r1.HasNext)

// Only with CreateAt
opts = model.GetPostsOptions{
Expand All @@ -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)
require.Nil(t, r1.HasNext)

// Non-CRT mode
opts = model.GetPostsOptions{
Expand All @@ -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)
require.Nil(t, r1.HasNext)

lastPostID = r1.Order[len(r1.Order)-1]
lastPostCreateAt = r1.Posts[lastPostID].CreateAt
Expand All @@ -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)
require.Nil(t, r1.HasNext)

// Going from bottom to top now.
firstPostCreateAt = r1.Posts[r1.Order[1]].CreateAt
Expand All @@ -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)
require.Nil(t, r1.HasNext)

// Only with CreateAt
opts = model.GetPostsOptions{
Expand All @@ -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)
require.Nil(t, r1.HasNext)
})
}

Expand Down
2 changes: 1 addition & 1 deletion server/public/model/post_list.go
Expand Up @@ -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"`
}
Expand Down

0 comments on commit d2ac27c

Please sign in to comment.