Skip to content

Commit

Permalink
Fix: Remove some bugs from chat context (#110)
Browse files Browse the repository at this point in the history
* fix: remove bugs

- remove bug for chat gateway
- fix bug where user was able to find promote to admin button

* fix: remove a few more bugs from chat

- add mute block handler when trying to send messages when the user is muted
- simplify channelpopover handler logic

---------

Co-authored-by: Italo A <[email protected]>
  • Loading branch information
vcwild and iaurg authored Nov 22, 2023
1 parent 829839b commit 05ca1d7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion backend/src/chat/chat.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,11 @@ export class ChatGateway
async demoteToMember(
@MessageBody('user') user: string,
@MessageBody('chatId', new ParseIntPipe()) chatId: number,
@ConnectedSocket() client: Socket,
) {
const login = client.handshake.auth?.user?.login;
const member = await this.chatService.getMemberFromChat(chatId, user);
const you = await this.chatService.getMemberFromChat(chatId, user);
const you = await this.chatService.getMemberFromChat(chatId, login);
if (!member || !you) {
this.logger.error('User not found');
return;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Chat/ChatUsersChannelPopOver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default function ChatUsersChannelPopOver({
modifiers: [{ name: "arrow", options: { element: arrowElement } }],
placement: "left",
});

// import user from useContext but rename it as currentUser
const { user: currentUser, setUpdate } = useContext(ChatContext);

Expand Down Expand Up @@ -247,7 +248,6 @@ export default function ChatUsersChannelPopOver({
/>
) /*TODO: Make this command responsive */
}

{
user.role !== "MEMBER" && (
<Medal
Expand Down
13 changes: 8 additions & 5 deletions frontend/src/components/Chat/OpenChannel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChatContext } from "@/contexts/ChatContext";
import { PaperPlaneTilt, UsersThree, XCircle } from "@phosphor-icons/react";
import { PaperPlaneTilt, PencilSimpleSlash, UsersThree, XCircle } from "@phosphor-icons/react";
import { useContext, useEffect, useState } from "react";
import ChatUsersChannelPopOver, { ChatMember } from "./ChatUsersChannelPopOver";
import chatService from "@/services/chatClient";
Expand Down Expand Up @@ -29,7 +29,8 @@ export function OpenChannel() {
const [numberOfUsersInChat, setNumberOfUsersInChat] = useState<number>(0);
const [users, setUsers] = useState<ChatMember[]>([]);
const [isLoading, setIsLoading] = useState(true);

const myUserList = users.filter(usr => usr.userLogin === user.login);
const myUser = myUserList[0] || null;

chatService.socket?.on("listMessages", (messages: Message[]) => {
setMessages(() => messages);
Expand Down Expand Up @@ -61,6 +62,8 @@ export function OpenChannel() {
});

const handleSendMessage = () => {
if (myUser && myUser.status === 'MUTED')
return;
chatService.socket?.emit("message", {
chatId: selectedChat.id,
content: message,
Expand Down Expand Up @@ -204,13 +207,13 @@ export function OpenChannel() {
}
}}
/>
<button
< button
className="bg-purple42-200 text-white rounded-lg p-3 placeholder-gray-700 absolute z-10 right-4"
onClick={() => handleSendMessage()} /*TODO: Check if other users are receiving the message */
>
<PaperPlaneTilt size={20} color="white" />
{myUser && myUser.status !== 'MUTED' ? <PaperPlaneTilt size={20} color="white" /> : <PencilSimpleSlash alt="Muted user" size={20} color="gray" />}
</button>
</div>
</div>
</div >
);
}

0 comments on commit 05ca1d7

Please sign in to comment.