mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-25 05:07:43 +00:00
Merge branch 'main' into chore/schema-changes
This commit is contained in:
commit
ead14c8bf0
9 changed files with 102 additions and 32 deletions
5
go.mod
5
go.mod
|
@ -15,10 +15,11 @@ require (
|
|||
github.com/go-redis/redismock/v8 v8.0.6
|
||||
github.com/gorilla/mux v1.8.0
|
||||
github.com/heroku/x v0.0.50
|
||||
github.com/jackc/pgx/v4 v4.15.0
|
||||
github.com/jackc/pgx/v4 v4.16.0
|
||||
github.com/joho/godotenv v1.4.0
|
||||
github.com/sideshow/apns2 v0.22.0
|
||||
github.com/sideshow/apns2 v0.23.0
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/smtp2go-oss/smtp2go-go v1.0.1 // indirect
|
||||
github.com/spf13/cobra v1.4.0
|
||||
github.com/stretchr/testify v1.7.1
|
||||
github.com/valyala/fastjson v1.6.3
|
||||
|
|
31
go.sum
31
go.sum
|
@ -164,8 +164,8 @@ github.com/jackc/pgconn v0.0.0-20190831204454-2fabfa3c18b7/go.mod h1:ZJKsE/KZfsU
|
|||
github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o=
|
||||
github.com/jackc/pgconn v1.9.0/go.mod h1:YctiPyvzfU11JFxoXokUOOKQXQmDMoJL9vJzHH8/2JY=
|
||||
github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI=
|
||||
github.com/jackc/pgconn v1.11.0 h1:HiHArx4yFbwl91X3qqIHtUFoiIfLNJXCQRsnzkiwwaQ=
|
||||
github.com/jackc/pgconn v1.11.0/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI=
|
||||
github.com/jackc/pgconn v1.12.0 h1:/RvQ24k3TnNdfBSW0ou9EOi5jx2cX7zfE8n2nLKuiP0=
|
||||
github.com/jackc/pgconn v1.12.0/go.mod h1:ZkhRC59Llhrq3oSfrikvwQ5NaxYExr6twkdkMLaKono=
|
||||
github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE=
|
||||
github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8=
|
||||
github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE=
|
||||
|
@ -182,22 +182,22 @@ github.com/jackc/pgproto3/v2 v2.0.0-rc3/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvW
|
|||
github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM=
|
||||
github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
||||
github.com/jackc/pgproto3/v2 v2.1.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
||||
github.com/jackc/pgproto3/v2 v2.2.0 h1:r7JypeP2D3onoQTCxWdTpCtJ4D+qpKr0TxvoyMhZ5ns=
|
||||
github.com/jackc/pgproto3/v2 v2.2.0/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
||||
github.com/jackc/pgproto3/v2 v2.3.0 h1:brH0pCGBDkBW07HWlN/oSBXrmo3WB0UvZd1pIuDcL8Y=
|
||||
github.com/jackc/pgproto3/v2 v2.3.0/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
||||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b h1:C8S2+VttkHFdOOCXJe+YGfa4vHYwlt4Zx+IVXQ97jYg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
|
||||
github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg=
|
||||
github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc=
|
||||
github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw=
|
||||
github.com/jackc/pgtype v1.8.1-0.20210724151600-32e20a603178/go.mod h1:C516IlIV9NKqfsMCXTdChteoXmwgUceqaLfjg2e3NlM=
|
||||
github.com/jackc/pgtype v1.10.0 h1:ILnBWrRMSXGczYvmkYD6PsYyVFUNLTnIUJHHDLmqk38=
|
||||
github.com/jackc/pgtype v1.10.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4=
|
||||
github.com/jackc/pgtype v1.11.0 h1:u4uiGPz/1hryuXzyaBhSk6dnIyyG2683olG2OV+UUgs=
|
||||
github.com/jackc/pgtype v1.11.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4=
|
||||
github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08CZQyj1PVQBHy9XOp5p8/SHH6a0psbY9Y=
|
||||
github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM=
|
||||
github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc=
|
||||
github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs=
|
||||
github.com/jackc/pgx/v4 v4.15.0 h1:B7dTkXsdILD3MF987WGGCcg+tvLW6bZJdEcqVFeU//w=
|
||||
github.com/jackc/pgx/v4 v4.15.0/go.mod h1:D/zyOyXiaM1TmVWnOM18p0xdDtdakRBa0RsVGI3U3bw=
|
||||
github.com/jackc/pgx/v4 v4.16.0 h1:4k1tROTJctHotannFYzu77dY3bgtMRymQP7tXQjqpPk=
|
||||
github.com/jackc/pgx/v4 v4.16.0/go.mod h1:N0A9sFdWzkw/Jy1lwoiB64F2+ugFZi987zRxcPez/wI=
|
||||
github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
||||
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
||||
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
||||
|
@ -286,8 +286,8 @@ github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9Nz
|
|||
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
|
||||
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sideshow/apns2 v0.22.0 h1:GGRYvXt+K4pAX9+wMkEntELcU47N4UTQfTfxjSdWcG8=
|
||||
github.com/sideshow/apns2 v0.22.0/go.mod h1:1o3nIz0P06JzbVfQQp5oLbGJYvVXGHOhVq7O7FfIZwU=
|
||||
github.com/sideshow/apns2 v0.23.0 h1:lpkikaZ995GIcKk6AFsYzHyezCrsrfEDvUWcWkEGErY=
|
||||
github.com/sideshow/apns2 v0.23.0/go.mod h1:7Fceu+sL0XscxrfLSkAoH6UtvKefq3Kq1n4W3ayQZqE=
|
||||
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||
|
@ -296,6 +296,8 @@ github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE
|
|||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/smtp2go-oss/smtp2go-go v1.0.1 h1:rwcoNLjOyigOzCjKp/guylKY/xJpoeypSxgtcC/g6DA=
|
||||
github.com/smtp2go-oss/smtp2go-go v1.0.1/go.mod h1:lkv36awQXRBWAvnd517FFESKvne8465KCu90lPThcEY=
|
||||
github.com/soveran/redisurl v0.0.0-20180322091936-eb325bc7a4b8/go.mod h1:FVJ8jbHu7QrNFs3bZEsv/L5JjearIAY9N0oXh2wk+6Y=
|
||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/spf13/cobra v0.0.2/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||
|
@ -389,7 +391,6 @@ golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHl
|
|||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20170513003010-84f0e6f92b10/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
|
@ -410,8 +411,9 @@ golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwY
|
|||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0=
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b h1:vI32FkLJNAWtGD4BwkThwEy6XS7ZLLMHkSkYfF8M0W0=
|
||||
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
|
@ -462,14 +464,15 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+R
|
|||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.0.0-20170512150324-19e51611da83/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
|
|
|
@ -107,6 +107,8 @@ func (a *api) Routes() *mux.Router {
|
|||
r.HandleFunc("/v1/receipt", a.checkReceiptHandler).Methods("POST")
|
||||
r.HandleFunc("/v1/receipt/{apns}", a.checkReceiptHandler).Methods("POST")
|
||||
|
||||
r.HandleFunc("/v1/contact", a.contactHandler).Methods("POST")
|
||||
|
||||
r.HandleFunc("/v1/test/bugsnag", a.testBugsnagHandler).Methods("POST")
|
||||
|
||||
r.Use(a.loggingMiddleware)
|
||||
|
|
35
internal/api/contact.go
Normal file
35
internal/api/contact.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/smtp2go-oss/smtp2go-go"
|
||||
)
|
||||
|
||||
type sendMessageRequest struct {
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
}
|
||||
|
||||
func (a *api) contactHandler(w http.ResponseWriter, r *http.Request) {
|
||||
smr := &sendMessageRequest{}
|
||||
if err := json.NewDecoder(r.Body).Decode(smr); err != nil {
|
||||
a.errorResponse(w, r, 500, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
msg := &smtp2go.Email{
|
||||
From: "🤖 Apollo API <robot@apollonotifications.com>",
|
||||
To: []string{"ultrasurvey@apolloapp.io"},
|
||||
Subject: smr.Title,
|
||||
TextBody: smr.Body,
|
||||
}
|
||||
|
||||
_, err := smtp2go.Send(msg)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r, 500, err.Error())
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
|
@ -276,7 +276,7 @@ func (iapr *IAPResponse) handleAppleResponse() {
|
|||
// For sandbox environment, be more lenient (just ensure bundle ID is accurate) because otherwise you'll break
|
||||
// things for TestFlight users (see: https://twitter.com/ChristianSelig/status/1414990459861098496)
|
||||
// TODO(andremedeiros): let this through for now
|
||||
if iapr.Environment == Sandbox && false {
|
||||
if iapr.Environment == Sandbox {
|
||||
ultraProduct := VerificationProduct{Name: "ultra", Status: "SANDBOX", SubscriptionType: "SANDBOX"}
|
||||
proProduct := VerificationProduct{Name: "pro", Status: "SANDBOX"}
|
||||
communityIconsProduct := VerificationProduct{Name: "community_icons", Status: "SANDBOX"}
|
||||
|
|
|
@ -82,6 +82,7 @@ type Thing struct {
|
|||
Title string `json:"title"`
|
||||
URL string `json:"url"`
|
||||
Flair string `json:"flair"`
|
||||
Thumbnail string `json:"thumbnail"`
|
||||
}
|
||||
|
||||
func (t *Thing) FullName() string {
|
||||
|
@ -118,6 +119,7 @@ func NewThing(val *fastjson.Value) *Thing {
|
|||
t.SelfText = string(data.GetStringBytes("selftext"))
|
||||
t.URL = string(data.GetStringBytes("url"))
|
||||
t.Flair = string(data.GetStringBytes("link_flair_text"))
|
||||
t.Thumbnail = string(data.GetStringBytes("thumbnail"))
|
||||
|
||||
return t
|
||||
}
|
||||
|
|
|
@ -25,6 +25,11 @@ const (
|
|||
backoff = 5 // How long we wait in between checking for notifications, in seconds
|
||||
pollDuration = 5 * time.Millisecond
|
||||
rate = 0.1
|
||||
|
||||
postReplyNotificationTitleFormat = "%s to %s"
|
||||
commentReplyNotificationTitleFormat = "%s in %s"
|
||||
privateMessageNotificationTitleFormat = "Message from %s"
|
||||
usernameMentionNotificationTitleFormat = "Mention in \u201c%s\u201d"
|
||||
)
|
||||
|
||||
type notificationsWorker struct {
|
||||
|
@ -418,8 +423,14 @@ func payloadFromMessage(acct domain.Account, msg *reddit.Thing, badgeCount int)
|
|||
|
||||
switch {
|
||||
case (msg.Kind == "t1" && msg.Type == "username_mention"):
|
||||
title := fmt.Sprintf(`Mention in “%s”`, postTitle)
|
||||
payload = payload.AlertTitle(title).Custom("type", "username")
|
||||
title := fmt.Sprintf(usernameMentionNotificationTitleFormat, postTitle)
|
||||
postID := reddit.PostIDFromContext(msg.Context)
|
||||
payload = payload.
|
||||
AlertTitle(title).
|
||||
Custom("comment_id", msg.ID).
|
||||
Custom("post_id", postID).
|
||||
Custom("subreddit", msg.Subreddit).
|
||||
Custom("type", "username")
|
||||
|
||||
pType, _ := reddit.SplitID(msg.ParentID)
|
||||
if pType == "t1" {
|
||||
|
@ -430,16 +441,19 @@ func payloadFromMessage(acct domain.Account, msg *reddit.Thing, badgeCount int)
|
|||
|
||||
payload = payload.Custom("subject", "comment").ThreadID("comment")
|
||||
case (msg.Kind == "t1" && msg.Type == "post_reply"):
|
||||
title := fmt.Sprintf(`%s to “%s”`, msg.Author, postTitle)
|
||||
title := fmt.Sprintf(postReplyNotificationTitleFormat, msg.Author, postTitle)
|
||||
postID := reddit.PostIDFromContext(msg.Context)
|
||||
payload = payload.
|
||||
AlertTitle(title).
|
||||
Category("inbox-post-reply").
|
||||
Custom("post_id", msg.ID).
|
||||
Custom("comment_id", msg.ID).
|
||||
Custom("post_id", postID).
|
||||
Custom("subject", "comment").
|
||||
Custom("subreddit", msg.Subreddit).
|
||||
Custom("type", "post").
|
||||
ThreadID("comment")
|
||||
case (msg.Kind == "t1" && msg.Type == "comment_reply"):
|
||||
title := fmt.Sprintf(`%s in “%s”`, msg.Author, postTitle)
|
||||
title := fmt.Sprintf(commentReplyNotificationTitleFormat, msg.Author, postTitle)
|
||||
postID := reddit.PostIDFromContext(msg.Context)
|
||||
payload = payload.
|
||||
AlertTitle(title).
|
||||
|
@ -447,14 +461,16 @@ func payloadFromMessage(acct domain.Account, msg *reddit.Thing, badgeCount int)
|
|||
Custom("comment_id", msg.ID).
|
||||
Custom("post_id", postID).
|
||||
Custom("subject", "comment").
|
||||
Custom("subreddit", msg.Subreddit).
|
||||
Custom("type", "comment").
|
||||
ThreadID("comment")
|
||||
case (msg.Kind == "t4"):
|
||||
title := fmt.Sprintf(`Message from %s`, msg.Author)
|
||||
title := fmt.Sprintf(privateMessageNotificationTitleFormat, msg.Author)
|
||||
payload = payload.
|
||||
AlertTitle(title).
|
||||
AlertSubtitle(postTitle).
|
||||
Category("inbox-private-message").
|
||||
Custom("comment_id", msg.ID).
|
||||
Custom("type", "private-message")
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,10 @@ type subredditsWorker struct {
|
|||
watcherRepo domain.WatcherRepository
|
||||
}
|
||||
|
||||
const subredditNotificationTitleFormat = "📣 %s"
|
||||
const (
|
||||
subredditNotificationTitleFormat = "📣 \u201c%s\u201d Watcher"
|
||||
subredditNotificationBodyFormat = "r/%s: \u201c%s\u201d"
|
||||
)
|
||||
|
||||
func NewSubredditsWorker(logger *logrus.Logger, statsd *statsd.Client, db *pgxpool.Pool, redis *redis.Client, queue rmq.Connection, consumers int) Worker {
|
||||
reddit := reddit.NewClient(
|
||||
|
@ -391,6 +394,9 @@ func (sc *subredditsConsumer) Consume(delivery rmq.Delivery) {
|
|||
title := fmt.Sprintf(subredditNotificationTitleFormat, watcher.Label)
|
||||
payload.AlertTitle(title)
|
||||
|
||||
body := fmt.Sprintf(subredditNotificationBodyFormat, subreddit.Name, post.Title)
|
||||
payload.AlertBody(body)
|
||||
|
||||
notification := &apns2.Notification{}
|
||||
notification.Topic = "com.christianselig.Apollo"
|
||||
notification.DeviceToken = watcher.Device.APNSToken
|
||||
|
@ -429,21 +435,22 @@ func (sc *subredditsConsumer) Consume(delivery rmq.Delivery) {
|
|||
}
|
||||
|
||||
func payloadFromPost(post *reddit.Thing) *payload.Payload {
|
||||
subtitle := fmt.Sprintf("r/%s", post.Subreddit)
|
||||
|
||||
payload := payload.
|
||||
NewPayload().
|
||||
AlertSubtitle(subtitle).
|
||||
AlertBody(post.Title).
|
||||
AlertSummaryArg(post.Subreddit).
|
||||
Category("post-watch").
|
||||
Category("subreddit-watcher").
|
||||
Custom("post_title", post.Title).
|
||||
Custom("post_id", post.ID).
|
||||
Custom("subreddit", post.Subreddit).
|
||||
Custom("author", post.Author).
|
||||
Custom("post_age", post.CreatedAt).
|
||||
ThreadID("subreddit-watcher").
|
||||
MutableContent().
|
||||
Sound("traloop.wav")
|
||||
|
||||
if post.Thumbnail != "" {
|
||||
payload.Custom("thumbnail", post.Thumbnail)
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ type trendingWorker struct {
|
|||
watcherRepo domain.WatcherRepository
|
||||
}
|
||||
|
||||
const trendingNotificationTitleFormat = "🔥 Trending in r/%s"
|
||||
const trendingNotificationTitleFormat = "🔥 r/%s Trending"
|
||||
|
||||
func NewTrendingWorker(logger *logrus.Logger, statsd *statsd.Client, db *pgxpool.Pool, redis *redis.Client, queue rmq.Connection, consumers int) Worker {
|
||||
reddit := reddit.NewClient(
|
||||
|
@ -321,17 +321,21 @@ func payloadFromTrendingPost(post *reddit.Thing) *payload.Payload {
|
|||
payload := payload.
|
||||
NewPayload().
|
||||
AlertTitle(title).
|
||||
AlertSubtitle(post.Title).
|
||||
AlertBody(post.Title).
|
||||
AlertSummaryArg(post.Subreddit).
|
||||
Category("post-watch").
|
||||
Category("trending-post").
|
||||
Custom("post_title", post.Title).
|
||||
Custom("post_id", post.ID).
|
||||
Custom("subreddit", post.Subreddit).
|
||||
Custom("author", post.Author).
|
||||
Custom("post_age", post.CreatedAt).
|
||||
ThreadID("trending-post").
|
||||
MutableContent().
|
||||
Sound("traloop.wav")
|
||||
|
||||
if post.Thumbnail != "" {
|
||||
payload.Custom("thumbnail", post.Thumbnail)
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue