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