finnal changes
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m22s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m22s
This commit is contained in:
parent
63354e85d5
commit
1015ee1643
@ -453,7 +453,6 @@ export class ChatService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if target user is an admin
|
|
||||||
const targetMembership = await prisma.chatRoomMember.findUnique({
|
const targetMembership = await prisma.chatRoomMember.findUnique({
|
||||||
where: {
|
where: {
|
||||||
userId_roomId: {
|
userId_roomId: {
|
||||||
@ -479,7 +478,6 @@ export class ChatService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove user from chat room
|
|
||||||
await prisma.chatRoomMember.delete({
|
await prisma.chatRoomMember.delete({
|
||||||
where: {
|
where: {
|
||||||
userId_roomId: {
|
userId_roomId: {
|
||||||
@ -489,7 +487,6 @@ export class ChatService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get updated chat room
|
|
||||||
const updatedRoom = await prisma.chatRoom.findUnique({
|
const updatedRoom = await prisma.chatRoom.findUnique({
|
||||||
where: { id: roomId },
|
where: { id: roomId },
|
||||||
include: {
|
include: {
|
||||||
|
|||||||
@ -2,12 +2,14 @@ import { prisma } from "@/config/database.js";
|
|||||||
import { checkMessageRateLimit } from "@/middleware/rateLimiter.js";
|
import { checkMessageRateLimit } from "@/middleware/rateLimiter.js";
|
||||||
import { ChatService } from "@/services/chatService.js";
|
import { ChatService } from "@/services/chatService.js";
|
||||||
import { MessageService } from "@/services/messageService.js";
|
import { MessageService } from "@/services/messageService.js";
|
||||||
import { AuthenticatedSocket, ReactToMessageRequest, SendMessageRequest } from "@/types/index.js";
|
import { AuthenticatedSocket, CreateChatRoomRequest, ReactToMessageRequest, SendMessageRequest } from "@/types/index.js";
|
||||||
import { Server } from "socket.io";
|
import { Server } from "socket.io";
|
||||||
|
|
||||||
export const handleConnection = async (io: Server, socket: AuthenticatedSocket) => {
|
export const handleConnection = async (io: Server, socket: AuthenticatedSocket) => {
|
||||||
console.log(`User connected: ${socket.user.username} (${socket.user.id})`);
|
console.log(`User connected: ${socket.user.username} (${socket.user.id})`);
|
||||||
|
|
||||||
|
socket.join(socket.userId);
|
||||||
|
|
||||||
await updateUserOnlineStatus(socket.userId, true);
|
await updateUserOnlineStatus(socket.userId, true);
|
||||||
|
|
||||||
const onlineUsers = await prisma.user.findMany({
|
const onlineUsers = await prisma.user.findMany({
|
||||||
@ -33,6 +35,8 @@ export const handleConnection = async (io: Server, socket: AuthenticatedSocket)
|
|||||||
|
|
||||||
socket.on("messages_seen", (data: { roomId: string; messageIds: string[] }) => handleMessagesSeen(io, socket, data));
|
socket.on("messages_seen", (data: { roomId: string; messageIds: string[] }) => handleMessagesSeen(io, socket, data));
|
||||||
|
|
||||||
|
socket.on("create_chat_room", (data: CreateChatRoomRequest) => handleCreateChatRoom(io, socket, data));
|
||||||
|
|
||||||
socket.on("disconnect", () => handleDisconnect(socket));
|
socket.on("disconnect", () => handleDisconnect(socket));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -220,6 +224,27 @@ const handleJoinRoom = async (socket: AuthenticatedSocket, roomId: string) => {
|
|||||||
await socket.join(roomId);
|
await socket.join(roomId);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleCreateChatRoom = async (io: Server, socket: AuthenticatedSocket, data: CreateChatRoomRequest) => {
|
||||||
|
try {
|
||||||
|
const result = await ChatService.createChatRoom(socket.userId, data);
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
const room = result.data;
|
||||||
|
|
||||||
|
room.members.forEach((member: { userId: string | string[] }) => {
|
||||||
|
io.to(member.userId).emit("chat_room_created", room);
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.emit("chat_room_created", room);
|
||||||
|
} else {
|
||||||
|
socket.emit("error", { message: result.error });
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error creating chat room: ${error}`);
|
||||||
|
socket.emit("error", { message: "Failed to create chat room" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleLeaveRoom = async (socket: AuthenticatedSocket, roomId: string) => {
|
const handleLeaveRoom = async (socket: AuthenticatedSocket, roomId: string) => {
|
||||||
await socket.leave(roomId);
|
await socket.leave(roomId);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user