Skip to content

Commit

Permalink
Don't notify on own posts
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed Jan 11, 2024
1 parent 672e64d commit 5edf920
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/resolvers/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default {
`SELECT "Item".*, "Item".created_at AS "sortTime", 'TerritoryPost' AS type
FROM "Item"
JOIN "Sub" ON "Item"."subName" = "Sub".name
WHERE "Sub"."userId" = $1
WHERE "Sub"."userId" = $1 AND "Item"."userId" <> $1
ORDER BY "sortTime" DESC
LIMIT ${LIMIT}+$3`
)
Expand Down
7 changes: 7 additions & 0 deletions lib/push-notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,16 @@ export const notifyZapped = async ({ models, id }) => {
export const notifyFounders = async ({ models, item }) => {
try {
const isPost = !!item.title

// only notify on posts in subs
if (!isPost || !item.subName) return

const author = await models.user.findUnique({ where: { id: item.userId } })
const sub = await models.sub.findUnique({ where: { name: item.subName } })

// don't send notifications own own posts to founders
if (sub.userId === author.id) return

const tag = `TERRITORY_POST-${sub.name}`
await sendUserNotification(sub.userId, {
title: `@${author.name} created a post in ~${sub.name}`,
Expand Down

0 comments on commit 5edf920

Please sign in to comment.