mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
properly propagte user into unreadRoomCount subscription
This commit is contained in:
parent
3e60ab6854
commit
e09c91235e
@ -63,8 +63,8 @@ export default {
|
|||||||
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
|
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
|
||||||
const createMessageCypher = `
|
const createMessageCypher = `
|
||||||
MATCH (currentUser:User { id: $currentUserId })-[:CHATS_IN]->(room:Room { id: $roomId })
|
MATCH (currentUser:User { id: $currentUserId })-[:CHATS_IN]->(room:Room { id: $roomId })
|
||||||
OPTIONAL MATCH (m:Message)-[:INSIDE]->(room)
|
OPTIONAL MATCH (m:Message)-[:INSIDE]->(room)<-[:CHATS_IN]-(otherUser:User)
|
||||||
WITH MAX(m.indexId) as maxIndex, room, currentUser
|
WITH MAX(m.indexId) as maxIndex, room, currentUser, otherUser
|
||||||
CREATE (currentUser)-[:CREATED]->(message:Message {
|
CREATE (currentUser)-[:CREATED]->(message:Message {
|
||||||
createdAt: toString(datetime()),
|
createdAt: toString(datetime()),
|
||||||
id: apoc.create.uuid(),
|
id: apoc.create.uuid(),
|
||||||
@ -74,7 +74,7 @@ export default {
|
|||||||
distributed: false,
|
distributed: false,
|
||||||
seen: false
|
seen: false
|
||||||
})-[:INSIDE]->(room)
|
})-[:INSIDE]->(room)
|
||||||
RETURN message { .*, room: properties(room), senderId: currentUser.id }
|
RETURN message { .*, room: properties(room), senderId: currentUser.id, otherUser: properties(otherUser) }
|
||||||
`
|
`
|
||||||
const createMessageTxResponse = await transaction.run(createMessageCypher, {
|
const createMessageTxResponse = await transaction.run(createMessageCypher, {
|
||||||
currentUserId,
|
currentUserId,
|
||||||
@ -86,11 +86,11 @@ export default {
|
|||||||
record.get('message'),
|
record.get('message'),
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO change user in context - mark message as seen
|
// TODO change user in context - mark message as seen - chattingUser is the correct user.
|
||||||
const roomCountUpdated = await RoomResolver.Query.UnreadRooms(null, null, context, null)
|
const roomCountUpdated = await RoomResolver.Query.UnreadRooms(null, null, context, null)
|
||||||
|
|
||||||
// send subscriptions
|
// send subscriptions
|
||||||
await pubsub.publish(ROOM_COUNT_UPDATED, { roomCountUpdated })
|
await pubsub.publish(ROOM_COUNT_UPDATED, { roomCountUpdated, user: message.otherUser })
|
||||||
|
|
||||||
return message
|
return message
|
||||||
})
|
})
|
||||||
|
|||||||
@ -9,8 +9,7 @@ export default {
|
|||||||
subscribe: withFilter(
|
subscribe: withFilter(
|
||||||
() => pubsub.asyncIterator(ROOM_COUNT_UPDATED),
|
() => pubsub.asyncIterator(ROOM_COUNT_UPDATED),
|
||||||
(payload, variables) => {
|
(payload, variables) => {
|
||||||
console.log('sub', payload, variables)
|
return payload.user.id === variables.userId
|
||||||
return true // payload.chatMessageAdded.senderId !== variables.userId
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user