Name des Chatpartners wird nun mit rolle angezeigt

This commit is contained in:
PxlLoewe
2025-07-29 13:21:47 -07:00
parent e134c9b2fa
commit 23f7671d42
2 changed files with 26 additions and 12 deletions

View File

@@ -5,7 +5,7 @@ import { Server, Socket } from "socket.io";
export const handleSendMessage = export const handleSendMessage =
(socket: Socket, io: Server) => (socket: Socket, io: Server) =>
async ( async (
{ userId, message }: { userId: string; message: string }, { userId, message, role }: { userId: string; message: string; role: string },
cb: (err: { error?: string }) => void, cb: (err: { error?: string }) => void,
) => { ) => {
const senderId = socket.data.user.id; const senderId = socket.data.user.id;
@@ -24,7 +24,7 @@ export const handleSendMessage =
receiverId: userId, receiverId: userId,
senderId, senderId,
receiverName: `${receiverUser?.firstname} ${receiverUser?.lastname[0]}. - ${receiverUser?.publicId}`, receiverName: `${receiverUser?.firstname} ${receiverUser?.lastname[0]}. - ${receiverUser?.publicId}`,
senderName: `${senderUser?.firstname} ${senderUser?.lastname[0]}. - ${senderUser?.publicId}`, senderName: `${senderUser?.firstname} ${senderUser?.lastname[0]}. - ${role ?? senderUser?.publicId}`,
}, },
}); });

View File

@@ -2,6 +2,8 @@ import { create } from "zustand";
import { ChatMessage } from "@repo/db"; import { ChatMessage } from "@repo/db";
import { dispatchSocket } from "(app)/dispatch/socket"; import { dispatchSocket } from "(app)/dispatch/socket";
import { pilotSocket } from "(app)/pilot/socket"; import { pilotSocket } from "(app)/pilot/socket";
import { useDispatchConnectionStore } from "_store/dispatch/connectionStore";
import { usePilotConnectionStore } from "_store/pilot/connectionStore";
interface ChatStore { interface ChatStore {
situationTabOpen: boolean; situationTabOpen: boolean;
@@ -16,7 +18,12 @@ interface ChatStore {
setOwnId: (id: string) => void; setOwnId: (id: string) => void;
chats: Record<string, { name: string; notification: boolean; messages: ChatMessage[] }>; chats: Record<string, { name: string; notification: boolean; messages: ChatMessage[] }>;
setChatNotification: (userId: string, notification: boolean) => void; setChatNotification: (userId: string, notification: boolean) => void;
sendMessage: (userId: string, message: string) => Promise<void>; sendMessage: (
userId: string,
message: string,
senderName?: string,
receiverName?: string,
) => Promise<void>;
addChat: (userId: string, name: string) => void; addChat: (userId: string, name: string) => void;
addMessage: (userId: string, message: ChatMessage) => void; addMessage: (userId: string, message: ChatMessage) => void;
removeChat: (userId: string) => void; removeChat: (userId: string) => void;
@@ -49,12 +56,13 @@ export const useLeftMenuStore = create<ChatStore>((set, get) => ({
}, },
setOwnId: (id: string) => set({ ownId: id }), setOwnId: (id: string) => set({ ownId: id }),
chats: {}, chats: {},
sendMessage: (userId: string, message: string) => { sendMessage: (userId, message) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (dispatchSocket.connected) { if (dispatchSocket.connected) {
const zone = useDispatchConnectionStore.getState().selectedZone;
dispatchSocket.emit( dispatchSocket.emit(
"send-message", "send-message",
{ userId, message }, { userId, message, role: zone },
({ error }: { error?: string }) => { ({ error }: { error?: string }) => {
if (error) { if (error) {
reject(error); reject(error);
@@ -64,13 +72,19 @@ export const useLeftMenuStore = create<ChatStore>((set, get) => ({
}, },
); );
} else if (pilotSocket.connected) { } else if (pilotSocket.connected) {
pilotSocket.emit("send-message", { userId, message }, ({ error }: { error?: string }) => { const bosCallsign = usePilotConnectionStore.getState().selectedStation?.bosCallsignShort;
if (error) {
reject(error); pilotSocket.emit(
} else { "send-message",
resolve(); { userId, message, role: bosCallsign },
} ({ error }: { error?: string }) => {
}); if (error) {
reject(error);
} else {
resolve();
}
},
);
} }
}); });
}, },