Skip to content

Commit

Permalink
🐛 (Channels): Fix channel comments and last message (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelruhmanSamy authored Dec 23, 2024
1 parent 9259b57 commit d84aa8c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
3 changes: 1 addition & 2 deletions app/src/features/chats/ChatBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function ChatBody() {

const { handleNextMentionMessage, mentionMessages } = useTraversalMentions();


useEffect(() => {
if (inView && hasNextPage && chatId) {
const container = scrollContainerRef.current;
Expand All @@ -71,7 +70,7 @@ function ChatBody() {
let messages = chat?.messages;

if (chat?.type === "channel") {
messages?.filter((msg) => !msg.parentMessageId);
messages = messages?.filter((msg) => !msg.parentMessageId);
}

const threadMessages = activeThread
Expand Down
7 changes: 4 additions & 3 deletions app/src/features/chats/ChatItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ const ChatItem = ({
}: ChatItemProps) => {
const navigate = useNavigate();

const timestamp = lastMessage?.timestamp || "No messages";
const lastMessageContent =
RenderWithMention(lastMessage?.content!, lastMessage?._id!) || "No messages";
const timestamp = lastMessage?.timestamp || "No Messages Found";
const lastMessageContent = lastMessage?.content
? RenderWithMention(lastMessage?.content!, lastMessage?._id!)
: "No Messages Found";

const { chatId } = useParams<{ chatId: string }>();

Expand Down
14 changes: 11 additions & 3 deletions app/src/features/chats/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ export function parseChatsToState(chatData?: any) {
(lastMessage: any) => lastMessage.chatId === chatId
)?.lastMessage;

let lastMessageContent = null;

if (incomingLastMessage) {
if (incomingLastMessage.isAppropriate) {
lastMessageContent = incomingLastMessage.content;
} else {
lastMessageContent = "🚫️ This message has inappropriate content.";
}
}

return {
_id: chatId,
isSeen: isSeen,
Expand All @@ -52,9 +62,7 @@ export function parseChatsToState(chatData?: any) {

lastMessage: {
_id: incomingLastMessage?.id,
content: incomingLastMessage?.isAppropriate
? incomingLastMessage?.content
: "🚫️ This message has inappropriate content.",
content: lastMessageContent,
senderId: incomingLastMessage?.senderId,
timestamp: incomingLastMessage?.timestamp,
contentType: incomingLastMessage?.contentType
Expand Down

0 comments on commit d84aa8c

Please sign in to comment.