diff --git a/app/components/MessageAttachments/MessageCall.tsx b/app/components/MessageAttachments/MessageCall.tsx index 478afdd..0e4ea35 100644 --- a/app/components/MessageAttachments/MessageCall.tsx +++ b/app/components/MessageAttachments/MessageCall.tsx @@ -4,6 +4,7 @@ import { Avatar, Box, Flex, Text } from "@mantine/core"; import { useRosettaColors } from "@/app/hooks/useRosettaColors"; import { IconPhoneOutgoing, IconX } from "@tabler/icons-react"; import { translateDurationToTime } from "@/app/providers/CallProvider/translateDurationTime"; +import { usePublicKey } from "@/app/providers/AccountProvider/usePublicKey"; export function MessageCall(props: AttachmentProps) { const { @@ -13,9 +14,10 @@ export function MessageCall(props: AttachmentProps) { props.attachment, props.parent, ); + const publicKey = usePublicKey(); const preview = getPreview(); - const callerRole = preview.split("::")[0]; - const duration = parseInt(preview.split("::")[1]); + const caller = props.parent.from == publicKey; + const duration = parseInt(preview); const colors = useRosettaColors(); const error = duration == 0; @@ -30,10 +32,10 @@ export function MessageCall(props: AttachmentProps) { {!error && <> - {callerRole == "0" && ( + {!caller && ( )} - {callerRole == "1" && ( + {caller && ( @@ -45,7 +47,7 @@ export function MessageCall(props: AttachmentProps) { { - error ? (callerRole == "0" ? "Missed call" : "Rejected call") : (callerRole == "0" ? "Incoming call" : "Outgoing call") + error ? (!caller ? "Missed call" : "Rejected call") : (!caller ? "Incoming call" : "Outgoing call") } {!error && diff --git a/app/providers/CallProvider/CallProvider.tsx b/app/providers/CallProvider/CallProvider.tsx index bf1d342..052d83b 100644 --- a/app/providers/CallProvider/CallProvider.tsx +++ b/app/providers/CallProvider/CallProvider.tsx @@ -462,21 +462,18 @@ export function CallProvider(props : CallProviderProps) { * Отправляет сообщение в диалог с звонящим с информацией о звонке */ const generateCallAttachment = () => { - let preview = ""; - if(roleRef.current == CallRole.CALLER){ - preview += "1::"; + if(roleRef.current != CallRole.CALLER){ + /** + * Только звонящий отправляет информацию о звонке в виде вложения, чтобы ее можно было отобразить в UI диалога, например длительность звонка + */ + return; } - if(roleRef.current == CallRole.CALLEE){ - preview += "0::"; - } - preview += duration.toString(); - sendMessage(activeCall, "", [{ id: generateRandomKey(16), - preview: preview, + preview: duration.toString(), type: AttachmentType.CALL, blob: "" - }], false); + }], true); } const accept = () => { diff --git a/app/providers/ProtocolProvider/protocol/packets/packet.message.ts b/app/providers/ProtocolProvider/protocol/packets/packet.message.ts index 66ba616..323908b 100644 --- a/app/providers/ProtocolProvider/protocol/packets/packet.message.ts +++ b/app/providers/ProtocolProvider/protocol/packets/packet.message.ts @@ -6,7 +6,7 @@ export enum AttachmentType { MESSAGES = 1, FILE = 2, AVATAR = 3, - CALL + CALL = 4 } export interface Attachment {