diff --git a/app/api/conversations/[id]/presence/route.ts b/app/api/conversations/[id]/presence/route.ts index 45cf90a..8259408 100644 --- a/app/api/conversations/[id]/presence/route.ts +++ b/app/api/conversations/[id]/presence/route.ts @@ -12,16 +12,15 @@ export async function PATCH( } const { id: conversationId } = await params; - const body = await req.json().catch(() => ({})); - const { markRead } = body as { markRead?: boolean }; + const { mark_read } = await req.json(); const timestamp = new Date(); - const data: { lastSeenAt: Date; lastReadAt?: Date } = { - lastSeenAt: timestamp, + const data: { last_seen_at: Date; last_read_at?: Date } = { + last_seen_at: timestamp, }; - if (markRead) { - data.lastReadAt = timestamp; + if (mark_read) { + data.last_read_at = timestamp; } await prisma.conversationParticipant.updateMany({ diff --git a/app/api/conversations/route.ts b/app/api/conversations/route.ts index c541544..ca8395a 100644 --- a/app/api/conversations/route.ts +++ b/app/api/conversations/route.ts @@ -47,11 +47,11 @@ export async function POST(req: Request) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } - const { otherUserId, otherUserEmail } = await req.json(); + const { other_user_id, other_user_email } = await req.json(); - if (!otherUserId) { + if (!other_user_id) { return NextResponse.json( - { error: "otherUserId is required." }, + { error: "other_user_id is required." }, { status: 400 }, ); } @@ -71,8 +71,8 @@ export async function POST(req: Request) { last_read_at: timestamp, }, { - user_id: otherUserId, - email: otherUserEmail ?? "", + user_id: other_user_id, + email: other_user_email ?? "", last_seen_at: EPOCH, last_read_at: EPOCH, }, diff --git a/app/api/messages/route.ts b/app/api/messages/route.ts index 360bbae..66b3955 100644 --- a/app/api/messages/route.ts +++ b/app/api/messages/route.ts @@ -58,10 +58,10 @@ export async function POST(req: Request) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } - const { conversationId, text, attachments } = await req.json(); + const { conversation_id, text, attachments } = await req.json(); if ( - !conversationId || + !conversation_id || (!text?.trim() && (!attachments || attachments.length === 0)) ) { return NextResponse.json( @@ -73,7 +73,7 @@ export async function POST(req: Request) { const participant = await prisma.conversationParticipant.findUnique({ where: { conversation_id_user_id: { - conversation_id: conversationId, + conversation_id, user_id: session.user.id, }, }, @@ -85,7 +85,7 @@ export async function POST(req: Request) { const message = await prisma.message.create({ data: { - conversation_id: conversationId, + conversation_id, sender_id: session.user.id, text: text?.trim() ?? "", attachments: attachments ?? [], @@ -101,11 +101,11 @@ export async function POST(req: Request) { created_at: message.created_at.toISOString(), }; - emitter.emit(`chat:${conversationId}`, { type: "message", data: payload }); + emitter.emit(`chat:${conversation_id}`, { type: "message", data: payload }); const participants = await prisma.conversationParticipant.findMany({ where: { - conversation_id: conversationId, + conversation_id, user_id: { not: session.user.id }, }, select: { user_id: true }, @@ -114,7 +114,7 @@ export async function POST(req: Request) { for (const p of participants) { emitter.emit(`user:${p.user_id}`, { type: "new_message", - data: { conversation_id: conversationId, sender_id: session.user.id }, + data: { conversation_id, sender_id: session.user.id }, }); } diff --git a/app/api/wakatime/sync/route.ts b/app/api/wakatime/sync/route.ts index b284c44..87f6299 100644 --- a/app/api/wakatime/sync/route.ts +++ b/app/api/wakatime/sync/route.ts @@ -1,30 +1,55 @@ import { NextResponse } from "next/server"; -import { getCurrentUser } from "@/app/lib/auth/user"; import { saveWakatimeApiKey, syncWakatimeData, validateWakatimeApiKey, } from "@/app/lib/wakatime/sync"; +import { auth } from "@/app/lib/auth"; -export async function GET(request: Request) { - const { user } = await getCurrentUser(); - const { searchParams } = new URL(request.url); - const apiKey = searchParams.get("apiKey") || ""; - const saveOnly = - searchParams.get("saveOnly") === "1" || - searchParams.get("saveOnly") === "true"; +export async function GET(req: Request) { + const session = await auth(); + if (!session?.user?.id) { + return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); + } - const validationError = validateWakatimeApiKey(apiKey); - if (validationError) { - return NextResponse.json({ error: validationError }, { status: 400 }); + const result = await syncWakatimeData({ + userId: session.user.id, + incomingApiKey: "", + storedApiKey: session.user.wakatime_api_key ?? undefined, + }); + + if (!result.success && result.status !== 200) { + return NextResponse.json( + { error: result.error }, + { status: result.status }, + ); } - if (!user) { + return NextResponse.json({ + success: result.success, + data: result.data, + error: result.error, + }); +} + +export async function POST(req: Request) { + const session = await auth(); + if (!session?.user?.id) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } - if (saveOnly) { - const result = await saveWakatimeApiKey({ userId: user.id, apiKey }); + const { api_key, save_only } = await req.json(); + + const validationError = validateWakatimeApiKey(api_key); + if (validationError) { + return NextResponse.json({ error: validationError }, { status: 400 }); + } + + if (save_only) { + const result = await saveWakatimeApiKey({ + userId: session.user.id, + apiKey: api_key, + }); if (!result.success) { return NextResponse.json( @@ -37,9 +62,9 @@ export async function GET(request: Request) { } const result = await syncWakatimeData({ - userId: user.id, - incomingApiKey: apiKey, - storedApiKey: user.wakatime_api_key, + userId: session.user.id, + incomingApiKey: api_key, + storedApiKey: session.user.wakatime_api_key, }); if (!result.success && result.status !== 200) { diff --git a/app/components/Chat.tsx b/app/components/Chat.tsx index 168d7a3..3062001 100644 --- a/app/components/Chat.tsx +++ b/app/components/Chat.tsx @@ -302,19 +302,18 @@ export default function Chat({ user }: { user: ChatUserShape }) { : undefined; const activeLabel = isGlobalActive - ? "Global Chat" + ? "Global" : activeOtherUser?.email?.split("@")[0] || "Unknown"; const activeSublabel = isGlobalActive - ? "Public Channel" + ? "Worldwide" : activeOtherUserOnline ? "Online" : "Offline"; - const activeSublabelClass = - activeOtherUserOnline || isGlobalActive - ? "text-emerald-600" - : "text-gray-500"; + const activeSublabelClass = activeOtherUserOnline + ? "text-emerald-600" + : "text-gray-500"; const typingIndicatorText = activeTypingState ? isGlobalActive @@ -355,15 +354,15 @@ export default function Chat({ user }: { user: ChatUserShape }) { attachments={allMediaAttachments} onChange={setMediaViewer} /> -
+
{/* Left Sidebar */}

- Message category + Messages

-
-
- {activeInitials} -
- {!isGlobalActive && activeOtherUserOnline && ( -
- )} -

{activeLabel} @@ -682,7 +671,7 @@ export default function Chat({ user }: { user: ChatUserShape }) { {/* Right Sidebar */} {conversationId && (