feat(chat): опрос ответов и восстановление переписки
This commit is contained in:
@@ -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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user