2024-03-20 00:37:31 +00:00
|
|
|
import { decodeCursor, LIMIT, nextNoteCursorEncoded } from '@/lib/cursor'
|
2024-07-01 17:02:29 +00:00
|
|
|
import { getItem, filterClause, whereClause, muteClause, activeOrMine } from './item'
|
2024-04-16 15:53:05 +00:00
|
|
|
import { getInvoice, getWithdrawl } from './wallet'
|
2024-10-25 19:10:37 +00:00
|
|
|
import { pushSubscriptionSchema, validateSchema } from '@/lib/validate'
|
2024-03-20 00:37:31 +00:00
|
|
|
import { replyToSubscription } from '@/lib/webPush'
|
2024-01-03 02:05:49 +00:00
|
|
|
import { getSub } from './sub'
|
2024-09-10 16:35:25 +00:00
|
|
|
import { GqlAuthenticationError, GqlInputError } from '@/lib/error'
|
2021-08-17 18:15:24 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
Query: {
|
2022-04-21 17:48:27 +00:00
|
|
|
notifications: async (parent, { cursor, inc }, { me, models }) => {
|
2021-08-17 18:15:24 +00:00
|
|
|
const decodedCursor = decodeCursor(cursor)
|
2021-08-17 23:59:22 +00:00
|
|
|
if (!me) {
|
2024-09-10 16:35:25 +00:00
|
|
|
throw new GqlAuthenticationError()
|
2021-08-17 23:59:22 +00:00
|
|
|
}
|
2021-08-17 18:15:24 +00:00
|
|
|
|
2022-05-02 01:01:33 +00:00
|
|
|
const meFull = await models.user.findUnique({ where: { id: me.id } })
|
|
|
|
|
2021-08-17 18:15:24 +00:00
|
|
|
/*
|
|
|
|
So that we can cursor over results, we union notifications together ...
|
|
|
|
this requires we have the same number of columns in all results
|
|
|
|
|
|
|
|
select "Item".id, NULL as earnedSats, "Item".created_at as created_at from
|
|
|
|
"Item" JOIN "Item" p ON "Item"."parentId" = p.id AND p."userId" = 622 AND
|
|
|
|
"Item"."userId" <> 622 UNION ALL select "Item".id, "Vote".sats as earnedSats,
|
|
|
|
"Vote".created_at as created_at FROM "Item" LEFT JOIN "Vote" on
|
|
|
|
"Vote"."itemId" = "Item".id AND "Vote"."userId" <> 622 AND "Vote".boost = false
|
|
|
|
WHERE "Item"."userId" = 622 ORDER BY created_at DESC;
|
|
|
|
|
|
|
|
Because we want to "collapse" time adjacent votes in the result
|
|
|
|
|
|
|
|
select vote.id, sum(vote."earnedSats") as "earnedSats", max(vote.voted_at)
|
|
|
|
as "createdAt" from (select "Item".*, "Vote".sats as "earnedSats",
|
|
|
|
"Vote".created_at as voted_at, ROW_NUMBER() OVER(ORDER BY "Vote".created_at) -
|
|
|
|
ROW_NUMBER() OVER(PARTITION BY "Item".id ORDER BY "Vote".created_at) as island
|
|
|
|
FROM "Item" LEFT JOIN "Vote" on "Vote"."itemId" = "Item".id AND
|
|
|
|
"Vote"."userId" <> 622 AND "Vote".boost = false WHERE "Item"."userId" = 622)
|
|
|
|
as vote group by vote.id, vote.island order by max(vote.voted_at) desc;
|
|
|
|
|
|
|
|
We can also "collapse" votes occuring within 1 hour intervals of each other
|
|
|
|
(I haven't yet combined with the above collapsing method .. but might be
|
|
|
|
overkill)
|
|
|
|
|
|
|
|
select "Item".id, sum("Vote".sats) as earnedSats, max("Vote".created_at)
|
|
|
|
as created_at, ROW_NUMBER() OVER(ORDER BY max("Vote".created_at)) - ROW_NUMBER()
|
|
|
|
OVER(PARTITION BY "Item".id ORDER BY max("Vote".created_at)) as island FROM
|
|
|
|
"Item" LEFT JOIN "Vote" on "Vote"."itemId" = "Item".id AND "Vote"."userId" <> 622
|
|
|
|
AND "Vote".boost = false WHERE "Item"."userId" = 622 group by "Item".id,
|
|
|
|
date_trunc('hour', "Vote".created_at) order by created_at desc;
|
|
|
|
|
2021-10-28 22:22:19 +00:00
|
|
|
island approach we used to take
|
2021-08-20 00:13:32 +00:00
|
|
|
(SELECT ${ITEM_SUBQUERY_FIELDS}, max(subquery.voted_at) as "sortTime",
|
2021-09-02 22:22:00 +00:00
|
|
|
sum(subquery.sats) as "earnedSats", false as mention
|
|
|
|
FROM
|
2021-09-08 21:51:23 +00:00
|
|
|
(SELECT ${ITEM_FIELDS}, "ItemAct".created_at as voted_at, "ItemAct".sats,
|
|
|
|
ROW_NUMBER() OVER(ORDER BY "ItemAct".created_at) -
|
|
|
|
ROW_NUMBER() OVER(PARTITION BY "Item".id ORDER BY "ItemAct".created_at) as island
|
|
|
|
FROM "ItemAct"
|
|
|
|
JOIN "Item" on "ItemAct"."itemId" = "Item".id
|
|
|
|
WHERE "ItemAct"."userId" <> $1
|
|
|
|
AND "ItemAct".created_at <= $2
|
|
|
|
AND "ItemAct".act <> 'BOOST'
|
2021-09-02 22:22:00 +00:00
|
|
|
AND "Item"."userId" = $1) subquery
|
2021-10-07 03:20:59 +00:00
|
|
|
GROUP BY ${ITEM_SUBQUERY_FIELDS}, subquery.island
|
|
|
|
ORDER BY max(subquery.voted_at) desc
|
|
|
|
LIMIT ${LIMIT}+$3)
|
2021-10-28 22:22:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// HACK to make notifications faster, we only return a limited sub set of the unioned
|
|
|
|
// queries ... we only ever need at most LIMIT+current offset in the child queries to
|
|
|
|
// have enough items to return in the union
|
2022-04-21 22:50:02 +00:00
|
|
|
|
|
|
|
const queries = []
|
|
|
|
|
2023-08-31 01:38:31 +00:00
|
|
|
const itemDrivenQueries = []
|
2023-08-29 19:38:00 +00:00
|
|
|
|
2023-08-31 01:38:31 +00:00
|
|
|
// Thread subscriptions
|
|
|
|
itemDrivenQueries.push(
|
2023-09-30 00:12:23 +00:00
|
|
|
`SELECT "Item".*, "Item".created_at AS "sortTime", 'Reply' AS type
|
|
|
|
FROM "ThreadSubscription"
|
2024-03-24 04:15:00 +00:00
|
|
|
JOIN "Reply" r ON "ThreadSubscription"."itemId" = r."ancestorId"
|
|
|
|
JOIN "Item" ON r."itemId" = "Item".id
|
2023-09-30 00:12:23 +00:00
|
|
|
${whereClause(
|
|
|
|
'"ThreadSubscription"."userId" = $1',
|
2024-03-24 04:15:00 +00:00
|
|
|
'r.created_at >= "ThreadSubscription".created_at',
|
|
|
|
'r.created_at < $2',
|
2024-04-04 00:39:46 +00:00
|
|
|
'r."userId" <> $1',
|
2024-03-24 04:15:00 +00:00
|
|
|
...(meFull.noteAllDescendants ? [] : ['r.level = 1'])
|
2023-09-30 00:12:23 +00:00
|
|
|
)}
|
|
|
|
ORDER BY "sortTime" DESC
|
2024-03-06 19:53:13 +00:00
|
|
|
LIMIT ${LIMIT}`
|
2023-08-31 01:38:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// User subscriptions
|
2023-09-28 20:02:25 +00:00
|
|
|
// Only include posts or comments created after the corresponding subscription was enabled, not _all_ from history
|
2023-08-31 01:38:31 +00:00
|
|
|
itemDrivenQueries.push(
|
2023-09-30 00:12:23 +00:00
|
|
|
`SELECT "Item".*, "Item".created_at AS "sortTime", 'FollowActivity' AS type
|
|
|
|
FROM "Item"
|
|
|
|
JOIN "UserSubscription" ON "Item"."userId" = "UserSubscription"."followeeId"
|
|
|
|
${whereClause(
|
2024-03-06 19:53:13 +00:00
|
|
|
'"Item".created_at < $2',
|
2023-09-30 00:12:23 +00:00
|
|
|
'"UserSubscription"."followerId" = $1',
|
|
|
|
`(
|
|
|
|
("Item"."parentId" IS NULL AND "UserSubscription"."postsSubscribedAt" IS NOT NULL AND "Item".created_at >= "UserSubscription"."postsSubscribedAt")
|
|
|
|
OR ("Item"."parentId" IS NOT NULL AND "UserSubscription"."commentsSubscribedAt" IS NOT NULL AND "Item".created_at >= "UserSubscription"."commentsSubscribedAt")
|
|
|
|
)`
|
|
|
|
)}
|
|
|
|
ORDER BY "sortTime" DESC
|
2024-03-06 19:53:13 +00:00
|
|
|
LIMIT ${LIMIT}`
|
2023-06-01 00:44:06 +00:00
|
|
|
)
|
|
|
|
|
2024-02-23 15:12:49 +00:00
|
|
|
// Territory subscriptions
|
|
|
|
itemDrivenQueries.push(
|
|
|
|
`SELECT "Item".*, "Item".created_at AS "sortTime", 'TerritoryPost' AS type
|
|
|
|
FROM "Item"
|
|
|
|
JOIN "SubSubscription" ON "Item"."subName" = "SubSubscription"."subName"
|
|
|
|
${whereClause(
|
2024-03-06 19:53:13 +00:00
|
|
|
'"Item".created_at < $2',
|
2024-02-23 15:12:49 +00:00
|
|
|
'"SubSubscription"."userId" = $1',
|
|
|
|
'"Item"."userId" <> $1',
|
|
|
|
'"Item"."parentId" IS NULL',
|
|
|
|
'"Item".created_at >= "SubSubscription".created_at'
|
|
|
|
)}
|
|
|
|
ORDER BY "sortTime" DESC
|
2024-03-06 19:53:13 +00:00
|
|
|
LIMIT ${LIMIT}`
|
2024-02-23 15:12:49 +00:00
|
|
|
)
|
2024-01-11 17:27:54 +00:00
|
|
|
|
2023-08-31 01:38:31 +00:00
|
|
|
// mentions
|
2023-06-02 21:48:39 +00:00
|
|
|
if (meFull.noteMentions) {
|
2023-08-31 01:38:31 +00:00
|
|
|
itemDrivenQueries.push(
|
2023-09-30 00:12:23 +00:00
|
|
|
`SELECT "Item".*, "Mention".created_at AS "sortTime", 'Mention' AS type
|
2023-06-02 21:48:39 +00:00
|
|
|
FROM "Mention"
|
|
|
|
JOIN "Item" ON "Mention"."itemId" = "Item".id
|
2023-09-28 20:02:25 +00:00
|
|
|
${whereClause(
|
2024-03-06 19:53:13 +00:00
|
|
|
'"Item".created_at < $2',
|
2023-09-28 20:02:25 +00:00
|
|
|
'"Mention"."userId" = $1',
|
2023-09-30 00:12:23 +00:00
|
|
|
'"Item"."userId" <> $1'
|
2023-09-28 20:02:25 +00:00
|
|
|
)}
|
2023-06-02 21:48:39 +00:00
|
|
|
ORDER BY "sortTime" DESC
|
2024-03-06 19:53:13 +00:00
|
|
|
LIMIT ${LIMIT}`
|
2023-06-02 21:48:39 +00:00
|
|
|
)
|
|
|
|
}
|
2024-06-03 17:12:42 +00:00
|
|
|
// item mentions
|
|
|
|
if (meFull.noteItemMentions) {
|
|
|
|
itemDrivenQueries.push(
|
|
|
|
`SELECT "Referrer".*, "ItemMention".created_at AS "sortTime", 'ItemMention' AS type
|
|
|
|
FROM "ItemMention"
|
|
|
|
JOIN "Item" "Referee" ON "ItemMention"."refereeId" = "Referee".id
|
|
|
|
JOIN "Item" "Referrer" ON "ItemMention"."referrerId" = "Referrer".id
|
|
|
|
${whereClause(
|
|
|
|
'"ItemMention".created_at < $2',
|
|
|
|
'"Referrer"."userId" <> $1',
|
|
|
|
'"Referee"."userId" = $1'
|
|
|
|
)}
|
|
|
|
ORDER BY "sortTime" DESC
|
|
|
|
LIMIT ${LIMIT}`
|
|
|
|
)
|
|
|
|
}
|
2023-08-31 01:38:31 +00:00
|
|
|
// Inner union to de-dupe item-driven notifications
|
|
|
|
queries.push(
|
|
|
|
// Only record per item ID
|
2023-09-30 00:12:23 +00:00
|
|
|
`(
|
|
|
|
SELECT DISTINCT ON (id) "Item".id::TEXT, "Item"."sortTime", NULL::BIGINT AS "earnedSats", "Item".type
|
2023-08-31 01:38:31 +00:00
|
|
|
FROM (
|
2023-09-30 00:12:23 +00:00
|
|
|
${itemDrivenQueries.map(q => `(${q})`).join(' UNION ALL ')}
|
|
|
|
) as "Item"
|
|
|
|
${whereClause(
|
2024-03-06 19:53:13 +00:00
|
|
|
'"Item".created_at < $2',
|
2023-09-30 00:12:23 +00:00
|
|
|
await filterClause(me, models),
|
2024-07-01 17:02:29 +00:00
|
|
|
muteClause(me),
|
|
|
|
activeOrMine(me))}
|
2023-09-30 00:12:23 +00:00
|
|
|
ORDER BY id ASC, CASE
|
|
|
|
WHEN type = 'Mention' THEN 1
|
|
|
|
WHEN type = 'Reply' THEN 2
|
|
|
|
WHEN type = 'FollowActivity' THEN 3
|
2024-01-11 17:27:54 +00:00
|
|
|
WHEN type = 'TerritoryPost' THEN 4
|
2024-06-03 17:12:42 +00:00
|
|
|
WHEN type = 'ItemMention' THEN 5
|
2023-09-30 00:12:23 +00:00
|
|
|
END ASC
|
|
|
|
)`
|
2023-08-31 01:38:31 +00:00
|
|
|
)
|
2023-06-02 21:48:39 +00:00
|
|
|
|
2024-03-05 19:56:02 +00:00
|
|
|
// territory transfers
|
|
|
|
queries.push(
|
|
|
|
`(SELECT "TerritoryTransfer".id::text, "TerritoryTransfer"."created_at" AS "sortTime", NULL as "earnedSats",
|
|
|
|
'TerritoryTransfer' AS type
|
|
|
|
FROM "TerritoryTransfer"
|
|
|
|
WHERE "TerritoryTransfer"."newUserId" = $1
|
|
|
|
AND "TerritoryTransfer"."created_at" <= $2
|
|
|
|
ORDER BY "sortTime" DESC
|
2024-03-06 20:35:45 +00:00
|
|
|
LIMIT ${LIMIT})`
|
2024-03-05 19:56:02 +00:00
|
|
|
)
|
|
|
|
|
2023-06-01 00:44:06 +00:00
|
|
|
if (meFull.noteItemSats) {
|
2022-04-21 22:50:02 +00:00
|
|
|
queries.push(
|
2024-03-24 19:16:29 +00:00
|
|
|
`(SELECT "Item".id::TEXT, "Item"."lastZapAt" AS "sortTime",
|
|
|
|
"Item".msats/1000 as "earnedSats", 'Votification' AS type
|
2023-06-01 00:44:06 +00:00
|
|
|
FROM "Item"
|
2024-03-24 19:16:29 +00:00
|
|
|
WHERE "Item"."userId" = $1
|
|
|
|
AND "Item"."lastZapAt" < $2
|
2023-06-01 00:44:06 +00:00
|
|
|
ORDER BY "sortTime" DESC
|
2024-03-06 19:53:13 +00:00
|
|
|
LIMIT ${LIMIT})`
|
2022-04-21 22:50:02 +00:00
|
|
|
)
|
2023-06-01 00:44:06 +00:00
|
|
|
}
|
|
|
|
|
2023-09-12 15:31:46 +00:00
|
|
|
if (meFull.noteForwardedSats) {
|
|
|
|
queries.push(
|
2024-03-24 19:16:29 +00:00
|
|
|
`(SELECT "Item".id::TEXT, "Item"."lastZapAt" AS "sortTime",
|
|
|
|
("Item".msats / 1000 * "ItemForward".pct / 100) as "earnedSats", 'ForwardedVotification' AS type
|
2023-09-12 15:31:46 +00:00
|
|
|
FROM "Item"
|
|
|
|
JOIN "ItemForward" ON "ItemForward"."itemId" = "Item".id AND "ItemForward"."userId" = $1
|
2024-03-24 19:16:29 +00:00
|
|
|
WHERE "Item"."userId" <> $1
|
|
|
|
AND "Item"."lastZapAt" < $2
|
2023-09-12 15:31:46 +00:00
|
|
|
ORDER BY "sortTime" DESC
|
2024-03-06 19:53:13 +00:00
|
|
|
LIMIT ${LIMIT})`
|
2023-09-12 15:31:46 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-06-01 00:44:06 +00:00
|
|
|
if (meFull.noteDeposits) {
|
2022-04-21 22:50:02 +00:00
|
|
|
queries.push(
|
2023-06-01 00:44:06 +00:00
|
|
|
`(SELECT "Invoice".id::text, "Invoice"."confirmedAt" AS "sortTime", FLOOR("msatsReceived" / 1000) as "earnedSats",
|
|
|
|
'InvoicePaid' AS type
|
|
|
|
FROM "Invoice"
|
|
|
|
WHERE "Invoice"."userId" = $1
|
|
|
|
AND "confirmedAt" IS NOT NULL
|
2023-09-19 00:30:26 +00:00
|
|
|
AND "isHeld" IS NULL
|
2024-07-01 17:02:29 +00:00
|
|
|
AND "actionState" IS NULL
|
2024-03-06 19:53:13 +00:00
|
|
|
AND created_at < $2
|
2022-03-22 19:53:48 +00:00
|
|
|
ORDER BY "sortTime" DESC
|
2024-03-06 19:53:13 +00:00
|
|
|
LIMIT ${LIMIT})`
|
2022-04-21 22:50:02 +00:00
|
|
|
)
|
2023-06-01 00:44:06 +00:00
|
|
|
}
|
2022-04-21 22:50:02 +00:00
|
|
|
|
2024-03-25 20:20:11 +00:00
|
|
|
if (meFull.noteWithdrawals) {
|
|
|
|
queries.push(
|
|
|
|
`(SELECT "Withdrawl".id::text, "Withdrawl".created_at AS "sortTime", FLOOR("msatsPaid" / 1000) as "earnedSats",
|
|
|
|
'WithdrawlPaid' AS type
|
|
|
|
FROM "Withdrawl"
|
|
|
|
WHERE "Withdrawl"."userId" = $1
|
|
|
|
AND status = 'CONFIRMED'
|
|
|
|
AND created_at < $2
|
|
|
|
ORDER BY "sortTime" DESC
|
|
|
|
LIMIT ${LIMIT})`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-06-01 00:44:06 +00:00
|
|
|
if (meFull.noteInvites) {
|
|
|
|
queries.push(
|
|
|
|
`(SELECT "Invite".id, MAX(users.created_at) AS "sortTime", NULL as "earnedSats",
|
|
|
|
'Invitification' AS type
|
|
|
|
FROM users JOIN "Invite" on users."inviteId" = "Invite".id
|
|
|
|
WHERE "Invite"."userId" = $1
|
2024-03-06 19:53:13 +00:00
|
|
|
AND users.created_at < $2
|
2023-06-01 00:44:06 +00:00
|
|
|
GROUP BY "Invite".id
|
|
|
|
ORDER BY "sortTime" DESC
|
2024-03-06 19:53:13 +00:00
|
|
|
LIMIT ${LIMIT})`
|
2023-06-01 00:44:06 +00:00
|
|
|
)
|
|
|
|
queries.push(
|
|
|
|
`(SELECT users.id::text, users.created_at AS "sortTime", NULL as "earnedSats",
|
|
|
|
'Referral' AS type
|
|
|
|
FROM users
|
|
|
|
WHERE "users"."referrerId" = $1
|
|
|
|
AND "inviteId" IS NULL
|
2024-03-06 19:53:13 +00:00
|
|
|
AND users.created_at < $2
|
|
|
|
ORDER BY "sortTime" DESC
|
|
|
|
LIMIT ${LIMIT})`
|
2023-06-01 00:44:06 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (meFull.noteEarning) {
|
|
|
|
queries.push(
|
2024-03-06 19:53:13 +00:00
|
|
|
`(SELECT min(id)::text, created_at AS "sortTime", FLOOR(sum(msats) / 1000) as "earnedSats",
|
2023-06-01 00:44:06 +00:00
|
|
|
'Earn' AS type
|
|
|
|
FROM "Earn"
|
|
|
|
WHERE "userId" = $1
|
2024-03-06 19:53:13 +00:00
|
|
|
AND created_at < $2
|
2024-07-11 00:23:05 +00:00
|
|
|
AND (type IS NULL OR type NOT IN ('FOREVER_REFERRAL', 'ONE_DAY_REFERRAL'))
|
2024-03-06 19:53:13 +00:00
|
|
|
GROUP BY "userId", created_at
|
|
|
|
ORDER BY "sortTime" DESC
|
|
|
|
LIMIT ${LIMIT})`
|
2023-06-01 00:44:06 +00:00
|
|
|
)
|
2023-11-21 23:32:22 +00:00
|
|
|
queries.push(
|
2024-03-06 19:53:13 +00:00
|
|
|
`(SELECT min(id)::text, created_at AS "sortTime", FLOOR(sum(msats) / 1000) as "earnedSats",
|
2023-11-21 23:32:22 +00:00
|
|
|
'Revenue' AS type
|
|
|
|
FROM "SubAct"
|
|
|
|
WHERE "userId" = $1
|
|
|
|
AND type = 'REVENUE'
|
2024-03-06 19:53:13 +00:00
|
|
|
AND created_at < $2
|
|
|
|
GROUP BY "userId", "subName", created_at
|
|
|
|
ORDER BY "sortTime" DESC
|
|
|
|
LIMIT ${LIMIT})`
|
2023-11-21 23:32:22 +00:00
|
|
|
)
|
2024-07-11 00:23:05 +00:00
|
|
|
queries.push(
|
|
|
|
`(SELECT min(id)::text, created_at AS "sortTime", FLOOR(sum(msats) / 1000) as "earnedSats",
|
|
|
|
'ReferralReward' AS type
|
|
|
|
FROM "Earn"
|
|
|
|
WHERE "userId" = $1
|
|
|
|
AND created_at < $2
|
|
|
|
AND type IN ('FOREVER_REFERRAL', 'ONE_DAY_REFERRAL')
|
|
|
|
GROUP BY "userId", created_at
|
|
|
|
ORDER BY "sortTime" DESC
|
|
|
|
LIMIT ${LIMIT})`
|
|
|
|
)
|
2023-06-01 00:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (meFull.noteCowboyHat) {
|
|
|
|
queries.push(
|
2024-03-06 19:53:13 +00:00
|
|
|
`(SELECT id::text, updated_at AS "sortTime", 0 as "earnedSats", 'Streak' AS type
|
2023-06-01 00:44:06 +00:00
|
|
|
FROM "Streak"
|
|
|
|
WHERE "userId" = $1
|
2024-03-06 19:53:13 +00:00
|
|
|
AND updated_at < $2
|
|
|
|
ORDER BY "sortTime" DESC
|
|
|
|
LIMIT ${LIMIT})`
|
2023-06-01 00:44:06 +00:00
|
|
|
)
|
2022-04-21 22:50:02 +00:00
|
|
|
}
|
|
|
|
|
2024-01-03 02:05:49 +00:00
|
|
|
queries.push(
|
|
|
|
`(SELECT "Sub".name::text, "Sub"."statusUpdatedAt" AS "sortTime", NULL as "earnedSats",
|
|
|
|
'SubStatus' AS type
|
|
|
|
FROM "Sub"
|
|
|
|
WHERE "Sub"."userId" = $1
|
|
|
|
AND "status" <> 'ACTIVE'
|
2024-03-06 19:53:13 +00:00
|
|
|
AND "statusUpdatedAt" < $2
|
2024-01-03 02:05:49 +00:00
|
|
|
ORDER BY "sortTime" DESC
|
2024-03-06 19:53:13 +00:00
|
|
|
LIMIT ${LIMIT})`
|
2024-01-03 02:05:49 +00:00
|
|
|
)
|
|
|
|
|
2024-05-19 20:52:02 +00:00
|
|
|
queries.push(
|
|
|
|
`(SELECT "Reminder".id::text, "Reminder"."remindAt" AS "sortTime", NULL as "earnedSats", 'Reminder' AS type
|
|
|
|
FROM "Reminder"
|
|
|
|
WHERE "Reminder"."userId" = $1
|
|
|
|
AND "Reminder"."remindAt" < $2
|
|
|
|
ORDER BY "sortTime" DESC
|
|
|
|
LIMIT ${LIMIT})`
|
|
|
|
)
|
|
|
|
|
2024-07-01 17:02:29 +00:00
|
|
|
queries.push(
|
|
|
|
`(SELECT "Invoice".id::text, "Invoice"."updated_at" AS "sortTime", NULL as "earnedSats", 'Invoicification' AS type
|
|
|
|
FROM "Invoice"
|
|
|
|
WHERE "Invoice"."userId" = $1
|
|
|
|
AND "Invoice"."updated_at" < $2
|
|
|
|
AND "Invoice"."actionState" = 'FAILED'
|
|
|
|
AND (
|
|
|
|
"Invoice"."actionType" = 'ITEM_CREATE' OR
|
|
|
|
"Invoice"."actionType" = 'ZAP' OR
|
|
|
|
"Invoice"."actionType" = 'DOWN_ZAP' OR
|
2024-09-19 18:13:14 +00:00
|
|
|
"Invoice"."actionType" = 'POLL_VOTE' OR
|
|
|
|
"Invoice"."actionType" = 'BOOST'
|
2024-07-01 17:02:29 +00:00
|
|
|
)
|
|
|
|
ORDER BY "sortTime" DESC
|
|
|
|
LIMIT ${LIMIT})`
|
|
|
|
)
|
|
|
|
|
2023-07-26 16:01:31 +00:00
|
|
|
const notifications = await models.$queryRawUnsafe(
|
2024-03-24 19:16:29 +00:00
|
|
|
`SELECT id, "sortTime", "earnedSats", type,
|
|
|
|
"sortTime" AS "minSortTime"
|
2022-07-05 20:18:59 +00:00
|
|
|
FROM
|
2024-03-24 19:16:29 +00:00
|
|
|
(${queries.join(' UNION ALL ')}) u
|
2021-10-07 03:20:59 +00:00
|
|
|
ORDER BY "sortTime" DESC
|
2024-03-06 19:53:13 +00:00
|
|
|
LIMIT ${LIMIT}`, me.id, decodedCursor.time)
|
2021-08-17 18:15:24 +00:00
|
|
|
|
2021-09-06 22:36:08 +00:00
|
|
|
if (decodedCursor.offset === 0) {
|
|
|
|
await models.user.update({ where: { id: me.id }, data: { checkedNotesAt: new Date() } })
|
|
|
|
}
|
2021-08-17 23:59:22 +00:00
|
|
|
|
2021-08-17 18:15:24 +00:00
|
|
|
return {
|
2022-05-02 01:01:33 +00:00
|
|
|
lastChecked: meFull.checkedNotesAt,
|
2024-03-06 19:53:13 +00:00
|
|
|
cursor: notifications.length === LIMIT ? nextNoteCursorEncoded(decodedCursor, notifications) : null,
|
2021-08-17 18:15:24 +00:00
|
|
|
notifications
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
Service worker rework, Web Target Share API & Web Push API (#324)
* npm uninstall next-pwa
next-pwa was last updated in August 2022.
There is also an issue which mentions that next-pwa is abandoned (?): https://github.com/shadowwalker/next-pwa/issues/482
But the main reason for me uninstalling it is that it adds a lot of preconfigured stuff which is not necessary for us.
It even lead to a bug since pages were cached without our knowledge.
So I will go with a different PWA approach. This different approach should do the following:
- make it more transparent what the service worker is doing
- gives us more control to configure the service worker and thus making it easier
* Use workbox-webpack-plugin
Every other plugin (`next-offline`, `next-workbox-webpack-plugin`, `next-with-workbox`, ...) added unnecessary configuration which felt contrary to how PWAs should be built.
(PWAs should progressivly enhance the website in small steps, see https://web.dev/learn/pwa/getting-started/#focus-on-a-feature)
These default configurations even lead to worse UX since they made invalid assumptions about stacker.news:
We _do not_ want to cache our start url and we _do not_ want to cache anything unless explicitly told to.
Almost every page on SN should be fresh for the best UX.
To achieve this, by default, the service worker falls back to the network (as if the service worker wasn't there).
Therefore, this should be the simplest configuration with a valid precache and cache busting support.
In the future, we can try to use prefetching to improve performance of navigation requests.
* Add support for Web Share Target API
See https://developer.chrome.com/articles/web-share-target/
* Use Web Push API for push notifications
I followed this (very good!) guide: https://web.dev/notifications/
* Refactor code related to Web Push
* Send push notification to users on events
* Merge notifications
* Send notification to author of every parent recursively
* Remove unused userId param in savePushSubscription
As it should be, the user id is retrieved from the authenticated user in the backend.
* Resubscribe user if push subscription changed
* Update old subscription if oldEndpoint was given
* Allow users to unsubscribe
* Use LTREE operator instead of recursive query
* Always show checkbox for push notifications
* Justify checkbox to end
* Update title of first push notification
* Fix warning from uncontrolled to controlled
* Add comment about Notification.requestPermission
* Fix timestamp
* Catch error on push subscription toggle
* Wrap function bodies in try/catch
* Use Promise.allSettled
* Filter subscriptions by user notification settings
* Fix user notification filter
* Use skipWaiting
---------
Co-authored-by: ekzyis <ek@stacker.news>
2023-07-04 19:36:07 +00:00
|
|
|
Mutation: {
|
|
|
|
savePushSubscription: async (parent, { endpoint, p256dh, auth, oldEndpoint }, { me, models }) => {
|
|
|
|
if (!me) {
|
2024-09-10 16:35:25 +00:00
|
|
|
throw new GqlAuthenticationError()
|
Service worker rework, Web Target Share API & Web Push API (#324)
* npm uninstall next-pwa
next-pwa was last updated in August 2022.
There is also an issue which mentions that next-pwa is abandoned (?): https://github.com/shadowwalker/next-pwa/issues/482
But the main reason for me uninstalling it is that it adds a lot of preconfigured stuff which is not necessary for us.
It even lead to a bug since pages were cached without our knowledge.
So I will go with a different PWA approach. This different approach should do the following:
- make it more transparent what the service worker is doing
- gives us more control to configure the service worker and thus making it easier
* Use workbox-webpack-plugin
Every other plugin (`next-offline`, `next-workbox-webpack-plugin`, `next-with-workbox`, ...) added unnecessary configuration which felt contrary to how PWAs should be built.
(PWAs should progressivly enhance the website in small steps, see https://web.dev/learn/pwa/getting-started/#focus-on-a-feature)
These default configurations even lead to worse UX since they made invalid assumptions about stacker.news:
We _do not_ want to cache our start url and we _do not_ want to cache anything unless explicitly told to.
Almost every page on SN should be fresh for the best UX.
To achieve this, by default, the service worker falls back to the network (as if the service worker wasn't there).
Therefore, this should be the simplest configuration with a valid precache and cache busting support.
In the future, we can try to use prefetching to improve performance of navigation requests.
* Add support for Web Share Target API
See https://developer.chrome.com/articles/web-share-target/
* Use Web Push API for push notifications
I followed this (very good!) guide: https://web.dev/notifications/
* Refactor code related to Web Push
* Send push notification to users on events
* Merge notifications
* Send notification to author of every parent recursively
* Remove unused userId param in savePushSubscription
As it should be, the user id is retrieved from the authenticated user in the backend.
* Resubscribe user if push subscription changed
* Update old subscription if oldEndpoint was given
* Allow users to unsubscribe
* Use LTREE operator instead of recursive query
* Always show checkbox for push notifications
* Justify checkbox to end
* Update title of first push notification
* Fix warning from uncontrolled to controlled
* Add comment about Notification.requestPermission
* Fix timestamp
* Catch error on push subscription toggle
* Wrap function bodies in try/catch
* Use Promise.allSettled
* Filter subscriptions by user notification settings
* Fix user notification filter
* Use skipWaiting
---------
Co-authored-by: ekzyis <ek@stacker.news>
2023-07-04 19:36:07 +00:00
|
|
|
}
|
|
|
|
|
2024-10-25 19:10:37 +00:00
|
|
|
await validateSchema(pushSubscriptionSchema, { endpoint, p256dh, auth })
|
Service worker rework, Web Target Share API & Web Push API (#324)
* npm uninstall next-pwa
next-pwa was last updated in August 2022.
There is also an issue which mentions that next-pwa is abandoned (?): https://github.com/shadowwalker/next-pwa/issues/482
But the main reason for me uninstalling it is that it adds a lot of preconfigured stuff which is not necessary for us.
It even lead to a bug since pages were cached without our knowledge.
So I will go with a different PWA approach. This different approach should do the following:
- make it more transparent what the service worker is doing
- gives us more control to configure the service worker and thus making it easier
* Use workbox-webpack-plugin
Every other plugin (`next-offline`, `next-workbox-webpack-plugin`, `next-with-workbox`, ...) added unnecessary configuration which felt contrary to how PWAs should be built.
(PWAs should progressivly enhance the website in small steps, see https://web.dev/learn/pwa/getting-started/#focus-on-a-feature)
These default configurations even lead to worse UX since they made invalid assumptions about stacker.news:
We _do not_ want to cache our start url and we _do not_ want to cache anything unless explicitly told to.
Almost every page on SN should be fresh for the best UX.
To achieve this, by default, the service worker falls back to the network (as if the service worker wasn't there).
Therefore, this should be the simplest configuration with a valid precache and cache busting support.
In the future, we can try to use prefetching to improve performance of navigation requests.
* Add support for Web Share Target API
See https://developer.chrome.com/articles/web-share-target/
* Use Web Push API for push notifications
I followed this (very good!) guide: https://web.dev/notifications/
* Refactor code related to Web Push
* Send push notification to users on events
* Merge notifications
* Send notification to author of every parent recursively
* Remove unused userId param in savePushSubscription
As it should be, the user id is retrieved from the authenticated user in the backend.
* Resubscribe user if push subscription changed
* Update old subscription if oldEndpoint was given
* Allow users to unsubscribe
* Use LTREE operator instead of recursive query
* Always show checkbox for push notifications
* Justify checkbox to end
* Update title of first push notification
* Fix warning from uncontrolled to controlled
* Add comment about Notification.requestPermission
* Fix timestamp
* Catch error on push subscription toggle
* Wrap function bodies in try/catch
* Use Promise.allSettled
* Filter subscriptions by user notification settings
* Fix user notification filter
* Use skipWaiting
---------
Co-authored-by: ekzyis <ek@stacker.news>
2023-07-04 19:36:07 +00:00
|
|
|
|
|
|
|
let dbPushSubscription
|
|
|
|
if (oldEndpoint) {
|
|
|
|
dbPushSubscription = await models.pushSubscription.update({
|
|
|
|
data: { userId: me.id, endpoint, p256dh, auth }, where: { endpoint: oldEndpoint }
|
|
|
|
})
|
2023-08-15 17:59:58 +00:00
|
|
|
console.log(`[webPush] updated subscription of user ${me.id}: old=${oldEndpoint} new=${endpoint}`)
|
Service worker rework, Web Target Share API & Web Push API (#324)
* npm uninstall next-pwa
next-pwa was last updated in August 2022.
There is also an issue which mentions that next-pwa is abandoned (?): https://github.com/shadowwalker/next-pwa/issues/482
But the main reason for me uninstalling it is that it adds a lot of preconfigured stuff which is not necessary for us.
It even lead to a bug since pages were cached without our knowledge.
So I will go with a different PWA approach. This different approach should do the following:
- make it more transparent what the service worker is doing
- gives us more control to configure the service worker and thus making it easier
* Use workbox-webpack-plugin
Every other plugin (`next-offline`, `next-workbox-webpack-plugin`, `next-with-workbox`, ...) added unnecessary configuration which felt contrary to how PWAs should be built.
(PWAs should progressivly enhance the website in small steps, see https://web.dev/learn/pwa/getting-started/#focus-on-a-feature)
These default configurations even lead to worse UX since they made invalid assumptions about stacker.news:
We _do not_ want to cache our start url and we _do not_ want to cache anything unless explicitly told to.
Almost every page on SN should be fresh for the best UX.
To achieve this, by default, the service worker falls back to the network (as if the service worker wasn't there).
Therefore, this should be the simplest configuration with a valid precache and cache busting support.
In the future, we can try to use prefetching to improve performance of navigation requests.
* Add support for Web Share Target API
See https://developer.chrome.com/articles/web-share-target/
* Use Web Push API for push notifications
I followed this (very good!) guide: https://web.dev/notifications/
* Refactor code related to Web Push
* Send push notification to users on events
* Merge notifications
* Send notification to author of every parent recursively
* Remove unused userId param in savePushSubscription
As it should be, the user id is retrieved from the authenticated user in the backend.
* Resubscribe user if push subscription changed
* Update old subscription if oldEndpoint was given
* Allow users to unsubscribe
* Use LTREE operator instead of recursive query
* Always show checkbox for push notifications
* Justify checkbox to end
* Update title of first push notification
* Fix warning from uncontrolled to controlled
* Add comment about Notification.requestPermission
* Fix timestamp
* Catch error on push subscription toggle
* Wrap function bodies in try/catch
* Use Promise.allSettled
* Filter subscriptions by user notification settings
* Fix user notification filter
* Use skipWaiting
---------
Co-authored-by: ekzyis <ek@stacker.news>
2023-07-04 19:36:07 +00:00
|
|
|
} else {
|
|
|
|
dbPushSubscription = await models.pushSubscription.create({
|
|
|
|
data: { userId: me.id, endpoint, p256dh, auth }
|
|
|
|
})
|
2023-08-15 17:59:58 +00:00
|
|
|
console.log(`[webPush] created subscription for user ${me.id}: endpoint=${endpoint}`)
|
Service worker rework, Web Target Share API & Web Push API (#324)
* npm uninstall next-pwa
next-pwa was last updated in August 2022.
There is also an issue which mentions that next-pwa is abandoned (?): https://github.com/shadowwalker/next-pwa/issues/482
But the main reason for me uninstalling it is that it adds a lot of preconfigured stuff which is not necessary for us.
It even lead to a bug since pages were cached without our knowledge.
So I will go with a different PWA approach. This different approach should do the following:
- make it more transparent what the service worker is doing
- gives us more control to configure the service worker and thus making it easier
* Use workbox-webpack-plugin
Every other plugin (`next-offline`, `next-workbox-webpack-plugin`, `next-with-workbox`, ...) added unnecessary configuration which felt contrary to how PWAs should be built.
(PWAs should progressivly enhance the website in small steps, see https://web.dev/learn/pwa/getting-started/#focus-on-a-feature)
These default configurations even lead to worse UX since they made invalid assumptions about stacker.news:
We _do not_ want to cache our start url and we _do not_ want to cache anything unless explicitly told to.
Almost every page on SN should be fresh for the best UX.
To achieve this, by default, the service worker falls back to the network (as if the service worker wasn't there).
Therefore, this should be the simplest configuration with a valid precache and cache busting support.
In the future, we can try to use prefetching to improve performance of navigation requests.
* Add support for Web Share Target API
See https://developer.chrome.com/articles/web-share-target/
* Use Web Push API for push notifications
I followed this (very good!) guide: https://web.dev/notifications/
* Refactor code related to Web Push
* Send push notification to users on events
* Merge notifications
* Send notification to author of every parent recursively
* Remove unused userId param in savePushSubscription
As it should be, the user id is retrieved from the authenticated user in the backend.
* Resubscribe user if push subscription changed
* Update old subscription if oldEndpoint was given
* Allow users to unsubscribe
* Use LTREE operator instead of recursive query
* Always show checkbox for push notifications
* Justify checkbox to end
* Update title of first push notification
* Fix warning from uncontrolled to controlled
* Add comment about Notification.requestPermission
* Fix timestamp
* Catch error on push subscription toggle
* Wrap function bodies in try/catch
* Use Promise.allSettled
* Filter subscriptions by user notification settings
* Fix user notification filter
* Use skipWaiting
---------
Co-authored-by: ekzyis <ek@stacker.news>
2023-07-04 19:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await replyToSubscription(dbPushSubscription.id, { title: 'Stacker News notifications are now active' })
|
|
|
|
|
|
|
|
return dbPushSubscription
|
|
|
|
},
|
|
|
|
deletePushSubscription: async (parent, { endpoint }, { me, models }) => {
|
|
|
|
if (!me) {
|
2024-09-10 16:35:25 +00:00
|
|
|
throw new GqlAuthenticationError()
|
Service worker rework, Web Target Share API & Web Push API (#324)
* npm uninstall next-pwa
next-pwa was last updated in August 2022.
There is also an issue which mentions that next-pwa is abandoned (?): https://github.com/shadowwalker/next-pwa/issues/482
But the main reason for me uninstalling it is that it adds a lot of preconfigured stuff which is not necessary for us.
It even lead to a bug since pages were cached without our knowledge.
So I will go with a different PWA approach. This different approach should do the following:
- make it more transparent what the service worker is doing
- gives us more control to configure the service worker and thus making it easier
* Use workbox-webpack-plugin
Every other plugin (`next-offline`, `next-workbox-webpack-plugin`, `next-with-workbox`, ...) added unnecessary configuration which felt contrary to how PWAs should be built.
(PWAs should progressivly enhance the website in small steps, see https://web.dev/learn/pwa/getting-started/#focus-on-a-feature)
These default configurations even lead to worse UX since they made invalid assumptions about stacker.news:
We _do not_ want to cache our start url and we _do not_ want to cache anything unless explicitly told to.
Almost every page on SN should be fresh for the best UX.
To achieve this, by default, the service worker falls back to the network (as if the service worker wasn't there).
Therefore, this should be the simplest configuration with a valid precache and cache busting support.
In the future, we can try to use prefetching to improve performance of navigation requests.
* Add support for Web Share Target API
See https://developer.chrome.com/articles/web-share-target/
* Use Web Push API for push notifications
I followed this (very good!) guide: https://web.dev/notifications/
* Refactor code related to Web Push
* Send push notification to users on events
* Merge notifications
* Send notification to author of every parent recursively
* Remove unused userId param in savePushSubscription
As it should be, the user id is retrieved from the authenticated user in the backend.
* Resubscribe user if push subscription changed
* Update old subscription if oldEndpoint was given
* Allow users to unsubscribe
* Use LTREE operator instead of recursive query
* Always show checkbox for push notifications
* Justify checkbox to end
* Update title of first push notification
* Fix warning from uncontrolled to controlled
* Add comment about Notification.requestPermission
* Fix timestamp
* Catch error on push subscription toggle
* Wrap function bodies in try/catch
* Use Promise.allSettled
* Filter subscriptions by user notification settings
* Fix user notification filter
* Use skipWaiting
---------
Co-authored-by: ekzyis <ek@stacker.news>
2023-07-04 19:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const subscription = await models.pushSubscription.findFirst({ where: { endpoint, userId: Number(me.id) } })
|
|
|
|
if (!subscription) {
|
2024-09-10 16:35:25 +00:00
|
|
|
throw new GqlInputError('endpoint not found')
|
Service worker rework, Web Target Share API & Web Push API (#324)
* npm uninstall next-pwa
next-pwa was last updated in August 2022.
There is also an issue which mentions that next-pwa is abandoned (?): https://github.com/shadowwalker/next-pwa/issues/482
But the main reason for me uninstalling it is that it adds a lot of preconfigured stuff which is not necessary for us.
It even lead to a bug since pages were cached without our knowledge.
So I will go with a different PWA approach. This different approach should do the following:
- make it more transparent what the service worker is doing
- gives us more control to configure the service worker and thus making it easier
* Use workbox-webpack-plugin
Every other plugin (`next-offline`, `next-workbox-webpack-plugin`, `next-with-workbox`, ...) added unnecessary configuration which felt contrary to how PWAs should be built.
(PWAs should progressivly enhance the website in small steps, see https://web.dev/learn/pwa/getting-started/#focus-on-a-feature)
These default configurations even lead to worse UX since they made invalid assumptions about stacker.news:
We _do not_ want to cache our start url and we _do not_ want to cache anything unless explicitly told to.
Almost every page on SN should be fresh for the best UX.
To achieve this, by default, the service worker falls back to the network (as if the service worker wasn't there).
Therefore, this should be the simplest configuration with a valid precache and cache busting support.
In the future, we can try to use prefetching to improve performance of navigation requests.
* Add support for Web Share Target API
See https://developer.chrome.com/articles/web-share-target/
* Use Web Push API for push notifications
I followed this (very good!) guide: https://web.dev/notifications/
* Refactor code related to Web Push
* Send push notification to users on events
* Merge notifications
* Send notification to author of every parent recursively
* Remove unused userId param in savePushSubscription
As it should be, the user id is retrieved from the authenticated user in the backend.
* Resubscribe user if push subscription changed
* Update old subscription if oldEndpoint was given
* Allow users to unsubscribe
* Use LTREE operator instead of recursive query
* Always show checkbox for push notifications
* Justify checkbox to end
* Update title of first push notification
* Fix warning from uncontrolled to controlled
* Add comment about Notification.requestPermission
* Fix timestamp
* Catch error on push subscription toggle
* Wrap function bodies in try/catch
* Use Promise.allSettled
* Filter subscriptions by user notification settings
* Fix user notification filter
* Use skipWaiting
---------
Co-authored-by: ekzyis <ek@stacker.news>
2023-07-04 19:36:07 +00:00
|
|
|
}
|
2023-08-15 17:59:58 +00:00
|
|
|
const deletedSubscription = await models.pushSubscription.delete({ where: { id: subscription.id } })
|
|
|
|
console.log(`[webPush] deleted subscription ${deletedSubscription.id} of user ${deletedSubscription.userId} due to client request`)
|
|
|
|
|
|
|
|
return deletedSubscription
|
Service worker rework, Web Target Share API & Web Push API (#324)
* npm uninstall next-pwa
next-pwa was last updated in August 2022.
There is also an issue which mentions that next-pwa is abandoned (?): https://github.com/shadowwalker/next-pwa/issues/482
But the main reason for me uninstalling it is that it adds a lot of preconfigured stuff which is not necessary for us.
It even lead to a bug since pages were cached without our knowledge.
So I will go with a different PWA approach. This different approach should do the following:
- make it more transparent what the service worker is doing
- gives us more control to configure the service worker and thus making it easier
* Use workbox-webpack-plugin
Every other plugin (`next-offline`, `next-workbox-webpack-plugin`, `next-with-workbox`, ...) added unnecessary configuration which felt contrary to how PWAs should be built.
(PWAs should progressivly enhance the website in small steps, see https://web.dev/learn/pwa/getting-started/#focus-on-a-feature)
These default configurations even lead to worse UX since they made invalid assumptions about stacker.news:
We _do not_ want to cache our start url and we _do not_ want to cache anything unless explicitly told to.
Almost every page on SN should be fresh for the best UX.
To achieve this, by default, the service worker falls back to the network (as if the service worker wasn't there).
Therefore, this should be the simplest configuration with a valid precache and cache busting support.
In the future, we can try to use prefetching to improve performance of navigation requests.
* Add support for Web Share Target API
See https://developer.chrome.com/articles/web-share-target/
* Use Web Push API for push notifications
I followed this (very good!) guide: https://web.dev/notifications/
* Refactor code related to Web Push
* Send push notification to users on events
* Merge notifications
* Send notification to author of every parent recursively
* Remove unused userId param in savePushSubscription
As it should be, the user id is retrieved from the authenticated user in the backend.
* Resubscribe user if push subscription changed
* Update old subscription if oldEndpoint was given
* Allow users to unsubscribe
* Use LTREE operator instead of recursive query
* Always show checkbox for push notifications
* Justify checkbox to end
* Update title of first push notification
* Fix warning from uncontrolled to controlled
* Add comment about Notification.requestPermission
* Fix timestamp
* Catch error on push subscription toggle
* Wrap function bodies in try/catch
* Use Promise.allSettled
* Filter subscriptions by user notification settings
* Fix user notification filter
* Use skipWaiting
---------
Co-authored-by: ekzyis <ek@stacker.news>
2023-07-04 19:36:07 +00:00
|
|
|
}
|
|
|
|
},
|
2021-08-17 18:15:24 +00:00
|
|
|
Notification: {
|
2022-01-19 21:02:38 +00:00
|
|
|
__resolveType: async (n, args, { models }) => n.type
|
|
|
|
},
|
|
|
|
Votification: {
|
2023-05-07 20:21:58 +00:00
|
|
|
item: async (n, args, { models, me }) => getItem(n, { id: n.id }, { models, me })
|
2022-01-19 21:02:38 +00:00
|
|
|
},
|
2023-09-12 15:31:46 +00:00
|
|
|
ForwardedVotification: {
|
|
|
|
item: async (n, args, { models, me }) => getItem(n, { id: n.id }, { models, me })
|
|
|
|
},
|
2022-01-19 21:02:38 +00:00
|
|
|
Reply: {
|
2023-05-07 20:21:58 +00:00
|
|
|
item: async (n, args, { models, me }) => getItem(n, { id: n.id }, { models, me })
|
2022-01-19 21:02:38 +00:00
|
|
|
},
|
2023-08-29 01:27:56 +00:00
|
|
|
FollowActivity: {
|
|
|
|
item: async (n, args, { models, me }) => getItem(n, { id: n.id }, { models, me })
|
|
|
|
},
|
2024-01-11 17:27:54 +00:00
|
|
|
TerritoryPost: {
|
|
|
|
item: async (n, args, { models, me }) => getItem(n, { id: n.id }, { models, me })
|
|
|
|
},
|
2024-05-19 20:52:02 +00:00
|
|
|
Reminder: {
|
|
|
|
item: async (n, args, { models, me }) => {
|
|
|
|
const { itemId } = await models.reminder.findUnique({ where: { id: Number(n.id) } })
|
|
|
|
return await getItem(n, { id: itemId }, { models, me })
|
|
|
|
}
|
|
|
|
},
|
2024-03-05 19:56:02 +00:00
|
|
|
TerritoryTransfer: {
|
|
|
|
sub: async (n, args, { models, me }) => {
|
|
|
|
const transfer = await models.territoryTransfer.findUnique({ where: { id: Number(n.id) }, include: { sub: true } })
|
|
|
|
return transfer.sub
|
|
|
|
}
|
|
|
|
},
|
2022-02-28 20:09:21 +00:00
|
|
|
JobChanged: {
|
2023-05-07 20:21:58 +00:00
|
|
|
item: async (n, args, { models, me }) => getItem(n, { id: n.id }, { models, me })
|
2022-02-28 20:09:21 +00:00
|
|
|
},
|
2024-01-03 02:05:49 +00:00
|
|
|
SubStatus: {
|
|
|
|
sub: async (n, args, { models, me }) => getSub(n, { name: n.id }, { models, me })
|
|
|
|
},
|
2023-11-21 23:32:22 +00:00
|
|
|
Revenue: {
|
|
|
|
subName: async (n, args, { models }) => {
|
|
|
|
const subAct = await models.subAct.findUnique({
|
|
|
|
where: {
|
|
|
|
id: Number(n.id)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return subAct.subName
|
|
|
|
}
|
|
|
|
},
|
2023-02-01 14:44:35 +00:00
|
|
|
Streak: {
|
|
|
|
days: async (n, args, { models }) => {
|
|
|
|
const res = await models.$queryRaw`
|
|
|
|
SELECT "endedAt" - "startedAt" AS days
|
|
|
|
FROM "Streak"
|
|
|
|
WHERE id = ${Number(n.id)} AND "endedAt" IS NOT NULL
|
|
|
|
`
|
|
|
|
|
|
|
|
return res.length ? res[0].days : null
|
2024-10-12 00:14:18 +00:00
|
|
|
},
|
|
|
|
type: async (n, args, { models }) => {
|
|
|
|
const res = await models.$queryRaw`
|
|
|
|
SELECT "type"
|
|
|
|
FROM "Streak"
|
|
|
|
WHERE id = ${Number(n.id)}
|
|
|
|
`
|
|
|
|
return res.length ? res[0].type : null
|
2023-02-01 14:44:35 +00:00
|
|
|
}
|
|
|
|
},
|
2022-09-12 18:55:34 +00:00
|
|
|
Earn: {
|
|
|
|
sources: async (n, args, { me, models }) => {
|
2023-07-26 16:01:31 +00:00
|
|
|
const [sources] = await models.$queryRawUnsafe(`
|
2022-09-12 18:55:34 +00:00
|
|
|
SELECT
|
|
|
|
FLOOR(sum(msats) FILTER(WHERE type = 'POST') / 1000) AS posts,
|
|
|
|
FLOOR(sum(msats) FILTER(WHERE type = 'COMMENT') / 1000) AS comments,
|
2023-07-09 17:21:11 +00:00
|
|
|
FLOOR(sum(msats) FILTER(WHERE type = 'TIP_POST') / 1000) AS "tipPosts",
|
|
|
|
FLOOR(sum(msats) FILTER(WHERE type = 'TIP_COMMENT') / 1000) AS "tipComments"
|
2022-09-12 18:55:34 +00:00
|
|
|
FROM "Earn"
|
|
|
|
WHERE "userId" = $1 AND created_at <= $2 AND created_at >= $3
|
|
|
|
`, Number(me.id), new Date(n.sortTime), new Date(n.minSortTime))
|
|
|
|
sources.posts ||= 0
|
|
|
|
sources.comments ||= 0
|
2023-07-09 17:21:11 +00:00
|
|
|
sources.tipPosts ||= 0
|
|
|
|
sources.tipComments ||= 0
|
|
|
|
if (sources.posts + sources.comments + sources.tipPosts + sources.tipComments > 0) {
|
2022-09-12 18:55:34 +00:00
|
|
|
return sources
|
|
|
|
}
|
|
|
|
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
},
|
2024-07-11 00:23:05 +00:00
|
|
|
ReferralReward: {
|
|
|
|
sources: async (n, args, { me, models }) => {
|
|
|
|
const [sources] = await models.$queryRawUnsafe(`
|
|
|
|
SELECT
|
|
|
|
COALESCE(FLOOR(sum(msats) FILTER(WHERE type = 'FOREVER_REFERRAL') / 1000), 0) AS forever,
|
|
|
|
COALESCE(FLOOR(sum(msats) FILTER(WHERE type = 'ONE_DAY_REFERRAL') / 1000), 0) AS "oneDay"
|
|
|
|
FROM "Earn"
|
|
|
|
WHERE "userId" = $1 AND created_at = $2
|
|
|
|
`, Number(me.id), new Date(n.sortTime))
|
|
|
|
if (sources.forever + sources.oneDay > 0) {
|
|
|
|
return sources
|
|
|
|
}
|
|
|
|
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
},
|
2022-01-19 21:02:38 +00:00
|
|
|
Mention: {
|
|
|
|
mention: async (n, args, { models }) => true,
|
2023-05-07 20:21:58 +00:00
|
|
|
item: async (n, args, { models, me }) => getItem(n, { id: n.id }, { models, me })
|
2022-01-19 21:02:38 +00:00
|
|
|
},
|
2024-06-03 17:12:42 +00:00
|
|
|
ItemMention: {
|
|
|
|
item: async (n, args, { models, me }) => getItem(n, { id: n.id }, { models, me })
|
|
|
|
},
|
2022-03-23 18:54:39 +00:00
|
|
|
InvoicePaid: {
|
|
|
|
invoice: async (n, args, { me, models }) => getInvoice(n, { id: n.id }, { me, models })
|
|
|
|
},
|
2024-07-01 17:02:29 +00:00
|
|
|
Invoicification: {
|
|
|
|
invoice: async (n, args, { me, models }) => getInvoice(n, { id: n.id }, { me, models })
|
|
|
|
},
|
2024-04-16 15:53:05 +00:00
|
|
|
WithdrawlPaid: {
|
|
|
|
withdrawl: async (n, args, { me, models }) => getWithdrawl(n, { id: n.id }, { me, models })
|
|
|
|
},
|
2022-01-19 21:02:38 +00:00
|
|
|
Invitification: {
|
|
|
|
invite: async (n, args, { models }) => {
|
|
|
|
return await models.invite.findUnique({
|
|
|
|
where: {
|
|
|
|
id: n.id
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2021-08-17 18:15:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-28 22:22:19 +00:00
|
|
|
// const ITEM_SUBQUERY_FIELDS =
|
|
|
|
// `subquery.id, subquery."createdAt", subquery."updatedAt", subquery.title, subquery.text,
|
|
|
|
// subquery.url, subquery."userId", subquery."parentId", subquery.path`
|
|
|
|
|
2022-03-15 16:30:11 +00:00
|
|
|
// const ITEM_GROUP_FIELDS =
|
|
|
|
// `"Item".id, "Item".created_at, "Item".updated_at, "Item".title,
|
|
|
|
// "Item".text, "Item".url, "Item"."userId", "Item"."parentId", ltree2text("Item"."path")`
|
2021-08-17 18:15:24 +00:00
|
|
|
|
2022-01-19 21:02:38 +00:00
|
|
|
// const ITEM_FIELDS =
|
|
|
|
// `"Item".id, "Item".created_at as "createdAt", "Item".updated_at as "updatedAt", "Item".title,
|
|
|
|
// "Item".text, "Item".url, "Item"."userId", "Item"."parentId", ltree2text("Item"."path") AS path`
|