Complete WatchLink V1 realtime features
This commit is contained in:
@@ -54,6 +54,65 @@ export async function createRoom(formData: FormData) {
|
||||
redirect(`/rooms/${encodeURIComponent(room.slug)}`);
|
||||
}
|
||||
|
||||
export async function deleteRoom(formData: FormData) {
|
||||
const user = await requireCurrentUser();
|
||||
const roomId = String(formData.get("roomId") || "");
|
||||
if (!roomId) return;
|
||||
|
||||
const room = await prisma.room.findUnique({
|
||||
where: { id: roomId },
|
||||
include: { members: { where: { userId: user.id }, select: { canManage: true } } }
|
||||
});
|
||||
|
||||
if (!room || room.isPersonal || !canManageRoom(user, room)) return;
|
||||
|
||||
await prisma.$transaction([
|
||||
prisma.auditEvent.create({
|
||||
data: {
|
||||
actorId: user.id,
|
||||
roomId: room.id,
|
||||
action: "room.delete",
|
||||
metadata: { slug: room.slug, name: room.name }
|
||||
}
|
||||
}),
|
||||
prisma.room.delete({ where: { id: room.id } })
|
||||
]);
|
||||
|
||||
revalidatePath("/rooms");
|
||||
revalidatePath("/dashboard");
|
||||
redirect("/rooms?deleted=1");
|
||||
}
|
||||
|
||||
export async function resetPersonalRoom(formData: FormData) {
|
||||
const user = await requireCurrentUser();
|
||||
const roomId = String(formData.get("roomId") || "");
|
||||
if (!roomId) return;
|
||||
|
||||
const room = await prisma.room.findUnique({
|
||||
where: { id: roomId },
|
||||
include: { members: { where: { userId: user.id }, select: { canManage: true } } }
|
||||
});
|
||||
|
||||
if (!room || !room.isPersonal || !canManageRoom(user, room)) return;
|
||||
|
||||
await prisma.$transaction([
|
||||
prisma.mediaSource.deleteMany({ where: { roomId: room.id } }),
|
||||
prisma.roomMessage.deleteMany({ where: { roomId: room.id } }),
|
||||
prisma.room.update({ where: { id: room.id }, data: { currentState: null } }),
|
||||
prisma.auditEvent.create({
|
||||
data: {
|
||||
actorId: user.id,
|
||||
roomId: room.id,
|
||||
action: "room.reset",
|
||||
metadata: { slug: room.slug }
|
||||
}
|
||||
})
|
||||
]);
|
||||
|
||||
revalidateRoom(room.slug);
|
||||
redirect(`/rooms/${encodeURIComponent(room.slug)}?rail=Settings&saved=1`);
|
||||
}
|
||||
|
||||
export async function updateRoomSettings(formData: FormData) {
|
||||
const user = await requireCurrentUser();
|
||||
const roomId = String(formData.get("roomId") || "");
|
||||
@@ -112,6 +171,33 @@ export async function addRoomMember(formData: FormData) {
|
||||
redirect(`/rooms/${encodeURIComponent(room.slug)}?rail=Invite&saved=1`);
|
||||
}
|
||||
|
||||
export async function removeRoomMember(formData: FormData) {
|
||||
const user = await requireCurrentUser();
|
||||
const roomId = String(formData.get("roomId") || "");
|
||||
const userId = String(formData.get("userId") || "");
|
||||
if (!roomId || !userId) return;
|
||||
|
||||
const room = await prisma.room.findUnique({
|
||||
where: { id: roomId },
|
||||
include: { members: { where: { userId: user.id }, select: { canManage: true } } }
|
||||
});
|
||||
|
||||
if (!room || !canManageRoom(user, room) || userId === room.ownerId) return;
|
||||
|
||||
await prisma.roomMember.deleteMany({ where: { roomId: room.id, userId } });
|
||||
await prisma.auditEvent.create({
|
||||
data: {
|
||||
actorId: user.id,
|
||||
roomId: room.id,
|
||||
action: "room.member.remove",
|
||||
metadata: { userId }
|
||||
}
|
||||
});
|
||||
|
||||
revalidateRoom(room.slug);
|
||||
redirect(`/rooms/${encodeURIComponent(room.slug)}?rail=Invite&saved=1`);
|
||||
}
|
||||
|
||||
function canManageRoom(
|
||||
user: Awaited<ReturnType<typeof requireCurrentUser>>,
|
||||
room: { ownerId: string | null; members: Array<{ canManage: boolean }> }
|
||||
|
||||
Reference in New Issue
Block a user