only one earn notification at a time
This commit is contained in:
parent
2608cbc326
commit
cef122141f
@ -116,19 +116,6 @@ export default {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (me.noteEarning) {
|
|
||||||
queries.push(
|
|
||||||
`(SELECT "Earn".id::text, "Earn".created_at AS "sortTime", FLOOR(msats / 1000) as "earnedSats",
|
|
||||||
'Earn' AS type
|
|
||||||
FROM "Earn"
|
|
||||||
WHERE "Earn"."userId" = $1
|
|
||||||
AND FLOOR(msats / 1000) > 0
|
|
||||||
AND created_at <= $2
|
|
||||||
ORDER BY "sortTime" DESC
|
|
||||||
LIMIT ${LIMIT}+$3)`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (me.noteMentions) {
|
if (me.noteMentions) {
|
||||||
queries.push(
|
queries.push(
|
||||||
`(SELECT "Item".id::TEXT, "Mention".created_at AS "sortTime", NULL as "earnedSats",
|
`(SELECT "Item".id::TEXT, "Mention".created_at AS "sortTime", NULL as "earnedSats",
|
||||||
@ -179,12 +166,28 @@ export default {
|
|||||||
LIMIT ${LIMIT}`, me.id, decodedCursor.time, decodedCursor.offset)
|
LIMIT ${LIMIT}`, me.id, decodedCursor.time, decodedCursor.offset)
|
||||||
|
|
||||||
const { checkedNotesAt } = await models.user.findUnique({ where: { id: me.id } })
|
const { checkedNotesAt } = await models.user.findUnique({ where: { id: me.id } })
|
||||||
|
let earn
|
||||||
if (decodedCursor.offset === 0) {
|
if (decodedCursor.offset === 0) {
|
||||||
|
if (me.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, 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() } })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(decodedCursor)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
lastChecked: checkedNotesAt,
|
lastChecked: checkedNotesAt,
|
||||||
|
earn,
|
||||||
cursor: notifications.length === LIMIT ? nextCursorEncoded(decodedCursor) : null,
|
cursor: notifications.length === LIMIT ? nextCursorEncoded(decodedCursor) : null,
|
||||||
notifications
|
notifications
|
||||||
}
|
}
|
||||||
|
@ -44,10 +44,11 @@ export default gql`
|
|||||||
}
|
}
|
||||||
|
|
||||||
union Notification = Reply | Votification | Mention
|
union Notification = Reply | Votification | Mention
|
||||||
| Invitification | JobChanged | Earn | InvoicePaid
|
| Invitification | Earn | JobChanged | InvoicePaid
|
||||||
|
|
||||||
type Notifications {
|
type Notifications {
|
||||||
lastChecked: String
|
lastChecked: String
|
||||||
|
earn: Notification
|
||||||
cursor: String
|
cursor: String
|
||||||
notifications: [Notification!]!
|
notifications: [Notification!]!
|
||||||
}
|
}
|
||||||
|
@ -110,11 +110,13 @@ function Notification ({ n }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Notifications ({ notifications, cursor, lastChecked, variables }) {
|
export default function Notifications ({ notifications, earn, cursor, lastChecked, variables }) {
|
||||||
const { data, fetchMore } = useQuery(NOTIFICATIONS, { variables })
|
const { data, fetchMore } = useQuery(NOTIFICATIONS, { variables })
|
||||||
|
|
||||||
|
console.log(data)
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
({ notifications: { notifications, cursor } } = data)
|
({ notifications: { notifications, earn, cursor } } = data)
|
||||||
}
|
}
|
||||||
|
|
||||||
const [fresh, old] =
|
const [fresh, old] =
|
||||||
@ -128,6 +130,7 @@ export default function Notifications ({ notifications, cursor, lastChecked, var
|
|||||||
<>
|
<>
|
||||||
{/* XXX we shouldn't use the index but we don't have a unique id in this union yet */}
|
{/* XXX we shouldn't use the index but we don't have a unique id in this union yet */}
|
||||||
<div className='fresh'>
|
<div className='fresh'>
|
||||||
|
{earn && <Notification n={earn} key='earn' />}
|
||||||
{fresh.map((n, i) => (
|
{fresh.map((n, i) => (
|
||||||
<Notification n={n} key={i} />
|
<Notification n={n} key={i} />
|
||||||
))}
|
))}
|
||||||
|
@ -10,6 +10,13 @@ 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 {
|
||||||
@ -47,10 +54,6 @@ export const NOTIFICATIONS = gql`
|
|||||||
...ItemFields
|
...ItemFields
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
... on Earn {
|
|
||||||
sortTime
|
|
||||||
earnedSats
|
|
||||||
}
|
|
||||||
... on InvoicePaid {
|
... on InvoicePaid {
|
||||||
sortTime
|
sortTime
|
||||||
earnedSats
|
earnedSats
|
||||||
|
@ -87,6 +87,7 @@ export default function getApolloClient () {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
cursor: incoming.cursor,
|
cursor: incoming.cursor,
|
||||||
|
earn: existing?.earn || incoming.earn,
|
||||||
notifications: [...(existing?.notifications || []), ...incoming.notifications],
|
notifications: [...(existing?.notifications || []), ...incoming.notifications],
|
||||||
lastChecked: incoming.lastChecked
|
lastChecked: incoming.lastChecked
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user