Merge branch 'master' into luke
This commit is contained in:
3
package-lock.json
generated
3
package-lock.json
generated
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"lockfileVersion": 1
|
|
||||||
}
|
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
import { Controller, UseGuards, HttpException, HttpStatus, Get, Post, Delete, Body, Req, Res } from '@nestjs/common';
|
import { Controller, UseGuards, HttpException, HttpStatus, Get, Post, Delete, Body, Req, Res } from '@nestjs/common';
|
||||||
import { AuthenticateGuard, TwoFactorGuard } from 'src/auth/42/guards/42guards';
|
import { AuthenticateGuard, TwoFactorGuard } from 'src/auth/42/guards/42guards';
|
||||||
import { ConnectedSocket } from '@nestjs/websockets';
|
|
||||||
import { ChatService } from './chat.service';
|
import { ChatService } from './chat.service';
|
||||||
import { User } from 'src/users/entities/user.entity';
|
import { User } from 'src/users/entities/user.entity';
|
||||||
import { PartialUsersDto } from 'src/users/dto/partial-users.dto';
|
|
||||||
import { roomDto } from './dto/room.dto';
|
|
||||||
import { setCurrentRoomDto } from './dto/setCurrentRoom.dto';
|
|
||||||
import { ChatGateway } from './chat.gateway';
|
import { ChatGateway } from './chat.gateway';
|
||||||
import { socketDto } from './dto/socket.dto';
|
|
||||||
import { Chatroom } from './entities/chatroom.entity';
|
import { Chatroom } from './entities/chatroom.entity';
|
||||||
|
import { socketDto } from './dto/socket.dto';
|
||||||
|
import { roomDto } from './dto/room.dto';
|
||||||
import { printCaller } from './dev/dev_utils';
|
import { printCaller } from './dev/dev_utils';
|
||||||
|
import { setCurrentRoomDto } from './dto/setCurrentRoom.dto';
|
||||||
|
import { muteDto } from './dto/mute.dto';
|
||||||
|
|
||||||
@Controller('chat')
|
@Controller('chat')
|
||||||
export class ChatController {
|
export class ChatController {
|
||||||
@@ -32,6 +31,7 @@ export class ChatController {
|
|||||||
new_room.users = room.users;
|
new_room.users = room.users;
|
||||||
if (room.allowed)
|
if (room.allowed)
|
||||||
new_room.allowed = room.allowed;
|
new_room.allowed = room.allowed;
|
||||||
|
|
||||||
return new_room;
|
return new_room;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,18 +52,34 @@ export class ChatController {
|
|||||||
|
|
||||||
let fields = ["name", "type", "users", "protection", "allowed_users"];
|
let fields = ["name", "type", "users", "protection", "allowed_users"];
|
||||||
const rooms = await this.chatService.getMyRooms(req.user.username, fields);
|
const rooms = await this.chatService.getMyRooms(req.user.username, fields);
|
||||||
|
const blocked = await this.chatService.getListBlockUser(req.user.username);
|
||||||
|
|
||||||
rooms.forEach(room => {
|
let filtered_rooms = rooms.filter(room =>
|
||||||
|
{
|
||||||
|
if (room.type === 'direct')
|
||||||
|
{
|
||||||
|
let roomname = room.users[0];
|
||||||
|
if (roomname === req.user.username)
|
||||||
|
roomname = room.users[1];
|
||||||
|
if (blocked.includes(roomname))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
const ret_rooms = filtered_rooms.map(room =>
|
||||||
|
{
|
||||||
|
let new_room = this.format_room(room);
|
||||||
if (room.protection)
|
if (room.protection)
|
||||||
{
|
{
|
||||||
if (room.allowed_users.includes(req.user.username))
|
if (room.allowed_users.includes(req.user.username))
|
||||||
room.allowed = true;
|
new_room.allowed = true;
|
||||||
else
|
else
|
||||||
room.allowed = false;
|
new_room.allowed = false;
|
||||||
}
|
}
|
||||||
|
return new_room;
|
||||||
});
|
});
|
||||||
|
|
||||||
const ret_rooms = rooms.map(room => this.format_room(room));
|
|
||||||
res.status(HttpStatus.OK).json({ rooms: ret_rooms });
|
res.status(HttpStatus.OK).json({ rooms: ret_rooms });
|
||||||
printCaller("- out ");
|
printCaller("- out ");
|
||||||
}
|
}
|
||||||
@@ -76,12 +92,59 @@ export class ChatController {
|
|||||||
printCaller("- in ");
|
printCaller("- in ");
|
||||||
|
|
||||||
const rooms: roomDto[] = await this.chatService.getAllOtherRoomsAndUsers(req.user.username)
|
const rooms: roomDto[] = await this.chatService.getAllOtherRoomsAndUsers(req.user.username)
|
||||||
|
const blocked = await this.chatService.getListBlockUser(req.user.username);
|
||||||
|
|
||||||
const ret_rooms = rooms.map(room => this.format_room(room));
|
let filtered_rooms = rooms.filter(room =>
|
||||||
|
{
|
||||||
|
if (room.type === 'user')
|
||||||
|
{
|
||||||
|
if (blocked.includes(room.name))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
const ret_rooms = filtered_rooms.map(room => this.format_room(room));
|
||||||
res.status(HttpStatus.OK).json({ rooms: ret_rooms });
|
res.status(HttpStatus.OK).json({ rooms: ret_rooms });
|
||||||
printCaller("- out ");
|
printCaller("- out ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthenticateGuard)
|
||||||
|
@UseGuards(TwoFactorGuard)
|
||||||
|
@Post('setadmin')
|
||||||
|
async setAdmin(@Body('username') username: string, @Req() req, @Res() res): Promise<void>
|
||||||
|
{
|
||||||
|
printCaller("- in ");
|
||||||
|
|
||||||
|
const current_room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||||
|
await this.chatService.setAdmin(req.user.username, username, current_room_name);
|
||||||
|
|
||||||
|
let message = `${username} is now admin`;
|
||||||
|
await this.chatService.addMessageToRoom(current_room_name, "SERVER", message);
|
||||||
|
let socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
||||||
|
let server = this.chatGateway.server;
|
||||||
|
await server.in(socket.room).emit('message', "SERVER", message);
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).json({ message: `${username} is now admin in room ${current_room_name}` });
|
||||||
|
printCaller("- out ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthenticateGuard)
|
||||||
|
@UseGuards(TwoFactorGuard)
|
||||||
|
@Get('isadmin')
|
||||||
|
async isAdmin(@Req() req, @Res() res): Promise<void>
|
||||||
|
{
|
||||||
|
printCaller("- in ");
|
||||||
|
|
||||||
|
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||||
|
const fields = ["admins"];
|
||||||
|
const room_db = await this.chatService.getRoomByName(room_name, fields);
|
||||||
|
const is_admin = room_db.admins.includes(req.user.username);
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).json({ condition: is_admin });
|
||||||
|
printCaller("- out ");
|
||||||
|
}
|
||||||
|
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@Get('current')
|
@Get('current')
|
||||||
@@ -162,6 +225,19 @@ export class ChatController {
|
|||||||
let response = "";
|
let response = "";
|
||||||
if (room.type === 'user')
|
if (room.type === 'user')
|
||||||
{
|
{
|
||||||
|
const blocked = await this.chatService.getListBlockUser(req.user.username);
|
||||||
|
if (blocked.includes(room.name))
|
||||||
|
{
|
||||||
|
console.log("throw error: error: true, code: 'BLOCKED_USER', message: 'you cannot enter this room, you blocked this user'");
|
||||||
|
throw new HttpException({ error: true, code: 'BLOCKED_USER', message: `you cannot enter this room, you blocked this user` }, HttpStatus.UNAUTHORIZED);
|
||||||
|
}
|
||||||
|
|
||||||
|
const find_room = await this.chatService.getRoomByName(`${req.user.username} + ${room.name}`);
|
||||||
|
if (find_room)
|
||||||
|
{
|
||||||
|
console.log("throw error: error: true, code: 'ROOM_CONFLICT', message: 'This room name already exist'");
|
||||||
|
throw new HttpException({ error: true, code: 'ROOM_CONFLICT', message: `This room name already exist` }, HttpStatus.CONFLICT);
|
||||||
|
}
|
||||||
room.type = 'direct';
|
room.type = 'direct';
|
||||||
room.users = [room.name, req.user.username];
|
room.users = [room.name, req.user.username];
|
||||||
room.name += ` + ${req.user.username}`;
|
room.name += ` + ${req.user.username}`;
|
||||||
@@ -205,7 +281,7 @@ export class ChatController {
|
|||||||
{
|
{
|
||||||
printCaller("- in ");
|
printCaller("- in ");
|
||||||
|
|
||||||
let fields = ["protection", "allowed_users"];
|
let fields = ["protection", "allowed_users", "type", "users"];
|
||||||
const room_db = await this.chatService.getRoomByName(room.name, fields);
|
const room_db = await this.chatService.getRoomByName(room.name, fields);
|
||||||
|
|
||||||
if (room_db.protection === true)
|
if (room_db.protection === true)
|
||||||
@@ -217,6 +293,19 @@ export class ChatController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const blocked = await this.chatService.getListBlockUser(req.user.username);
|
||||||
|
if (room_db.type === 'direct')
|
||||||
|
{
|
||||||
|
let roomname = room_db.users[0];
|
||||||
|
if (roomname === req.user.username)
|
||||||
|
roomname = room.users[1];
|
||||||
|
if (blocked.includes(roomname))
|
||||||
|
{
|
||||||
|
console.log("throw error: error: true, code: 'BLOCKED_USER', message: 'you cannot enter this room, you blocked this user'");
|
||||||
|
throw new HttpException({ error: true, code: 'BLOCKED_USER', message: `you cannot enter this room, you blocked this user` }, HttpStatus.UNAUTHORIZED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await this.chatService.setCurrentRoom(req.user.username, room.name);
|
await this.chatService.setCurrentRoom(req.user.username, room.name);
|
||||||
let socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
let socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
||||||
await this.chatService.socketChangeRoom(socket, room.name);
|
await this.chatService.socketChangeRoom(socket, room.name);
|
||||||
@@ -266,6 +355,7 @@ export class ChatController {
|
|||||||
// inform other connected users
|
// inform other connected users
|
||||||
let socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
let socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
||||||
await socket.to(socket.room).emit('message', "SERVER", message);
|
await socket.to(socket.room).emit('message', "SERVER", message);
|
||||||
|
await socket.to(socket.room).emit('new_password');
|
||||||
|
|
||||||
const ret_room = this.format_room(room);
|
const ret_room = this.format_room(room);
|
||||||
res.status(HttpStatus.OK).json({ room: ret_room });
|
res.status(HttpStatus.OK).json({ room: ret_room });
|
||||||
@@ -287,6 +377,7 @@ export class ChatController {
|
|||||||
// inform other connected users
|
// inform other connected users
|
||||||
let socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
let socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
||||||
await socket.to(socket.room).emit('message', "SERVER", message);
|
await socket.to(socket.room).emit('message', "SERVER", message);
|
||||||
|
await socket.to(socket.room).emit('new_password');
|
||||||
|
|
||||||
const ret_room = this.format_room(room);
|
const ret_room = this.format_room(room);
|
||||||
res.status(HttpStatus.OK).json({ room: ret_room });
|
res.status(HttpStatus.OK).json({ room: ret_room });
|
||||||
@@ -321,6 +412,14 @@ export class ChatController {
|
|||||||
{
|
{
|
||||||
printCaller("- in ");
|
printCaller("- in ");
|
||||||
|
|
||||||
|
|
||||||
|
const blocked = await this.chatService.getListBlockUser(req.user.username);
|
||||||
|
if (blocked.includes(username))
|
||||||
|
{
|
||||||
|
console.log("throw error: error: true, code: 'BLOCKED_USER', message: 'you cannot invite this user, you have blocked it'");
|
||||||
|
throw new HttpException({ error: true, code: 'BLOCKED_USER', message: `you cannot invite this user, you have blocked it` }, HttpStatus.UNAUTHORIZED);
|
||||||
|
}
|
||||||
|
|
||||||
let current_room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
let current_room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||||
let room = await this.chatService.addUserToRoom(username, current_room_name);
|
let room = await this.chatService.addUserToRoom(username, current_room_name);
|
||||||
let message = `${username} joined the room`;
|
let message = `${username} joined the room`;
|
||||||
@@ -363,7 +462,17 @@ export class ChatController {
|
|||||||
printCaller("- in ");
|
printCaller("- in ");
|
||||||
|
|
||||||
const messages = await this.chatService.getMessagesFromCurrentRoom(req.user.username);
|
const messages = await this.chatService.getMessagesFromCurrentRoom(req.user.username);
|
||||||
res.status(HttpStatus.OK).json({ messages: messages });
|
|
||||||
|
console.log("messages:", messages);
|
||||||
|
const blocked = await this.chatService.getListBlockUser(req.user.username);
|
||||||
|
let filtered_messages = messages.filter(message =>
|
||||||
|
{
|
||||||
|
if (blocked.includes(message.name))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).json({ messages: filtered_messages });
|
||||||
printCaller("- out ");
|
printCaller("- out ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,14 +486,32 @@ export class ChatController {
|
|||||||
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||||
const room = await this.chatService.getRoomByName(room_name);
|
const room = await this.chatService.getRoomByName(room_name);
|
||||||
const users = room.users;
|
const users = room.users;
|
||||||
|
const admins = room.admins;
|
||||||
|
const blocked = await this.chatService.getListBlockUser(req.user.username);
|
||||||
|
|
||||||
let index = users.indexOf(req.user.username);
|
let index = users.indexOf(req.user.username);
|
||||||
if (index > -1)
|
if (index > -1)
|
||||||
{
|
|
||||||
users.splice(index, 1);
|
users.splice(index, 1);
|
||||||
}
|
|
||||||
|
|
||||||
res.status(HttpStatus.OK).json({ users: users });
|
let ret_users = users.map(username =>
|
||||||
|
{
|
||||||
|
let new_user =
|
||||||
|
{
|
||||||
|
name: username,
|
||||||
|
isadmin: false,
|
||||||
|
isblocked: false,
|
||||||
|
};
|
||||||
|
if (admins.includes(username))
|
||||||
|
new_user.isadmin = true;
|
||||||
|
if (blocked.includes(username))
|
||||||
|
new_user.isblocked = true;
|
||||||
|
console.log("new_user:", new_user);
|
||||||
|
|
||||||
|
return new_user;
|
||||||
|
});
|
||||||
|
console.log("ret_user:", ret_users);
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).json({ users: ret_users });
|
||||||
printCaller("- out ");
|
printCaller("- out ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,6 +524,137 @@ export class ChatController {
|
|||||||
|
|
||||||
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||||
const users = await this.chatService.getAllUsersNotInRoom(room_name);
|
const users = await this.chatService.getAllUsersNotInRoom(room_name);
|
||||||
|
|
||||||
|
const blocked = await this.chatService.getListBlockUser(req.user.username);
|
||||||
|
let filtered_users = users.filter(user =>
|
||||||
|
{
|
||||||
|
if (blocked.includes(user.username))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).json({ users: filtered_users });
|
||||||
|
printCaller("- out ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthenticateGuard)
|
||||||
|
@UseGuards(TwoFactorGuard)
|
||||||
|
@Post('setmute')
|
||||||
|
async setMuteUser(@Body('mute') mute: muteDto, @Body('time') time: string, @Req() req, @Res() res): Promise<void>
|
||||||
|
{
|
||||||
|
printCaller("- in ");
|
||||||
|
|
||||||
|
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||||
|
await this.chatService.addMute(req.user.username, room_name, mute);
|
||||||
|
|
||||||
|
// inform other connected users
|
||||||
|
let message = `${req.user.username} has muted ${mute.name} untill ${time}`;
|
||||||
|
let socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
||||||
|
let server = this.chatGateway.server;
|
||||||
|
await this.chatService.addMessageToRoom(room_name, "SERVER", message);
|
||||||
|
await server.in(socket.room).emit('message', "SERVER", message);
|
||||||
|
|
||||||
|
const room = await this.chatService.getRoomByName(room_name);
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).json({ message: message });
|
||||||
|
printCaller("- out ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthenticateGuard)
|
||||||
|
@UseGuards(TwoFactorGuard)
|
||||||
|
@Post('ismute')
|
||||||
|
async isuserMute(@Body('username') username: string, @Req() req, @Res() res): Promise<void>
|
||||||
|
{
|
||||||
|
printCaller("- in ");
|
||||||
|
|
||||||
|
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||||
|
const current_room = await this.chatService.getRoomByName(room_name);
|
||||||
|
let mute = current_room.mutes.find(mute => mute.name === username);
|
||||||
|
console.log("mute:", mute);
|
||||||
|
console.log("username:", username);
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).json({ mute: mute });
|
||||||
|
printCaller("- out ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthenticateGuard)
|
||||||
|
@UseGuards(TwoFactorGuard)
|
||||||
|
@Post('unmute')
|
||||||
|
async unMute(@Body('username') username: string, @Req() req, @Res() res): Promise<void>
|
||||||
|
{
|
||||||
|
printCaller("- in ");
|
||||||
|
|
||||||
|
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||||
|
|
||||||
|
const fields = ["admins"];
|
||||||
|
const room_db = await this.chatService.getRoomByName(room_name, fields);
|
||||||
|
const is_admin = room_db.admins.includes(req.user.username);
|
||||||
|
if (!is_admin)
|
||||||
|
{
|
||||||
|
console.log("throw error: error: true, code: 'UNMUTE_NEED_ADMIN', message: 'you cannot unmute a user if you are not admin in the room'");
|
||||||
|
throw new HttpException({ error: true, code: 'UNMUTE_NEED_ADMIN', message: `you cannot unmute a user if you are not admin in the room` }, HttpStatus.UNAUTHORIZED);
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.chatService.removeMute(username, room_name);
|
||||||
|
|
||||||
|
let message = `${req.user.username} has un-muted ${username}`;
|
||||||
|
let socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
||||||
|
let server = this.chatGateway.server;
|
||||||
|
await this.chatService.addMessageToRoom(room_name, "SERVER", message);
|
||||||
|
await server.in(socket.room).emit('message', "SERVER", message);
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).json({ message: "successfull unmute" });
|
||||||
|
printCaller("- out ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthenticateGuard)
|
||||||
|
@UseGuards(TwoFactorGuard)
|
||||||
|
@Post('block')
|
||||||
|
async blockUser(@Body('username') username: string, @Req() req, @Res() res): Promise<void>
|
||||||
|
{
|
||||||
|
printCaller("- in ");
|
||||||
|
|
||||||
|
await this.chatService.addBlockUser(req.user.username, username);
|
||||||
|
|
||||||
|
let user_socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
||||||
|
user_socket.join(`${username}_not_emit`);
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).json({ message: "successfull block" });
|
||||||
|
printCaller("- out ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthenticateGuard)
|
||||||
|
@UseGuards(TwoFactorGuard)
|
||||||
|
@Post('unblock')
|
||||||
|
async unBlockUser(@Body('username') username: string, @Req() req, @Res() res): Promise<void>
|
||||||
|
{
|
||||||
|
printCaller("- in ");
|
||||||
|
|
||||||
|
await this.chatService.removeBlockUser(req.user.username, username);
|
||||||
|
let user_socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
||||||
|
user_socket.leave(`${username}_not_emit`);
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).json({ message: "successfull unblock" });
|
||||||
|
printCaller("- out ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthenticateGuard)
|
||||||
|
@UseGuards(TwoFactorGuard)
|
||||||
|
@Get('listblock')
|
||||||
|
async listBlockUser(@Req() req, @Res() res): Promise<void>
|
||||||
|
{
|
||||||
|
printCaller("- in ");
|
||||||
|
|
||||||
|
let block_users = await this.chatService.getListBlockUser(req.user.username);
|
||||||
|
let users = block_users.map(user =>
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
name: user,
|
||||||
|
isadmin: false,
|
||||||
|
isblocked: true,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
res.status(HttpStatus.OK).json({ users: users });
|
res.status(HttpStatus.OK).json({ users: users });
|
||||||
printCaller("- out ");
|
printCaller("- out ");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { WebSocketGateway, SubscribeMessage, WebSocketServer, MessageBody, Conne
|
|||||||
import { UsersService } from 'src/users/users.service';
|
import { UsersService } from 'src/users/users.service';
|
||||||
import { ChatService } from './chat.service';
|
import { ChatService } from './chat.service';
|
||||||
import { socketDto } from './dto/socket.dto';
|
import { socketDto } from './dto/socket.dto';
|
||||||
|
import { printCaller } from './dev/dev_utils';
|
||||||
|
|
||||||
@WebSocketGateway(5000, {
|
@WebSocketGateway(5000, {
|
||||||
path: '/chat',
|
path: '/chat',
|
||||||
@@ -22,9 +23,24 @@ implements OnGatewayConnection, OnGatewayDisconnect
|
|||||||
server;
|
server;
|
||||||
|
|
||||||
async handleConnection(socket: socketDto) {
|
async handleConnection(socket: socketDto) {
|
||||||
console.log('- socket connected :', socket.id, socket.handshake.query.username);
|
printCaller('- socket connected :', socket.id, socket.handshake.query.username);
|
||||||
|
|
||||||
socket.username = socket.handshake.query.username.toString();
|
socket.username = socket.handshake.query.username.toString();
|
||||||
this.sockets.set(socket.username, socket);
|
this.sockets.set(socket.username, socket);
|
||||||
|
|
||||||
|
printCaller("--- socket.username:", socket.username);
|
||||||
|
|
||||||
|
let not_emit: string = `${socket.username}_not_emit`;
|
||||||
|
socket.join(not_emit);
|
||||||
|
let blocked = await this.chatService.getListBlockUser(socket.username);
|
||||||
|
blocked.forEach(user =>
|
||||||
|
{
|
||||||
|
not_emit = `${user}_not_emit`;
|
||||||
|
socket.join(not_emit);
|
||||||
|
});
|
||||||
|
|
||||||
|
let current_room = await this.chatService.getCurrentRoomName(socket.username);
|
||||||
|
socket.join(current_room);
|
||||||
}
|
}
|
||||||
async handleDisconnect(socket: socketDto) {
|
async handleDisconnect(socket: socketDto) {
|
||||||
this.sockets.delete(socket.username);
|
this.sockets.delete(socket.username);
|
||||||
|
|||||||
@@ -3,14 +3,17 @@ import { ChatController } from './chat.controller';
|
|||||||
import { ChatService } from './chat.service';
|
import { ChatService } from './chat.service';
|
||||||
import { ChatGateway } from './chat.gateway';
|
import { ChatGateway } from './chat.gateway';
|
||||||
import { UsersModule } from 'src/users/users.module';
|
import { UsersModule } from 'src/users/users.module';
|
||||||
|
import { FriendshipsModule } from 'src/friendship/friendships.module';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { Chatroom } from './entities/chatroom.entity';
|
import { Chatroom } from './entities/chatroom.entity';
|
||||||
import { User } from 'src/users/entities/user.entity';
|
import { User } from 'src/users/entities/user.entity';
|
||||||
|
import { Friendship } from 'src/friendship/entities/friendship.entity';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forFeature([Chatroom, User]),
|
TypeOrmModule.forFeature([Chatroom, User, Friendship]),
|
||||||
UsersModule,
|
UsersModule,
|
||||||
|
FriendshipsModule,
|
||||||
],
|
],
|
||||||
controllers: [
|
controllers: [
|
||||||
ChatController,
|
ChatController,
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
import { HttpException, HttpStatus, Injectable, Res } from '@nestjs/common';
|
import { HttpException, HttpStatus, Injectable, Res } from '@nestjs/common';
|
||||||
import { User } from 'src/users/entities/user.entity';
|
import { User } from 'src/users/entities/user.entity';
|
||||||
import { UsersService } from 'src/users/users.service';
|
import { Friendship, FriendshipStatus } from 'src/friendship/entities/friendship.entity';
|
||||||
import { Chatroom } from './entities/chatroom.entity';
|
import { Chatroom } from './entities/chatroom.entity';
|
||||||
import { Repository } from 'typeorm';
|
import { UsersService } from 'src/users/users.service';
|
||||||
|
import { FriendshipService } from 'src/friendship/friendship.service';
|
||||||
|
import { SendableFriendship } from 'src/friendship/sendableFriendship';
|
||||||
|
import { Repository, Brackets } from 'typeorm';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { roomDto } from './dto/room.dto';
|
import { roomDto } from './dto/room.dto';
|
||||||
import { messagesDto } from './dto/messages.dto';
|
import { messagesDto } from './dto/messages.dto';
|
||||||
import { socketDto } from './dto/socket.dto';
|
import { socketDto } from './dto/socket.dto';
|
||||||
import * as bcrypt from 'bcrypt';
|
import * as bcrypt from 'bcrypt';
|
||||||
import { printCaller } from './dev/dev_utils';
|
import { printCaller } from './dev/dev_utils';
|
||||||
|
import { muteDto } from './dto/mute.dto';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -16,10 +20,13 @@ export class ChatService {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private usersService: UsersService,
|
private usersService: UsersService,
|
||||||
|
private friendshipService: FriendshipService,
|
||||||
@InjectRepository(User)
|
@InjectRepository(User)
|
||||||
private readonly userRepository: Repository<User>,
|
private readonly userRepository: Repository<User>,
|
||||||
@InjectRepository(Chatroom)
|
@InjectRepository(Chatroom)
|
||||||
private readonly chatroomRepository: Repository<Chatroom>,
|
private readonly chatroomRepository: Repository<Chatroom>,
|
||||||
|
@InjectRepository(Friendship)
|
||||||
|
private readonly friendshipRepository: Repository<Friendship>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
// temp for test
|
// temp for test
|
||||||
@@ -35,6 +42,8 @@ export class ChatService {
|
|||||||
{
|
{
|
||||||
printCaller("-- in ");
|
printCaller("-- in ");
|
||||||
|
|
||||||
|
//await this.sleep(1000);
|
||||||
|
|
||||||
const queryBuilder = this.chatroomRepository
|
const queryBuilder = this.chatroomRepository
|
||||||
.createQueryBuilder('chatroom')
|
.createQueryBuilder('chatroom')
|
||||||
.where('chatroom.users LIKE :user_name', { user_name: `%${username}%` });
|
.where('chatroom.users LIKE :user_name', { user_name: `%${username}%` });
|
||||||
@@ -202,8 +211,9 @@ export class ChatService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
room_db.allowed_users.push(username);
|
room_db.allowed_users.push(username);
|
||||||
printCaller("-- out ");
|
|
||||||
await this.chatroomRepository.save(room_db);
|
await this.chatroomRepository.save(room_db);
|
||||||
|
|
||||||
|
printCaller("-- out ");
|
||||||
}
|
}
|
||||||
|
|
||||||
async setPassword(username: string, message: string, room: roomDto, old_password?: string): Promise<void>
|
async setPassword(username: string, message: string, room: roomDto, old_password?: string): Promise<void>
|
||||||
@@ -216,14 +226,20 @@ export class ChatService {
|
|||||||
throw new HttpException({ error: true, code: 'DIRECT_PASSWORD_FORBIDDEN', message: `you cannot set a password in a direct message room` }, HttpStatus.FORBIDDEN);
|
throw new HttpException({ error: true, code: 'DIRECT_PASSWORD_FORBIDDEN', message: `you cannot set a password in a direct message room` }, HttpStatus.FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
const current_room = await this.getRoomByName(room.name);
|
const room_db = await this.getRoomByName(room.name);
|
||||||
|
|
||||||
|
if (!room_db.admins.includes(username))
|
||||||
|
{
|
||||||
|
console.log("throw error: error: true, code: 'NO_ADMIN', message: 'only admins are allowed to set or modify password'");
|
||||||
|
throw new HttpException({ error: true, code: 'NO_ADMIN', message: `only admins are allowed to set or modify password` }, HttpStatus.FORBIDDEN);
|
||||||
|
}
|
||||||
|
|
||||||
if (!room.password)
|
if (!room.password)
|
||||||
{
|
{
|
||||||
console.log("throw error: error: true, code: 'NO_PASSWORD', message: 'this room has no password protection'");
|
console.log("throw error: error: true, code: 'NO_PASSWORD', message: 'this room has no password protection'");
|
||||||
throw new HttpException({ error: true, code: 'NO_PASSWORD', message: `this room has no password protection` }, HttpStatus.FORBIDDEN);
|
throw new HttpException({ error: true, code: 'NO_PASSWORD', message: `this room has no password protection` }, HttpStatus.FORBIDDEN);
|
||||||
}
|
}
|
||||||
if (current_room.protection)
|
if (room_db.protection)
|
||||||
{
|
{
|
||||||
if (room.protection && !old_password)
|
if (room.protection && !old_password)
|
||||||
{
|
{
|
||||||
@@ -232,7 +248,13 @@ export class ChatService {
|
|||||||
}
|
}
|
||||||
if (old_password)
|
if (old_password)
|
||||||
{
|
{
|
||||||
const is_match = await bcrypt.compare(old_password, current_room.hash);
|
const is_old_match = await bcrypt.compare(room.password, room_db.hash);
|
||||||
|
if (is_old_match)
|
||||||
|
{
|
||||||
|
printCaller(`throw error: error: true, code: 'SAME_PASSWORD', message: 'you provided the same password'`);
|
||||||
|
throw new HttpException({ error: true, code: 'SAME_PASSWORD', message: `you provided the same password` }, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
const is_match = await bcrypt.compare(old_password, room_db.hash);
|
||||||
if (!is_match)
|
if (!is_match)
|
||||||
{
|
{
|
||||||
printCaller(`throw error: error: true, code: 'BAD_PASSWORD', message: 'you provided a bad password'`);
|
printCaller(`throw error: error: true, code: 'BAD_PASSWORD', message: 'you provided a bad password'`);
|
||||||
@@ -248,18 +270,117 @@ export class ChatService {
|
|||||||
hash = await bcrypt.hash(password, saltOrRounds);
|
hash = await bcrypt.hash(password, saltOrRounds);
|
||||||
|
|
||||||
// add password to chatroom
|
// add password to chatroom
|
||||||
current_room.allowed_users = room.allowed_users;
|
room_db.allowed_users = room.allowed_users;
|
||||||
current_room.protection = room.protection;
|
room_db.protection = room.protection;
|
||||||
if (room.protection)
|
if (room.protection)
|
||||||
current_room.hash = hash;
|
room_db.hash = hash;
|
||||||
else
|
else
|
||||||
delete current_room.hash;
|
delete room_db.hash;
|
||||||
current_room.messages.push({ name: "SERVER", message: message });
|
room_db.messages.push({ name: "SERVER", message: message });
|
||||||
await this.chatroomRepository.save(current_room);
|
await this.chatroomRepository.save(room_db);
|
||||||
|
|
||||||
printCaller("-- out ");
|
printCaller("-- out ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async setAdmin(current_username: string, user_username: string, room_name: string): Promise<void>
|
||||||
|
{
|
||||||
|
printCaller("-- in ");
|
||||||
|
|
||||||
|
const room_db = await this.getRoomByName(room_name);
|
||||||
|
if (room_db.type === "direct")
|
||||||
|
{
|
||||||
|
printCaller(`throw error: error: true, code: 'NO_DIRECT_ADMIN', message: 'there are no admins in direct messages'`);
|
||||||
|
throw new HttpException({ error: true, code: 'NO_DIRECT_ADMIN', message: `there are no admins in direct messages` }, HttpStatus.UNAUTHORIZED);
|
||||||
|
}
|
||||||
|
if (!room_db.admins.includes(current_username))
|
||||||
|
{
|
||||||
|
printCaller(`throw error: error: true, code: 'NOT_ADMIN', message: 'you cannot set someone else as admin, since you are not admin yourself'`);
|
||||||
|
throw new HttpException({ error: true, code: 'NOT_ADMIN', message: `you cannot set someone else as admin, since you are not admin yourself` }, HttpStatus.UNAUTHORIZED);
|
||||||
|
}
|
||||||
|
|
||||||
|
room_db.admins.push(user_username);
|
||||||
|
await this.chatroomRepository.save(room_db);
|
||||||
|
|
||||||
|
printCaller("-- out ");
|
||||||
|
}
|
||||||
|
|
||||||
|
async findOneRelationshipByUsername(friendUsername : string, username : string)
|
||||||
|
{
|
||||||
|
printCaller("-- in ");
|
||||||
|
|
||||||
|
const friendship = await this.friendshipRepository
|
||||||
|
.createQueryBuilder('friendship')
|
||||||
|
.leftJoinAndSelect('friendship.sender', 'sender')
|
||||||
|
.leftJoinAndSelect('friendship.receiver', 'receiver')
|
||||||
|
.where (
|
||||||
|
new Brackets((qb) => {
|
||||||
|
qb.where (
|
||||||
|
new Brackets((subAQb) => {
|
||||||
|
subAQb.where('sender.username = :username', {username : username})
|
||||||
|
.andWhere('receiver.username = :friendUsername', {friendUsername : friendUsername})
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.orWhere (
|
||||||
|
new Brackets((subBQb) => {
|
||||||
|
subBQb.where('sender.username = :friendUsername2', {friendUsername2 : friendUsername})
|
||||||
|
.andWhere('receiver.username = :username2', {username2 : username})
|
||||||
|
.andWhere('friendship.status != :status', {status : FriendshipStatus.BLOCKED})
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.getOne();
|
||||||
|
|
||||||
|
console.log("friendship:", friendship);
|
||||||
|
if (!friendship)
|
||||||
|
return null;
|
||||||
|
return new SendableFriendship(friendship);
|
||||||
|
|
||||||
|
printCaller("-- out ");
|
||||||
|
}
|
||||||
|
|
||||||
|
async addBlockUser(username: string, to_block_username: string): Promise<void>
|
||||||
|
{
|
||||||
|
printCaller("-- in ");
|
||||||
|
|
||||||
|
let user = await this.getUserByName(username);
|
||||||
|
let relation = await this.findOneRelationshipByUsername(to_block_username, username);
|
||||||
|
if (relation)
|
||||||
|
{
|
||||||
|
let blocked_friendship = await this.friendshipService.blockFriendship(relation.id, user);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const newFriendshipDto = {"receiverUsername": to_block_username, "status": FriendshipStatus.BLOCKED};
|
||||||
|
await this.friendshipService.create(newFriendshipDto, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
printCaller("-- out ");
|
||||||
|
}
|
||||||
|
|
||||||
|
async removeBlockUser(username: string, to_unblock_username: string): Promise<void>
|
||||||
|
{
|
||||||
|
printCaller("-- in ");
|
||||||
|
|
||||||
|
let user = await this.getUserByName(username);
|
||||||
|
let relation = await this.findOneRelationshipByUsername(to_unblock_username, username);
|
||||||
|
await this.friendshipService.removeFriendship(relation.id, user);
|
||||||
|
|
||||||
|
printCaller("-- out ");
|
||||||
|
}
|
||||||
|
|
||||||
|
async getListBlockUser(username: string): Promise<string[]>
|
||||||
|
{
|
||||||
|
printCaller("-- in ");
|
||||||
|
|
||||||
|
let user = await this.getUserByName(username);
|
||||||
|
let friends_users = await this.friendshipService.findAllBlockedFriends(user.id);
|
||||||
|
let users = friends_users.map(user => user.receiverUsername);
|
||||||
|
|
||||||
|
printCaller("-- out ");
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ADDERS *************************************************
|
/* ADDERS *************************************************
|
||||||
*/
|
*/
|
||||||
@@ -280,6 +401,7 @@ export class ChatService {
|
|||||||
newChatroom.name = room.name;
|
newChatroom.name = room.name;
|
||||||
newChatroom.type = room.type;
|
newChatroom.type = room.type;
|
||||||
newChatroom.owner = username;
|
newChatroom.owner = username;
|
||||||
|
newChatroom.admins = [username];
|
||||||
newChatroom.users = room.users;
|
newChatroom.users = room.users;
|
||||||
newChatroom.allowed_users = [];
|
newChatroom.allowed_users = [];
|
||||||
newChatroom.protection = false;
|
newChatroom.protection = false;
|
||||||
@@ -316,9 +438,42 @@ export class ChatService {
|
|||||||
message: message,
|
message: message,
|
||||||
};
|
};
|
||||||
my_room.messages.push(chat_message);
|
my_room.messages.push(chat_message);
|
||||||
|
await this.chatroomRepository.save(my_room);
|
||||||
|
|
||||||
|
printCaller("-- out ");
|
||||||
|
}
|
||||||
|
|
||||||
|
async addMute(username: string, room_name: string, mute: muteDto): Promise<void>
|
||||||
|
{
|
||||||
|
printCaller("-- in ");
|
||||||
|
|
||||||
|
const room_db = await this.getRoomByName(room_name);
|
||||||
|
|
||||||
|
if (!room_db.admins.includes(username))
|
||||||
|
{
|
||||||
|
console.log("throw error: error: true, code: 'NO_ADMIN', message: 'only admins are allowed to set or modify mute time'");
|
||||||
|
throw new HttpException({ error: true, code: 'NO_ADMIN', message: `only admins are allowed to set or modify mute time` }, HttpStatus.FORBIDDEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!room_db.mutes)
|
||||||
|
room_db.mutes = [mute];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
let already_here = false;
|
||||||
|
room_db.mutes.forEach(mute_elem =>
|
||||||
|
{
|
||||||
|
if (mute_elem.name === mute.name)
|
||||||
|
{
|
||||||
|
already_here = true;
|
||||||
|
mute_elem.date = mute.date;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!already_here)
|
||||||
|
room_db.mutes.push(mute);
|
||||||
|
}
|
||||||
|
await this.chatroomRepository.save(room_db);
|
||||||
|
|
||||||
printCaller("-- out ");
|
printCaller("-- out ");
|
||||||
await this.chatroomRepository.save(my_room);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -350,6 +505,21 @@ export class ChatService {
|
|||||||
return "successfully leaving room";
|
return "successfully leaving room";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async removeMute(username: string, room_name: string): Promise<void>
|
||||||
|
{
|
||||||
|
printCaller("-- in ");
|
||||||
|
|
||||||
|
const room_db = await this.getRoomByName(room_name);
|
||||||
|
|
||||||
|
let index = room_db.mutes.findIndex(mute => mute.name === username);
|
||||||
|
if (index > -1)
|
||||||
|
room_db.mutes.splice(index, 1);
|
||||||
|
|
||||||
|
await this.chatroomRepository.save(room_db);
|
||||||
|
|
||||||
|
printCaller("-- out ");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* SEARCH IN USER *****************************************
|
/* SEARCH IN USER *****************************************
|
||||||
*/
|
*/
|
||||||
@@ -416,8 +586,44 @@ export class ChatService {
|
|||||||
{
|
{
|
||||||
printCaller("-- in ");
|
printCaller("-- in ");
|
||||||
|
|
||||||
socket.to(socket.room).emit('message', socket.username, message);
|
|
||||||
let room_name = await this.getCurrentRoomName(socket.username);
|
let room_name = await this.getCurrentRoomName(socket.username);
|
||||||
|
|
||||||
|
const current_room = await this.getRoomByName(room_name);
|
||||||
|
|
||||||
|
if (current_room.protection)
|
||||||
|
{
|
||||||
|
if (!current_room.allowed_users.includes(socket.username))
|
||||||
|
{
|
||||||
|
socket.emit('message', "SERVER", "your message was not sent because you need to validate the password");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (current_room.mutes)
|
||||||
|
{
|
||||||
|
let current_mute = current_room.mutes.find(mute => mute.name === socket.username);
|
||||||
|
if (current_mute)
|
||||||
|
{
|
||||||
|
let date_diff = 1;
|
||||||
|
if (current_mute.date)
|
||||||
|
{
|
||||||
|
const date_now = new Date();
|
||||||
|
const date_mute = new Date(current_mute.date);
|
||||||
|
date_diff = date_mute.getTime() - date_now.getTime();
|
||||||
|
}
|
||||||
|
if (date_diff > 0)
|
||||||
|
{
|
||||||
|
socket.emit('message', "SERVER", "your message was not sent because you are muted");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
await this.removeMute(current_mute.name, room_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("socket rooms:", socket.rooms);
|
||||||
|
let socket_name = `${socket.username}_not_emit`;
|
||||||
|
console.log("socket_name:", socket_name);
|
||||||
|
await socket.to(socket.room).except(socket_name).emit('message', socket.username, message);
|
||||||
await this.addMessageToRoom(room_name, socket.username, message);
|
await this.addMessageToRoom(room_name, socket.username, message);
|
||||||
|
|
||||||
printCaller("-- out ");
|
printCaller("-- out ");
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export function printCaller(prefix: string = "") {
|
export function printCaller(...prefix)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
throw new Error();
|
throw new Error();
|
||||||
@@ -8,6 +9,6 @@ export function printCaller(prefix: string = "") {
|
|||||||
Error.captureStackTrace(e);
|
Error.captureStackTrace(e);
|
||||||
let stack = e.stack.split('\n');
|
let stack = e.stack.split('\n');
|
||||||
let caller = stack[2].trim();
|
let caller = stack[2].trim();
|
||||||
console.log(prefix + ' ' + caller);
|
console.log(...prefix, caller);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
14
srcs/requirements/nestjs/api_back/src/chat/dto/mute.dto.ts
Normal file
14
srcs/requirements/nestjs/api_back/src/chat/dto/mute.dto.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { IsNotEmpty, IsString, IsDate, IsOptional } from "class-validator";
|
||||||
|
|
||||||
|
export class muteDto
|
||||||
|
{
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@IsDate()
|
||||||
|
@IsOptional()
|
||||||
|
date?: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -31,6 +31,11 @@ export class roomDto
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
owner?: string;
|
owner?: string;
|
||||||
|
|
||||||
|
@IsArray()
|
||||||
|
@IsString({ each: true })
|
||||||
|
@IsOptional()
|
||||||
|
admins?: string[];
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
client_name?: string;
|
client_name?: string;
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ export class socketDto extends Socket
|
|||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
room: string;
|
room: string;
|
||||||
|
|
||||||
|
@IsBoolean()
|
||||||
|
@IsOptional()
|
||||||
|
new_password?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { Entity, Column, ManyToOne, ManyToMany, JoinTable, PrimaryGeneratedColumn } from "typeorm";
|
import { Entity, Column, CreateDateColumn, ManyToOne, ManyToMany, JoinTable, PrimaryGeneratedColumn } from "typeorm";
|
||||||
import { IsBoolean, IsEmpty, IsInt, IsIn, IsNotEmpty, IsNumber, IsArray, IsString, IsOptional, IsEnum } from "class-validator";
|
import { IsBoolean, IsEmpty, IsInt, IsIn, IsNotEmpty, IsNumber, IsArray, IsString, IsOptional, IsEnum } from "class-validator";
|
||||||
import { Exclude, Expose } from 'class-transformer';
|
import { Exclude, Expose } from 'class-transformer';
|
||||||
import { User } from 'src/users/entities/user.entity';
|
import { User } from 'src/users/entities/user.entity';
|
||||||
import { messagesDto } from 'src/chat/dto/messages.dto';
|
import { messagesDto } from 'src/chat/dto/messages.dto';
|
||||||
|
import { muteDto } from 'src/chat/dto/mute.dto';
|
||||||
|
|
||||||
@Entity('chatroom')
|
@Entity('chatroom')
|
||||||
export class Chatroom
|
export class Chatroom
|
||||||
@@ -25,11 +26,6 @@ export class Chatroom
|
|||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
protection: boolean = false;
|
protection: boolean = false;
|
||||||
|
|
||||||
@Column({ nullable: true })
|
|
||||||
@IsBoolean()
|
|
||||||
@IsOptional()
|
|
||||||
allowed?: boolean;
|
|
||||||
|
|
||||||
@Column({ nullable: true })
|
@Column({ nullable: true })
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@@ -38,6 +34,11 @@ export class Chatroom
|
|||||||
@Column()
|
@Column()
|
||||||
owner: string; // username
|
owner: string; // username
|
||||||
|
|
||||||
|
@Column("simple-array")
|
||||||
|
@IsArray()
|
||||||
|
@IsString({ each: true })
|
||||||
|
admins: string[]; // username
|
||||||
|
|
||||||
@Column("simple-array")
|
@Column("simple-array")
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@IsString({ each: true })
|
@IsString({ each: true })
|
||||||
@@ -50,5 +51,9 @@ export class Chatroom
|
|||||||
|
|
||||||
@Column("json")
|
@Column("json")
|
||||||
messages: messagesDto[];
|
messages: messagesDto[];
|
||||||
|
|
||||||
|
@Column("json", { nullable: true })
|
||||||
|
@IsOptional()
|
||||||
|
mutes?: muteDto[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ export class FriendshipService {
|
|||||||
if (relation.receiver && relation.receiver.id === user.id) {
|
if (relation.receiver && relation.receiver.id === user.id) {
|
||||||
// console.log('friendship.service blockFriendship trying to delete and recreate a friendship with block')
|
// console.log('friendship.service blockFriendship trying to delete and recreate a friendship with block')
|
||||||
// console.log({...relation})
|
// console.log({...relation})
|
||||||
const newFriendshipDto = {"receiverUsername": relation.sender.username, "receiverId": relation.sender.id, "status": FriendshipStatus.BLOCKED};
|
const newFriendshipDto = {"receiverUsername": relation.sender.username, "status": FriendshipStatus.BLOCKED};
|
||||||
await this.removeFriendship(relationshipId, user);
|
await this.removeFriendship(relationshipId, user);
|
||||||
return await this.create(newFriendshipDto, user);
|
return await this.create(newFriendshipDto, user);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ body {
|
|||||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
||||||
/* tmp? */
|
/* tmp? */
|
||||||
background-color: #333;
|
background-color: #333;
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import Router, { replace } from "svelte-spa-router";
|
import Router, { replace } from "svelte-spa-router";
|
||||||
import { primaryRoutes } from "./routes/primaryRoutes.js";
|
import { primaryRoutes } from "./routes/primaryRoutes.js";
|
||||||
import { location } from 'svelte-spa-router';
|
import { location } from 'svelte-spa-router';
|
||||||
|
import Chat from './pieces/chat/Chat.svelte';
|
||||||
import Header from './pieces/Header.svelte';
|
import Header from './pieces/Header.svelte';
|
||||||
|
|
||||||
const conditionsFailed = (event) => {
|
const conditionsFailed = (event) => {
|
||||||
@@ -17,6 +18,7 @@
|
|||||||
{#if ($location !== '/')}
|
{#if ($location !== '/')}
|
||||||
<Header/>
|
<Header/>
|
||||||
{/if}
|
{/if}
|
||||||
|
<Chat />
|
||||||
|
|
||||||
<Router routes={primaryRoutes} on:conditionsFailed={conditionsFailed}/>
|
<Router routes={primaryRoutes} on:conditionsFailed={conditionsFailed}/>
|
||||||
|
|
||||||
|
|||||||
@@ -190,6 +190,7 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
#canvas_container {
|
#canvas_container {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
|
|||||||
@@ -15,11 +15,9 @@
|
|||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Chat color="bisque"/>
|
|
||||||
|
|
||||||
<div class="background-pages">
|
<div class="background-pages">
|
||||||
<div class="outer">
|
<div class="outer">
|
||||||
{#if user}
|
{#if user !== undefined}
|
||||||
<GenerateUserDisplay user={user}/>
|
<GenerateUserDisplay user={user}/>
|
||||||
<button on:click={() => (push('/profile/settings'))}>Profile Settings</button>
|
<button on:click={() => (push('/profile/settings'))}>Profile Settings</button>
|
||||||
{:else}
|
{:else}
|
||||||
@@ -28,6 +26,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
div.outer{
|
div.outer{
|
||||||
|
|||||||
@@ -70,7 +70,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
resize: vertical;
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background: #FB8B24;
|
background: #FB8B24;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|||||||
@@ -2,14 +2,114 @@
|
|||||||
|
|
||||||
import Layouts from './Chat_layouts.svelte';
|
import Layouts from './Chat_layouts.svelte';
|
||||||
import { init_socket } from './Socket_chat';
|
import { init_socket } from './Socket_chat';
|
||||||
|
import { location } from 'svelte-spa-router';
|
||||||
|
|
||||||
export let color = "transparent";
|
let style_light =
|
||||||
|
{
|
||||||
|
lines_width: "1px",
|
||||||
|
lines_color: "rgb(30, 30, 30)",
|
||||||
|
lines_light_color: "rgb(70, 70, 70)",
|
||||||
|
bg_color: "rgb(251, 139, 36)",
|
||||||
|
bg_light_color: "rgb(251, 156, 81)",
|
||||||
|
|
||||||
|
btn_color: "rgb(220, 220, 220)",
|
||||||
|
btn_color_hover: "rgb(200, 200, 200)",
|
||||||
|
btn_color_active: "rgb(190, 190, 190)",
|
||||||
|
btn_color_border: "rgb(150, 150, 150)",
|
||||||
|
|
||||||
|
btn_light_color: "rgb(235, 235, 235)",
|
||||||
|
btn_light_color_hover: "rgb(220, 220, 220)",
|
||||||
|
btn_light_color_active: "rgb(210, 210, 210)",
|
||||||
|
btn_color_border: "rgb(200, 200, 200)",
|
||||||
|
|
||||||
|
chat_me_color: "rgb(250, 230, 220)",
|
||||||
|
chat_me_bg_color: "rgb(210, 105, 30)",
|
||||||
|
chat_name_color: "rgb(230, 230, 230)",
|
||||||
|
chat_other_color: "rgb(250, 250, 250)",
|
||||||
|
chat_other_bg_color: "rgb(190, 130, 70)",
|
||||||
|
chat_serveur_color: "rgb(110, 110, 110)",
|
||||||
|
chat_msg_bg_color: "rgb(251, 163, 80)",
|
||||||
|
chat_conv_bg_color: "rgb(251, 163, 80)",
|
||||||
|
}
|
||||||
|
let style_dark =
|
||||||
|
{
|
||||||
|
lines_width: "2px",
|
||||||
|
lines_color: "rgb(200, 200, 200)",
|
||||||
|
lines_light_color: "rgb(100, 100, 100)",
|
||||||
|
bg_color: "rgb( 50, 50, 50)",
|
||||||
|
bg_light_color: "rgb( 35, 35, 35)",
|
||||||
|
|
||||||
|
btn_color: "rgb(220, 220, 220)",
|
||||||
|
btn_color_hover: "rgb(100, 100, 100)",
|
||||||
|
btn_color_active: "rgb( 90, 90, 90)",
|
||||||
|
btn_color_border: "rgb(150, 150, 150)",
|
||||||
|
|
||||||
|
btn_light_color: "rgb(235, 235, 235)",
|
||||||
|
btn_light_color_hover: "rgb(220, 220, 220)",
|
||||||
|
btn_light_color_active: "rgb(210, 210, 210)",
|
||||||
|
btn_color_border: "rgb(200, 200, 200)",
|
||||||
|
|
||||||
|
chat_me_color: "rgb(230, 230, 230)",
|
||||||
|
chat_me_bg_color: "rgb(110, 110, 110)",
|
||||||
|
chat_name_color: "rgb(110, 110, 110)",
|
||||||
|
chat_other_color: "rgb( 90, 90, 90)",
|
||||||
|
chat_other_bg_color: "rgb(210, 210, 210)",
|
||||||
|
chat_serveur_color: "rgb(190, 190, 190)",
|
||||||
|
chat_msg_bg_color: "rgb( 82, 82, 82)",
|
||||||
|
chat_conv_bg_color: "rgb( 82, 82, 82)",
|
||||||
|
}
|
||||||
|
|
||||||
|
let style = style_light;
|
||||||
|
|
||||||
|
console.log("location:",$location);
|
||||||
|
if ($location !== '/')
|
||||||
init_socket();
|
init_socket();
|
||||||
|
|
||||||
|
function change_style(loc)
|
||||||
|
{
|
||||||
|
console.log("change color, location:", loc);
|
||||||
|
if (loc.startsWith("/game"))
|
||||||
|
style = style_dark;
|
||||||
|
if (loc.startsWith("/spectator"))
|
||||||
|
style = style_dark;
|
||||||
|
if (loc.startsWith("/ranking"))
|
||||||
|
style = style_light;
|
||||||
|
if (loc.startsWith("/profile"))
|
||||||
|
style = style_light;
|
||||||
|
}
|
||||||
|
|
||||||
|
$: change_style($location);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Layouts color={color} />
|
{#if $location !== '/' && $location !== '/game'}
|
||||||
|
<Layouts
|
||||||
|
--lines_width={style.lines_width}
|
||||||
|
--lines_color={style.lines_color}
|
||||||
|
--lines_light_color={style.lines_light_color}
|
||||||
|
--bg_color={style.bg_color}
|
||||||
|
--bg_light_color={style.bg_light_color}
|
||||||
|
|
||||||
|
--btn_color={style.btn_color}
|
||||||
|
--btn_color_hover={style.btn_color_hover}
|
||||||
|
--btn_color_active={style.btn_color_active}
|
||||||
|
--btn_color_border={style.btn_color_border}
|
||||||
|
|
||||||
|
--btn_light_color={style.btn_light_color}
|
||||||
|
--btn_light_color_hover={style.btn_light_color_hover}
|
||||||
|
--btn_light_color_active={style.btn_light_color_active}
|
||||||
|
--btn_light_color_border={style.btn_color_border}
|
||||||
|
|
||||||
|
--chat_me_color={style.chat_me_color}
|
||||||
|
--chat_me_bg_color={style.chat_me_bg_color}
|
||||||
|
--chat_name_color={style.chat_name_color}
|
||||||
|
--chat_other_color={style.chat_other_color}
|
||||||
|
--chat_other_bg_color={style.chat_other_bg_color}
|
||||||
|
--chat_serveur_color={style.chat_serveur_color}
|
||||||
|
--chat_msg_bg_color={style.chat_msg_bg_color}
|
||||||
|
--chat_conv_bg_color={style.chat_conv_bg_color}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<style></style>
|
<style></style>
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,10 @@
|
|||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!--
|
||||||
<div class="{$layout} chat_box" style="background-color: {color};">
|
<div class="{$layout} chat_box" style="background-color: {color};">
|
||||||
|
-->
|
||||||
|
<div class="{$layout} chat_box">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -22,7 +25,8 @@
|
|||||||
padding: 0px;
|
padding: 0px;
|
||||||
width: auto;
|
width: auto;
|
||||||
height: auto;
|
height: auto;
|
||||||
border: 1px solid black;
|
border: var(--lines_width) solid var(--lines_color);
|
||||||
|
background-color: var(--bg_color);
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +38,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* gobal variables styles
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* Hide scrollbar
|
/* Hide scrollbar
|
||||||
*/
|
*/
|
||||||
.chat_box :global(*) {
|
.chat_box :global(*) {
|
||||||
@@ -67,6 +75,7 @@
|
|||||||
.chat_box :global(.grid_box p) {
|
.chat_box :global(.grid_box p) {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
|
color: var(--lines_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -95,7 +104,7 @@
|
|||||||
}
|
}
|
||||||
.chat_box :global(.__show_if_only_child:only-child) {
|
.chat_box :global(.__show_if_only_child:only-child) {
|
||||||
display: flex;
|
display: flex;
|
||||||
color: rgb(100, 100, 100);
|
color: var(--lines_light_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -110,7 +119,7 @@
|
|||||||
/* __border_top
|
/* __border_top
|
||||||
*/
|
*/
|
||||||
.chat_box :global(.__border_top) {
|
.chat_box :global(.__border_top) {
|
||||||
border-top: 1px solid black;
|
border-top: var(--lines_width) solid var(--lines_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -122,7 +131,7 @@
|
|||||||
.chat_box :global(.__check_change_next:checked ~ .__to_block),
|
.chat_box :global(.__check_change_next:checked ~ .__to_block),
|
||||||
.chat_box :global(.__check_change_next:checked ~ .__to_block *) {
|
.chat_box :global(.__check_change_next:checked ~ .__to_block *) {
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
color: rgb(100, 100, 100);
|
color: var(--lines_light_color);
|
||||||
}
|
}
|
||||||
.chat_box :global(.__to_show) {
|
.chat_box :global(.__to_show) {
|
||||||
display: none;
|
display: none;
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
/* global variables
|
/* global variables
|
||||||
*/
|
*/
|
||||||
export let color;
|
|
||||||
let room = "";
|
let room = "";
|
||||||
let admin = false;
|
let admin = false;
|
||||||
let layouts = ["home", "home"];
|
let layouts = ["home", "home"];
|
||||||
@@ -28,8 +27,6 @@
|
|||||||
*/
|
*/
|
||||||
function set_layouts($layout)
|
function set_layouts($layout)
|
||||||
{
|
{
|
||||||
//console.log("layouts:", layouts);
|
|
||||||
//console.log("layout:", $layout);
|
|
||||||
if ($layout.length === 0)
|
if ($layout.length === 0)
|
||||||
layout.set(layouts[0]);
|
layout.set(layouts[0]);
|
||||||
else if ($layout === "close")
|
else if ($layout === "close")
|
||||||
@@ -40,13 +37,12 @@
|
|||||||
layouts = [$layout, "home"];
|
layouts = [$layout, "home"];
|
||||||
else
|
else
|
||||||
layouts = [$layout, layouts[0]];
|
layouts = [$layout, layouts[0]];
|
||||||
//console.log("- layouts:", layouts);
|
|
||||||
}
|
}
|
||||||
$: set_layouts($layout);
|
$: set_layouts($layout);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ChatBox color={color}>
|
<ChatBox>
|
||||||
|
|
||||||
{#if $layout === "home"}
|
{#if $layout === "home"}
|
||||||
<HomeLayout />
|
<HomeLayout />
|
||||||
|
|||||||
@@ -29,17 +29,6 @@
|
|||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
/*
|
|
||||||
- default config
|
|
||||||
- for btn list
|
|
||||||
- for transparent btn
|
|
||||||
- for deactivated btn
|
|
||||||
- for icon
|
|
||||||
- for 3 dots btn
|
|
||||||
- for close btn
|
|
||||||
- for back btn
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/* default config
|
/* default config
|
||||||
*/
|
*/
|
||||||
@@ -50,25 +39,29 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
outline: none;
|
outline: none;
|
||||||
border: none;
|
border: none;
|
||||||
background-color: rgb(220, 220, 220);
|
border-radius: 0px;
|
||||||
|
background-color: var(--btn_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
button p {
|
button p {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
:global(.chat_box) button p {
|
||||||
|
color: var(--lines_light_color);
|
||||||
|
}
|
||||||
button:hover {
|
button:hover {
|
||||||
background-color: rgb(200, 200, 200);
|
background-color: var(--btn_color_hover);
|
||||||
}
|
}
|
||||||
button:active {
|
button:active {
|
||||||
background-color: rgb(190, 190, 190);
|
background-color: var(--btn_color_active);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .list
|
/* .list
|
||||||
*/
|
*/
|
||||||
.list:not(:hover) {
|
.list:not(:hover) {
|
||||||
background-color: rgb(240, 240, 240);
|
background-color: var(--btn_light_color);
|
||||||
}
|
}
|
||||||
.list p {
|
.list p {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
@@ -80,6 +73,9 @@
|
|||||||
.transparent:not(:hover) {
|
.transparent:not(:hover) {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
|
:global(.chat_box) button.transparent p {
|
||||||
|
color: var(--lines_color);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .deactivated
|
/* .deactivated
|
||||||
@@ -88,6 +84,9 @@
|
|||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
:global(.chat_box) button.deactivate p {
|
||||||
|
color: var(--lines_color);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .border
|
/* .border
|
||||||
@@ -100,19 +99,19 @@
|
|||||||
/* .light
|
/* .light
|
||||||
*/
|
*/
|
||||||
.light {
|
.light {
|
||||||
background-color: rgb(233, 233, 233);
|
background-color: var(--btn_light_color);
|
||||||
}
|
}
|
||||||
.light.border {
|
.light.border {
|
||||||
border: 1px solid rgb(204, 204, 204);
|
border: var(--lines_width) solid var(--btn_light_color_border);
|
||||||
}
|
}
|
||||||
.light:hover {
|
.light:hover {
|
||||||
background-color: rgb(220, 220, 220);
|
background-color: var(--btn_light_color_hover);
|
||||||
}
|
}
|
||||||
.light.border:hover {
|
.light.border:hover {
|
||||||
border-color: rgb(200, 200, 200);
|
border-color: var(--btn_light_color_border);
|
||||||
}
|
}
|
||||||
.light:active {
|
.light:active {
|
||||||
background-color: rgb(210, 210, 210);
|
background-color: var(--btn_light_color_active);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -151,6 +150,7 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
transform: translateY(-50%);
|
transform: translateY(-50%);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
color: var(--lines_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -159,11 +159,11 @@
|
|||||||
.close::before {
|
.close::before {
|
||||||
content: "";
|
content: "";
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: calc(50% - 1px);
|
top: calc(50% - var(--lines_width) / 2);
|
||||||
left: 5px;
|
left: 5px;
|
||||||
width: 20px;
|
width: 20px;
|
||||||
height: 2px;
|
height: var(--lines_width);
|
||||||
background-color: black;
|
background-color: var(--lines_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -176,8 +176,8 @@
|
|||||||
left: 6px;
|
left: 6px;
|
||||||
width: 14px;
|
width: 14px;
|
||||||
height: 14px;
|
height: 14px;
|
||||||
border-left: 1px solid black;
|
border-left: var(--lines_width) solid var(--lines_color);
|
||||||
border-bottom: 1px solid black;
|
border-bottom: var(--lines_width) solid var(--lines_color);
|
||||||
transform: rotate(45deg);
|
transform: rotate(45deg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@
|
|||||||
width: 13px;
|
width: 13px;
|
||||||
height: 10px;
|
height: 10px;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
background-color: rgb(110, 110, 110);
|
background-color: var(--lines_color);
|
||||||
}
|
}
|
||||||
.blocked::after {
|
.blocked::after {
|
||||||
content: "";
|
content: "";
|
||||||
@@ -211,7 +211,18 @@
|
|||||||
height: 13px;
|
height: 13px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
border: 3px solid rgb(110, 110, 110);
|
border: 3px solid var(--lines_color);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* .admin
|
||||||
|
*/
|
||||||
|
.admin p {
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
.admin :global(span) {
|
||||||
|
margin-left: auto;
|
||||||
|
color: var(--lines_light_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,15 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
/*
|
||||||
|
var(--chat_me_color)
|
||||||
|
var(--chat_me_bg_color)
|
||||||
|
var(--chat_other_color)
|
||||||
|
var(--chat_other_bg_color)
|
||||||
|
var(--chat_name_color)
|
||||||
|
var(--chat_input_color)
|
||||||
|
var(--chat_input_bg_color)
|
||||||
|
*/
|
||||||
.chat_msg {
|
.chat_msg {
|
||||||
/*
|
/*
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
@@ -22,7 +31,7 @@
|
|||||||
*/
|
*/
|
||||||
.chat_msg {
|
.chat_msg {
|
||||||
margin-left: 0px;
|
margin-left: 0px;
|
||||||
background-color: rgb(210, 210, 210);
|
background-color: var(--chat_other_bg_color);
|
||||||
max-width: 80%;
|
max-width: 80%;
|
||||||
}
|
}
|
||||||
.chat_msg p {
|
.chat_msg p {
|
||||||
@@ -31,24 +40,28 @@
|
|||||||
.chat_msg p.name {
|
.chat_msg p.name {
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: rgb(100, 100, 100);
|
color: var(--chat_name_color);
|
||||||
}
|
}
|
||||||
.chat_msg p.msg {
|
.chat_msg p.msg {
|
||||||
margin: 5px 0px;
|
margin: 5px 0px;
|
||||||
|
color: var(--chat_other_color);
|
||||||
}
|
}
|
||||||
.chat_msg p.msg :global(*) {
|
.chat_msg p.msg :global(*) {
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
/* msg perso
|
/* me msg
|
||||||
*/
|
*/
|
||||||
.chat_msg.me {
|
.chat_msg.me {
|
||||||
margin-right: 0px;
|
margin-right: 0px;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
background-color: rgb(210, 110, 10);
|
background-color: var(--chat_me_bg_color);
|
||||||
}
|
}
|
||||||
.chat_msg.me p.name {
|
.chat_msg.me p.name {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
.chat_msg.me p.msg {
|
||||||
|
color: var(--chat_me_color);
|
||||||
|
}
|
||||||
/* msg server
|
/* msg server
|
||||||
*/
|
*/
|
||||||
.chat_msg.SERVER {
|
.chat_msg.SERVER {
|
||||||
@@ -61,7 +74,7 @@
|
|||||||
.chat_msg.SERVER p.msg {
|
.chat_msg.SERVER p.msg {
|
||||||
margin: 0px auto;
|
margin: 0px auto;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: rgb(100, 100, 100);
|
color: var(--chat_serveur_color);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import { msgs, layout, allowed_chars } from './Store_chat';
|
import { msgs, layout, allowed_chars } from './Store_chat';
|
||||||
import { change_room, create_room } from './Request_rooms';
|
import { change_room, create_room } from './Request_rooms';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { FetchResponse } from './Types_chat';
|
import type { FetchResponse } from './Types_chat';
|
||||||
import Button from './Element_button.svelte';
|
import Button from './Element_button.svelte';
|
||||||
import Warning from './Element_warning.svelte';
|
import Warning from './Element_warning.svelte';
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { layout, msgs, user, current_room } from './Store_chat';
|
import { layout, msgs, user, current_room } from './Store_chat';
|
||||||
import { change_room, get_room_messages, get_my_rooms } from './Request_rooms';
|
import { change_room, get_room_messages, get_my_rooms } from './Request_rooms';
|
||||||
|
import { to_print } from './Utils_chat';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import Button from './Element_button.svelte';
|
import Button from './Element_button.svelte';
|
||||||
|
|
||||||
@@ -10,9 +11,9 @@
|
|||||||
// go to clicked room
|
// go to clicked room
|
||||||
async function go_to_room(room)
|
async function go_to_room(room)
|
||||||
{
|
{
|
||||||
console.log("inside go_to_room");
|
to_print("inside go_to_room");
|
||||||
|
|
||||||
console.log("room:", room);
|
to_print("room:", room);
|
||||||
if (room.protection && !room.allowed)
|
if (room.protection && !room.allowed)
|
||||||
{
|
{
|
||||||
await current_room.set(room);
|
await current_room.set(room);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { layout, user, current_room } from './Store_chat';
|
import { layout, user, current_room } from './Store_chat';
|
||||||
import { get_all_users, invite_user } from './Request_rooms';
|
import { get_all_users, invite_user } from './Request_rooms';
|
||||||
|
import { to_print } from './Utils_chat';
|
||||||
import Button from './Element_button.svelte';
|
import Button from './Element_button.svelte';
|
||||||
|
|
||||||
export let back = "";
|
export let back = "";
|
||||||
@@ -11,7 +12,7 @@
|
|||||||
// invite user in this room
|
// invite user in this room
|
||||||
async function invite_this_user(username: string)
|
async function invite_this_user(username: string)
|
||||||
{
|
{
|
||||||
console.log("inside invite_this_user");
|
to_print("inside invite_this_user");
|
||||||
|
|
||||||
invite_user(username);
|
invite_user(username);
|
||||||
layout.set("room");
|
layout.set("room");
|
||||||
|
|||||||
@@ -1,10 +1,80 @@
|
|||||||
<script>
|
<script lang="ts">
|
||||||
|
|
||||||
import { layout } from './Store_chat';
|
import { layout, settings_user } from './Store_chat';
|
||||||
|
import { set_mute, get_is_mute, get_unmute } from './Request_rooms';
|
||||||
import Button from './Element_button.svelte';
|
import Button from './Element_button.svelte';
|
||||||
|
import Warning from './Element_warning.svelte';
|
||||||
|
|
||||||
export let back = "";
|
export let back = "";
|
||||||
|
|
||||||
|
let response: FetchResponse;
|
||||||
|
let show_error = false;
|
||||||
|
let is_mute = false;
|
||||||
|
let mute_date: date;
|
||||||
|
let date_string: string;
|
||||||
|
get_is_mute($settings_user).then(response =>
|
||||||
|
{
|
||||||
|
if (response && response.name)
|
||||||
|
is_mute = true;
|
||||||
|
if (response && response.date)
|
||||||
|
mute_date = response.date;
|
||||||
|
if (mute_date)
|
||||||
|
date_string = stringify_date(new Date(mute_date));
|
||||||
|
else
|
||||||
|
date_string = "eternity";
|
||||||
|
});
|
||||||
|
|
||||||
|
let is_forever;
|
||||||
|
let minutes: number = 0;
|
||||||
|
let hours: number = 0;
|
||||||
|
let days: number = 0;
|
||||||
|
|
||||||
|
function stringify_date(str_date: Date)
|
||||||
|
{
|
||||||
|
return `${str_date.getFullYear()}/${str_date.getMonth() + 1}/${str_date.getDate()} at ${str_date.getHours()}:${str_date.getMinutes()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleSubmit(evt)
|
||||||
|
{
|
||||||
|
let formIsValid = evt.target.checkValidity();
|
||||||
|
|
||||||
|
if (!formIsValid)
|
||||||
|
return;
|
||||||
|
|
||||||
|
console.log("is_forever:", is_forever);
|
||||||
|
console.log("minutes:", minutes);
|
||||||
|
console.log("hours:", hours);
|
||||||
|
console.log("days:", days);
|
||||||
|
|
||||||
|
let date_limit: Date;
|
||||||
|
let time: string;
|
||||||
|
|
||||||
|
if (is_forever)
|
||||||
|
time = "eternity";
|
||||||
|
else
|
||||||
|
{
|
||||||
|
let duration = minutes * (1000 * 60) + hours * (1000 * 60 * 60) + days * (1000 * 60 * 60 * 24);
|
||||||
|
console.log("duration:", duration);
|
||||||
|
|
||||||
|
let date_start = new Date();
|
||||||
|
date_limit = new Date(date_start.getTime() + duration);
|
||||||
|
time = stringify_date(date_limit);
|
||||||
|
console.log("time:", time);
|
||||||
|
}
|
||||||
|
|
||||||
|
response = await set_mute(date_limit, $settings_user, time);
|
||||||
|
// print error
|
||||||
|
if (response.status >= 300 || response.error)
|
||||||
|
show_error = response.error;
|
||||||
|
|
||||||
|
layout.set("room");
|
||||||
|
}
|
||||||
|
async function unmute()
|
||||||
|
{
|
||||||
|
get_unmute($settings_user);
|
||||||
|
layout.set("room");
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="grid_box">
|
<div class="grid_box">
|
||||||
@@ -16,7 +86,7 @@
|
|||||||
|
|
||||||
<!-- user -->
|
<!-- user -->
|
||||||
<Button my_class="user deactivate">
|
<Button my_class="user deactivate">
|
||||||
<user>
|
{$settings_user}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<!-- close -->
|
<!-- close -->
|
||||||
@@ -25,160 +95,168 @@
|
|||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<!-- panel_mute -->
|
<!-- panel_mute -->
|
||||||
|
|
||||||
<!-- MUTE -->
|
|
||||||
<div class="panel panel_mute __border_top">
|
<div class="panel panel_mute __border_top">
|
||||||
|
{#if show_error}
|
||||||
|
<Warning content={response.message}/>
|
||||||
|
{/if}
|
||||||
|
{#if is_mute === true }
|
||||||
|
<p class="__center">this user is mute untill {date_string}</p>
|
||||||
|
<Button on:click={unmute}>
|
||||||
|
un-mute
|
||||||
|
</Button>
|
||||||
|
{:else}
|
||||||
|
<form on:submit|preventDefault={handleSubmit}>
|
||||||
<p class="__center">mute this user for a time :</p>
|
<p class="__center">mute this user for a time :</p>
|
||||||
<form>
|
|
||||||
<!-- forever -->
|
<!-- forever -->
|
||||||
<input id="chat_mute_forever" class="__check_change_next" type="checkbox">
|
<input id="chat_mute_forever" bind:checked={is_forever} class="__check_change_next" type="checkbox">
|
||||||
<label for="chat_mute_forever" class="_checkbox"><p>forever</p></label>
|
<label for="chat_mute_forever" class="_checkbox"><p>forever</p></label>
|
||||||
<div class="__to_block">
|
<div class="__to_block">
|
||||||
<!-- minutes -->
|
<!-- minutes -->
|
||||||
<label for="chat_mute_minutes" class="_select">
|
<label for="chat_mute_minutes" class="_select">
|
||||||
<p>minutes :</p>
|
<p>minutes :</p>
|
||||||
<select id="chat_mute_minutes">
|
<select id="chat_mute_minutes" bind:value={minutes}>
|
||||||
<option value="01">00</option>
|
<option>00</option>
|
||||||
<option value="01">01</option>
|
<option>01</option>
|
||||||
<option value="02">02</option>
|
<option>02</option>
|
||||||
<option value="03">03</option>
|
<option>03</option>
|
||||||
<option value="04">04</option>
|
<option>04</option>
|
||||||
<option value="05">05</option>
|
<option>05</option>
|
||||||
<option value="06">06</option>
|
<option>06</option>
|
||||||
<option value="07">07</option>
|
<option>07</option>
|
||||||
<option value="10">10</option>
|
<option>10</option>
|
||||||
<option value="11">11</option>
|
<option>11</option>
|
||||||
<option value="12">12</option>
|
<option>12</option>
|
||||||
<option value="13">13</option>
|
<option>13</option>
|
||||||
<option value="14">14</option>
|
<option>14</option>
|
||||||
<option value="15">15</option>
|
<option>15</option>
|
||||||
<option value="16">16</option>
|
<option>16</option>
|
||||||
<option value="17">17</option>
|
<option>17</option>
|
||||||
<option value="20">20</option>
|
<option>20</option>
|
||||||
<option value="21">21</option>
|
<option>21</option>
|
||||||
<option value="22">22</option>
|
<option>22</option>
|
||||||
<option value="23">23</option>
|
<option>23</option>
|
||||||
<option value="24">24</option>
|
<option>24</option>
|
||||||
<option value="25">25</option>
|
<option>25</option>
|
||||||
<option value="26">26</option>
|
<option>26</option>
|
||||||
<option value="27">27</option>
|
<option>27</option>
|
||||||
<option value="30">30</option>
|
<option>30</option>
|
||||||
<option value="31">31</option>
|
<option>31</option>
|
||||||
<option value="32">32</option>
|
<option>32</option>
|
||||||
<option value="33">33</option>
|
<option>33</option>
|
||||||
<option value="34">34</option>
|
<option>34</option>
|
||||||
<option value="35">35</option>
|
<option>35</option>
|
||||||
<option value="36">36</option>
|
<option>36</option>
|
||||||
<option value="37">37</option>
|
<option>37</option>
|
||||||
<option value="40">40</option>
|
<option>40</option>
|
||||||
<option value="41">41</option>
|
<option>41</option>
|
||||||
<option value="42">42</option>
|
<option>42</option>
|
||||||
<option value="43">43</option>
|
<option>43</option>
|
||||||
<option value="44">44</option>
|
<option>44</option>
|
||||||
<option value="45">45</option>
|
<option>45</option>
|
||||||
<option value="46">46</option>
|
<option>46</option>
|
||||||
<option value="47">47</option>
|
<option>47</option>
|
||||||
<option value="50">50</option>
|
<option>50</option>
|
||||||
<option value="51">51</option>
|
<option>51</option>
|
||||||
<option value="52">52</option>
|
<option>52</option>
|
||||||
<option value="53">53</option>
|
<option>53</option>
|
||||||
<option value="54">54</option>
|
<option>54</option>
|
||||||
<option value="55">55</option>
|
<option>55</option>
|
||||||
<option value="56">56</option>
|
<option>56</option>
|
||||||
<option value="57">57</option>
|
<option>57</option>
|
||||||
<option value="60">60</option>
|
<option>60</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<!-- hours -->
|
<!-- hours -->
|
||||||
<label for="chat_mute_hours" class="_select">
|
<label for="chat_mute_hours" class="_select">
|
||||||
<p>hours :</p>
|
<p>hours :</p>
|
||||||
<select id="chat_mute_hours">
|
<select id="chat_mute_hours">
|
||||||
<option value="01">00</option>
|
<option>00</option>
|
||||||
<option value="01">01</option>
|
<option>01</option>
|
||||||
<option value="02">02</option>
|
<option>02</option>
|
||||||
<option value="03">03</option>
|
<option>03</option>
|
||||||
<option value="04">04</option>
|
<option>04</option>
|
||||||
<option value="05">05</option>
|
<option>05</option>
|
||||||
<option value="06">06</option>
|
<option>06</option>
|
||||||
<option value="07">07</option>
|
<option>07</option>
|
||||||
<option value="10">10</option>
|
<option>10</option>
|
||||||
<option value="11">11</option>
|
<option>11</option>
|
||||||
<option value="12">12</option>
|
<option>12</option>
|
||||||
<option value="13">13</option>
|
<option>13</option>
|
||||||
<option value="14">14</option>
|
<option>14</option>
|
||||||
<option value="15">15</option>
|
<option>15</option>
|
||||||
<option value="16">16</option>
|
<option>16</option>
|
||||||
<option value="17">17</option>
|
<option>17</option>
|
||||||
<option value="20">20</option>
|
<option>20</option>
|
||||||
<option value="21">21</option>
|
<option>21</option>
|
||||||
<option value="22">22</option>
|
<option>22</option>
|
||||||
<option value="23">23</option>
|
<option>23</option>
|
||||||
<option value="24">24</option>
|
<option>24</option>
|
||||||
<option value="25">25</option>
|
<option>25</option>
|
||||||
<option value="26">26</option>
|
<option>26</option>
|
||||||
<option value="27">27</option>
|
<option>27</option>
|
||||||
<option value="30">30</option>
|
<option>30</option>
|
||||||
<option value="31">31</option>
|
<option>31</option>
|
||||||
<option value="32">32</option>
|
<option>32</option>
|
||||||
<option value="33">33</option>
|
<option>33</option>
|
||||||
<option value="34">34</option>
|
<option>34</option>
|
||||||
<option value="35">35</option>
|
<option>35</option>
|
||||||
<option value="36">36</option>
|
<option>36</option>
|
||||||
<option value="37">37</option>
|
<option>37</option>
|
||||||
<option value="40">40</option>
|
<option>40</option>
|
||||||
<option value="41">41</option>
|
<option>41</option>
|
||||||
<option value="42">42</option>
|
<option>42</option>
|
||||||
<option value="43">43</option>
|
<option>43</option>
|
||||||
<option value="44">44</option>
|
<option>44</option>
|
||||||
<option value="45">45</option>
|
<option>45</option>
|
||||||
<option value="46">46</option>
|
<option>46</option>
|
||||||
<option value="47">47</option>
|
<option>47</option>
|
||||||
<option value="50">50</option>
|
<option>50</option>
|
||||||
<option value="51">51</option>
|
<option>51</option>
|
||||||
<option value="52">52</option>
|
<option>52</option>
|
||||||
<option value="53">53</option>
|
<option>53</option>
|
||||||
<option value="54">54</option>
|
<option>54</option>
|
||||||
<option value="55">55</option>
|
<option>55</option>
|
||||||
<option value="56">56</option>
|
<option>56</option>
|
||||||
<option value="57">57</option>
|
<option>57</option>
|
||||||
<option value="60">60</option>
|
<option>60</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<!-- days -->
|
<!-- days -->
|
||||||
<label for="chat_mute_days" class="_select">
|
<label for="chat_mute_days" class="_select">
|
||||||
<p>days :</p>
|
<p>days :</p>
|
||||||
<select id="chat_mute_days">
|
<select id="chat_mute_days">
|
||||||
<option value="00">00</option>
|
<option>00</option>
|
||||||
<option value="01">01</option>
|
<option>01</option>
|
||||||
<option value="02">02</option>
|
<option>02</option>
|
||||||
<option value="03">03</option>
|
<option>03</option>
|
||||||
<option value="04">04</option>
|
<option>04</option>
|
||||||
<option value="05">05</option>
|
<option>05</option>
|
||||||
<option value="06">06</option>
|
<option>06</option>
|
||||||
<option value="07">07</option>
|
<option>07</option>
|
||||||
<option value="10">10</option>
|
<option>10</option>
|
||||||
<option value="11">11</option>
|
<option>11</option>
|
||||||
<option value="12">12</option>
|
<option>12</option>
|
||||||
<option value="13">13</option>
|
<option>13</option>
|
||||||
<option value="14">14</option>
|
<option>14</option>
|
||||||
<option value="15">15</option>
|
<option>15</option>
|
||||||
<option value="16">16</option>
|
<option>16</option>
|
||||||
<option value="17">17</option>
|
<option>17</option>
|
||||||
<option value="20">20</option>
|
<option>20</option>
|
||||||
<option value="21">21</option>
|
<option>21</option>
|
||||||
<option value="22">22</option>
|
<option>22</option>
|
||||||
<option value="23">23</option>
|
<option>23</option>
|
||||||
<option value="24">24</option>
|
<option>24</option>
|
||||||
<option value="25">25</option>
|
<option>25</option>
|
||||||
<option value="26">26</option>
|
<option>26</option>
|
||||||
<option value="27">27</option>
|
<option>27</option>
|
||||||
<option value="30">30</option>
|
<option>30</option>
|
||||||
<option value="31">31</option>
|
<option>31</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<input type="submit" value="⮡">
|
<input type="submit" value="⮡">
|
||||||
</form>
|
</form>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { layout, msgs, user, socket, current_room } from './Store_chat';
|
import { layout, msgs, user, socket, current_room } from './Store_chat';
|
||||||
import { join_room, change_room, get_room_messages, get_all_rooms } from './Request_rooms';
|
import { join_room, change_room, get_room_messages, get_all_rooms } from './Request_rooms';
|
||||||
|
import { to_print } from './Utils_chat';
|
||||||
import Button from './Element_button.svelte';
|
import Button from './Element_button.svelte';
|
||||||
|
|
||||||
export let back = "";
|
export let back = "";
|
||||||
@@ -11,7 +12,7 @@
|
|||||||
// join the room
|
// join the room
|
||||||
async function join_rooms(room)
|
async function join_rooms(room)
|
||||||
{
|
{
|
||||||
console.log("inside join_room");
|
to_print("inside join_room");
|
||||||
|
|
||||||
const updated_room = await join_room(room);
|
const updated_room = await join_room(room);
|
||||||
if (updated_room.protection)
|
if (updated_room.protection)
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
import { layout, current_room } from './Store_chat';
|
import { layout, current_room } from './Store_chat';
|
||||||
import { change_room, validate_password, change_password, add_password, remove_password } from './Request_rooms';
|
import { change_room, validate_password, change_password, add_password, remove_password } from './Request_rooms';
|
||||||
import { FetchResponse } from './Types_chat';
|
import type { FetchResponse } from './Types_chat';
|
||||||
|
import { to_print } from './Utils_chat';
|
||||||
import Button from './Element_button.svelte';
|
import Button from './Element_button.svelte';
|
||||||
import Warning from './Element_warning.svelte';
|
import Warning from './Element_warning.svelte';
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@
|
|||||||
|
|
||||||
async function handleSubmit(evt)
|
async function handleSubmit(evt)
|
||||||
{
|
{
|
||||||
console.log("in handleSubmit");
|
to_print("in handleSubmit");
|
||||||
|
|
||||||
let formIsValid = evt.target.checkValidity();
|
let formIsValid = evt.target.checkValidity();
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
if (msg.length > 0) {
|
if (msg.length > 0) {
|
||||||
socket.emit('message', msg);
|
socket.emit('message', msg);
|
||||||
add_msg("me", msg);
|
add_msg("me", msg);
|
||||||
console.log(msgs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = "";
|
msg = "";
|
||||||
@@ -42,7 +41,7 @@
|
|||||||
|
|
||||||
<!-- room_name -->
|
<!-- room_name -->
|
||||||
<Button new_layout="room_set" my_class="room_name transparent">
|
<Button new_layout="room_set" my_class="room_name transparent">
|
||||||
{$current_room.name}
|
{$current_room.client_name}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<!-- close -->
|
<!-- close -->
|
||||||
@@ -112,8 +111,11 @@
|
|||||||
|
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
background-color: white;
|
background-color: var(--chat_msg_bg_color);
|
||||||
border: 1px solid black;
|
border: var(--lines_width) solid var(--lines_color);
|
||||||
|
}
|
||||||
|
.grid_box .text_area {
|
||||||
|
color: var(--lines_color);
|
||||||
}
|
}
|
||||||
.grid_box .text_area:focus {
|
.grid_box .text_area:focus {
|
||||||
height: auto;
|
height: auto;
|
||||||
@@ -129,7 +131,8 @@
|
|||||||
*/
|
*/
|
||||||
.grid_box .panel_msg {
|
.grid_box .panel_msg {
|
||||||
flex-direction: column-reverse;
|
flex-direction: column-reverse;
|
||||||
border: 1px solid black;
|
border: var(--lines_width) solid var(--lines_color);
|
||||||
|
background-color: var(--chat_conv_bg_color);
|
||||||
}
|
}
|
||||||
.grid_box .msg_thread {
|
.grid_box .msg_thread {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
@@ -1,23 +1,30 @@
|
|||||||
<script>
|
<script lang="ts">
|
||||||
|
|
||||||
import { layout, current_room } from './Store_chat';
|
import { layout, current_room, settings_user } from './Store_chat';
|
||||||
import { get_room_users, leave_room } from './Request_rooms';
|
import { get_room_users, leave_room, get_is_admin } from './Request_rooms';
|
||||||
|
import { User } from './Types_chat';
|
||||||
|
import { to_print } from './Utils_chat';
|
||||||
import Button from './Element_button.svelte';
|
import Button from './Element_button.svelte';
|
||||||
|
|
||||||
export let back = "";
|
export let back = "";
|
||||||
|
|
||||||
let users = get_room_users();
|
let users: User[] = get_room_users();
|
||||||
|
|
||||||
console.log("current_room:", $current_room);
|
let is_admin = false;
|
||||||
|
get_is_admin().then(response => is_admin = response);
|
||||||
|
|
||||||
function user_profile()
|
to_print("current_room:", $current_room);
|
||||||
|
|
||||||
|
function user_profile(room_user: string)
|
||||||
{
|
{
|
||||||
console.log("in user_profile");
|
to_print("in user_profile");
|
||||||
|
settings_user.set(room_user);
|
||||||
|
layout.set("user");
|
||||||
}
|
}
|
||||||
|
|
||||||
function user_leave_room()
|
function user_leave_room()
|
||||||
{
|
{
|
||||||
console.log("in leave_room");
|
to_print("in leave_room");
|
||||||
leave_room();
|
leave_room();
|
||||||
layout.set("home");
|
layout.set("home");
|
||||||
}
|
}
|
||||||
@@ -33,7 +40,7 @@
|
|||||||
|
|
||||||
<!-- room_name -->
|
<!-- room_name -->
|
||||||
<Button my_class="room_name deactivate">
|
<Button my_class="room_name deactivate">
|
||||||
{$current_room.name}
|
{$current_room.client_name}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<!-- close -->
|
<!-- close -->
|
||||||
@@ -51,6 +58,8 @@
|
|||||||
invite someone
|
invite someone
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if is_admin === true }
|
||||||
|
<p class="__center">you are admin in this room</p>
|
||||||
{#if $current_room.protection }
|
{#if $current_room.protection }
|
||||||
<p class="__center">this room is password protected</p>
|
<p class="__center">this room is password protected</p>
|
||||||
<Button new_layout="change_password">
|
<Button new_layout="change_password">
|
||||||
@@ -64,6 +73,7 @@
|
|||||||
add password
|
add password
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
|
{/if}
|
||||||
<p>room users :</p>
|
<p>room users :</p>
|
||||||
<div class="room_users">
|
<div class="room_users">
|
||||||
<div class="__show_if_only_child">
|
<div class="__show_if_only_child">
|
||||||
@@ -73,8 +83,11 @@
|
|||||||
<p>list of users is loading...</p>
|
<p>list of users is loading...</p>
|
||||||
{:then users}
|
{:then users}
|
||||||
{#each users as user}
|
{#each users as user}
|
||||||
<Button new_layout="user" my_class="list" on:click={user_profile}>
|
<Button my_class="list admin {user.isblocked ? 'blocked' : ''}" on:click={function(){user_profile(user)}}>
|
||||||
{user}
|
{user.name}
|
||||||
|
{#if user.isadmin }
|
||||||
|
<span>admin</span>
|
||||||
|
{/if}
|
||||||
</Button>
|
</Button>
|
||||||
{/each}
|
{/each}
|
||||||
{/await}
|
{/await}
|
||||||
|
|||||||
@@ -1,10 +1,22 @@
|
|||||||
<script>
|
<script lang="ts">
|
||||||
|
|
||||||
import { layout } from './Store_chat';
|
import { layout, settings_user } from './Store_chat';
|
||||||
|
import { list_block_user } from './Request_rooms';
|
||||||
|
import { User } from './Types_chat';
|
||||||
|
import { to_print } from './Utils_chat';
|
||||||
import Button from './Element_button.svelte';
|
import Button from './Element_button.svelte';
|
||||||
|
|
||||||
export let back = "";
|
export let back = "";
|
||||||
|
|
||||||
|
let users: User[] = list_block_user();
|
||||||
|
|
||||||
|
async function user_profile(room_user: string)
|
||||||
|
{
|
||||||
|
to_print("in user_profile");
|
||||||
|
await settings_user.set(room_user);
|
||||||
|
layout.set("user");
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="grid_box">
|
<div class="grid_box">
|
||||||
@@ -31,21 +43,15 @@
|
|||||||
<div class="__show_if_only_child">
|
<div class="__show_if_only_child">
|
||||||
<p class="__center">/ you have blocked no one /</p>
|
<p class="__center">/ you have blocked no one /</p>
|
||||||
</div>
|
</div>
|
||||||
<!-- placeholders
|
{#await users}
|
||||||
<Button bind:layout new_layout="user" my_class="list blocked">
|
<p>list of users is loading...</p>
|
||||||
user 1
|
{:then users}
|
||||||
|
{#each users as user}
|
||||||
|
<Button my_class="list blocked" on:click={function(){user_profile(user)}}>
|
||||||
|
{user.name}
|
||||||
</Button>
|
</Button>
|
||||||
<Button bind:layout new_layout="user" my_class="list blocked">
|
{/each}
|
||||||
user 2
|
{/await}
|
||||||
</Button>
|
|
||||||
<Button bind:layout new_layout="user" my_class="list blocked">
|
|
||||||
user 3
|
|
||||||
</Button>
|
|
||||||
<Button bind:layout new_layout="user" my_class="list blocked">
|
|
||||||
user 4
|
|
||||||
</Button>
|
|
||||||
------------- -->
|
|
||||||
<!-- END placeholders -->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,60 @@
|
|||||||
<script>
|
<script lang="ts">
|
||||||
|
|
||||||
import { layout } from './Store_chat';
|
import { layout, current_room, settings_user } from './Store_chat';
|
||||||
|
import { get_is_admin, make_admin, set_block_user, remove_block_user } from './Request_rooms';
|
||||||
|
import type { FetchResponse } from './Types_chat';
|
||||||
|
import { to_print } from './Utils_chat';
|
||||||
import Button from './Element_button.svelte';
|
import Button from './Element_button.svelte';
|
||||||
|
import { push } from "svelte-spa-router";
|
||||||
|
import { invited_username } from '../store_invitation';
|
||||||
|
import Warning from './Element_warning.svelte';
|
||||||
|
|
||||||
export let back = "";
|
export let back = "";
|
||||||
|
|
||||||
let mute = "mute";
|
let is_admin = false;
|
||||||
let block = "block";
|
get_is_admin().then(response => is_admin = response);
|
||||||
|
|
||||||
|
let response: FetchResponse;
|
||||||
|
let show_error = false;
|
||||||
|
|
||||||
import { push } from "svelte-spa-router";
|
|
||||||
import { invited_username } from '../store_invitation';
|
|
||||||
function game_invitation()
|
function game_invitation()
|
||||||
{
|
{
|
||||||
const usernamePLACEHOLDER = "hulamy";
|
to_print("in game_invitation");
|
||||||
invited_username.set(usernamePLACEHOLDER);
|
const username = $settings_user.name;
|
||||||
|
invited_username.set(username);
|
||||||
push("/game");
|
push("/game");
|
||||||
}
|
}
|
||||||
|
function view_profile()
|
||||||
|
{
|
||||||
|
to_print("in view_profile");
|
||||||
|
push(`/profile/users/${$settings_user.name}`);
|
||||||
|
}
|
||||||
|
async function block_user()
|
||||||
|
{
|
||||||
|
to_print("in block_user");
|
||||||
|
await set_block_user($settings_user.name);
|
||||||
|
layout.set("room");
|
||||||
|
}
|
||||||
|
async function unblock_user()
|
||||||
|
{
|
||||||
|
to_print("in unblock_user");
|
||||||
|
await remove_block_user($settings_user.name);
|
||||||
|
layout.set("room");
|
||||||
|
}
|
||||||
|
async function get_list_block_user()
|
||||||
|
{
|
||||||
|
to_print("in get_list_block_user");
|
||||||
|
await list_block_user();
|
||||||
|
}
|
||||||
|
async function make_user_admin()
|
||||||
|
{
|
||||||
|
to_print("in make_user_admin");
|
||||||
|
response = await make_admin($settings_user.name);
|
||||||
|
//show errors
|
||||||
|
if (response.status >= 300 || response.error)
|
||||||
|
show_error = response.error;
|
||||||
|
layout.set("room");
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -28,7 +67,7 @@
|
|||||||
|
|
||||||
<!-- user -->
|
<!-- user -->
|
||||||
<Button my_class="user deactivate">
|
<Button my_class="user deactivate">
|
||||||
<user>
|
{$settings_user.name}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<!-- close -->
|
<!-- close -->
|
||||||
@@ -39,29 +78,38 @@
|
|||||||
<!-- room_name -->
|
<!-- room_name -->
|
||||||
{#if back === "room_set"}
|
{#if back === "room_set"}
|
||||||
<Button my_class="room_name deactivate __border_top">
|
<Button my_class="room_name deactivate __border_top">
|
||||||
<room_name>
|
{$current_room.client_name}
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<!-- panel_user -->
|
<!-- panel_user -->
|
||||||
<div class="panel panel_user __border_top">
|
<div class="panel panel_user __border_top">
|
||||||
|
{#if show_error}
|
||||||
|
<Warning content={response.message}/>
|
||||||
|
{/if}
|
||||||
<p class="__center">user options :</p>
|
<p class="__center">user options :</p>
|
||||||
<Button>
|
<Button on:click={view_profile}>
|
||||||
view profile
|
view profile
|
||||||
</Button>
|
</Button>
|
||||||
<Button on_click={() => game_invitation()}>
|
<Button on:click={game_invitation}>
|
||||||
game invitation
|
game invitation
|
||||||
</Button>
|
</Button>
|
||||||
<Button>
|
{#if $settings_user.isblocked}
|
||||||
{block}
|
<Button on:click={unblock_user}>
|
||||||
|
unblock
|
||||||
</Button>
|
</Button>
|
||||||
|
{:else}
|
||||||
|
<Button on:click={block_user}>
|
||||||
|
block
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if back === "room_set"}
|
{#if is_admin && back === "room_set" && $current_room.type !== "direct"}
|
||||||
<Button>
|
<Button on:click={make_user_admin}>
|
||||||
make admin
|
make admin
|
||||||
</Button>
|
</Button>
|
||||||
<Button>
|
<Button new_layout="mute">
|
||||||
{mute}
|
mute
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
import { msgs, user, layout, socket, current_room } from './Store_chat';
|
import { msgs, user, layout, socket, current_room } from './Store_chat';
|
||||||
import { Room, FetchResponse, FetchMethod } from './Types_chat';
|
import type { Room, FetchResponse } from './Types_chat';
|
||||||
|
import { FetchMethod, Mute, User } from './Types_chat';
|
||||||
|
import { to_print } from './Utils_chat';
|
||||||
import { fetch_chat_request, set_client_name_on_room, fill_fetch_response } from './Request_utils';
|
import { fetch_chat_request, set_client_name_on_room, fill_fetch_response } from './Request_utils';
|
||||||
|
|
||||||
export async function get_room_messages()
|
export async function get_room_messages()
|
||||||
{
|
{
|
||||||
console.log("in get_room_messages");
|
to_print("in get_room_messages");
|
||||||
|
|
||||||
let response: FetchResponse = await fetch_chat_request('messages', FetchMethod.GET);
|
let response: FetchResponse = await fetch_chat_request('messages', FetchMethod.GET);
|
||||||
|
|
||||||
const messages = response.messages;
|
const messages = response.messages;
|
||||||
|
|
||||||
if (messages === null)
|
if (messages === null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -24,33 +25,33 @@ export async function get_room_messages()
|
|||||||
|
|
||||||
export async function create_room(room: Room)
|
export async function create_room(room: Room)
|
||||||
{
|
{
|
||||||
console.log("in create_room");
|
to_print("in create_room");
|
||||||
|
|
||||||
console.log("room sent to create:", room);
|
to_print("room sent to create:", room);
|
||||||
let response: FetchResponse = await fetch_chat_request('create', FetchMethod.POST, room);
|
let response: FetchResponse = await fetch_chat_request('create', FetchMethod.POST, room);
|
||||||
console.log("room returned from create:", response.room);
|
to_print("room returned from create:", response.room);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function join_room(room: Room)
|
export async function join_room(room: Room)
|
||||||
{
|
{
|
||||||
console.log("in join_room");
|
to_print("in join_room");
|
||||||
|
|
||||||
console.log("room sent to join:", room);
|
to_print("room sent to join:", room);
|
||||||
let response: FetchResponse = await fetch_chat_request('join', FetchMethod.POST, room);
|
let response: FetchResponse = await fetch_chat_request('join', FetchMethod.POST, room);
|
||||||
console.log("room returned from join:", response.room);
|
to_print("room returned from join:", response.room);
|
||||||
|
|
||||||
return response.room;
|
return response.room;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function change_room(room: Room)
|
export async function change_room(room: Room)
|
||||||
{
|
{
|
||||||
console.log("in change_room");
|
to_print("in change_room");
|
||||||
|
|
||||||
console.log("room sent to change:", room);
|
to_print("room sent to change:", room);
|
||||||
let response: FetchResponse = await fetch_chat_request('change', FetchMethod.POST, room);
|
let response: FetchResponse = await fetch_chat_request('change', FetchMethod.POST, room);
|
||||||
console.log("room returned from change:", response.room);
|
to_print("room returned from change:", response.room);
|
||||||
|
|
||||||
await get_room_messages();
|
await get_room_messages();
|
||||||
|
|
||||||
@@ -62,29 +63,29 @@ console.log("room returned from change:", response.room);
|
|||||||
|
|
||||||
export async function validate_password(room: Room)
|
export async function validate_password(room: Room)
|
||||||
{
|
{
|
||||||
console.log("in validate_password");
|
to_print("in validate_password");
|
||||||
|
|
||||||
console.log("room sent to validate password:", room);
|
to_print("room sent to validate password:", room);
|
||||||
let response: FetchResponse = await fetch_chat_request('passwordauth', FetchMethod.POST, room);
|
let response: FetchResponse = await fetch_chat_request('passwordauth', FetchMethod.POST, room);
|
||||||
console.log("room returned from validate password:", response.room);
|
to_print("room returned from validate password:", response.room);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function add_password(room: Room)
|
export async function add_password(room: Room)
|
||||||
{
|
{
|
||||||
console.log("in add_password");
|
to_print("in add_password");
|
||||||
|
|
||||||
console.log("room sent to add password:", room);
|
to_print("room sent to add password:", room);
|
||||||
let response: FetchResponse = await fetch_chat_request('addpassword', FetchMethod.POST, room);
|
let response: FetchResponse = await fetch_chat_request('addpassword', FetchMethod.POST, room);
|
||||||
console.log("room returned from add password:", response.room);
|
to_print("room returned from add password:", response.room);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function change_password(room: Room, old_password: string)
|
export async function change_password(room: Room, old_password: string)
|
||||||
{
|
{
|
||||||
console.log("in send_password");
|
to_print("in send_password");
|
||||||
|
|
||||||
let request_body =
|
let request_body =
|
||||||
{
|
{
|
||||||
@@ -92,27 +93,27 @@ export async function change_password(room: Room, old_password: string)
|
|||||||
old_password: old_password,
|
old_password: old_password,
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("room sent to change password:", room);
|
to_print("room sent to change password:", room);
|
||||||
let response: FetchResponse = await fetch_chat_request('changepassword', FetchMethod.POST, request_body);
|
let response: FetchResponse = await fetch_chat_request('changepassword', FetchMethod.POST, request_body);
|
||||||
console.log("room returned from change password:", response.room);
|
to_print("room returned from change password:", response.room);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function remove_password(room: Room)
|
export async function remove_password(room: Room)
|
||||||
{
|
{
|
||||||
console.log("in send_password");
|
to_print("in send_password");
|
||||||
|
|
||||||
console.log("room sent to remove password:", room);
|
to_print("room sent to remove password:", room);
|
||||||
let response: FetchResponse = await fetch_chat_request('removepassword', FetchMethod.DELETE, room);
|
let response: FetchResponse = await fetch_chat_request('removepassword', FetchMethod.DELETE, room);
|
||||||
console.log("room returned from remove password:", response.room);
|
to_print("room returned from remove password:", response.room);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function invite_user(user_name: string)
|
export async function invite_user(user_name: string)
|
||||||
{
|
{
|
||||||
console.log("in invite_user");
|
to_print("in invite_user");
|
||||||
|
|
||||||
let response: FetchResponse = await fetch_chat_request('invite', FetchMethod.POST, {username: user_name});
|
let response: FetchResponse = await fetch_chat_request('invite', FetchMethod.POST, {username: user_name});
|
||||||
|
|
||||||
@@ -121,7 +122,7 @@ export async function invite_user(user_name: string)
|
|||||||
|
|
||||||
export async function get_my_rooms()
|
export async function get_my_rooms()
|
||||||
{
|
{
|
||||||
console.log("in get_my_rooms");
|
to_print("in get_my_rooms");
|
||||||
|
|
||||||
let response: FetchResponse = await fetch_chat_request('myrooms', FetchMethod.GET);
|
let response: FetchResponse = await fetch_chat_request('myrooms', FetchMethod.GET);
|
||||||
|
|
||||||
@@ -132,35 +133,119 @@ export async function get_my_rooms()
|
|||||||
|
|
||||||
export async function get_all_rooms()
|
export async function get_all_rooms()
|
||||||
{
|
{
|
||||||
console.log("in get_all_rooms");
|
to_print("in get_all_rooms");
|
||||||
|
|
||||||
let response: FetchResponse = await fetch_chat_request('allrooms', FetchMethod.GET);
|
let response: FetchResponse = await fetch_chat_request('allrooms', FetchMethod.GET);
|
||||||
|
|
||||||
return response.rooms;
|
return response.rooms;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_room_users()
|
export async function get_room_users(): Promise<User[]>
|
||||||
{
|
{
|
||||||
console.log("in get_room_users");
|
to_print("in get_room_users");
|
||||||
|
|
||||||
let response: FetchResponse = await fetch_chat_request('roomusers', FetchMethod.GET);
|
let response: FetchResponse = await fetch_chat_request('roomusers', FetchMethod.GET);
|
||||||
|
to_print("response from get_room_users:", response);
|
||||||
|
|
||||||
return response.users;
|
return response.users;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_all_users()
|
export async function get_all_users()
|
||||||
{
|
{
|
||||||
console.log("in get_all_users");
|
to_print("in get_all_users");
|
||||||
|
|
||||||
let response: FetchResponse = await fetch_chat_request('users', FetchMethod.GET);
|
let response: FetchResponse = await fetch_chat_request('users', FetchMethod.GET);
|
||||||
|
|
||||||
return response.users;
|
return response.users;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function leave_room()
|
export async function leave_room(): Promise<void>
|
||||||
{
|
{
|
||||||
console.log("in leave_room");
|
to_print("in leave_room");
|
||||||
|
|
||||||
let response: FetchResponse = await fetch_chat_request('leave', FetchMethod.DELETE);
|
let response: FetchResponse = await fetch_chat_request('leave', FetchMethod.DELETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function make_admin(username): Promise<FetchResponse>
|
||||||
|
{
|
||||||
|
to_print("in is_admin");
|
||||||
|
|
||||||
|
to_print("username sent to setadmin:", username);
|
||||||
|
let response: FetchResponse = await fetch_chat_request('setadmin', FetchMethod.POST, {username: username} );
|
||||||
|
to_print("response from setadmin:", response);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function get_is_admin(): Promise<boolean>
|
||||||
|
{
|
||||||
|
to_print("in is_admin");
|
||||||
|
|
||||||
|
let response: FetchResponse = await fetch_chat_request('isadmin', FetchMethod.GET);
|
||||||
|
to_print("is_admin return:", response.condition);
|
||||||
|
|
||||||
|
return response.condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function set_mute(date_limit: Date, username: string, time: string): Promise<FetchResponse>
|
||||||
|
{
|
||||||
|
to_print("in set_mute");
|
||||||
|
|
||||||
|
let body =
|
||||||
|
{
|
||||||
|
mute:
|
||||||
|
{
|
||||||
|
name: username,
|
||||||
|
date: date_limit,
|
||||||
|
},
|
||||||
|
time: time,
|
||||||
|
}
|
||||||
|
|
||||||
|
to_print("setmute send body:", body);
|
||||||
|
let response: FetchResponse = await fetch_chat_request('setmute', FetchMethod.POST, body );
|
||||||
|
to_print("setmute return:", response);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function get_is_mute(username: string): Promise<Mute>
|
||||||
|
{
|
||||||
|
to_print("in get_is_mute");
|
||||||
|
|
||||||
|
let response: FetchResponse = await fetch_chat_request('ismute', FetchMethod.POST, {username: username} );
|
||||||
|
to_print("ismute return:", response);
|
||||||
|
|
||||||
|
return response.mute;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function get_unmute(username: string): Promise<void>
|
||||||
|
{
|
||||||
|
to_print("in get_unmute");
|
||||||
|
|
||||||
|
await fetch_chat_request('unmute', FetchMethod.POST, {username: username} );
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function set_block_user(username: string): Promise<void>
|
||||||
|
{
|
||||||
|
to_print("in set_block_user");
|
||||||
|
|
||||||
|
await fetch_chat_request('block', FetchMethod.POST, {username: username} );
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function remove_block_user(username: string): Promise<void>
|
||||||
|
{
|
||||||
|
to_print("in set_block_user");
|
||||||
|
|
||||||
|
await fetch_chat_request('unblock', FetchMethod.POST, {username: username} );
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function list_block_user(username: string): Promise<string[]>
|
||||||
|
{
|
||||||
|
to_print("in list_block_user");
|
||||||
|
|
||||||
|
let response = await fetch_chat_request('listblock', FetchMethod.GET);
|
||||||
|
to_print("response.users:", response.users);
|
||||||
|
|
||||||
|
return response.users;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { user } from './Store_chat';
|
import { user } from './Store_chat';
|
||||||
import { Room, FetchResponse, FetchInit, FetchMethod } from './Types_chat';
|
import type { Room, FetchResponse, FetchInit, FetchMethod } from './Types_chat';
|
||||||
|
import { to_print } from './Utils_chat';
|
||||||
|
|
||||||
export async function fetch_chat_request(route: string, fetchMethod: FetchMethod, param?: any)
|
export async function fetch_chat_request(route: string, fetchMethod: FetchMethod, param?: any)
|
||||||
{
|
{
|
||||||
console.log("in fetch_chat_request");
|
to_print("in fetch_chat_request");
|
||||||
|
|
||||||
let response: FetchResponse = { status: 0 };
|
let response: FetchResponse = { status: 0 };
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ export async function fetch_chat_request(route: string, fetchMethod: FetchMethod
|
|||||||
|
|
||||||
export function set_client_name_on_room(room: Room)
|
export function set_client_name_on_room(room: Room)
|
||||||
{
|
{
|
||||||
console.log("in set_client_name_on_room");
|
to_print("in set_client_name_on_room");
|
||||||
|
|
||||||
if (room.type === 'direct')
|
if (room.type === 'direct')
|
||||||
{
|
{
|
||||||
@@ -50,7 +51,7 @@ export function set_client_name_on_room(room: Room)
|
|||||||
|
|
||||||
export function fill_fetch_response(response: FetchResponse, data: any)
|
export function fill_fetch_response(response: FetchResponse, data: any)
|
||||||
{
|
{
|
||||||
console.log("in fill_fetch_response");
|
to_print("in fill_fetch_response");
|
||||||
|
|
||||||
Object.keys(data).forEach(key =>
|
Object.keys(data).forEach(key =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
import io from 'socket.io-client';
|
import io from 'socket.io-client';
|
||||||
import { set_socket, set_user } from './Store_chat';
|
import { user, msgs, layout, set_socket, set_user } from './Store_chat';
|
||||||
import { user, msgs } from './Store_chat';
|
import { to_print } from './Utils_chat';
|
||||||
|
|
||||||
const address = `http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}`;
|
const address = `http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}`;
|
||||||
|
|
||||||
export async function init_socket()
|
export async function init_socket()
|
||||||
{
|
{
|
||||||
|
to_print("in init_socket");
|
||||||
|
console.log("here");
|
||||||
const response = await fetch(`${address}/api/v2/user`);
|
const response = await fetch(`${address}/api/v2/user`);
|
||||||
const response_data = await response.json();
|
const response_data = await response.json();
|
||||||
|
to_print("-- response_data:", response_data);
|
||||||
|
|
||||||
set_user(response_data);
|
set_user(response_data);
|
||||||
|
|
||||||
@@ -19,6 +22,7 @@ export async function init_socket()
|
|||||||
username: response_data.username,
|
username: response_data.username,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
console.log("horo");
|
||||||
set_socket(socket);
|
set_socket(socket);
|
||||||
|
|
||||||
socket_states(socket);
|
socket_states(socket);
|
||||||
@@ -29,11 +33,17 @@ function socket_events(socket)
|
|||||||
{
|
{
|
||||||
socket.on('message', function(from, message)
|
socket.on('message', function(from, message)
|
||||||
{
|
{
|
||||||
console.log("received msg:", message, from);
|
to_print("received msg:", message, from);
|
||||||
if (from === user.username)
|
if (from === user.username)
|
||||||
from = "me";
|
from = "me";
|
||||||
msgs.update(msgs => [...msgs, { name: from, message: message }]);
|
msgs.update(msgs => [...msgs, { name: from, message: message }]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('new_password', function()
|
||||||
|
{
|
||||||
|
to_print("notification new password");
|
||||||
|
layout.set("password");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function socket_states(socket)
|
function socket_states(socket)
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
import { Room } from './Types_chat';
|
import type { Room, Message, User } from './Types_chat';
|
||||||
|
|
||||||
export let msgs = writable([]);
|
export let msgs = writable<Message[]>();
|
||||||
|
export let my_rooms = writable<Room[]>();
|
||||||
|
export let all_rooms = writable<Room[]>();
|
||||||
|
export let current_room = writable<Room>();
|
||||||
|
export let settings_user = writable<User>();
|
||||||
export let layout = writable("close");
|
export let layout = writable("close");
|
||||||
export let current_room: Room = writable({
|
|
||||||
name: "",
|
|
||||||
type: "",
|
|
||||||
protection: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
export let user;
|
export let user;
|
||||||
export let socket;
|
export let socket;
|
||||||
|
|||||||
@@ -8,13 +8,37 @@ export interface Room
|
|||||||
allowed?: boolean;
|
allowed?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Mute
|
||||||
|
{
|
||||||
|
name: string;
|
||||||
|
date: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Message
|
||||||
|
{
|
||||||
|
name: string;
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface User
|
||||||
|
{
|
||||||
|
name: string;
|
||||||
|
isadmin: boolean;
|
||||||
|
isblocked: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export interface FetchResponse
|
export interface FetchResponse
|
||||||
{
|
{
|
||||||
status: number;
|
status: number;
|
||||||
error?: boolean;
|
error?: boolean;
|
||||||
code?: string;
|
code?: string;
|
||||||
message?: string;
|
message?: string;
|
||||||
|
messages?: Message[];
|
||||||
|
users?: User[];
|
||||||
room?: Room;
|
room?: Room;
|
||||||
|
rooms?: Room[];
|
||||||
|
condition?: boolean;
|
||||||
|
mute?: Mute;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FetchInit
|
export interface FetchInit
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export function to_print(...args)
|
||||||
|
{
|
||||||
|
console.log(...args);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user