Reimplemented outdated code, added encryption keys for each room, added support for profile images, added friend requests via url/qr-code
This commit is contained in:
1 parent
508f17315e
commit
32e4bf8b32
58 files changed
+3270
-362
No files matched your search
@@ -0,0 +1,34 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { sendMessage, decryptIncomingMessage } from "@/utils/rooms/messages";
|
||||
|
||||
export type SendMessageState = { error: string } | { messageId: string } | null;
|
||||
|
||||
export async function sendMessageAction(
|
||||
roomId: string,
|
||||
_prevState: SendMessageState,
|
||||
formData: FormData,
|
||||
): Promise<SendMessageState> {
|
||||
const value = formData.get("message");
|
||||
if (typeof value !== "string" || !value.trim()) {
|
||||
return { error: "Message cannot be empty." };
|
||||
}
|
||||
|
||||
const result = await sendMessage(roomId, value.trim());
|
||||
if (result.error) {
|
||||
return { error: result.error };
|
||||
}
|
||||
|
||||
revalidatePath(`/rooms/${roomId}`);
|
||||
return { messageId: result.messageId };
|
||||
}
|
||||
|
||||
export async function decryptMessageAction(
|
||||
roomId: string,
|
||||
encryptedValue: string,
|
||||
iv: string,
|
||||
authTag: string,
|
||||
): Promise<{ plaintext: string } | { error: string }> {
|
||||
return decryptIncomingMessage(roomId, encryptedValue, iv, authTag);
|
||||
}
|
||||
Reference in new issue
Block a user