fixed admins when owner leaves

This commit is contained in:
simplonco
2023-01-18 05:42:26 +01:00
parent 4ccd3a4b93
commit 94f9213ac7

View File

@@ -721,8 +721,8 @@ export class ChatService {
const room = await this.getRoomByName(room_name); const room = await this.getRoomByName(room_name);
if(!room) if(!room)
{ {
printCallerError(`ERROR in chat: room not found for ${username}`); console.log("throw error: error: true, code: 'ROOM_NOT_FOUND', message: 'room_not_found'");
return []; throw new HttpException({ error: true, code: 'ROOM_NOT_FOUND', message: `room_not_found` }, HttpStatus.NOT_FOUND);
} }
if (!room.users.includes(username)) if (!room.users.includes(username))
{ {
@@ -731,8 +731,8 @@ export class ChatService {
} }
if (room.type === "direct") if (room.type === "direct")
{ {
console.log("throw error: error: true, code: 'LEAVE_DIRECY_FORBIDDEN', message: 'you cannot leave a direct messages conversation'"); console.log("throw error: error: true, code: 'LEAVE_DIRECT_FORBIDDEN', message: 'you cannot leave a direct messages conversation'");
throw new HttpException({ error: true, code: 'LEAVE_DIRECY_FORBIDDEN', message: `you cannot leave a direct messages conversation` }, HttpStatus.FORBIDDEN); throw new HttpException({ error: true, code: 'LEAVE_DIRECT_FORBIDDEN', message: `you cannot leave a direct messages conversation` }, HttpStatus.FORBIDDEN);
} }
// delete user from room // delete user from room
@@ -749,6 +749,7 @@ export class ChatService {
else if (room.users) else if (room.users)
{ {
room.owner = room.users[0]; room.owner = room.users[0];
room.admins = [room.users[0]];
messages.push(`${room.owner} is now owner of this room`); messages.push(`${room.owner} is now owner of this room`);
} }
else else