mention notifications are functional
This commit is contained in:
parent
3370675d61
commit
4b64912333
@ -43,13 +43,15 @@ export default {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
let notifications = await models.$queryRaw(`
|
let notifications = await models.$queryRaw(`
|
||||||
SELECT ${ITEM_FIELDS}, "Item".created_at as sort_time, NULL as "earnedSats"
|
SELECT ${ITEM_FIELDS}, "Item".created_at as sort_time, NULL as "earnedSats",
|
||||||
|
false as mention
|
||||||
From "Item"
|
From "Item"
|
||||||
JOIN "Item" p ON "Item"."parentId" = p.id
|
JOIN "Item" p ON "Item"."parentId" = p.id
|
||||||
WHERE p."userId" = $1
|
WHERE p."userId" = $1
|
||||||
AND "Item"."userId" <> $1 AND "Item".created_at <= $2
|
AND "Item"."userId" <> $1 AND "Item".created_at <= $2
|
||||||
UNION ALL
|
UNION ALL
|
||||||
(SELECT ${ITEM_SUBQUERY_FIELDS}, max(subquery.voted_at) as sort_time, sum(subquery.sats) as "earnedSats"
|
(SELECT ${ITEM_SUBQUERY_FIELDS}, max(subquery.voted_at) as sort_time,
|
||||||
|
sum(subquery.sats) as "earnedSats", false as mention
|
||||||
FROM
|
FROM
|
||||||
(SELECT ${ITEM_FIELDS}, "Vote".created_at as voted_at, "Vote".sats,
|
(SELECT ${ITEM_FIELDS}, "Vote".created_at as voted_at, "Vote".sats,
|
||||||
ROW_NUMBER() OVER(ORDER BY "Vote".created_at) -
|
ROW_NUMBER() OVER(ORDER BY "Vote".created_at) -
|
||||||
@ -57,10 +59,18 @@ export default {
|
|||||||
FROM "Vote"
|
FROM "Vote"
|
||||||
JOIN "Item" on "Vote"."itemId" = "Item".id
|
JOIN "Item" on "Vote"."itemId" = "Item".id
|
||||||
WHERE "Vote"."userId" <> $1
|
WHERE "Vote"."userId" <> $1
|
||||||
AND "Item".created_at <= $2
|
AND "Vote".created_at <= $2
|
||||||
AND "Vote".boost = false
|
AND "Vote".boost = false
|
||||||
AND "Item"."userId" = $1) subquery
|
AND "Item"."userId" = $1) subquery
|
||||||
GROUP BY ${ITEM_SUBQUERY_FIELDS}, subquery.island ORDER BY max(subquery.voted_at) desc)
|
GROUP BY ${ITEM_SUBQUERY_FIELDS}, subquery.island ORDER BY max(subquery.voted_at) desc)
|
||||||
|
UNION ALL
|
||||||
|
(SELECT ${ITEM_FIELDS}, "Mention".created_at as sort_time, NULL as "earnedSats",
|
||||||
|
true as mention
|
||||||
|
FROM "Mention"
|
||||||
|
JOIN "Item" on "Mention"."itemId" = "Item".id
|
||||||
|
WHERE "Mention"."userId" = $1
|
||||||
|
AND "Mention".created_at <= $2
|
||||||
|
AND "Item"."userId" <> $1)
|
||||||
ORDER BY sort_time DESC
|
ORDER BY sort_time DESC
|
||||||
OFFSET $3
|
OFFSET $3
|
||||||
LIMIT ${LIMIT}`, me.id, decodedCursor.time, decodedCursor.offset)
|
LIMIT ${LIMIT}`, me.id, decodedCursor.time, decodedCursor.offset)
|
||||||
@ -80,7 +90,7 @@ export default {
|
|||||||
},
|
},
|
||||||
Notification: {
|
Notification: {
|
||||||
__resolveType: async (notification, args, { models }) =>
|
__resolveType: async (notification, args, { models }) =>
|
||||||
notification.earnedSats ? 'Votification' : 'Reply'
|
notification.earnedSats ? 'Votification' : (notification.mention ? 'Mention' : 'Reply')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,20 @@ export default {
|
|||||||
WHERE p."userId" = $1
|
WHERE p."userId" = $1
|
||||||
AND ("Item".created_at > $2 OR $2 IS NULL) AND "Item"."userId" <> $1
|
AND ("Item".created_at > $2 OR $2 IS NULL) AND "Item"."userId" <> $1
|
||||||
LIMIT 1`, user.id, user.checkedNotesAt)
|
LIMIT 1`, user.id, user.checkedNotesAt)
|
||||||
return !!newReplies.length
|
if (newReplies.length > 0) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if they have any mentions since checkedNotesAt
|
||||||
|
const newMentions = await models.$queryRaw(`
|
||||||
|
SELECT "Item".id, "Item".created_at
|
||||||
|
From "Mention"
|
||||||
|
JOIN "Item" ON "Mention"."itemId" = "Item".id
|
||||||
|
WHERE "Mention"."userId" = $1
|
||||||
|
AND ("Mention".created_at > $2 OR $2 IS NULL)
|
||||||
|
AND "Item"."userId" <> $1
|
||||||
|
LIMIT 1`, user.id, user.checkedNotesAt)
|
||||||
|
return newMentions.length > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,12 @@ export default gql`
|
|||||||
item: Item!
|
item: Item!
|
||||||
}
|
}
|
||||||
|
|
||||||
union Notification = Reply | Votification
|
type Mention {
|
||||||
|
mention: Boolean!
|
||||||
|
item: Item!
|
||||||
|
}
|
||||||
|
|
||||||
|
union Notification = Reply | Votification | Mention
|
||||||
|
|
||||||
type Notifications {
|
type Notifications {
|
||||||
cursor: String
|
cursor: String
|
||||||
|
@ -41,8 +41,16 @@ export default function Notifications ({ variables, ...props }) {
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{n.__typename === 'Votification' && <small className='font-weight-bold text-success ml-2'>your {n.item.title ? 'post' : 'reply'} stacked {n.earnedSats} sats</small>}
|
{n.__typename === 'Votification' &&
|
||||||
<div className={n.__typename === 'Votification' ? `ml-sm-4 ml-2 ${n.item.title ? 'pb-2' : ''}` : ''}>
|
<small className='font-weight-bold text-success ml-2'>your {n.item.title ? 'post' : 'reply'} stacked {n.earnedSats} sats</small>}
|
||||||
|
{n.__typename === 'Mention' &&
|
||||||
|
<small className='font-weight-bold text-info ml-2'>you were mentioned in</small>}
|
||||||
|
<div className={
|
||||||
|
n.__typename === 'Votification' || n.__typename === 'Mention'
|
||||||
|
? `ml-sm-4 ml-2 ${n.item.title ? 'pb-2' : ''}`
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
>
|
||||||
{n.item.title
|
{n.item.title
|
||||||
? <Item item={n.item} />
|
? <Item item={n.item} />
|
||||||
: <Comment item={n.item} noReply includeParent rootText={n.__typename === 'Reply' ? 'replying to you on:' : undefined} clickToContext {...props} />}
|
: <Comment item={n.item} noReply includeParent rootText={n.__typename === 'Reply' ? 'replying to you on:' : undefined} clickToContext {...props} />}
|
||||||
|
@ -9,6 +9,13 @@ export const NOTIFICATIONS = gql`
|
|||||||
cursor
|
cursor
|
||||||
notifications {
|
notifications {
|
||||||
__typename
|
__typename
|
||||||
|
... on Mention {
|
||||||
|
mention
|
||||||
|
item {
|
||||||
|
...ItemFields
|
||||||
|
text
|
||||||
|
}
|
||||||
|
}
|
||||||
... on Votification {
|
... on Votification {
|
||||||
earnedSats
|
earnedSats
|
||||||
item {
|
item {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user