I want to make a chat app with react, node, socket.io, and Prisma. I am unable to add direct message (dm) functionality but added group functionality.
My Schema
datasource db {
url = env("DATABASE_URL")
provider = "postgresql"
}
generator client {
provider = "prisma-client-js"
}
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
email String @unique
username String
password String
sender Messages @relation("sender")
receiver Messages @relation("receiver")
}
model Group {
id Int @id @default(autoincrement())
messages Messages[]
user Users[]
}
model Messages {
id Int @id @default(autoincrement())
text String
group Group @relation(fields: [groupId], references: [id])
groupId Int
sender User @relation("sender", fields: [senderId], references: [id])
senderId Int
reciever User @relation("reciever", fields: [recieverId], references: [id])
recieverId Int
}
Top comments (3)
I don't have any experience with Prisma but you should be able to message a specific client in Socket using the Client's ID (which would be managed on your Node Server).
This is the socket documentation that talks about a client talking directly to a client: socket.io/docs/v4/server-socket-in...
Only think I would note is that is has become my practice to have a object that connects my Socket generated Client ID to the my custom created user IDs. That way I can always correlate the two when a client is connected to the server.
what kind of issues are you having?
have you tried to apply the same logic you use for group messages but have only two users in the room?
I have done group messages, private messages, but stuck on a part on how to check user's friends or whome he chats with