properly propagte user into unreadRoomCount subscription

This commit is contained in:
Ulf Gebhardt 2023-07-17 13:11:33 +02:00
parent 3e60ab6854
commit e09c91235e
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
2 changed files with 6 additions and 7 deletions

View File

@ -63,8 +63,8 @@ export default {
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
const createMessageCypher = `
MATCH (currentUser:User { id: $currentUserId })-[:CHATS_IN]->(room:Room { id: $roomId })
OPTIONAL MATCH (m:Message)-[:INSIDE]->(room)
WITH MAX(m.indexId) as maxIndex, room, currentUser
OPTIONAL MATCH (m:Message)-[:INSIDE]->(room)<-[:CHATS_IN]-(otherUser:User)
WITH MAX(m.indexId) as maxIndex, room, currentUser, otherUser
CREATE (currentUser)-[:CREATED]->(message:Message {
createdAt: toString(datetime()),
id: apoc.create.uuid(),
@ -74,7 +74,7 @@ export default {
distributed: false,
seen: false
})-[: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, {
currentUserId,
@ -86,11 +86,11 @@ export default {
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)
// send subscriptions
await pubsub.publish(ROOM_COUNT_UPDATED, { roomCountUpdated })
await pubsub.publish(ROOM_COUNT_UPDATED, { roomCountUpdated, user: message.otherUser })
return message
})

View File

@ -9,8 +9,7 @@ export default {
subscribe: withFilter(
() => pubsub.asyncIterator(ROOM_COUNT_UPDATED),
(payload, variables) => {
console.log('sub', payload, variables)
return true // payload.chatMessageAdded.senderId !== variables.userId
return payload.user.id === variables.userId
},
),
},