feat(chat): опрос ответов и восстановление переписки

This commit is contained in:
Дмитрий
2026-07-13 07:17:38 +03:00
parent cfd26e38ef
commit b4c4900635
3 changed files with 58 additions and 0 deletions
@@ -47,4 +47,29 @@ class ChatController extends Controller
return response()->json(['message_id' => (int) $row->id]);
}
/**
* Опрос окошка: «что нового в разговоре после реплики N?».
* after=0 вся переписка (клиент перезагрузил страницу и вернулся).
*/
public function messages(Request $request, string $chat): JsonResponse
{
$after = max(0, (int) $request->query('after', '0'));
$rows = BotDialog::query()
->where('chat_id', $chat)
->where('id', '>', $after)
->orderBy('id')
->limit(100)
->get(['id', 'direction', 'message', 'created_at']);
return response()->json([
'messages' => $rows->map(fn (BotDialog $d) => [
'id' => (int) $d->id,
'direction' => $d->direction,
'text' => $d->message,
'at' => $d->created_at?->toIso8601String(),
])->all(),
]);
}
}