mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
start with chat notifications
This commit is contained in:
parent
d75566a8ce
commit
9c052ea1cd
@ -1,7 +1,19 @@
|
|||||||
import { neo4jgraphql } from 'neo4j-graphql-js'
|
import { neo4jgraphql } from 'neo4j-graphql-js'
|
||||||
import Resolver from './helpers/Resolver'
|
import Resolver from './helpers/Resolver'
|
||||||
|
import { withFilter } from 'graphql-subscriptions'
|
||||||
|
import { pubsub, CHAT_MESSAGE_ADDED } from '../../server'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
Subscription: {
|
||||||
|
chatMessageAdded: {
|
||||||
|
subscribe: withFilter(
|
||||||
|
() => pubsub.asyncIterator(CHAT_MESSAGE_ADDED),
|
||||||
|
(payload, variables) => {
|
||||||
|
return payload.chatMessageAdded.senderId !== variables.userId
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
Query: {
|
Query: {
|
||||||
Message: async (object, params, context, resolveInfo) => {
|
Message: async (object, params, context, resolveInfo) => {
|
||||||
const { roomId } = params
|
const { roomId } = params
|
||||||
@ -72,7 +84,7 @@ export default {
|
|||||||
distributed: false,
|
distributed: false,
|
||||||
seen: false
|
seen: false
|
||||||
})-[:INSIDE]->(room)
|
})-[:INSIDE]->(room)
|
||||||
RETURN message { .* }
|
RETURN message { .*, room: properties(room), senderId: currentUser.id }
|
||||||
`
|
`
|
||||||
const createMessageTxResponse = await transaction.run(createMessageCypher, {
|
const createMessageTxResponse = await transaction.run(createMessageCypher, {
|
||||||
currentUserId,
|
currentUserId,
|
||||||
@ -82,6 +94,10 @@ export default {
|
|||||||
const [message] = await createMessageTxResponse.records.map((record) =>
|
const [message] = await createMessageTxResponse.records.map((record) =>
|
||||||
record.get('message'),
|
record.get('message'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// send subscriptions
|
||||||
|
await pubsub.publish(CHAT_MESSAGE_ADDED, { chatMessageAdded: message })
|
||||||
|
|
||||||
return message
|
return message
|
||||||
})
|
})
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -45,3 +45,7 @@ type Query {
|
|||||||
orderBy: [_MessageOrdering]
|
orderBy: [_MessageOrdering]
|
||||||
): [Message]
|
): [Message]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Subscription {
|
||||||
|
chatMessageAdded(userId: ID!): Message
|
||||||
|
}
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import bodyParser from 'body-parser'
|
|||||||
import { graphqlUploadExpress } from 'graphql-upload'
|
import { graphqlUploadExpress } from 'graphql-upload'
|
||||||
|
|
||||||
export const NOTIFICATION_ADDED = 'NOTIFICATION_ADDED'
|
export const NOTIFICATION_ADDED = 'NOTIFICATION_ADDED'
|
||||||
|
export const CHAT_MESSAGE_ADDED = 'CHAT_MESSAGE_ADDED'
|
||||||
const { REDIS_DOMAIN, REDIS_PORT, REDIS_PASSWORD } = CONFIG
|
const { REDIS_DOMAIN, REDIS_PORT, REDIS_PASSWORD } = CONFIG
|
||||||
let prodPubsub, devPubsub
|
let prodPubsub, devPubsub
|
||||||
const options = {
|
const options = {
|
||||||
|
|||||||
@ -14,8 +14,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { mapGetters } from 'vuex'
|
||||||
import CounterIcon from '~/components/_new/generic/CounterIcon/CounterIcon'
|
import CounterIcon from '~/components/_new/generic/CounterIcon/CounterIcon'
|
||||||
import { unreadRoomsQuery } from '~/graphql/Rooms'
|
import { unreadRoomsQuery } from '~/graphql/Rooms'
|
||||||
|
import { chatMessageAdded } from '~/graphql/Messages'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ChatNotificationMenu',
|
name: 'ChatNotificationMenu',
|
||||||
@ -27,6 +29,11 @@ export default {
|
|||||||
count: 0,
|
count: 0,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
...mapGetters({
|
||||||
|
user: 'auth/user',
|
||||||
|
}),
|
||||||
|
},
|
||||||
apollo: {
|
apollo: {
|
||||||
UnreadRooms: {
|
UnreadRooms: {
|
||||||
query() {
|
query() {
|
||||||
@ -35,6 +42,18 @@ export default {
|
|||||||
update({ UnreadRooms }) {
|
update({ UnreadRooms }) {
|
||||||
this.count = UnreadRooms
|
this.count = UnreadRooms
|
||||||
},
|
},
|
||||||
|
subscribeToMore: {
|
||||||
|
document: chatMessageAdded(),
|
||||||
|
variables() {
|
||||||
|
return {
|
||||||
|
userId: this.user.id,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateQuery: (previousResult, { subscriptionData }) => {
|
||||||
|
// TODO emit chat reload
|
||||||
|
return { UnreadRooms: previousResult.UnreadRooms + 1}
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -146,6 +146,7 @@ export default {
|
|||||||
const {
|
const {
|
||||||
data: { notificationAdded: newNotification },
|
data: { notificationAdded: newNotification },
|
||||||
} = subscriptionData
|
} = subscriptionData
|
||||||
|
|
||||||
return {
|
return {
|
||||||
notifications: unionBy(
|
notifications: unionBy(
|
||||||
[newNotification],
|
[newNotification],
|
||||||
|
|||||||
@ -27,3 +27,16 @@ export const createMessageMutation = () => {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const chatMessageAdded = () => {
|
||||||
|
return gql`
|
||||||
|
subscription chatMessageAdded($userId: ID!) {
|
||||||
|
chatMessageAdded(userId: $userId) {
|
||||||
|
id
|
||||||
|
room {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user