mention notifications are functional

This commit is contained in:
keyan 2021-08-18 18:00:54 -05:00
parent 3370675d61
commit 4b64912333
5 changed files with 51 additions and 8 deletions

View File

@ -43,13 +43,15 @@ export default {
*/
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"
JOIN "Item" p ON "Item"."parentId" = p.id
WHERE p."userId" = $1
AND "Item"."userId" <> $1 AND "Item".created_at <= $2
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
(SELECT ${ITEM_FIELDS}, "Vote".created_at as voted_at, "Vote".sats,
ROW_NUMBER() OVER(ORDER BY "Vote".created_at) -
@ -57,10 +59,18 @@ export default {
FROM "Vote"
JOIN "Item" on "Vote"."itemId" = "Item".id
WHERE "Vote"."userId" <> $1
AND "Item".created_at <= $2
AND "Vote".created_at <= $2
AND "Vote".boost = false
AND "Item"."userId" = $1) subquery
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
OFFSET $3
LIMIT ${LIMIT}`, me.id, decodedCursor.time, decodedCursor.offset)
@ -80,7 +90,7 @@ export default {
},
Notification: {
__resolveType: async (notification, args, { models }) =>
notification.earnedSats ? 'Votification' : 'Reply'
notification.earnedSats ? 'Votification' : (notification.mention ? 'Mention' : 'Reply')
}
}

View File

@ -96,7 +96,20 @@ export default {
WHERE p."userId" = $1
AND ("Item".created_at > $2 OR $2 IS NULL) AND "Item"."userId" <> $1
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
}
}
}

View File

@ -14,7 +14,12 @@ export default gql`
item: Item!
}
union Notification = Reply | Votification
type Mention {
mention: Boolean!
item: Item!
}
union Notification = Reply | Votification | Mention
type Notifications {
cursor: String

View File

@ -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>}
<div className={n.__typename === 'Votification' ? `ml-sm-4 ml-2 ${n.item.title ? 'pb-2' : ''}` : ''}>
{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 === '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
? <Item item={n.item} />
: <Comment item={n.item} noReply includeParent rootText={n.__typename === 'Reply' ? 'replying to you on:' : undefined} clickToContext {...props} />}

View File

@ -9,6 +9,13 @@ export const NOTIFICATIONS = gql`
cursor
notifications {
__typename
... on Mention {
mention
item {
...ItemFields
text
}
}
... on Votification {
earnedSats
item {