mirror of
https://github.com/mrusme/neonmodem.git
synced 2024-06-16 06:25:23 +00:00
Compare commits
8 Commits
1538e657fb
...
f60646f959
Author | SHA1 | Date | |
---|---|---|---|
|
f60646f959 | ||
|
494b856c9e | ||
|
cdf54c70e9 | ||
|
7fb12fe84f | ||
|
30fb8e80e9 | ||
|
3a7d2af100 | ||
|
fb84533aea | ||
|
a047a392bd |
2
go.mod
2
go.mod
|
@ -62,7 +62,7 @@ require (
|
|||
github.com/yuin/goldmark-emoji v1.0.2 // indirect
|
||||
go.uber.org/atomic v1.11.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
golang.org/x/image v0.9.0 // indirect
|
||||
golang.org/x/image v0.10.0 // indirect
|
||||
golang.org/x/net v0.17.0 // indirect
|
||||
golang.org/x/sync v0.3.0 // indirect
|
||||
golang.org/x/sys v0.13.0 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -322,8 +322,8 @@ golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMx
|
|||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.0.0-20191206065243-da761ea9ff43/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.9.0 h1:QrzfX26snvCM20hIhBwuHI/ThTg18b/+kcKdXHvnR+g=
|
||||
golang.org/x/image v0.9.0/go.mod h1:jtrku+n79PfroUbvDdeUWMAI+heR786BofxrbiSF+J0=
|
||||
golang.org/x/image v0.10.0 h1:gXjUUtwtx5yOE0VKWq1CH4IJAClq4UGgUA3i+rpON9M=
|
||||
golang.org/x/image v0.10.0/go.mod h1:jtrku+n79PfroUbvDdeUWMAI+heR786BofxrbiSF+J0=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
|
|
|
@ -50,5 +50,7 @@ func (sys *System) Connect(sysURL string) error {
|
|||
sys.config["url"] = sysURL
|
||||
sys.config["credentials"] = credentials
|
||||
|
||||
sys.config["MaxSubscriptions"] = MaxSubscriptions
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
4
system/lemmy/constant.go
Normal file
4
system/lemmy/constant.go
Normal file
|
@ -0,0 +1,4 @@
|
|||
package lemmy
|
||||
|
||||
// Limit the maximum number of subscription queries
|
||||
const MaxSubscriptions = 10000
|
|
@ -18,6 +18,7 @@ import (
|
|||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
type System struct {
|
||||
ID int
|
||||
config map[string]interface{}
|
||||
|
@ -154,36 +155,79 @@ func (sys *System) Load() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (sys *System) ListForums() ([]forum.Forum, error) {
|
||||
resp, err := sys.client.Communities(context.Background(), types.ListCommunities{
|
||||
Type: types.NewOptional(types.ListingTypeSubscribed),
|
||||
})
|
||||
func communityFullname(community types.CommunitySafe) (communityName string) {
|
||||
url, err := url.Parse(community.ActorID)
|
||||
if err != nil {
|
||||
return []forum.Forum{}, err
|
||||
return community.Name
|
||||
} else {
|
||||
return community.Name + "@" + url.Host
|
||||
}
|
||||
}
|
||||
|
||||
func (sys *System) ListForums() ([]forum.Forum, error) {
|
||||
var models []forum.Forum
|
||||
var maxSubscriptions int
|
||||
if sys.config["MaxSubscriptions"] != nil {
|
||||
maxSubscriptions = sys.config["MaxSubscriptions"].(int)
|
||||
} else {
|
||||
maxSubscriptions = MaxSubscriptions
|
||||
}
|
||||
page := 1
|
||||
queryLimit := 50
|
||||
for page < maxSubscriptions {
|
||||
resp, err := sys.client.Communities(context.Background(), types.ListCommunities{
|
||||
Type: types.NewOptional(types.ListingTypeSubscribed),
|
||||
Page: types.NewOptional(int64(page)),
|
||||
Limit: types.NewOptional(int64(queryLimit)),
|
||||
})
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
if len(resp.Communities) == 0 {
|
||||
break
|
||||
}
|
||||
for _, i := range resp.Communities {
|
||||
models = append(models, forum.Forum{
|
||||
ID: strconv.Itoa(i.Community.ID),
|
||||
Name: i.Community.Name,
|
||||
Name: communityFullname(i.Community),
|
||||
|
||||
Info: i.Community.Description.ValueOr(i.Community.Title),
|
||||
|
||||
SysIDX: sys.ID,
|
||||
})
|
||||
}
|
||||
|
||||
page += 1
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
var getPosts types.GetPosts
|
||||
if showAll {
|
||||
getPosts = types.GetPosts{
|
||||
Type: types.NewOptional(types.ListingTypeSubscribed),
|
||||
Sort: types.NewOptional(types.SortTypeNew),
|
||||
Limit: types.NewOptional(int64(50)),
|
||||
})
|
||||
}
|
||||
} else {
|
||||
getPosts = types.GetPosts{
|
||||
Type: types.NewOptional(types.ListingTypeSubscribed),
|
||||
Sort: types.NewOptional(types.SortTypeNew),
|
||||
Limit: types.NewOptional(int64(50)),
|
||||
CommunityID: types.NewOptional(communityID),
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := sys.client.Posts(context.Background(), getPosts)
|
||||
if err != nil {
|
||||
return []post.Post{}, err
|
||||
}
|
||||
|
@ -191,7 +235,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("")
|
||||
|
@ -223,7 +266,7 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
|
|||
|
||||
Forum: forum.Forum{
|
||||
ID: strconv.Itoa(i.Post.CommunityID),
|
||||
Name: i.Community.Name,
|
||||
Name: communityFullname(i.Community),
|
||||
|
||||
SysIDX: sys.ID,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue
Block a user