fix(conversations): exclude canal='turnero' messages from main conversations list
All queries in get_conversations.php now filter (canal IS NULL OR canal='bot') so the main chat only shows bot conversations and the turnero chat stays isolated. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
4d04fea1de
commit
7eea2ff7ba
@@ -64,24 +64,27 @@ try {
|
|||||||
|
|
||||||
$sql .= "
|
$sql .= "
|
||||||
FROM users u
|
FROM users u
|
||||||
LEFT JOIN conversations c ON c.user_id = u.id
|
LEFT JOIN conversations c ON c.user_id = u.id AND (c.canal IS NULL OR c.canal = 'bot')
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
SELECT t1.* FROM conversations t1
|
SELECT t1.* FROM conversations t1
|
||||||
JOIN (
|
JOIN (
|
||||||
SELECT user_id, MAX(created_at) AS last_time FROM conversations GROUP BY user_id
|
SELECT user_id, MAX(created_at) AS last_time FROM conversations
|
||||||
|
WHERE (canal IS NULL OR canal = 'bot') GROUP BY user_id
|
||||||
) t2 ON t1.user_id = t2.user_id AND t1.created_at = t2.last_time
|
) t2 ON t1.user_id = t2.user_id AND t1.created_at = t2.last_time
|
||||||
|
WHERE (t1.canal IS NULL OR t1.canal = 'bot')
|
||||||
) lm ON lm.user_id = u.id";
|
) lm ON lm.user_id = u.id";
|
||||||
|
|
||||||
// Agregar condición de búsqueda si existe
|
// Agregar condición de búsqueda si existe
|
||||||
if (!empty($search)) {
|
if (!empty($search)) {
|
||||||
$sql .= "
|
$sql .= "
|
||||||
WHERE (
|
WHERE (
|
||||||
u.name LIKE ?
|
u.name LIKE ?
|
||||||
OR u.phone_number LIKE ?
|
OR u.phone_number LIKE ?
|
||||||
OR EXISTS (
|
OR EXISTS (
|
||||||
SELECT 1 FROM conversations c2
|
SELECT 1 FROM conversations c2
|
||||||
WHERE c2.user_id = u.id
|
WHERE c2.user_id = u.id
|
||||||
AND c2.content LIKE ?
|
AND c2.content LIKE ?
|
||||||
|
AND (c2.canal IS NULL OR c2.canal = 'bot')
|
||||||
)
|
)
|
||||||
)";
|
)";
|
||||||
}
|
}
|
||||||
@@ -147,9 +150,9 @@ try {
|
|||||||
} else {
|
} else {
|
||||||
// Conteo normal sin búsqueda
|
// Conteo normal sin búsqueda
|
||||||
if ($filter === 'unread') {
|
if ($filter === 'unread') {
|
||||||
$totalRow = $db->fetch("SELECT COUNT(DISTINCT user_id) AS count FROM conversations c WHERE c.direction = 'incoming' AND (c.is_read IS NULL OR c.is_read = 0)");
|
$totalRow = $db->fetch("SELECT COUNT(DISTINCT user_id) AS count FROM conversations c WHERE c.direction = 'incoming' AND (c.is_read IS NULL OR c.is_read = 0) AND (c.canal IS NULL OR c.canal = 'bot')");
|
||||||
} else {
|
} else {
|
||||||
$totalRow = $db->fetch("SELECT COUNT(DISTINCT user_id) AS count FROM conversations");
|
$totalRow = $db->fetch("SELECT COUNT(DISTINCT user_id) AS count FROM conversations WHERE (canal IS NULL OR canal = 'bot')");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$total = isset($totalRow['count']) ? intval($totalRow['count']) : 0;
|
$total = isset($totalRow['count']) ? intval($totalRow['count']) : 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user