diff --git a/containers/api/src/app.controller.ts b/containers/api/src/app.controller.ts
index e652ec46..b1692d3a 100644
--- a/containers/api/src/app.controller.ts
+++ b/containers/api/src/app.controller.ts
@@ -76,6 +76,15 @@ export class AppController {
return await this.userService.addFriend(user, data.username);
}
+ @UseGuards(JwtAuthGuard)
+ @Post('/block')
+ async newBlocked(@Request() req, @Body() data: any) {
+ // return await this.userService.getFriends(req.user.username);
+ console.log(`user= ${req.user.username}`)
+ const user = await this.userService.findOne(req.user.username)
+ return await this.userService.addBlocked(user, data.username);
+ }
+
@UseGuards(JwtAuthGuard)
@Get('/invite')
async getInvite(@Request() req) {
@@ -317,13 +326,20 @@ export class AppController {
//========================================================================================================
//========================================================================================================
+ @UseGuards(JwtAuthGuard)
@Post('/conv')
async createConv(@Request() req, @Body() data: any) {
///create conv and return it ? id?
console.log(`data post /conv= ${data}`);
console.log(`data post /conv= ${data.members}`);
console.log(`data post /conv= ${data.name}`);
+
+ // const param = data;
+ const amIhere = data.members.includes(req.user.username);
+ if (!amIhere)
+ data.members.push(req.user.username)
// let test = {id: 2, members: "cc"};
+ data.owner = req.user.username
return await this.chatService.createConv(data);
// res.json(messages);
}
diff --git a/containers/api/src/auth/login42.ts b/containers/api/src/auth/login42.ts
index 929afb39..da09b7f3 100644
--- a/containers/api/src/auth/login42.ts
+++ b/containers/api/src/auth/login42.ts
@@ -73,6 +73,7 @@ export class loginClass {
otp_verified: false,
friendRequest: null,
friends: null,
+ blocked: null,
photo: null,
};
await this.usersService.create(user);
diff --git a/containers/api/src/model/chat.entity.ts b/containers/api/src/model/chat.entity.ts
index 246197ac..eb483c35 100644
--- a/containers/api/src/model/chat.entity.ts
+++ b/containers/api/src/model/chat.entity.ts
@@ -8,7 +8,7 @@ import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, BaseEntity }
@Column('text', { array: true, nullable: true })
members: string[];
- @Column({ nullable: true })
+ @Column({ default: "Unnamed Conv" })
name: string
@Column({ nullable: true })
@@ -17,11 +17,14 @@ import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, BaseEntity }
// @Column()
// members: string;// arry ??? one to many ???
- @Column({ nullable: true })
- banned: string;// arry ??? one to many ???
+ @Column('text', { array: true, nullable: true })
+ banned: string[];
+
+ @Column('text', { array: true, nullable: true })
+ admin: string[];
@Column({ nullable: true })
- admin: string;// arry ??? one to many ???
+ owner: string;
@Column({ nullable: true })
messages: string;
diff --git a/containers/api/src/model/user.entity.ts b/containers/api/src/model/user.entity.ts
index 1928c9fa..5ddd7709 100644
--- a/containers/api/src/model/user.entity.ts
+++ b/containers/api/src/model/user.entity.ts
@@ -68,6 +68,9 @@ export class User {
@Column('text', { array: true, nullable: true })
friends: string[];
+ @Column('text', { array: true, nullable: true })
+ blocked: string[];
+
@OneToMany(() => MatchLog, (child) => child.parent, { eager: true })
children: MatchLog[];
diff --git a/containers/api/src/users/users.service.ts b/containers/api/src/users/users.service.ts
index 433cea6f..b8761fcf 100644
--- a/containers/api/src/users/users.service.ts
+++ b/containers/api/src/users/users.service.ts
@@ -79,9 +79,21 @@ export class UsersService {
}
async addFriend(user: User, username: string) {
+ if (!(await this.findOne(username)))
+ return (0);
user.friends = user.friends || [];
user.friends.push(username);
this.save(user);
+ return (1);
+ }
+
+ async addBlocked(user: User, username: string) {
+ if (!(await this.findOne(username)))
+ return (0);
+ user.blocked = user.blocked || [];
+ user.blocked.push(username);
+ this.save(user);
+ return (1);
}
async getRanking() {
diff --git a/containers/react/src/components/Alert/GreenAlert.jsx b/containers/react/src/components/Alert/GreenAlert.jsx
index cded387b..4cd27860 100644
--- a/containers/react/src/components/Alert/GreenAlert.jsx
+++ b/containers/react/src/components/Alert/GreenAlert.jsx
@@ -31,7 +31,7 @@ function GreenAlert ({handleClose, text}){
{text}
- {setTimeout(handleClose, 3000)} + {setTimeout(handleClose, 1500)} ) } diff --git a/containers/react/src/components/Alert/RedAlert.jsx b/containers/react/src/components/Alert/RedAlert.jsx index 3a9104b1..1a61f27d 100644 --- a/containers/react/src/components/Alert/RedAlert.jsx +++ b/containers/react/src/components/Alert/RedAlert.jsx @@ -30,7 +30,7 @@ function RedAlert ({handleClose, text}) {{text}
- {setTimeout(handleClose, 3000)} + {setTimeout(handleClose, 1500)} ) } diff --git a/containers/react/src/components/Messages/Chats.jsx b/containers/react/src/components/Messages/Chats.jsx index 0fbf3230..b694b9ae 100644 --- a/containers/react/src/components/Messages/Chats.jsx +++ b/containers/react/src/components/Messages/Chats.jsx @@ -224,38 +224,75 @@ function Chats(){ } } + + const [friend, setFriend] = useState(""); const [modalOpen, setModalOpen] = useState(false); const [addFriend, setAddFriend] = useState(false); const [block, setBlock] = useState(false); + + const [showAddFriendAlert, setShowAddFriendAlert] = useState(false); + const [showBlockAlert, setShowBlockAlert] = useState(false); + const close = () => setModalOpen(false); const open = () => setModalOpen(true); - const closeAddFriend = () => setAddFriend(false); - const closeBlock = () => setBlock(false); - const handleFriend = e => { - setFriend(e.target.value) - }; + // const closeAddFriend = () => setAddFriend(false); + // const closeBlock = () => setBlock(false); - // const findValue = () => { - // // setFind(false); - // console.log(friend); - // Rank.map((tab) => { - // if (tab.name === friend) - // { - // console.log("ok bon"); - // setFind(true); - // } - // }) - // console.log(find); - // // if (!find) - // }; + + const handleFriend = (event) => { + setFriend(event.target.value); + }; - // console.log(`data user1= ${user.username}`) - - // while (user === null) - // ; + const handleAddFriend = async () => { + try{ + const res = await api.post("/friend", {username: friend}) + // if (res.data === 1) + // console.log("res in friend= ", res) + console.log("res in friend= ", res.data) + if(res.data === 1) + { + setAddFriend(true); + setBlock(false); // Reset block state + setShowBlockAlert(false); + } + else + setAddFriend(false); + setShowAddFriendAlert(true); + } catch(err) { + console.log(err) + } + }; + + const handleBlockFriend = async () => { + try{ + const res = await api.post("/block", {username: friend}) + // if(1) + if (res.data === 1) + { + setBlock(true); + setAddFriend(false); // Reset addFriend state + setShowAddFriendAlert(false); + } + else + setBlock(false); + setShowBlockAlert(true); + } catch(err) { + console.log(err) + } + }; + + const closeAddFriend = () => { + setAddFriend(false); + setShowAddFriendAlert(false); + }; + + const closeBlock = () => { + setBlock(false); + setShowBlockAlert(false); + }; //======================================================================================================== @@ -290,13 +327,17 @@ function Chats(){New Convewrstion
+ {/*New Conversation
*/} -{/* First selection */} + {selectTags.map((selectTag) => ( +