mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Update notifications
- create only one relationship by using merge, but do not update createdAt attribute/update test - order by updatedAt_desc
This commit is contained in:
parent
67d68db231
commit
16d7e6c91a
@ -24,9 +24,13 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => {
|
|||||||
MATCH (user: User)
|
MATCH (user: User)
|
||||||
WHERE user.id in $idsOfUsers
|
WHERE user.id in $idsOfUsers
|
||||||
AND NOT (user)<-[:BLOCKED]-(author)
|
AND NOT (user)<-[:BLOCKED]-(author)
|
||||||
CREATE (post)-[notification:NOTIFIED {reason: $reason}]->(user)
|
MERGE (post)-[notification:NOTIFIED {reason: $reason}]->(user)
|
||||||
SET notification.read = FALSE
|
SET notification.read = FALSE
|
||||||
SET notification.createdAt = toString(datetime())
|
SET (
|
||||||
|
CASE
|
||||||
|
WHEN notification.createdAt IS NULL
|
||||||
|
THEN notification END ).createdAt = toString(datetime())
|
||||||
|
SET notification.updatedAt = toString(datetime())
|
||||||
`
|
`
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -37,9 +41,13 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => {
|
|||||||
WHERE user.id in $idsOfUsers
|
WHERE user.id in $idsOfUsers
|
||||||
AND NOT (user)<-[:BLOCKED]-(author)
|
AND NOT (user)<-[:BLOCKED]-(author)
|
||||||
AND NOT (user)<-[:BLOCKED]-(postAuthor)
|
AND NOT (user)<-[:BLOCKED]-(postAuthor)
|
||||||
CREATE (comment)-[notification:NOTIFIED {reason: $reason}]->(user)
|
MERGE (comment)-[notification:NOTIFIED {reason: $reason}]->(user)
|
||||||
SET notification.read = FALSE
|
SET notification.read = FALSE
|
||||||
SET notification.createdAt = toString(datetime())
|
SET (
|
||||||
|
CASE
|
||||||
|
WHEN notification.createdAt IS NULL
|
||||||
|
THEN notification END ).createdAt = toString(datetime())
|
||||||
|
SET notification.updatedAt = toString(datetime())
|
||||||
`
|
`
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -50,9 +58,13 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => {
|
|||||||
WHERE user.id in $idsOfUsers
|
WHERE user.id in $idsOfUsers
|
||||||
AND NOT (user)<-[:BLOCKED]-(author)
|
AND NOT (user)<-[:BLOCKED]-(author)
|
||||||
AND NOT (author)<-[:BLOCKED]-(user)
|
AND NOT (author)<-[:BLOCKED]-(user)
|
||||||
CREATE (comment)-[notification:NOTIFIED {reason: $reason}]->(user)
|
MERGE (comment)-[notification:NOTIFIED {reason: $reason}]->(user)
|
||||||
SET notification.read = FALSE
|
SET notification.read = FALSE
|
||||||
SET notification.createdAt = toString(datetime())
|
SET (
|
||||||
|
CASE
|
||||||
|
WHEN notification.createdAt IS NULL
|
||||||
|
THEN notification END ).createdAt = toString(datetime())
|
||||||
|
SET notification.updatedAt = toString(datetime())
|
||||||
`
|
`
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@ -77,7 +77,7 @@ afterEach(async () => {
|
|||||||
describe('notifications', () => {
|
describe('notifications', () => {
|
||||||
const notificationQuery = gql`
|
const notificationQuery = gql`
|
||||||
query($read: Boolean) {
|
query($read: Boolean) {
|
||||||
notifications(read: $read, orderBy: createdAt_desc) {
|
notifications(read: $read, orderBy: updatedAt_desc) {
|
||||||
read
|
read
|
||||||
reason
|
reason
|
||||||
createdAt
|
createdAt
|
||||||
|
|||||||
@ -32,11 +32,11 @@ export default {
|
|||||||
whereClause = ''
|
whereClause = ''
|
||||||
}
|
}
|
||||||
switch (args.orderBy) {
|
switch (args.orderBy) {
|
||||||
case 'createdAt_asc':
|
case 'updatedAt_asc':
|
||||||
orderByClause = 'ORDER BY notification.createdAt ASC'
|
orderByClause = 'ORDER BY notification.updatedAt ASC'
|
||||||
break
|
break
|
||||||
case 'createdAt_desc':
|
case 'updatedAt_desc':
|
||||||
orderByClause = 'ORDER BY notification.createdAt DESC'
|
orderByClause = 'ORDER BY notification.updatedAt DESC'
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
orderByClause = ''
|
orderByClause = ''
|
||||||
|
|||||||
@ -2,6 +2,7 @@ type NOTIFIED {
|
|||||||
from: NotificationSource
|
from: NotificationSource
|
||||||
to: User
|
to: User
|
||||||
createdAt: String
|
createdAt: String
|
||||||
|
updatedAt: String
|
||||||
read: Boolean
|
read: Boolean
|
||||||
reason: NotificationReason
|
reason: NotificationReason
|
||||||
}
|
}
|
||||||
@ -11,6 +12,8 @@ union NotificationSource = Post | Comment
|
|||||||
enum NotificationOrdering {
|
enum NotificationOrdering {
|
||||||
createdAt_asc
|
createdAt_asc
|
||||||
createdAt_desc
|
createdAt_desc
|
||||||
|
updatedAt_asc
|
||||||
|
updatedAt_desc
|
||||||
}
|
}
|
||||||
|
|
||||||
enum NotificationReason {
|
enum NotificationReason {
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<ds-button
|
<ds-button v-if="totalNotifications <= 0" class="notifications-menu" disabled icon="bell">
|
||||||
v-if="totalNotifications <= 0"
|
{{ totalNotifications }}
|
||||||
class="notifications-menu"
|
</ds-button>
|
||||||
disabled
|
|
||||||
icon="bell"
|
|
||||||
>{{ totalNotifications }}</ds-button>
|
|
||||||
<dropdown v-else class="notifications-menu" :placement="placement">
|
<dropdown v-else class="notifications-menu" :placement="placement">
|
||||||
<template slot="default" slot-scope="{ toggleMenu }">
|
<template slot="default" slot-scope="{ toggleMenu }">
|
||||||
<ds-button primary icon="bell" @click.prevent="toggleMenu">{{ totalNotifications }}</ds-button>
|
<ds-button primary icon="bell" @click.prevent="toggleMenu">
|
||||||
|
{{ totalNotifications }}
|
||||||
|
</ds-button>
|
||||||
</template>
|
</template>
|
||||||
<template slot="popover">
|
<template slot="popover">
|
||||||
<div class="notifications-menu-popover">
|
<div class="notifications-menu-popover">
|
||||||
|
|||||||
@ -97,7 +97,7 @@ export const notificationQuery = i18n => {
|
|||||||
${postFragment(lang)}
|
${postFragment(lang)}
|
||||||
|
|
||||||
query {
|
query {
|
||||||
notifications(read: false, orderBy: createdAt_desc) {
|
notifications(read: false, orderBy: updatedAt_desc) {
|
||||||
read
|
read
|
||||||
reason
|
reason
|
||||||
createdAt
|
createdAt
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user