From fad7191035a05480b2f7ce4c95667cf8b3542474 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Mon, 12 Jul 2021 14:15:13 -0400 Subject: [PATCH] add most of the missing fields --- cmd/apollo-worker-notifications/main.go | 11 ++++++----- internal/reddit/types.go | 22 ++++++++++++---------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/cmd/apollo-worker-notifications/main.go b/cmd/apollo-worker-notifications/main.go index 9093632..54f01ae 100644 --- a/cmd/apollo-worker-notifications/main.go +++ b/cmd/apollo-worker-notifications/main.go @@ -370,7 +370,7 @@ func (c *Consumer) Consume(delivery rmq.Delivery) { for _, msg := range msgs.MessageListing.Messages { notification := &apns2.Notification{} notification.Topic = "com.christianselig.Apollo" - notification.Payload = payloadFromMessage(&msg) + notification.Payload = payloadFromMessage(account, &msg, len(msgs.MessageListing.Messages)) for _, device := range devices { notification.DeviceToken = device.APNSToken @@ -404,7 +404,7 @@ func (c *Consumer) Consume(delivery rmq.Delivery) { }).Debug("finishing job") } -func payloadFromMessage(msg *reddit.MessageData) *payload.Payload { +func payloadFromMessage(acct *data.Account, msg *reddit.MessageData, badgeCount int) *payload.Payload { postBody := msg.Body if len(postBody) > 2000 { postBody = msg.Body[:2000] @@ -418,7 +418,7 @@ func payloadFromMessage(msg *reddit.MessageData) *payload.Payload { postTitle = fmt.Sprintf("%s…", postTitle[0:75]) } - payload := payload.NewPayload().Sound("traloop.wav").AlertBody(postBody).Custom("author", msg.Author).Custom("parent_id", msg.ParentID).AlertSummaryArg(msg.Author).MutableContent() + payload := payload.NewPayload().Sound("traloop.wav").AlertBody(postBody).Custom("author", msg.Author).Custom("parent_id", msg.ParentID).AlertSummaryArg(msg.Author).MutableContent().Badge(badgeCount).Custom("post_title", msg.LinkTitle).Custom("destination_author", msg.Destination).Custom("subreddit", msg.Subreddit) switch { case (msg.Kind == "t1" && msg.Type == "username_mention"): @@ -436,11 +436,12 @@ func payloadFromMessage(msg *reddit.MessageData) *payload.Payload { break case (msg.Kind == "t1" && msg.Type == "post_reply"): title := fmt.Sprintf(`%s to “%s”`, msg.Author, postTitle) - payload = payload.AlertTitle(title).Custom("type", "post").Category("inbox-post-reply").Custom("subject", "comment").ThreadID("comment") + payload = payload.AlertTitle(title).Custom("type", "post").Category("inbox-post-reply").Custom("subject", "comment").ThreadID("comment").Custom("post_id", msg.ID) break case (msg.Kind == "t1" && msg.Type == "comment_reply"): title := fmt.Sprintf(`%s in “%s”`, msg.Author, postTitle) - payload = payload.AlertTitle(title).Custom("type", "comment").Category("inbox-comment-reply").Custom("subject", "comment").ThreadID("comment") + _, postID := reddit.SplitID(msg.ParentID) + payload = payload.AlertTitle(title).Custom("type", "comment").Category("inbox-comment-reply").Custom("subject", "comment").ThreadID("comment").Custom("post_id", postID).Custom("comment_id", msg.ID) break case (msg.Kind == "t4"): title := fmt.Sprintf(`Message from %s`, msg.Author) diff --git a/internal/reddit/types.go b/internal/reddit/types.go index 2dda199..eba8247 100644 --- a/internal/reddit/types.go +++ b/internal/reddit/types.go @@ -3,16 +3,18 @@ package reddit import "fmt" type Message struct { - ID string `json:"id"` - Kind string `json:"kind"` - Type string `json:"type"` - Author string `json:"author"` - Subject string `json:"subject"` - Body string `json:"body"` - CreatedAt float64 `json:"created_utc"` - Context string `json:"context"` - ParentID string `json:"parent_id"` - LinkTitle string `json:"link_title"` + ID string `json:"id"` + Kind string `json:"kind"` + Type string `json:"type"` + Author string `json:"author"` + Subject string `json:"subject"` + Body string `json:"body"` + CreatedAt float64 `json:"created_utc"` + Context string `json:"context"` + ParentID string `json:"parent_id"` + LinkTitle string `json:"link_title"` + Destination string `json:"dest"` + Subreddit string `json:"subreddit"` } type MessageData struct {