(wip): chat decryption stuff
This commit is contained in:
parent
2777ba34ca
commit
de0a153bce
3 changed files with 39 additions and 20 deletions
|
|
@ -29,6 +29,9 @@ import MessageContextMenu from "./messageContextMenu";
|
||||||
import Media from "./media";
|
import Media from "./media";
|
||||||
import { useStorage } from "@tensamin/storage/context";
|
import { useStorage } from "@tensamin/storage/context";
|
||||||
import { useMTP } from "@tensamin/mtp";
|
import { useMTP } from "@tensamin/mtp";
|
||||||
|
import { useChat } from "../context";
|
||||||
|
import { decryptChatText } from "@tensamin/crypto/chatSecret";
|
||||||
|
import { log, toast } from "@tensamin/shared/log";
|
||||||
|
|
||||||
function MessageComponent({
|
function MessageComponent({
|
||||||
grouped,
|
grouped,
|
||||||
|
|
@ -125,11 +128,29 @@ function MessageComponent({
|
||||||
};
|
};
|
||||||
}, [message.MessageState, load, messageStateReadUpdate]);
|
}, [message.MessageState, load, messageStateReadUpdate]);
|
||||||
|
|
||||||
|
// Message decryption
|
||||||
|
const { chatSecret } = useChat();
|
||||||
|
const [decryptedContent, setDecryptedContent] = useState<string | undefined>(
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
useEffect(() => {
|
||||||
|
if (!chatSecret) return;
|
||||||
|
|
||||||
|
decryptChatText(chatSecret, message.Content).then(
|
||||||
|
setDecryptedContent,
|
||||||
|
(err) => {
|
||||||
|
toast("error", "Failed to decrypt message", String(err));
|
||||||
|
log(1, "chat", "red", err);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}, [chatSecret, message.Content]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
// pt-3 is to get a gap between messages
|
// pt-3 is to get a gap between messages
|
||||||
className={`${grouped ? "" : "pt-3"} w-full flex justify-start transition-opacity duration-150 ${opacityClass}`}
|
className={`${grouped ? "" : "pt-3"} w-full flex justify-start transition-opacity duration-150 ${opacityClass}`}
|
||||||
>
|
>
|
||||||
|
{user && decryptedContent ? (
|
||||||
<MessageContextMenu
|
<MessageContextMenu
|
||||||
content={message.Content}
|
content={message.Content}
|
||||||
messageId={message.SendTime}
|
messageId={message.SendTime}
|
||||||
|
|
@ -143,7 +164,6 @@ function MessageComponent({
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{user ? (
|
|
||||||
<>
|
<>
|
||||||
{grouped ? (
|
{grouped ? (
|
||||||
<p className="w-9 text-xs group-hover:visible invisible text-muted-foreground">
|
<p className="w-9 text-xs group-hover:visible invisible text-muted-foreground">
|
||||||
|
|
@ -220,12 +240,12 @@ function MessageComponent({
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
</div>
|
||||||
|
</MessageContextMenu>
|
||||||
) : (
|
) : (
|
||||||
"Loading"
|
"Loading"
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</MessageContextMenu>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ import {
|
||||||
deriveChatId,
|
deriveChatId,
|
||||||
deriveChatSecretId,
|
deriveChatSecretId,
|
||||||
decryptChatText,
|
decryptChatText,
|
||||||
encryptChatText,
|
|
||||||
kemPublicKeyFromPublicKeyBundle,
|
kemPublicKeyFromPublicKeyBundle,
|
||||||
ownKemPublicKeyFromKeyring,
|
ownKemPublicKeyFromKeyring,
|
||||||
randomChatSecret,
|
randomChatSecret,
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ const authPayload = z.object({
|
||||||
UserId: z.number(),
|
UserId: z.number(),
|
||||||
LastMessage: z
|
LastMessage: z
|
||||||
.object({
|
.object({
|
||||||
content: z.base64(),
|
Content: z.base64(),
|
||||||
SenderId: z.number(),
|
SenderId: z.number(),
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue