mute almost done, still changing layout
This commit is contained in:
@@ -462,8 +462,6 @@ export class ChatController {
|
||||
{
|
||||
printCaller("- in ");
|
||||
|
||||
console.log("mute:", mute);
|
||||
|
||||
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||
await this.chatService.addMute(req.user.username, room_name, mute);
|
||||
|
||||
@@ -476,11 +474,51 @@ export class ChatController {
|
||||
//await server.to(socket.id).emit('muted');
|
||||
|
||||
const room = await this.chatService.getRoomByName(room_name);
|
||||
console.log("room:", room);
|
||||
|
||||
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);
|
||||
|
||||
res.status(HttpStatus.OK).json({ message: "successfull unmute" });
|
||||
printCaller("- out ");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -519,9 +519,13 @@ export class ChatService {
|
||||
let current_mute = current_room.mutes.find(mute => mute.name === socket.username);
|
||||
if (current_mute)
|
||||
{
|
||||
const date_now = new Date();
|
||||
const date_mute = new Date(current_mute.date);
|
||||
const date_diff = date_mute.getTime() - date_now.getTime();
|
||||
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");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IsNotEmpty, IsString, IsDate } from "class-validator";
|
||||
import { IsNotEmpty, IsString, IsDate, IsOptional } from "class-validator";
|
||||
|
||||
export class muteDto
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
|
||||
import { layout, settings_user } from './Store_chat';
|
||||
import { setMute } from './Request_rooms';
|
||||
import { set_mute, get_is_mute, get_unmute } from './Request_rooms';
|
||||
import Button from './Element_button.svelte';
|
||||
import Warning from './Element_warning.svelte';
|
||||
|
||||
@@ -9,11 +9,33 @@
|
||||
|
||||
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.date)
|
||||
{
|
||||
is_mute = true;
|
||||
mute_date = response.date;
|
||||
}
|
||||
if (mute_date)
|
||||
date_string = stringify_date(new Date(mute_date));
|
||||
else
|
||||
date_string = "eternity";
|
||||
date_string = date_string;
|
||||
});
|
||||
|
||||
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();
|
||||
@@ -21,53 +43,38 @@
|
||||
if (!formIsValid)
|
||||
return;
|
||||
|
||||
console.log("is_forever:", is_forever);
|
||||
console.log("minutes:", minutes);
|
||||
console.log("hours:", hours);
|
||||
console.log("days:", days);
|
||||
|
||||
let duration = minutes * (1000 * 60) + hours * (1000 * 60 * 60) + days * (1000 * 60 * 60 * 24);
|
||||
console.log("duration:", duration);
|
||||
let date_limit: Date;
|
||||
let time: string;
|
||||
|
||||
let date_start = new Date();
|
||||
let date_limit = new Date(date_start.getTime() + duration);
|
||||
let time: string = `${date_limit.getFullYear()}/${date_limit.getMonth() + 1}/${date_limit.getDate()} at ${date_limit.getHours()}:${date_limit.getMinutes()}`;
|
||||
console.log("time:", time);
|
||||
if (is_forever)
|
||||
time = "eternity";
|
||||
else
|
||||
{
|
||||
let duration = minutes * (1000 * 60) + hours * (1000 * 60 * 60) + days * (1000 * 60 * 60 * 24);
|
||||
console.log("duration:", duration);
|
||||
|
||||
response = await setMute(date_limit, $settings_user, time);
|
||||
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");
|
||||
|
||||
/*
|
||||
function remaining_time()
|
||||
{
|
||||
const seconds_elem = document.getElementById("add");
|
||||
const seconds_value = seconds_elem.value;
|
||||
if (seconds_value)
|
||||
{
|
||||
date_start = new Date();
|
||||
date_limit = new Date(date_start.getTime() + seconds_value * 1000);
|
||||
seconds_elem.value = "";
|
||||
}
|
||||
else if (!date_start)
|
||||
return;
|
||||
|
||||
const now_date = new Date();
|
||||
const date_diff = date_limit - now_date;
|
||||
|
||||
const diff = `
|
||||
${Math.floor(date_diff / (1000 * 1 * 60 * 60 * 24))}d
|
||||
${Math.floor(date_diff / (1000 * 1 * 60 * 60))}h
|
||||
${Math.floor(date_diff / (1000 * 1 * 60))}m
|
||||
${Math.floor(date_diff / (1000 * 1))}s`;
|
||||
document.getElementById("limit").innerHTML = diff.toString();
|
||||
|
||||
document.getElementById("remains").innerHTML = date_diff > 0;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
async function unmute()
|
||||
{
|
||||
get_unmute($settings_user);
|
||||
layout.set("room");
|
||||
}
|
||||
|
||||
</script>
|
||||
@@ -94,157 +101,164 @@
|
||||
{#if show_error}
|
||||
<Warning content={response.message}/>
|
||||
{/if}
|
||||
<p class="__center">mute this user for a time :</p>
|
||||
<form on:submit|preventDefault={handleSubmit}>
|
||||
<!-- forever -->
|
||||
<input id="chat_mute_forever" class="__check_change_next" type="checkbox">
|
||||
<label for="chat_mute_forever" class="_checkbox"><p>forever</p></label>
|
||||
<div class="__to_block">
|
||||
<!-- minutes -->
|
||||
<label for="chat_mute_minutes" class="_select">
|
||||
<p>minutes :</p>
|
||||
<select id="chat_mute_minutes" bind:value={minutes}>
|
||||
<option>00</option>
|
||||
<option>01</option>
|
||||
<option>02</option>
|
||||
<option>03</option>
|
||||
<option>04</option>
|
||||
<option>05</option>
|
||||
<option>06</option>
|
||||
<option>07</option>
|
||||
<option>10</option>
|
||||
<option>11</option>
|
||||
<option>12</option>
|
||||
<option>13</option>
|
||||
<option>14</option>
|
||||
<option>15</option>
|
||||
<option>16</option>
|
||||
<option>17</option>
|
||||
<option>20</option>
|
||||
<option>21</option>
|
||||
<option>22</option>
|
||||
<option>23</option>
|
||||
<option>24</option>
|
||||
<option>25</option>
|
||||
<option>26</option>
|
||||
<option>27</option>
|
||||
<option>30</option>
|
||||
<option>31</option>
|
||||
<option>32</option>
|
||||
<option>33</option>
|
||||
<option>34</option>
|
||||
<option>35</option>
|
||||
<option>36</option>
|
||||
<option>37</option>
|
||||
<option>40</option>
|
||||
<option>41</option>
|
||||
<option>42</option>
|
||||
<option>43</option>
|
||||
<option>44</option>
|
||||
<option>45</option>
|
||||
<option>46</option>
|
||||
<option>47</option>
|
||||
<option>50</option>
|
||||
<option>51</option>
|
||||
<option>52</option>
|
||||
<option>53</option>
|
||||
<option>54</option>
|
||||
<option>55</option>
|
||||
<option>56</option>
|
||||
<option>57</option>
|
||||
<option>60</option>
|
||||
</select>
|
||||
</label>
|
||||
<!-- hours -->
|
||||
<label for="chat_mute_hours" class="_select">
|
||||
<p>hours :</p>
|
||||
<select id="chat_mute_hours">
|
||||
<option>00</option>
|
||||
<option>01</option>
|
||||
<option>02</option>
|
||||
<option>03</option>
|
||||
<option>04</option>
|
||||
<option>05</option>
|
||||
<option>06</option>
|
||||
<option>07</option>
|
||||
<option>10</option>
|
||||
<option>11</option>
|
||||
<option>12</option>
|
||||
<option>13</option>
|
||||
<option>14</option>
|
||||
<option>15</option>
|
||||
<option>16</option>
|
||||
<option>17</option>
|
||||
<option>20</option>
|
||||
<option>21</option>
|
||||
<option>22</option>
|
||||
<option>23</option>
|
||||
<option>24</option>
|
||||
<option>25</option>
|
||||
<option>26</option>
|
||||
<option>27</option>
|
||||
<option>30</option>
|
||||
<option>31</option>
|
||||
<option>32</option>
|
||||
<option>33</option>
|
||||
<option>34</option>
|
||||
<option>35</option>
|
||||
<option>36</option>
|
||||
<option>37</option>
|
||||
<option>40</option>
|
||||
<option>41</option>
|
||||
<option>42</option>
|
||||
<option>43</option>
|
||||
<option>44</option>
|
||||
<option>45</option>
|
||||
<option>46</option>
|
||||
<option>47</option>
|
||||
<option>50</option>
|
||||
<option>51</option>
|
||||
<option>52</option>
|
||||
<option>53</option>
|
||||
<option>54</option>
|
||||
<option>55</option>
|
||||
<option>56</option>
|
||||
<option>57</option>
|
||||
<option>60</option>
|
||||
</select>
|
||||
</label>
|
||||
<!-- days -->
|
||||
<label for="chat_mute_days" class="_select">
|
||||
<p>days :</p>
|
||||
<select id="chat_mute_days">
|
||||
<option>00</option>
|
||||
<option>01</option>
|
||||
<option>02</option>
|
||||
<option>03</option>
|
||||
<option>04</option>
|
||||
<option>05</option>
|
||||
<option>06</option>
|
||||
<option>07</option>
|
||||
<option>10</option>
|
||||
<option>11</option>
|
||||
<option>12</option>
|
||||
<option>13</option>
|
||||
<option>14</option>
|
||||
<option>15</option>
|
||||
<option>16</option>
|
||||
<option>17</option>
|
||||
<option>20</option>
|
||||
<option>21</option>
|
||||
<option>22</option>
|
||||
<option>23</option>
|
||||
<option>24</option>
|
||||
<option>25</option>
|
||||
<option>26</option>
|
||||
<option>27</option>
|
||||
<option>30</option>
|
||||
<option>31</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<input type="submit" value="⮡">
|
||||
</form>
|
||||
{#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>
|
||||
<!-- forever -->
|
||||
<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>
|
||||
<div class="__to_block">
|
||||
<!-- minutes -->
|
||||
<label for="chat_mute_minutes" class="_select">
|
||||
<p>minutes :</p>
|
||||
<select id="chat_mute_minutes" bind:value={minutes}>
|
||||
<option>00</option>
|
||||
<option>01</option>
|
||||
<option>02</option>
|
||||
<option>03</option>
|
||||
<option>04</option>
|
||||
<option>05</option>
|
||||
<option>06</option>
|
||||
<option>07</option>
|
||||
<option>10</option>
|
||||
<option>11</option>
|
||||
<option>12</option>
|
||||
<option>13</option>
|
||||
<option>14</option>
|
||||
<option>15</option>
|
||||
<option>16</option>
|
||||
<option>17</option>
|
||||
<option>20</option>
|
||||
<option>21</option>
|
||||
<option>22</option>
|
||||
<option>23</option>
|
||||
<option>24</option>
|
||||
<option>25</option>
|
||||
<option>26</option>
|
||||
<option>27</option>
|
||||
<option>30</option>
|
||||
<option>31</option>
|
||||
<option>32</option>
|
||||
<option>33</option>
|
||||
<option>34</option>
|
||||
<option>35</option>
|
||||
<option>36</option>
|
||||
<option>37</option>
|
||||
<option>40</option>
|
||||
<option>41</option>
|
||||
<option>42</option>
|
||||
<option>43</option>
|
||||
<option>44</option>
|
||||
<option>45</option>
|
||||
<option>46</option>
|
||||
<option>47</option>
|
||||
<option>50</option>
|
||||
<option>51</option>
|
||||
<option>52</option>
|
||||
<option>53</option>
|
||||
<option>54</option>
|
||||
<option>55</option>
|
||||
<option>56</option>
|
||||
<option>57</option>
|
||||
<option>60</option>
|
||||
</select>
|
||||
</label>
|
||||
<!-- hours -->
|
||||
<label for="chat_mute_hours" class="_select">
|
||||
<p>hours :</p>
|
||||
<select id="chat_mute_hours">
|
||||
<option>00</option>
|
||||
<option>01</option>
|
||||
<option>02</option>
|
||||
<option>03</option>
|
||||
<option>04</option>
|
||||
<option>05</option>
|
||||
<option>06</option>
|
||||
<option>07</option>
|
||||
<option>10</option>
|
||||
<option>11</option>
|
||||
<option>12</option>
|
||||
<option>13</option>
|
||||
<option>14</option>
|
||||
<option>15</option>
|
||||
<option>16</option>
|
||||
<option>17</option>
|
||||
<option>20</option>
|
||||
<option>21</option>
|
||||
<option>22</option>
|
||||
<option>23</option>
|
||||
<option>24</option>
|
||||
<option>25</option>
|
||||
<option>26</option>
|
||||
<option>27</option>
|
||||
<option>30</option>
|
||||
<option>31</option>
|
||||
<option>32</option>
|
||||
<option>33</option>
|
||||
<option>34</option>
|
||||
<option>35</option>
|
||||
<option>36</option>
|
||||
<option>37</option>
|
||||
<option>40</option>
|
||||
<option>41</option>
|
||||
<option>42</option>
|
||||
<option>43</option>
|
||||
<option>44</option>
|
||||
<option>45</option>
|
||||
<option>46</option>
|
||||
<option>47</option>
|
||||
<option>50</option>
|
||||
<option>51</option>
|
||||
<option>52</option>
|
||||
<option>53</option>
|
||||
<option>54</option>
|
||||
<option>55</option>
|
||||
<option>56</option>
|
||||
<option>57</option>
|
||||
<option>60</option>
|
||||
</select>
|
||||
</label>
|
||||
<!-- days -->
|
||||
<label for="chat_mute_days" class="_select">
|
||||
<p>days :</p>
|
||||
<select id="chat_mute_days">
|
||||
<option>00</option>
|
||||
<option>01</option>
|
||||
<option>02</option>
|
||||
<option>03</option>
|
||||
<option>04</option>
|
||||
<option>05</option>
|
||||
<option>06</option>
|
||||
<option>07</option>
|
||||
<option>10</option>
|
||||
<option>11</option>
|
||||
<option>12</option>
|
||||
<option>13</option>
|
||||
<option>14</option>
|
||||
<option>15</option>
|
||||
<option>16</option>
|
||||
<option>17</option>
|
||||
<option>20</option>
|
||||
<option>21</option>
|
||||
<option>22</option>
|
||||
<option>23</option>
|
||||
<option>24</option>
|
||||
<option>25</option>
|
||||
<option>26</option>
|
||||
<option>27</option>
|
||||
<option>30</option>
|
||||
<option>31</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<input type="submit" value="⮡">
|
||||
</form>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { msgs, user, layout, socket, current_room } from './Store_chat';
|
||||
import type { Room, FetchResponse } from './Types_chat';
|
||||
import { FetchMethod } from './Types_chat';
|
||||
import { FetchMethod, Mute } from './Types_chat';
|
||||
import { to_print } from './Utils_chat';
|
||||
import { fetch_chat_request, set_client_name_on_room, fill_fetch_response } from './Request_utils';
|
||||
|
||||
@@ -122,7 +122,7 @@ export async function invite_user(user_name: string)
|
||||
|
||||
export async function get_my_rooms()
|
||||
{
|
||||
to_print("-------------------------------------------------------------------------------------------------------in get_my_rooms");
|
||||
to_print("in get_my_rooms");
|
||||
|
||||
let response: FetchResponse = await fetch_chat_request('myrooms', FetchMethod.GET);
|
||||
|
||||
@@ -186,9 +186,9 @@ to_print("is_admin return:", response.is_admin);
|
||||
return response.is_admin;
|
||||
}
|
||||
|
||||
export async function setMute(date_limit: Date, username: string, time: string): Promise<FetchResponse>
|
||||
export async function set_mute(date_limit: Date, username: string, time: string): Promise<FetchResponse>
|
||||
{
|
||||
to_print("in is_admin");
|
||||
to_print("in set_mute");
|
||||
|
||||
let body =
|
||||
{
|
||||
@@ -207,3 +207,20 @@ 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} );
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,12 @@ export interface Room
|
||||
allowed?: boolean;
|
||||
}
|
||||
|
||||
export interface Mute
|
||||
{
|
||||
name: string;
|
||||
date: Date;
|
||||
}
|
||||
|
||||
export interface Message
|
||||
{
|
||||
name: string;
|
||||
@@ -31,6 +37,7 @@ export interface FetchResponse
|
||||
room?: Room;
|
||||
rooms?: Room[];
|
||||
is_admin?: boolean;
|
||||
mute?: Mute;
|
||||
}
|
||||
|
||||
export interface FetchInit
|
||||
|
||||
Reference in New Issue
Block a user