diff --git a/apps/dispatch-server/socket-events/send-message.ts b/apps/dispatch-server/socket-events/send-message.ts index d6b8a39c..c9990138 100644 --- a/apps/dispatch-server/socket-events/send-message.ts +++ b/apps/dispatch-server/socket-events/send-message.ts @@ -5,7 +5,7 @@ import { Server, Socket } from "socket.io"; export const handleSendMessage = (socket: Socket, io: Server) => async ( - { userId, message }: { userId: string; message: string }, + { userId, message, role }: { userId: string; message: string; role: string }, cb: (err: { error?: string }) => void, ) => { const senderId = socket.data.user.id; @@ -24,7 +24,7 @@ export const handleSendMessage = receiverId: userId, senderId, 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}`, }, }); diff --git a/apps/dispatch/app/_store/leftMenuStore.ts b/apps/dispatch/app/_store/leftMenuStore.ts index 54decb3a..819b9808 100644 --- a/apps/dispatch/app/_store/leftMenuStore.ts +++ b/apps/dispatch/app/_store/leftMenuStore.ts @@ -2,6 +2,8 @@ import { create } from "zustand"; import { ChatMessage } from "@repo/db"; import { dispatchSocket } from "(app)/dispatch/socket"; import { pilotSocket } from "(app)/pilot/socket"; +import { useDispatchConnectionStore } from "_store/dispatch/connectionStore"; +import { usePilotConnectionStore } from "_store/pilot/connectionStore"; interface ChatStore { situationTabOpen: boolean; @@ -16,7 +18,12 @@ interface ChatStore { setOwnId: (id: string) => void; chats: Record; setChatNotification: (userId: string, notification: boolean) => void; - sendMessage: (userId: string, message: string) => Promise; + sendMessage: ( + userId: string, + message: string, + senderName?: string, + receiverName?: string, + ) => Promise; addChat: (userId: string, name: string) => void; addMessage: (userId: string, message: ChatMessage) => void; removeChat: (userId: string) => void; @@ -49,12 +56,13 @@ export const useLeftMenuStore = create((set, get) => ({ }, setOwnId: (id: string) => set({ ownId: id }), chats: {}, - sendMessage: (userId: string, message: string) => { + sendMessage: (userId, message) => { return new Promise((resolve, reject) => { if (dispatchSocket.connected) { + const zone = useDispatchConnectionStore.getState().selectedZone; dispatchSocket.emit( "send-message", - { userId, message }, + { userId, message, role: zone }, ({ error }: { error?: string }) => { if (error) { reject(error); @@ -64,13 +72,19 @@ export const useLeftMenuStore = create((set, get) => ({ }, ); } else if (pilotSocket.connected) { - pilotSocket.emit("send-message", { userId, message }, ({ error }: { error?: string }) => { - if (error) { - reject(error); - } else { - resolve(); - } - }); + const bosCallsign = usePilotConnectionStore.getState().selectedStation?.bosCallsignShort; + + pilotSocket.emit( + "send-message", + { userId, message, role: bosCallsign }, + ({ error }: { error?: string }) => { + if (error) { + reject(error); + } else { + resolve(); + } + }, + ); } }); },