better reward notifications
This commit is contained in:
parent
9d3c52ed00
commit
9581160944
|
@ -159,34 +159,44 @@ export default {
|
||||||
LIMIT ${LIMIT}+$3)`
|
LIMIT ${LIMIT}+$3)`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (meFull.noteEarning) {
|
||||||
|
queries.push(
|
||||||
|
`SELECT id::text, created_at AS "sortTime", FLOOR(msats / 1000) as "earnedSats",
|
||||||
|
'Earn' AS type
|
||||||
|
FROM "Earn"
|
||||||
|
WHERE "userId" = $1
|
||||||
|
AND created_at <= $2`
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we do all this crazy subquery stuff to make 'reward' islands
|
||||||
const notifications = await models.$queryRaw(
|
const notifications = await models.$queryRaw(
|
||||||
`${queries.join(' UNION ALL ')}
|
`SELECT MAX(id) AS id, MAX("sortTime") AS "sortTime", sum("earnedSats") AS "earnedSats", type
|
||||||
|
FROM
|
||||||
|
(SELECT *,
|
||||||
|
CASE
|
||||||
|
WHEN type = 'Earn' THEN
|
||||||
|
ROW_NUMBER() OVER(ORDER BY "sortTime" DESC) -
|
||||||
|
ROW_NUMBER() OVER(PARTITION BY type = 'Earn' ORDER BY "sortTime" DESC)
|
||||||
|
ELSE
|
||||||
|
ROW_NUMBER() OVER(ORDER BY "sortTime" DESC)
|
||||||
|
END as island
|
||||||
|
FROM
|
||||||
|
(${queries.join(' UNION ALL ')}) u
|
||||||
|
) sub
|
||||||
|
GROUP BY type, island
|
||||||
ORDER BY "sortTime" DESC
|
ORDER BY "sortTime" DESC
|
||||||
OFFSET $3
|
OFFSET $3
|
||||||
LIMIT ${LIMIT}`, me.id, decodedCursor.time, decodedCursor.offset)
|
LIMIT ${LIMIT}`, me.id, decodedCursor.time, decodedCursor.offset)
|
||||||
|
|
||||||
let earn
|
|
||||||
if (decodedCursor.offset === 0) {
|
if (decodedCursor.offset === 0) {
|
||||||
if (meFull.noteEarning) {
|
|
||||||
const earnings = await models.$queryRaw(
|
|
||||||
`SELECT MAX("Earn".id)::text, MAX("Earn".created_at) AS "sortTime", FLOOR(SUM(msats) / 1000) as "earnedSats",
|
|
||||||
'Earn' AS type
|
|
||||||
FROM "Earn"
|
|
||||||
WHERE "Earn"."userId" = $1
|
|
||||||
AND created_at >= $2`, me.id, meFull.checkedNotesAt)
|
|
||||||
if (earnings.length > 0 && earnings[0].earnedSats > 0) {
|
|
||||||
earn = earnings[0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await models.user.update({ where: { id: me.id }, data: { checkedNotesAt: new Date() } })
|
await models.user.update({ where: { id: me.id }, data: { checkedNotesAt: new Date() } })
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
lastChecked: meFull.checkedNotesAt,
|
lastChecked: meFull.checkedNotesAt,
|
||||||
earn,
|
|
||||||
cursor: notifications.length === LIMIT ? nextCursorEncoded(decodedCursor) : null,
|
cursor: notifications.length === LIMIT ? nextCursorEncoded(decodedCursor) : null,
|
||||||
notifications
|
notifications
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,6 @@ export default gql`
|
||||||
|
|
||||||
type Notifications {
|
type Notifications {
|
||||||
lastChecked: String
|
lastChecked: String
|
||||||
earn: Notification
|
|
||||||
cursor: String
|
cursor: String
|
||||||
notifications: [Notification!]!
|
notifications: [Notification!]!
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,13 +10,6 @@ export const NOTIFICATIONS = gql`
|
||||||
notifications(cursor: $cursor, inc: $inc) {
|
notifications(cursor: $cursor, inc: $inc) {
|
||||||
cursor
|
cursor
|
||||||
lastChecked
|
lastChecked
|
||||||
earn {
|
|
||||||
__typename
|
|
||||||
... on Earn {
|
|
||||||
sortTime
|
|
||||||
earnedSats
|
|
||||||
}
|
|
||||||
}
|
|
||||||
notifications {
|
notifications {
|
||||||
__typename
|
__typename
|
||||||
... on Mention {
|
... on Mention {
|
||||||
|
@ -35,6 +28,10 @@ export const NOTIFICATIONS = gql`
|
||||||
text
|
text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
... on Earn {
|
||||||
|
sortTime
|
||||||
|
earnedSats
|
||||||
|
}
|
||||||
... on Reply {
|
... on Reply {
|
||||||
sortTime
|
sortTime
|
||||||
item {
|
item {
|
||||||
|
|
Loading…
Reference in New Issue