1 1081cf75 2024-11-04 o // Package lemmy provides a client interface to the Lemmy HTTP API version 3.
12 1081cf75 2024-11-04 o type Community struct {
13 1081cf75 2024-11-04 o ID int `json:"id"`
14 1081cf75 2024-11-04 o FName string `json:"name"`
15 1081cf75 2024-11-04 o Title string `json:"title"`
17 1081cf75 2024-11-04 o ActorID string `json:"actor_id"`
18 1081cf75 2024-11-04 o Published time.Time
21 1081cf75 2024-11-04 o func (c *Community) Name() string { return c.String() }
22 1081cf75 2024-11-04 o func (c *Community) Size() int64 { return 0 }
23 1081cf75 2024-11-04 o func (c *Community) Mode() fs.FileMode { return fs.ModeDir | 0o0555 }
24 1081cf75 2024-11-04 o func (c *Community) ModTime() time.Time { return c.Published }
25 1081cf75 2024-11-04 o func (c *Community) IsDir() bool { return c.Mode().IsDir() }
26 1081cf75 2024-11-04 o func (c *Community) Sys() interface{} { return nil }
28 1081cf75 2024-11-04 o func (c Community) String() string {
32 1081cf75 2024-11-04 o noscheme := strings.TrimPrefix(c.ActorID, "https://")
33 1081cf75 2024-11-04 o instance, _, _ := strings.Cut(noscheme, "/")
34 1081cf75 2024-11-04 o return fmt.Sprintf("%s@%s", c.FName, instance)
37 1081cf75 2024-11-04 o type Post struct {
39 1081cf75 2024-11-04 o Title string `json:"name"`
41 1081cf75 2024-11-04 o CreatorID int `json:"creator_id"`
43 1081cf75 2024-11-04 o Published time.Time
44 1081cf75 2024-11-04 o Updated time.Time
45 1081cf75 2024-11-04 o Creator Person `json:"-"`
48 1081cf75 2024-11-04 o func (p *Post) Name() string { return strconv.Itoa(p.ID) }
50 1081cf75 2024-11-04 o func (p *Post) Size() int64 {
51 1081cf75 2024-11-04 o return int64(len(p.Body))
54 1081cf75 2024-11-04 o func (p *Post) Mode() fs.FileMode { return fs.ModeDir | 0o0555 }
55 1081cf75 2024-11-04 o func (p *Post) IsDir() bool { return p.Mode().IsDir() }
56 1081cf75 2024-11-04 o func (p *Post) Sys() interface{} { return nil }
57 1081cf75 2024-11-04 o func (p *Post) ModTime() time.Time {
58 1081cf75 2024-11-04 o if p.Updated.IsZero() {
59 1081cf75 2024-11-04 o return p.Published
61 1081cf75 2024-11-04 o return p.Updated
64 1081cf75 2024-11-04 o type Comment struct {
66 1081cf75 2024-11-04 o PostID int `json:"post_id"`
67 1081cf75 2024-11-04 o // Holds ordered comment IDs referenced by this comment
68 1081cf75 2024-11-04 o // for threading.
71 1081cf75 2024-11-04 o CreatorID int `json:"creator_id"`
72 1081cf75 2024-11-04 o Published time.Time
73 1081cf75 2024-11-04 o Updated time.Time
74 1081cf75 2024-11-04 o ActivityURL string `json:"ap_id"`
75 1081cf75 2024-11-04 o Creator Person `json:"-"`
78 1081cf75 2024-11-04 o func (c *Comment) Name() string { return strconv.Itoa(c.ID) }
80 1081cf75 2024-11-04 o func (c *Comment) Size() int64 { return 0 }
81 1081cf75 2024-11-04 o func (c *Comment) Mode() fs.FileMode { return 0444 }
82 1081cf75 2024-11-04 o func (c *Comment) ModTime() time.Time {
83 1081cf75 2024-11-04 o if c.Updated.IsZero() {
84 1081cf75 2024-11-04 o return c.Published
86 1081cf75 2024-11-04 o return c.Updated
88 1081cf75 2024-11-04 o func (c *Comment) IsDir() bool { return c.Mode().IsDir() }
89 1081cf75 2024-11-04 o func (c *Comment) Sys() interface{} { return nil }
91 1081cf75 2024-11-04 o // ParseCommentPath returns the comment IDs referenced by a Comment.
92 1081cf75 2024-11-04 o func ParseCommentPath(s string) []int {
93 1081cf75 2024-11-04 o elems := strings.Split(s, ".")
94 1081cf75 2024-11-04 o if len(elems) == 1 {
97 1081cf75 2024-11-04 o if elems[0] != "0" {
100 1081cf75 2024-11-04 o refs := make([]int, len(elems))
101 1081cf75 2024-11-04 o for i, ele := range elems {
102 1081cf75 2024-11-04 o id, err := strconv.Atoi(ele)
103 1081cf75 2024-11-04 o if err != nil {
111 1081cf75 2024-11-04 o type Person struct {
112 1081cf75 2024-11-04 o ID int `json:"id"`
113 1081cf75 2024-11-04 o Name string `json:"name"`
114 1081cf75 2024-11-04 o ActorID string `json:"actor_id"`
115 1081cf75 2024-11-04 o Local bool `json:"local"`
118 1081cf75 2024-11-04 o func (p Person) String() string {
122 1081cf75 2024-11-04 o noscheme := strings.TrimPrefix(p.ActorID, "https://")
123 1081cf75 2024-11-04 o instance, _, _ := strings.Cut(noscheme, "/")
124 1081cf75 2024-11-04 o return fmt.Sprintf("%s@%s", p.Name, instance)