Initial Commit
linter / quality (push) Canceled after 0s
tests / ci (8.3) (push) Canceled after 0s
tests / ci (8.4) (push) Canceled after 0s
tests / ci (8.5) (push) Canceled after 0s

This commit is contained in:
2026-08-28 23:20:23 +10:00
parent f00405ed24
commit cc225414e0
8 changed files with 578 additions and 4 deletions
+72
View File
@@ -0,0 +1,72 @@
<?php
namespace App\Http\Controllers;
use App\Models\DirectMessage;
use App\Models\DirectThread;
use Illuminate\Http\JsonResponse;
class ThreadController extends Controller
{
public function index(): JsonResponse
{
$threads = DirectThread::query()
->with(['messages' => fn ($query) => $query->orderByDesc('timestamp')->limit(1)])
->orderByDesc('last_activity_at')
->get()
->map(function (DirectThread $thread) {
$last = $thread->messages->first();
return [
'thread_id' => $thread->thread_id,
'thread_title' => $thread->thread_title,
'is_group' => $thread->is_group,
'participants' => $thread->participants,
'last_activity_at' => $thread->last_activity_at,
'muted' => $thread->muted,
'last_message' => $last ? [
'username' => $last->username,
'text' => $last->text,
'item_type' => $last->item_type,
'timestamp' => $last->timestamp,
] : null,
];
});
return response()->json($threads);
}
public function show(string $threadId): JsonResponse
{
$thread = DirectThread::findOrFail($threadId);
$messages = $thread->messages()
->orderBy('timestamp')
->get()
->map(fn (DirectMessage $message) => [
'id' => $message->id,
'user_id' => $message->user_id,
'username' => $message->username,
'full_name' => $message->full_name,
'item_type' => $message->item_type,
'text' => $message->text,
'timestamp' => $message->timestamp,
'shared_url' => $message->shared_url,
'shared_preview_image' => $message->shared_preview_image,
'shared_title' => $message->shared_title,
'shared_caption' => $message->shared_caption,
'reactions' => $message->reactions,
'replied_to_id' => $message->replied_to_id,
'replied_to_text' => $message->replied_to_text,
]);
return response()->json([
'thread_id' => $thread->thread_id,
'thread_title' => $thread->thread_title,
'is_group' => $thread->is_group,
'participants' => $thread->participants,
'muted' => $thread->muted,
'messages' => $messages,
]);
}
}