commit - 4c497c575cd1d39337adc22dfb9ee2b2d23042cf
commit + 2a4edef3d088dbb3d4653ffa1edf6920955c7f79
blob - c8087b3a191946d99eda401cd408e29da0810beb
blob + ee83ee254f6554490a600bccba8a6f1de979529b
--- client.go
+++ client.go
params := map[string]string{
"type_": string(mode),
- "limit": "30", // TODO go through pages
- "sort": "New", // Required - Lemmy bug - even though we don't care about sorting.
+ "limit": "30", // TODO go through pages
+ "sort": "New",
}
if mode == ListSubscribed {
if c.authToken == "" {
return communities, nil
}
-func (c *Client) LookupCommunity(name string) (Community, error) {
+func (c *Client) LookupCommunity(name string) (Community, Counts, error) {
if !c.ready {
if err := c.init(); err != nil {
- return Community{}, err
+ return Community{}, Counts{}, err
}
}
params := map[string]string{"name": name}
resp, err := c.get("community", params)
if err != nil {
- return Community{}, err
+ return Community{}, Counts{}, err
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusNotFound {
- return Community{}, ErrNotFound
+ return Community{}, Counts{}, ErrNotFound
} else if resp.StatusCode != http.StatusOK {
- return Community{}, fmt.Errorf("remote status %s: %w", resp.Status, decodeError(resp.Body))
+ return Community{}, Counts{}, fmt.Errorf("remote status %s: %w", resp.Status, decodeError(resp.Body))
}
type response struct {
View struct {
Community Community
+ Counts Counts
} `json:"community_view"`
}
var cres response
if err := json.NewDecoder(resp.Body).Decode(&cres); err != nil {
- return Community{}, fmt.Errorf("decode community response: %w", err)
+ return Community{}, Counts{}, fmt.Errorf("decode community response: %w", err)
}
- return cres.View.Community, nil
+ return cres.View.Community, cres.View.Counts, nil
}
func (c *Client) Posts(community string, mode ListMode) ([]Post, error) {
"community_name": community,
"limit": "30",
"type_": string(mode),
- "sort": "New", // Required - Lemmy bug - even though we don't care about sorting.
+ "sort": "New",
}
resp, err := c.get("post/list", params)
if err != nil {
var jresponse struct {
Posts []struct {
- Post Post
+ Post Post
+ Creator Person
}
}
if err := json.NewDecoder(resp.Body).Decode(&jresponse); err != nil {
}
var posts []Post
for _, post := range jresponse.Posts {
+ post.Post.Creator = post.Creator
posts = append(posts, post.Post)
}
return posts, nil
params := map[string]string{
"post_id": strconv.Itoa(post),
"type_": string(mode),
- "sort": "New", // Required - Lemmy bug - even though we don't care about sorting.
+ "limit": "30",
+ "sort": "New",
}
resp, err := c.get("comment/list", params)
if err != nil {
var jresponse struct {
Comments []struct {
Comment Comment
+ Creator Person
}
}
if err := json.NewDecoder(resp.Body).Decode(&jresponse); err != nil {
}
var comments []Comment
for _, comment := range jresponse.Comments {
+ comment.Comment.Creator = comment.Creator
comments = append(comments, comment.Comment)
}
return comments, nil
}
return jerr
}
+
+type Counts struct {
+ Posts int
+ Comments int
+ CommunityID int `json:"community_id"`
+ PostID int `json:"post_id"`
+}
blob - 023adbc6b2985e9e542b3452e9af34072dc71850
blob + 59d0d76dadbcfaa8839516f898f9138b05834559
--- decode.go
+++ decode.go
if err := json.NewDecoder(r).Decode(&jresp); err != nil {
return Post{}, Person{}, Community{}, fmt.Errorf("decode post: %w", err)
}
+ jresp.PostView.Post.Creator = jresp.PostView.Creator
return jresp.PostView.Post, jresp.PostView.Creator, jresp.PostView.Community, nil
}
blob - 3a1bbd61539a774aec3760301b0e3a5fbbc12703
blob + 0e77af598acb419e017ac16d27b15bf86ec8c861
--- fs/file.go
+++ fs/file.go
}
func (f *comFile) Stat() (fs.FileInfo, error) {
- community, err := f.client.LookupCommunity(f.name)
+ community, _, err := f.client.LookupCommunity(f.name)
if err != nil {
return nil, &fs.PathError{"stat", f.name, err}
}
blob - 635e8a6a94b392f31739c7fe63046b5eb64392f0
blob + 798eb37e257ab1e4e90922d31f86ab832ec5688f
--- fs/fs.go
+++ fs/fs.go
community, ok := fsys.Communities[elems[0]]
if !ok {
var err error
- community, err = fsys.Client.LookupCommunity(elems[0])
+ community, _, err = fsys.Client.LookupCommunity(elems[0])
if errors.Is(err, lemmy.ErrNotFound) {
return nil, &fs.PathError{"open", name, fs.ErrNotExist}
} else if err != nil {