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