commit 4c497c575cd1d39337adc22dfb9ee2b2d23042cf from: Oliver Lowe date: Sun Feb 04 11:02:36 2024 UTC lemmy: fix up, export comment path parsing for commands commit - 53469cfb86b05905dd8bb219db400e31be3f0169 commit + 4c497c575cd1d39337adc22dfb9ee2b2d23042cf blob - f30ed30b332e1105f93591f3ae88cc4fc3ba7626 blob + bfd8c68f667c8b63dc9833c24659b00d7a55acba --- lemmy.go +++ lemmy.go @@ -2,7 +2,6 @@ package lemmy import ( - "errors" "fmt" "io/fs" "strconv" @@ -43,6 +42,7 @@ type Post struct { URL string Published time.Time Updated time.Time + Creator Person `json:"-"` } func (p *Post) Name() string { return strconv.Itoa(p.ID) } @@ -61,10 +61,12 @@ type Comment struct { PostID int `json:"post_id"` // Holds ordered comment IDs referenced by this comment // for threading. - References []int - Content string - CreatorID int `json:"creator_id"` - Published time.Time + Path string + Content string + CreatorID int `json:"creator_id"` + Published time.Time + ActivityURL string `json:"ap_id"` + Creator Person `json:"-"` } func (c *Comment) Name() string { return strconv.Itoa(c.ID) } @@ -75,24 +77,24 @@ func (c *Comment) ModTime() time.Time { return time.Un func (c *Comment) IsDir() bool { return c.Mode().IsDir() } func (c *Comment) Sys() interface{} { return nil } -// parseCommentPath returns the comment IDs from the path field of a Comment. -func parseCommentPath(s string) ([]int, error) { +// ParseCommentPath returns the comment IDs referenced by a Comment. +func ParseCommentPath(s string) []int { elems := strings.Split(s, ".") if len(elems) == 1 { - return nil, errors.New("only one comment in path") + return []int{} } if elems[0] != "0" { - return nil, fmt.Errorf("expected comment id 0, got %s", elems[0]) + return []int{} } refs := make([]int, len(elems)) - for _, ele := range elems { + for i, ele := range elems { id, err := strconv.Atoi(ele) if err != nil { - return nil, fmt.Errorf("parse comment id: %w", err) + return refs } - refs = append(refs, id) + refs[i] = id } - return refs, nil + return refs } type Person struct {