From a1c83dcbc1ef7ec114efcc5fa6585857da22f7cc Mon Sep 17 00:00:00 2001 From: sedeve Date: Wed, 15 Nov 2023 17:41:16 +0100 Subject: [PATCH] add block user even if he is not a friend and status in profile --- backend/code/src/gateways/gateways.gateway.ts | 1 + .../code/src/Components/Profile/index.tsx | 73 +++++++++++++++++++ .../code/src/Components/Settings/index.tsx | 3 - 3 files changed, 74 insertions(+), 3 deletions(-) diff --git a/backend/code/src/gateways/gateways.gateway.ts b/backend/code/src/gateways/gateways.gateway.ts index 7ea63d4..9d5f394 100644 --- a/backend/code/src/gateways/gateways.gateway.ts +++ b/backend/code/src/gateways/gateways.gateway.ts @@ -193,6 +193,7 @@ export class Gateways implements OnGatewayConnection, OnGatewayDisconnect { @SubscribeMessage('status') async handleStatusEvent(@MessageBody() data: any) { + console.log('status event', data); const userId = data.userId; const status = this.server.sockets.adapter.rooms.get(`User:${userId}`)?.size ? 'online' diff --git a/frontend/code/src/Components/Profile/index.tsx b/frontend/code/src/Components/Profile/index.tsx index 6e87130..a1b055f 100644 --- a/frontend/code/src/Components/Profile/index.tsx +++ b/frontend/code/src/Components/Profile/index.tsx @@ -30,6 +30,7 @@ import { BlockedUsersModal } from "../Chat/Components/RoomChatHelpers"; import { blockUserCall } from "../Chat/Services/FriendsServices"; import { AxiosError } from "axios"; import { InvitationWaiting } from "../Layout/Assets/Invitationacceptance"; +import { classNames } from "../../Utils/helpers"; type FRIENDSHIP = "none" | "friend" | "sent" | "recive" | "blocked" | undefined; export const Profile = () => { const user = useUserStore(); @@ -42,6 +43,7 @@ export const Profile = () => { const ChatState = useChatStore(); const LayoutState = useModalStore(); const socketStore = useSocketStore(); + const [onlineStatus, setOnlineStatus] = useState("offline"); const inviteWaitingModalRef = useRef(null); useEffect(() => { @@ -72,6 +74,27 @@ export const Profile = () => { //eslint-disable-next-line }, [params, user]); + + useEffect(() => { + if (params.id === "me" || params.id === user.id) { + return; + } + socketStore?.socket?.emit( + "status", + { userId: params.id }, + (data: { status: string; inGame: boolean }) => { + console.log(data); + if (data.status === "online" && !data.inGame) { + setOnlineStatus("online"); + } else if (data.status === "online" && data.inGame) { + setOnlineStatus("inGame"); + } else { + setOnlineStatus("offline"); + } + }, + ); + }, [params.id, socketStore?.socket, user.id]); + console.log(status); const sendRequest = async () => { setDisabled("btn-disabled"); @@ -164,6 +187,23 @@ export const Profile = () => { ) : ( )} + + {params.id !== "me" && + params.id !== user.id && + status === "friend" && ( + + {onlineStatus} + + )}
@@ -202,6 +242,39 @@ export const Profile = () => { Send request +
+ +
    + +
  • { + ChatState.setIsLoading(true); + await blockUserCall(profile.id).then((res) => { + ChatState.setIsLoading(false); + if ( + res?.status === 200 || + res?.status === 201 + ) { + toast.success("User Blocked"); + navigate("/chat"); + } else { + toast.error("Could Not Block User"); + } + }); + }} + > +
    Block
    +
  • +
    +
+
)} {params.id !== "me" && diff --git a/frontend/code/src/Components/Settings/index.tsx b/frontend/code/src/Components/Settings/index.tsx index 6851e31..7f7fc8e 100644 --- a/frontend/code/src/Components/Settings/index.tsx +++ b/frontend/code/src/Components/Settings/index.tsx @@ -44,7 +44,6 @@ export const Setting = () => { Profile Settings
-

change preview

@@ -89,7 +88,6 @@ export const Setting = () => {
-

change preview

@@ -108,7 +106,6 @@ export const Setting = () => {
-

change preview