add unreadCount property

This commit is contained in:
Moriz Wahl 2023-07-14 12:34:12 +02:00
parent 2fe93892a1
commit 1fd67aa581
4 changed files with 13 additions and 1 deletions

View File

@ -8,6 +8,7 @@ export const createRoomMutation = () => {
roomId
roomName
lastMessageAt
unreadCount
users {
_id
id
@ -29,6 +30,7 @@ export const roomQuery = () => {
roomId
roomName
lastMessageAt
unreadCount
lastMessage {
_id
id

View File

@ -126,6 +126,7 @@ describe('Room', () => {
id: expect.any(String),
roomId: result.data.CreateRoom.id,
roomName: 'Other Chatting User',
unreadCount: 0,
users: expect.arrayContaining([
{
_id: 'chatting-user',
@ -241,6 +242,7 @@ describe('Room', () => {
id: expect.any(String),
roomId: result.data.Room[0].id,
roomName: 'Chatting User',
unreadCount: 0,
users: expect.arrayContaining([
{
_id: 'chatting-user',

View File

@ -34,7 +34,8 @@ export default {
RETURN room {
.*,
users: [properties(currentUser), properties(user)],
roomName: roomName
roomName: roomName,
unreadCount: toString(0)
}
`
const createRommTxResponse = await transaction.run(createRoomCypher, {

View File

@ -23,6 +23,13 @@ type Room {
WITH message ORDER BY message.createdAt DESC LIMIT 1
RETURN message
""")
unreadCount: Int @cypher(statement: """
MATCH (this)<-[:INSIDE]-(message:Message)<-[:CREATED]-(user:User)
WHERE NOT user.id = $cypherParams.currentUserId
AND NOT message.seen
RETURN count(message)
""")
}
type Mutation {