unbanned unblocked
This commit is contained in:
parent
80ff5f6c9f
commit
ba60337c71
@ -3,10 +3,10 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* app.controller.ts :+: :+: :+: */
|
/* app.controller.ts :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/06/17 01:00:00 by apommier #+# #+# */
|
/* Created: 2023/06/17 01:00:00 by apommier #+# #+# */
|
||||||
/* Updated: 2023/06/25 00:10:18 by apommier ### ########.fr */
|
/* Updated: 2023/06/26 02:19:48 by sadjigui ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
@ -3,10 +3,10 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* chat.service.ts :+: :+: :+: */
|
/* chat.service.ts :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/06/17 01:00:25 by apommier #+# #+# */
|
/* Created: 2023/06/17 01:00:25 by apommier #+# #+# */
|
||||||
/* Updated: 2023/06/24 18:47:59 by apommier ### ########.fr */
|
/* Updated: 2023/06/26 02:21:38 by sadjigui ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -84,10 +84,15 @@ async banUser(convId: number, username: string) {
|
|||||||
|
|
||||||
conv.banned = conv.banned || [];
|
conv.banned = conv.banned || [];
|
||||||
if (conv.banned.find(item => item === username))
|
if (conv.banned.find(item => item === username))
|
||||||
return (1);
|
{
|
||||||
|
conv.banned = conv.banned.filter((item) => item !== username);
|
||||||
|
this.save(conv);
|
||||||
|
return (2);
|
||||||
|
}
|
||||||
conv.members = conv.members.filter((item) => item !== username);
|
conv.members = conv.members.filter((item) => item !== username);
|
||||||
conv.banned.push(username);
|
conv.banned.push(username);
|
||||||
this.save(conv);
|
this.save(conv);
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
async inviteUser(convId: number, username: string) {
|
async inviteUser(convId: number, username: string) {
|
||||||
|
|||||||
@ -3,10 +3,10 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* users.service.ts :+: :+: :+: */
|
/* users.service.ts :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/06/17 01:00:07 by apommier #+# #+# */
|
/* Created: 2023/06/17 01:00:07 by apommier #+# #+# */
|
||||||
/* Updated: 2023/06/24 23:30:52 by apommier ### ########.fr */
|
/* Updated: 2023/06/26 02:23:16 by sadjigui ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -143,7 +143,11 @@ export class UsersService {
|
|||||||
return (0);
|
return (0);
|
||||||
user.blocked = user.blocked || [];
|
user.blocked = user.blocked || [];
|
||||||
if (user.blocked.find(item => item === username))
|
if (user.blocked.find(item => item === username))
|
||||||
return (1);
|
{
|
||||||
|
this.save(user);
|
||||||
|
user.blocked = user.blocked.filter((item) => item !== username);
|
||||||
|
return (2);
|
||||||
|
}
|
||||||
user.blocked.push(username);
|
user.blocked.push(username);
|
||||||
this.save(user);
|
this.save(user);
|
||||||
return (1);
|
return (1);
|
||||||
|
|||||||
@ -251,25 +251,27 @@ function Chats(){
|
|||||||
return ;
|
return ;
|
||||||
handleSubmit(e);
|
handleSubmit(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const [friend, setFriend] = useState("");
|
const [friend, setFriend] = useState("");
|
||||||
// const [modalOpen, setModalOpen] = useState(false);
|
// const [modalOpen, setModalOpen] = useState(false);
|
||||||
const [addFriend, setAddFriend] = useState(false);
|
const [addFriend, setAddFriend] = useState(false);
|
||||||
const [block, setBlock] = useState(false);
|
const [block, setBlock] = useState(false);
|
||||||
|
|
||||||
const [showAddFriendAlert, setShowAddFriendAlert] = useState(false);
|
const [showAddFriendAlert, setShowAddFriendAlert] = useState(false);
|
||||||
const [showBlockAlert, setShowBlockAlert] = useState(false);
|
const [showBlockAlert, setShowBlockAlert] = useState(false);
|
||||||
|
|
||||||
const [setting, setSetting] = useState(false);
|
const [setting, setSetting] = useState(false);
|
||||||
|
|
||||||
const [newGameModalOpen, setNewGameModalOpen] = useState(false);
|
const [newGameModalOpen, setNewGameModalOpen] = useState(false);
|
||||||
const [newConversationModalOpen, setNewConversationModalOpen] = useState(false);
|
const [newConversationModalOpen, setNewConversationModalOpen] = useState(false);
|
||||||
|
|
||||||
const [selectTags, setSelectTag] = useState([{ id: 1, selectedOption: ''}]);
|
const [selectTags, setSelectTag] = useState([{ id: 1, selectedOption: ''}]);
|
||||||
const [users, setUsers] = useState<User[]>([]);
|
const [users, setUsers] = useState<User[]>([]);
|
||||||
|
|
||||||
|
const [unblock, setUnblock] = useState(false);
|
||||||
|
const closeUnblock = () => setUnblock(false);
|
||||||
|
|
||||||
const openNewGameModal = () => {
|
const openNewGameModal = () => {
|
||||||
setNewGameModalOpen(true);
|
setNewGameModalOpen(true);
|
||||||
@ -323,10 +325,13 @@ function Chats(){
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleBlockFriend = async () => {
|
const handleBlockFriend = async () => {
|
||||||
try{
|
try{
|
||||||
const res = await api.post("/block", {username: friend})
|
const res = await api.post("/block", {username: friend})
|
||||||
// if(1)
|
// if(1)
|
||||||
|
if (res.data === 2)
|
||||||
|
setUnblock(true);
|
||||||
if (res.data === 1)
|
if (res.data === 1)
|
||||||
{
|
{
|
||||||
setBlock(true);
|
setBlock(true);
|
||||||
@ -469,6 +474,9 @@ function Chats(){
|
|||||||
{showBlockAlert && !block && (
|
{showBlockAlert && !block && (
|
||||||
<RedAlert handleClose={closeBlock} text={friend + ' was not found'} />
|
<RedAlert handleClose={closeBlock} text={friend + ' was not found'} />
|
||||||
)}
|
)}
|
||||||
|
{unblock ? (
|
||||||
|
<GreenAlert handleClose={closeUnblock} text={friend + ' was unblocked'} />
|
||||||
|
):("")}
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
</TouchDiv>
|
</TouchDiv>
|
||||||
{currentChat && isAdmin ? (
|
{currentChat && isAdmin ? (
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { motion } from "framer-motion";
|
import { AnimatePresence, motion } from "framer-motion";
|
||||||
import Backdrop from "../Sidebar/Backdrop.tsx";
|
import Backdrop from "../Sidebar/Backdrop.tsx";
|
||||||
// import { Rank } from "../../DataBase/DataRank"
|
// import { Rank } from "../../DataBase/DataRank"
|
||||||
import '../../styles/Messages.css'
|
import '../../styles/Messages.css'
|
||||||
@ -9,6 +9,7 @@ import api from "../../script/axiosApi.tsx";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import {User} from "../../../interfaces.tsx"
|
import {User} from "../../../interfaces.tsx"
|
||||||
import { Socket } from "socket.io-client";
|
import { Socket } from "socket.io-client";
|
||||||
|
import GreenAlert from "../Alert/GreenAlert.tsx";
|
||||||
|
|
||||||
|
|
||||||
const dropIn = {
|
const dropIn = {
|
||||||
@ -161,13 +162,18 @@ const ModalSetting = ({handleClose, convId, socket }: ModalSettingProps) => {
|
|||||||
handleClose();
|
handleClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const [unban, setUnban] = useState(false);
|
||||||
|
const closeUnban = () => setUnban(false);
|
||||||
const handleBan = async () => {
|
const handleBan = async () => {
|
||||||
// console.log("ban option= ", selectedUser)
|
// console.log("ban option= ", selectedUser)
|
||||||
try{
|
try{
|
||||||
// console.log("user select=", selectedUser.length)
|
// console.log("user select=", selectedUser.length)
|
||||||
if (!selectedUser.length)
|
if (!selectedUser.length)
|
||||||
return ;
|
return ;
|
||||||
await api.post("/ban", {convId: convId, username: selectedUser})
|
const res = await api.post("/ban", {convId: convId, username: selectedUser})
|
||||||
|
if (res.data === 2)
|
||||||
|
setUnban(true);
|
||||||
|
|
||||||
if (socket)
|
if (socket)
|
||||||
{
|
{
|
||||||
console.log("emit to ban server")
|
console.log("emit to ban server")
|
||||||
@ -293,7 +299,7 @@ const ModalSetting = ({handleClose, convId, socket }: ModalSettingProps) => {
|
|||||||
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<Link to="#" onClick={handleInvite} className="submit">Send</Link>
|
<Link to="#" onClick={handleInvite} className="submit">Invite</Link>
|
||||||
<Link to="#" onClick={handleBan} className="submit">Ban</Link>
|
<Link to="#" onClick={handleBan} className="submit">Ban</Link>
|
||||||
<Link to="#" onClick={mute ? darkMute : lightMute} className={mute ? "darkSubmit": "submit"}>Mute</Link>
|
<Link to="#" onClick={mute ? darkMute : lightMute} className={mute ? "darkSubmit": "submit"}>Mute</Link>
|
||||||
<Link to="#" onClick={handleAdmin} className="submit">Admin</Link>
|
<Link to="#" onClick={handleAdmin} className="submit">Admin</Link>
|
||||||
@ -310,6 +316,11 @@ const ModalSetting = ({handleClose, convId, socket }: ModalSettingProps) => {
|
|||||||
onChange={(e) => setTime(e.target.value)}
|
onChange={(e) => setTime(e.target.value)}
|
||||||
/>
|
/>
|
||||||
):("")}
|
):("")}
|
||||||
|
<AnimatePresence initial={false} onExitComplete={() => null}>
|
||||||
|
{unban ? (
|
||||||
|
<GreenAlert handleClose={closeUnban} text={selectedUser+": was unbanned"} />
|
||||||
|
): ("")}
|
||||||
|
</AnimatePresence>
|
||||||
|
|
||||||
</motion.div>
|
</motion.div>
|
||||||
</Backdrop>
|
</Backdrop>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user