Skip to content

Commit

Permalink
implement reply count logic to paginator on BE
Browse files Browse the repository at this point in the history
  • Loading branch information
krustowski committed Sep 11, 2024
1 parent dc7507a commit 0163498
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/backend/posts/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func getPosts(w http.ResponseWriter, r *http.Request) {
// fetch page according to the logged user
pExport, uExport := GetOnePage(opts)
if pExport == nil || uExport == nil {
resp.Message = "error while requesting more page, one exported map is nil!"
resp.Message = "error while requesting more pages, one exported map is nil!"
resp.Code = http.StatusInternalServerError

l.Println(resp.Message, resp.Code)
Expand Down
21 changes: 13 additions & 8 deletions pkg/backend/posts/paginate.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,22 @@ func GetOnePage(opts PageOptions) (map[string]models.Post, map[string]models.Use
flowList = opts.FlowList
}

// filter out all posts for such callerID
// assign reply count to each post
for _, post := range allPosts {
if post.ReplyToID == "" {
continue
}

// calculate the reply count for each post
/*if post.ReplyToID != "" {
origo, found := allPosts[post.ReplyToID]
if found {
origo.ReplyCount++
allPosts[post.ReplyToID] = origo
}
}*/
origo, found := allPosts[post.ReplyToID]
if found {
origo.ReplyCount++
allPosts[origo.ID] = origo
}
}

// filter out all posts for such callerID
for _, post := range allPosts {
// check the caller's flow list, skip on unfollowed, or unknown user
if value, found := flowList[post.Nickname]; !found || !value {
continue
Expand Down

0 comments on commit 0163498

Please sign in to comment.