diff --git a/api/user.go b/api/user.go index c98758c..4ffd4b3 100644 --- a/api/user.go +++ b/api/user.go @@ -111,7 +111,7 @@ func (client *Client) FetchUserComments(username string, page string) ([]Comment q := req.URL.Query() q.Add("client_id", client.ClientID) - q.Add("filter[account]", "eq:wouldaponybyanyothernamebeasoffencive") + q.Add("filter[account]", "eq:"+username) q.Add("include", "account,post") q.Add("sort", "new") @@ -150,20 +150,30 @@ func (client *Client) FetchUserComments(username string, page string) ([]Comment } func parseSubmission(value gjson.Result) Submission { - coverData := value.Get("images.#(id==\"" + value.Get("cover").String() + "\")") - cover := Media{ - Id: value.Get("id").String(), - Description: value.Get("description").String(), - Type: strings.Split(value.Get("type").String(), "/")[0], - Url: strings.ReplaceAll(value.Get("link").String(), "https://i.imgur.com", ""), - } - if coverData.Exists() { + var cover Media + c := value.Get("cover") + coverData := value.Get("images.#(id==\"" + c.String() + "\")") + switch { + case c.Type == gjson.String && coverData.Exists(): cover = Media{ Id: coverData.Get("id").String(), Description: coverData.Get("description").String(), Type: strings.Split(coverData.Get("type").String(), "/")[0], Url: strings.ReplaceAll(coverData.Get("link").String(), "https://i.imgur.com", ""), } + // This case is when fetching comments + case c.Type != gjson.Null: + cover = Media{ + Id: c.Get("id").String(), + Url: c.Get("url").String(), + } + default: + cover = Media{ + Id: value.Get("id").String(), + Description: value.Get("description").String(), + Type: strings.Split(value.Get("type").String(), "/")[0], + Url: strings.ReplaceAll(value.Get("link").String(), "https://i.imgur.com", ""), + } } id := value.Get("id").String() diff --git a/pages/user.go b/pages/user.go index 0a9cc4b..05b0355 100644 --- a/pages/user.go +++ b/pages/user.go @@ -1,6 +1,7 @@ package pages import ( + "fmt" "strconv" "codeberg.org/rimgo/rimgo/utils" @@ -96,6 +97,8 @@ func HandleUserComments(c *fiber.Ctx) error { return err } + fmt.Println(comments[0].Post.Cover.Url) //FIXME:debug + return c.Render("userComments", fiber.Map{ "user": user, "comments": comments, diff --git a/views/partials/contextComment.hbs b/views/partials/contextComment.hbs index 8088271..1faf833 100644 --- a/views/partials/contextComment.hbs +++ b/views/partials/contextComment.hbs @@ -1,38 +1,39 @@ - -
[deleted] - on post title here {{Post.Title}}
- {{/equal}} +{{this.User.Username}}
+ + {{/noteq}} + {{#equal this.User.Username "[deleted]"}} +[deleted]
+ {{/equal}} +{{{this.Comment}}}
+{{{this.Comment}}}
-