Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/features/team/components/real-team-chat-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function RealTeamChatPanel({ projectGroup }: RealTeamChatPanelProps) {
const { mutate: markChatRead } = useMarkChatReadMutation();
const { connectionMessage, connectionState, isConnected, sendMessage } =
useProjectGroupChat({
currentUserId: projectGroup.currentUserId,
enabled: true,
projectGroupId: projectGroup.projectGroupId,
});
Expand Down Expand Up @@ -213,9 +214,7 @@ function ChatBubble({ message }: { message: ChatMessage }) {
<p
className={cn(
"font-mono text-xs",
message.mine
? "text-blue-100"
: "text-muted-foreground",
message.mine ? "text-blue-100" : "text-muted-foreground",
)}
>
{formatChatTime(message.createdAt)}
Expand Down
24 changes: 22 additions & 2 deletions src/features/team/hooks/use-project-group-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ type ChatConnectionState =
| "error";

export function useProjectGroupChat({
currentUserId,
enabled,
projectGroupId,
}: {
currentUserId: number | undefined;
enabled: boolean;
projectGroupId: number | undefined;
}) {
Expand Down Expand Up @@ -83,10 +85,14 @@ export function useProjectGroupChat({
if (!chatMessage) {
return;
}
const ownedChatMessage = applyChatMessageOwnership(
chatMessage,
currentUserId,
);

queryClient.setQueryData<ChatMessagePage>(
chatQueryKeys.messages(projectGroupId),
(current) => appendChatMessagePage(current, chatMessage),
(current) => appendChatMessagePage(current, ownedChatMessage),
);
},
);
Expand Down Expand Up @@ -120,7 +126,7 @@ export function useProjectGroupChat({
clientRef.current = null;
void client.deactivate();
};
}, [enabled, projectGroupId, queryClient]);
}, [currentUserId, enabled, projectGroupId, queryClient]);

const sendMessage = useCallback(
(content: string) => {
Expand Down Expand Up @@ -180,3 +186,17 @@ function parseChatMessage(message: IMessage) {
return null;
}
}

function applyChatMessageOwnership(
message: ChatMessage,
currentUserId: number | undefined,
): ChatMessage {
if (typeof currentUserId !== "number") {
return message;
}

return {
...message,
mine: message.senderUserId === currentUserId,
};
}
Loading