don't alert user posts in private subreddits

This commit is contained in:
Andre Medeiros 2021-10-09 12:19:52 -04:00
parent 38e596b27e
commit 009d60dc2f
4 changed files with 7374 additions and 17 deletions

7335
internal/reddit/testdata/user_posts.json vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -73,6 +73,7 @@ type Thing struct {
LinkTitle string `json:"link_title"`
Destination string `json:"dest"`
Subreddit string `json:"subreddit"`
SubredditType string `json:"subreddit_type"`
Score int64 `json:"score"`
SelfText string `json:"selftext"`
Title string `json:"title"`
@ -102,6 +103,7 @@ func NewThing(val *fastjson.Value) *Thing {
t.LinkTitle = string(data.GetStringBytes("link_title"))
t.Destination = string(data.GetStringBytes("dest"))
t.Subreddit = string(data.GetStringBytes("subreddit"))
t.SubredditType = string(data.GetStringBytes("subreddit_type"))
t.Score = data.GetInt64("score")
t.Title = string(data.GetStringBytes("title"))

View file

@ -128,3 +128,19 @@ func TestUserResponseParsing(t *testing.T) {
assert.Equal(t, "changelog", u.Name)
assert.Equal(t, true, u.AcceptFollowers)
}
func TestUserPostsParsing(t *testing.T) {
bb, err := ioutil.ReadFile("testdata/user_posts.json")
assert.NoError(t, err)
val, err := parser.ParseBytes(bb)
assert.NoError(t, err)
ret := NewListingResponse(val)
ps := ret.(*ListingResponse)
assert.NotNil(t, ps)
post := ps.Children[0]
assert.Equal(t, "public", post.SubredditType)
}

View file

@ -220,6 +220,10 @@ func (uc *usersConsumer) Consume(delivery rmq.Delivery) {
}
for _, post := range posts.Children {
if post.SubredditType == "private" {
continue
}
notification := &apns2.Notification{}
notification.Topic = "com.christianselig.Apollo"
notification.Payload = payloadFromUserPost(post)