(feat): add live messages
(feat): update licenses (feat): update livekit logging (feat): add basic grid layout (fix): remove deeplink log message
This commit is contained in:
parent
3768488e49
commit
8e294d230e
21 changed files with 510 additions and 51 deletions
|
|
@ -1,14 +1,43 @@
|
|||
import * as React from "react";
|
||||
import { useCrypto } from "@tensamin/crypto/context";
|
||||
import { useStorage } from "@tensamin/storage/context";
|
||||
import { useUser } from "@tensamin/user/context";
|
||||
import { useTTP } from "@tensamin/ttp";
|
||||
import { createContext, useEffect, useContext } from "react";
|
||||
import z from "zod";
|
||||
import { toast as sonnerToast } from "sonner";
|
||||
import { message as messageSchema } from "@tensamin/shared/data";
|
||||
|
||||
export const context = React.createContext<contextType | undefined>(undefined);
|
||||
export const context = createContext<contextType | undefined>(undefined);
|
||||
|
||||
/**
|
||||
* Executes Provider.
|
||||
* @param props Parameter props.
|
||||
* @returns unknown.
|
||||
*/
|
||||
export default function Provider(props: { children: React.ReactNode }) {
|
||||
// live_messages
|
||||
const { subscribePush } = useTTP();
|
||||
const { load } = useStorage();
|
||||
const { get } = useUser();
|
||||
const { decryptText, getSharedSecret } = useCrypto();
|
||||
|
||||
useEffect(() => {
|
||||
subscribePush(async (ttpMessage) => {
|
||||
if (ttpMessage.type === "message_live") {
|
||||
const { message, sender_id } = ttpMessage.data as {
|
||||
message: z.infer<typeof messageSchema>;
|
||||
sender_id: number;
|
||||
};
|
||||
|
||||
const decryptedContent = await decryptText(
|
||||
await getSharedSecret(
|
||||
await load("private_key"),
|
||||
await get(await load("user_id")).then((data) => data.public_key),
|
||||
await get(sender_id).then((data) => data.public_key),
|
||||
),
|
||||
message.content,
|
||||
);
|
||||
|
||||
sonnerToast(decryptedContent, {
|
||||
icon: <div>A</div>,
|
||||
});
|
||||
}
|
||||
});
|
||||
}, [subscribePush, decryptText, getSharedSecret, load, get]);
|
||||
|
||||
return (
|
||||
<context.Provider value={{ test: () => {} }}>
|
||||
|
|
@ -27,7 +56,7 @@ type contextType = {
|
|||
* @returns contextType.
|
||||
*/
|
||||
export function useNotifications(): contextType {
|
||||
const ctx = React.useContext(context);
|
||||
const ctx = useContext(context);
|
||||
if (!ctx) {
|
||||
throw new Error("useNotifications must be used within a ChatProvider");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue