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,42 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { sendFriendRequest, acceptFriend } from "@/utils/friends/friends";
|
||||
import { UUID_REGEX } from "@/utils/validation";
|
||||
|
||||
export type AddFriendState = {
|
||||
success?: boolean;
|
||||
error?: string;
|
||||
} | null;
|
||||
|
||||
export async function addFriendAction(
|
||||
_prevState: AddFriendState,
|
||||
formData: FormData,
|
||||
): Promise<AddFriendState> {
|
||||
const userId = formData.get("userId");
|
||||
if (typeof userId !== "string" || !userId.trim()) {
|
||||
return { error: "User ID is required." };
|
||||
}
|
||||
|
||||
const trimmed = userId.trim();
|
||||
|
||||
if (!UUID_REGEX.test(trimmed)) {
|
||||
return { error: "Please enter a valid user ID (UUID format)." };
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await sendFriendRequest(trimmed);
|
||||
if (result === false) {
|
||||
return { error: "Could not send friend request. It may already exist." };
|
||||
}
|
||||
revalidatePath("/friends");
|
||||
return { success: true };
|
||||
} catch {
|
||||
return { error: "Something went wrong. Please try again." };
|
||||
}
|
||||
}
|
||||
|
||||
export async function acceptRequestAction(senderId: string) {
|
||||
await acceptFriend(senderId);
|
||||
revalidatePath("/friends");
|
||||
}
|
||||
Reference in new issue
Block a user