From f267db8497b412b4f2605969e3660a93f83ef886 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Thu, 7 Apr 2022 11:35:59 -0400 Subject: [PATCH 01/15] fix ambiguous expires_at --- internal/repository/postgres_account.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/repository/postgres_account.go b/internal/repository/postgres_account.go index 798a204..c84a5a2 100644 --- a/internal/repository/postgres_account.go +++ b/internal/repository/postgres_account.go @@ -186,7 +186,7 @@ func (p *postgresAccountRepository) Disassociate(ctx context.Context, acc *domai func (p *postgresAccountRepository) GetByAPNSToken(ctx context.Context, token string) ([]domain.Account, error) { query := ` - SELECT accounts.id, username, accounts.account_id, access_token, refresh_token, expires_at, last_message_id, last_checked_at, last_unstuck_at + SELECT accounts.id, username, accounts.account_id, access_token, refresh_token, accounts.expires_at, last_message_id, last_checked_at, last_unstuck_at FROM accounts INNER JOIN devices_accounts ON accounts.id = devices_accounts.account_id INNER JOIN devices ON devices.id = devices_accounts.device_id From 63f1fc976357d78a041817a16e8508f38204973f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Apr 2022 08:20:04 +0000 Subject: [PATCH 02/15] Bump github.com/sideshow/apns2 from 0.22.0 to 0.23.0 Bumps [github.com/sideshow/apns2](https://github.com/sideshow/apns2) from 0.22.0 to 0.23.0. - [Release notes](https://github.com/sideshow/apns2/releases) - [Commits](https://github.com/sideshow/apns2/compare/v0.22.0...v0.23.0) --- updated-dependencies: - dependency-name: github.com/sideshow/apns2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index a6062a6..3c760ff 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/heroku/x v0.0.50 github.com/jackc/pgx/v4 v4.15.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/spf13/cobra v1.4.0 github.com/stretchr/testify v1.7.1 diff --git a/go.sum b/go.sum index 00da36a..b9c367a 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -389,7 +389,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 +409,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 +462,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= From b97e712d5734e05e99151e209776ac97125b7d7e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Apr 2022 08:16:30 +0000 Subject: [PATCH 03/15] Bump github.com/jackc/pgx/v4 from 4.15.0 to 4.16.0 Bumps [github.com/jackc/pgx/v4](https://github.com/jackc/pgx) from 4.15.0 to 4.16.0. - [Release notes](https://github.com/jackc/pgx/releases) - [Changelog](https://github.com/jackc/pgx/blob/master/CHANGELOG.md) - [Commits](https://github.com/jackc/pgx/compare/v4.15.0...v4.16.0) --- updated-dependencies: - dependency-name: github.com/jackc/pgx/v4 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index a6062a6..d694a34 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ 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/sirupsen/logrus v1.8.1 diff --git a/go.sum b/go.sum index 00da36a..3a8e4d7 100644 --- a/go.sum +++ b/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= @@ -468,8 +468,9 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3 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= From 2027760e1e6559c48d656dbf16d5a868220f3c0d Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Sun, 1 May 2022 13:00:29 -0400 Subject: [PATCH 04/15] Change Subreddit watcher notification --- internal/worker/subreddits.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/worker/subreddits.go b/internal/worker/subreddits.go index d5747ff..673c98a 100644 --- a/internal/worker/subreddits.go +++ b/internal/worker/subreddits.go @@ -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,12 +435,8 @@ 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"). Custom("post_title", post.Title). From 8502a67352c3f1774be562e55cff2b14692ed2aa Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Sun, 1 May 2022 13:04:05 -0400 Subject: [PATCH 05/15] Change trending notification --- internal/worker/trending.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/internal/worker/trending.go b/internal/worker/trending.go index b27a3bd..ff29662 100644 --- a/internal/worker/trending.go +++ b/internal/worker/trending.go @@ -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( @@ -318,10 +318,9 @@ func (tc *trendingConsumer) Consume(delivery rmq.Delivery) { func payloadFromTrendingPost(post *reddit.Thing) *payload.Payload { title := fmt.Sprintf(trendingNotificationTitleFormat, post.Subreddit) - payload := payload. + return payload. NewPayload(). AlertTitle(title). - AlertSubtitle(post.Title). AlertBody(post.Title). AlertSummaryArg(post.Subreddit). Category("post-watch"). @@ -332,6 +331,4 @@ func payloadFromTrendingPost(post *reddit.Thing) *payload.Payload { Custom("post_age", post.CreatedAt). MutableContent(). Sound("traloop.wav") - - return payload } From a429ee99876fa1c4b735c6483d93cdd4079e6985 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Sun, 1 May 2022 13:09:08 -0400 Subject: [PATCH 06/15] change remaining notification titles --- internal/worker/notifications.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/worker/notifications.go b/internal/worker/notifications.go index d03d107..3107d10 100644 --- a/internal/worker/notifications.go +++ b/internal/worker/notifications.go @@ -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 { @@ -416,7 +421,7 @@ 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) + title := fmt.Sprintf(usernameMentionNotificationTitleFormat, postTitle) payload = payload.AlertTitle(title).Custom("type", "username") pType, _ := reddit.SplitID(msg.ParentID) @@ -428,7 +433,7 @@ 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) payload = payload. AlertTitle(title). Category("inbox-post-reply"). @@ -437,7 +442,7 @@ func payloadFromMessage(acct domain.Account, msg *reddit.Thing, badgeCount int) 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). @@ -448,7 +453,7 @@ func payloadFromMessage(acct domain.Account, msg *reddit.Thing, badgeCount int) 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). From b886dd3fab0021e5ad1cdddd93a883247d62fe50 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Sun, 1 May 2022 13:18:16 -0400 Subject: [PATCH 07/15] Fix post reply notifications --- internal/worker/notifications.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/worker/notifications.go b/internal/worker/notifications.go index 3107d10..7102d26 100644 --- a/internal/worker/notifications.go +++ b/internal/worker/notifications.go @@ -434,10 +434,12 @@ 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(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("type", "post"). ThreadID("comment") From 91456dc9b9621f816a70b2a775505bd2a5bae7f3 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Sun, 1 May 2022 13:20:36 -0400 Subject: [PATCH 08/15] include comment_id for private messages --- internal/worker/notifications.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/worker/notifications.go b/internal/worker/notifications.go index 7102d26..6240b32 100644 --- a/internal/worker/notifications.go +++ b/internal/worker/notifications.go @@ -460,6 +460,7 @@ func payloadFromMessage(acct domain.Account, msg *reddit.Thing, badgeCount int) AlertTitle(title). AlertSubtitle(postTitle). Category("inbox-private-message"). + Custom("comment_id", msg.ID). Custom("type", "private-message") } From c2a77e7c66a79db1a208f45cdfce68593f616d42 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Sun, 1 May 2022 13:22:18 -0400 Subject: [PATCH 09/15] add comment_id on username mention --- internal/worker/notifications.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/worker/notifications.go b/internal/worker/notifications.go index 6240b32..15042c1 100644 --- a/internal/worker/notifications.go +++ b/internal/worker/notifications.go @@ -422,7 +422,10 @@ func payloadFromMessage(acct domain.Account, msg *reddit.Thing, badgeCount int) switch { case (msg.Kind == "t1" && msg.Type == "username_mention"): title := fmt.Sprintf(usernameMentionNotificationTitleFormat, postTitle) - payload = payload.AlertTitle(title).Custom("type", "username") + payload = payload. + AlertTitle(title). + Custom("comment_id", msg.ID). + Custom("type", "username") pType, _ := reddit.SplitID(msg.ParentID) if pType == "t1" { From e48460572ad25d412352a9a2e76b6ff169a507a6 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Sun, 1 May 2022 13:24:10 -0400 Subject: [PATCH 10/15] include subreddit fields too --- internal/worker/notifications.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/worker/notifications.go b/internal/worker/notifications.go index 15042c1..0fc865f 100644 --- a/internal/worker/notifications.go +++ b/internal/worker/notifications.go @@ -422,9 +422,12 @@ func payloadFromMessage(acct domain.Account, msg *reddit.Thing, badgeCount int) switch { case (msg.Kind == "t1" && msg.Type == "username_mention"): 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) @@ -444,6 +447,7 @@ 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", "post"). ThreadID("comment") case (msg.Kind == "t1" && msg.Type == "comment_reply"): @@ -455,6 +459,7 @@ 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"): From 63344348dfab449b4e13d37a45099dc14528e394 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Sun, 1 May 2022 13:28:12 -0400 Subject: [PATCH 11/15] Fix notification categories for watchers --- internal/worker/subreddits.go | 2 +- internal/worker/trending.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/worker/subreddits.go b/internal/worker/subreddits.go index 673c98a..da742b5 100644 --- a/internal/worker/subreddits.go +++ b/internal/worker/subreddits.go @@ -438,7 +438,7 @@ func payloadFromPost(post *reddit.Thing) *payload.Payload { payload := payload. NewPayload(). AlertSummaryArg(post.Subreddit). - Category("post-watch"). + Category("subreddit-watch"). Custom("post_title", post.Title). Custom("post_id", post.ID). Custom("subreddit", post.Subreddit). diff --git a/internal/worker/trending.go b/internal/worker/trending.go index ff29662..09af392 100644 --- a/internal/worker/trending.go +++ b/internal/worker/trending.go @@ -323,7 +323,7 @@ func payloadFromTrendingPost(post *reddit.Thing) *payload.Payload { AlertTitle(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). From 9ba4498c080db53dbd8bcb510093486b3be88199 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Sun, 1 May 2022 13:33:09 -0400 Subject: [PATCH 12/15] Add post thumbnails too --- internal/reddit/types.go | 2 ++ internal/worker/subreddits.go | 4 ++++ internal/worker/trending.go | 8 +++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/reddit/types.go b/internal/reddit/types.go index 4a170ee..64dad0a 100644 --- a/internal/reddit/types.go +++ b/internal/reddit/types.go @@ -79,6 +79,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 { @@ -114,6 +115,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 } diff --git a/internal/worker/subreddits.go b/internal/worker/subreddits.go index da742b5..0c141e9 100644 --- a/internal/worker/subreddits.go +++ b/internal/worker/subreddits.go @@ -447,5 +447,9 @@ func payloadFromPost(post *reddit.Thing) *payload.Payload { MutableContent(). Sound("traloop.wav") + if post.Thumbnail != "" { + payload.Custom("thumbnail", post.Thumbnail) + } + return payload } diff --git a/internal/worker/trending.go b/internal/worker/trending.go index 09af392..f1cde16 100644 --- a/internal/worker/trending.go +++ b/internal/worker/trending.go @@ -318,7 +318,7 @@ func (tc *trendingConsumer) Consume(delivery rmq.Delivery) { func payloadFromTrendingPost(post *reddit.Thing) *payload.Payload { title := fmt.Sprintf(trendingNotificationTitleFormat, post.Subreddit) - return payload. + payload := payload. NewPayload(). AlertTitle(title). AlertBody(post.Title). @@ -331,4 +331,10 @@ func payloadFromTrendingPost(post *reddit.Thing) *payload.Payload { Custom("post_age", post.CreatedAt). MutableContent(). Sound("traloop.wav") + + if post.Thumbnail != "" { + payload.Custom("thumbnail", post.Thumbnail) + } + + return payload } From 49b1acc906af5203b7f96929d8b290b5fd846f0e Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Sun, 1 May 2022 13:36:35 -0400 Subject: [PATCH 13/15] Add threadID --- internal/worker/subreddits.go | 3 ++- internal/worker/trending.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/worker/subreddits.go b/internal/worker/subreddits.go index 0c141e9..b1c4339 100644 --- a/internal/worker/subreddits.go +++ b/internal/worker/subreddits.go @@ -438,12 +438,13 @@ func payloadFromPost(post *reddit.Thing) *payload.Payload { payload := payload. NewPayload(). AlertSummaryArg(post.Subreddit). - Category("subreddit-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") diff --git a/internal/worker/trending.go b/internal/worker/trending.go index f1cde16..ccdeabd 100644 --- a/internal/worker/trending.go +++ b/internal/worker/trending.go @@ -329,6 +329,7 @@ func payloadFromTrendingPost(post *reddit.Thing) *payload.Payload { Custom("subreddit", post.Subreddit). Custom("author", post.Author). Custom("post_age", post.CreatedAt). + ThreadID("trending-post"). MutableContent(). Sound("traloop.wav") From 41f504d10c730dd589cf0e67bb0d24e27c2bcbb5 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Sun, 1 May 2022 13:57:30 -0400 Subject: [PATCH 14/15] add contact endpoint --- go.mod | 1 + go.sum | 2 ++ internal/api/api.go | 2 ++ internal/api/contact.go | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 internal/api/contact.go diff --git a/go.mod b/go.mod index 1106b9a..6241748 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( github.com/joho/godotenv v1.4.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 diff --git a/go.sum b/go.sum index ddf98f8..4a5576e 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/api/api.go b/internal/api/api.go index ecab0a7..1766c31 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -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) diff --git a/internal/api/contact.go b/internal/api/contact.go new file mode 100644 index 0000000..9a0d62f --- /dev/null +++ b/internal/api/contact.go @@ -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 ", + 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) +} From e5bf631a0b9ebf96d6d27cdc4886ad57abf1bef6 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Sun, 1 May 2022 14:05:30 -0400 Subject: [PATCH 15/15] check itunes receipts --- internal/itunes/receipt.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/itunes/receipt.go b/internal/itunes/receipt.go index f6891ea..185c458 100644 --- a/internal/itunes/receipt.go +++ b/internal/itunes/receipt.go @@ -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"}