Skip to content

Commit

Permalink
resolves mrusme#37 Keep lemmy results 50 but query specific community
Browse files Browse the repository at this point in the history
  • Loading branch information
BreadMakesYouFat committed Jun 24, 2023
1 parent 19556e2 commit 06fd4b6
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions system/lemmy/lemmy.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,23 +178,35 @@ func (sys *System) ListForums() ([]forum.Forum, error) {
}

func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
resp, err := sys.client.Posts(context.Background(), types.GetPosts{
Type: types.NewOptional(types.ListingTypeSubscribed),
Sort: types.NewOptional(types.SortTypeNew),
Limit: types.NewOptional(int64(50)),
})

if err != nil {
return []post.Post{}, err
}

var communityID int
var showAll bool
var err error

communityID, err = strconv.Atoi(forumID)
if err != nil {
showAll = true
}

resp := &types.GetPostsResponse{}
if showAll {
resp, err = sys.client.Posts(context.Background(), types.GetPosts{
Type: types.NewOptional(types.ListingTypeSubscribed),
Sort: types.NewOptional(types.SortTypeNew),
Limit: types.NewOptional(int64(50)),
})
} else {
resp, err = sys.client.Posts(context.Background(), types.GetPosts{
Type: types.NewOptional(types.ListingTypeSubscribed),
Sort: types.NewOptional(types.SortTypeNew),
Limit: types.NewOptional(int64(50)),
CommunityID: types.NewOptional(communityID),
})
}

if err != nil {
return []post.Post{}, err
}

cfg := sys.GetConfig()
baseURL := cfg["url"].(string)

Expand Down

0 comments on commit 06fd4b6

Please sign in to comment.