mirror of
https://github.com/mrusme/neonmodem.git
synced 2024-11-03 04:27:16 -05:00
Lemmy filter improvements
resolves mrusme/neonmodem#32 Filter for lemmy communities resolves mrusme/neonmodem#37 Keep lemmy results 50 but query specific community Show all subscribed lemmy communities + re-query for results from that specific community when selected
This commit is contained in:
parent
72d42efc7f
commit
a047a392bd
@ -155,14 +155,19 @@ func (sys *System) Load() error {
|
||||
}
|
||||
|
||||
func (sys *System) ListForums() ([]forum.Forum, error) {
|
||||
var models []forum.Forum
|
||||
for j := 1; j < 100; j++ {
|
||||
resp, err := sys.client.Communities(context.Background(), types.ListCommunities{
|
||||
Type: types.NewOptional(types.ListingTypeSubscribed),
|
||||
Page: types.NewOptional(int64(j)),
|
||||
Limit: types.NewOptional(int64(50)),
|
||||
})
|
||||
if err != nil {
|
||||
return []forum.Forum{}, err
|
||||
break
|
||||
}
|
||||
if len(resp.Communities) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
var models []forum.Forum
|
||||
for _, i := range resp.Communities {
|
||||
models = append(models, forum.Forum{
|
||||
ID: strconv.Itoa(i.Community.ID),
|
||||
@ -173,16 +178,35 @@ func (sys *System) ListForums() ([]forum.Forum, error) {
|
||||
SysIDX: sys.ID,
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
return models, nil
|
||||
}
|
||||
|
||||
func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
|
||||
resp, err := sys.client.Posts(context.Background(), types.GetPosts{
|
||||
var models []post.Post
|
||||
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
|
||||
@ -191,7 +215,6 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
|
||||
cfg := sys.GetConfig()
|
||||
baseURL := cfg["url"].(string)
|
||||
|
||||
var models []post.Post
|
||||
for _, i := range resp.Posts {
|
||||
t := "post"
|
||||
body := i.Post.Body.ValueOr("")
|
||||
|
Loading…
Reference in New Issue
Block a user