up
This commit is contained in:
@@ -159,8 +159,35 @@ try {
|
||||
$conversations = [];
|
||||
}
|
||||
|
||||
// Si hay búsqueda, obtener el snippet del mensaje que coincidió (no solo el último)
|
||||
$matchedContentMap = [];
|
||||
if (!empty($search)) {
|
||||
$userIds = array_column($conversations, 'user_id');
|
||||
if (!empty($userIds)) {
|
||||
$placeholders = implode(',', array_fill(0, count($userIds), '?'));
|
||||
$searchParam = '%' . $search . '%';
|
||||
$params2 = array_merge([$searchParam], $userIds);
|
||||
$matchedRows = $db->fetchAll(
|
||||
"SELECT user_id, content FROM conversations
|
||||
WHERE content LIKE ? AND user_id IN ($placeholders)
|
||||
ORDER BY created_at DESC",
|
||||
$params2
|
||||
);
|
||||
// Guardar el primer mensaje coincidente por usuario
|
||||
foreach ($matchedRows as $row) {
|
||||
if (!isset($matchedContentMap[$row['user_id']])) {
|
||||
$matchedContentMap[$row['user_id']] = mb_substr($row['content'], 0, 80);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Formatear datos para el frontend
|
||||
$conversations = array_map(function($conv) {
|
||||
$conversations = array_map(function($conv) use ($matchedContentMap, $search) {
|
||||
$matched = null;
|
||||
if (!empty($search) && isset($matchedContentMap[$conv['user_id']])) {
|
||||
$matched = $matchedContentMap[$conv['user_id']];
|
||||
}
|
||||
return [
|
||||
'user_id' => intval($conv['user_id']),
|
||||
'name' => $conv['name'] ?? $conv['phone_number'],
|
||||
@@ -178,7 +205,8 @@ try {
|
||||
'advisor_requested' => isset($conv['advisor_requested']) ? (bool)$conv['advisor_requested'] : false,
|
||||
'in_service' => isset($conv['in_service']) ? (bool)$conv['in_service'] : false,
|
||||
'in_service_by' => isset($conv['in_service_by']) ? intval($conv['in_service_by']) : null,
|
||||
'in_service_at' => $conv['in_service_at'] ?? null
|
||||
'in_service_at' => $conv['in_service_at'] ?? null,
|
||||
'matched_content' => $matched // snippet del mensaje que coincidió (solo en búsqueda)
|
||||
];
|
||||
}, $conversations);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user