From d2649bb51c3aaadbd331d40a20f3bd7ecd4a804d Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 11 Feb 2019 15:28:38 +0100 Subject: [PATCH] fixed double count in read messages Former-commit-id: e3661ad675c7dcd70fbea3bc5a41b3f103a376a0 --- pandora_console/include/functions_messages.php | 11 +++++++++-- pandora_console/include/functions_notifications.php | 6 +++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/functions_messages.php b/pandora_console/include/functions_messages.php index 4b9c66c1c1..4cee825ecc 100644 --- a/pandora_console/include/functions_messages.php +++ b/pandora_console/include/functions_messages.php @@ -363,9 +363,11 @@ function messages_get_count( $sql = sprintf( 'SELECT count(*) FROM ( - SELECT tm.*, utimestamp_read > 0 as "read" FROM tmensajes tm + SELECT DISTINCT tm.*, utimestamp_read > 0 as "read" + FROM tmensajes tm LEFT JOIN tnotification_user nu ON tm.id_mensaje=nu.id_mensaje + AND nu.id_user="%s" LEFT JOIN (tnotification_group ng INNER JOIN tusuario_perfil up ON ng.id_group=up.id_grupo @@ -377,6 +379,7 @@ function messages_get_count( %s', $user, $user, + $user, $read ); @@ -467,11 +470,14 @@ function messages_get_overview( ON tns.id=tm.id_source'; } + // Using distinct because could be double assignment due group/user. $sql = sprintf( 'SELECT * FROM ( - SELECT tm.*, utimestamp_read > 0 as "read" %s FROM tmensajes tm + SELECT DISTINCT tm.*, utimestamp_read > 0 as "read" %s + FROM tmensajes tm LEFT JOIN tnotification_user nu ON tm.id_mensaje=nu.id_mensaje + AND nu.id_user="%s" LEFT JOIN (tnotification_group ng INNER JOIN tusuario_perfil up ON ng.id_group=up.id_grupo @@ -486,6 +492,7 @@ function messages_get_overview( ORDER BY %s %s', $source_fields, + $config['id_user'], $source_join, $config['id_user'], $config['id_user'], diff --git a/pandora_console/include/functions_notifications.php b/pandora_console/include/functions_notifications.php index 1901e47e7b..cebbc1f5b5 100644 --- a/pandora_console/include/functions_notifications.php +++ b/pandora_console/include/functions_notifications.php @@ -131,10 +131,13 @@ function check_notification_readable(int $id_message) return false; } + // Using distinct to avoid double response on group messages read by user. $sql = sprintf( - 'SELECT tm.*, utimestamp_read > 0 as "read" FROM tmensajes tm + 'SELECT DISTINCT tm.*, utimestamp_read > 0 as "read" + FROM tmensajes tm LEFT JOIN tnotification_user nu ON tm.id_mensaje=nu.id_mensaje + AND nu.id_user="%s" AND tm.id_mensaje=%d LEFT JOIN (tnotification_group ng INNER JOIN tusuario_perfil up @@ -143,6 +146,7 @@ function check_notification_readable(int $id_message) ) ON tm.id_mensaje=ng.id_mensaje WHERE utimestamp_erased is null AND (nu.id_user="%s" OR (up.id_usuario="%s" AND ng.id_group=0))', + $config['id_user'], $id_message, $config['id_user'], $config['id_user']