(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 { useStorage } from "@tensamin/storage/context";
|
||||
import { useMTP } from "@tensamin/mtp";
|
||||
import { useChat } from "../context";
|
||||
import { decryptChatText } from "@tensamin/crypto/chatSecret";
|
||||
import { log, toast } from "@tensamin/shared/log";
|
||||
|
||||
function MessageComponent({
|
||||
grouped,
|
||||
|
|
@ -125,11 +128,29 @@ function MessageComponent({
|
|||
};
|
||||
}, [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 (
|
||||
<div
|
||||
// pt-3 is to get a gap between messages
|
||||
className={`${grouped ? "" : "pt-3"} w-full flex justify-start transition-opacity duration-150 ${opacityClass}`}
|
||||
>
|
||||
{user && decryptedContent ? (
|
||||
<MessageContextMenu
|
||||
content={message.Content}
|
||||
messageId={message.SendTime}
|
||||
|
|
@ -143,7 +164,6 @@ function MessageComponent({
|
|||
},
|
||||
)}
|
||||
>
|
||||
{user ? (
|
||||
<>
|
||||
{grouped ? (
|
||||
<p className="w-9 text-xs group-hover:visible invisible text-muted-foreground">
|
||||
|
|
@ -220,12 +240,12 @@ function MessageComponent({
|
|||
)}
|
||||
</div>
|
||||
</>
|
||||
</div>
|
||||
</MessageContextMenu>
|
||||
) : (
|
||||
"Loading"
|
||||
)}
|
||||
</div>
|
||||
</MessageContextMenu>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import {
|
|||
deriveChatId,
|
||||
deriveChatSecretId,
|
||||
decryptChatText,
|
||||
encryptChatText,
|
||||
kemPublicKeyFromPublicKeyBundle,
|
||||
ownKemPublicKeyFromKeyring,
|
||||
randomChatSecret,
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ const authPayload = z.object({
|
|||
UserId: z.number(),
|
||||
LastMessage: z
|
||||
.object({
|
||||
content: z.base64(),
|
||||
Content: z.base64(),
|
||||
SenderId: z.number(),
|
||||
})
|
||||
.optional(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue