Add post thumbnails too

This commit is contained in:
Andre Medeiros 2022-05-01 13:33:09 -04:00
parent 63344348df
commit 9ba4498c08
3 changed files with 13 additions and 1 deletions

View file

@ -79,6 +79,7 @@ type Thing struct {
Title string `json:"title"` Title string `json:"title"`
URL string `json:"url"` URL string `json:"url"`
Flair string `json:"flair"` Flair string `json:"flair"`
Thumbnail string `json:"thumbnail"`
} }
func (t *Thing) FullName() string { func (t *Thing) FullName() string {
@ -114,6 +115,7 @@ func NewThing(val *fastjson.Value) *Thing {
t.SelfText = string(data.GetStringBytes("selftext")) t.SelfText = string(data.GetStringBytes("selftext"))
t.URL = string(data.GetStringBytes("url")) t.URL = string(data.GetStringBytes("url"))
t.Flair = string(data.GetStringBytes("link_flair_text")) t.Flair = string(data.GetStringBytes("link_flair_text"))
t.Thumbnail = string(data.GetStringBytes("thumbnail"))
return t return t
} }

View file

@ -447,5 +447,9 @@ func payloadFromPost(post *reddit.Thing) *payload.Payload {
MutableContent(). MutableContent().
Sound("traloop.wav") Sound("traloop.wav")
if post.Thumbnail != "" {
payload.Custom("thumbnail", post.Thumbnail)
}
return payload return payload
} }

View file

@ -318,7 +318,7 @@ func (tc *trendingConsumer) Consume(delivery rmq.Delivery) {
func payloadFromTrendingPost(post *reddit.Thing) *payload.Payload { func payloadFromTrendingPost(post *reddit.Thing) *payload.Payload {
title := fmt.Sprintf(trendingNotificationTitleFormat, post.Subreddit) title := fmt.Sprintf(trendingNotificationTitleFormat, post.Subreddit)
return payload. payload := payload.
NewPayload(). NewPayload().
AlertTitle(title). AlertTitle(title).
AlertBody(post.Title). AlertBody(post.Title).
@ -331,4 +331,10 @@ func payloadFromTrendingPost(post *reddit.Thing) *payload.Payload {
Custom("post_age", post.CreatedAt). Custom("post_age", post.CreatedAt).
MutableContent(). MutableContent().
Sound("traloop.wav") Sound("traloop.wav")
if post.Thumbnail != "" {
payload.Custom("thumbnail", post.Thumbnail)
}
return payload
} }