minor fix notification direct assignment

Former-commit-id: 59ffb2338377ac2c3270681e6905f5d853add16b
This commit is contained in:
fbsanchez 2019-02-18 18:13:22 +01:00
parent bb83f4ba4a
commit af110f4820
1 changed files with 34 additions and 24 deletions

View File

@ -356,49 +356,59 @@ function messages_get_count(
if (!empty($incl_read)) {
// Do not filter.
$read = '';
$read = ' 1=1 ';
} else {
// Retrieve only unread messages.
$read = 'where t.read is null';
$read = ' t.read is null';
}
if ($ignore_source === true) {
$source_select = '';
$source_sql = '';
$source_extra = '';
} else {
$source_select = ',IF(ns.user_editable,nsu.enabled,ns.enabled) as enabled';
// Row in tnotification_source_user could exist or not.
$source_sql = sprintf(
'INNER JOIN tnotification_source ns
ON tm.id_source = ns.id
AND ns.enabled = 1
INNER JOIN tnotification_source_user nsu
ON nsu.id_source=ns.id
AND nsu.enabled = 1
AND nsu.id_user = "%s"',
'INNER JOIN (
tnotification_source ns
LEFT JOIN tnotification_source_user nsu
ON ns.id=nsu.id_source
AND nsu.id_user="test")
ON tm.id_source=ns.id',
$user
);
$source_extra = 'AND (t.enabled=1 OR t.enabled is null)';
}
$sql = sprintf(
'SELECT count(*) FROM (
SELECT DISTINCT tm.*, utimestamp_read > 0 as "read"
'SELECT count(*) as "n" FROM (
SELECT
tm.*,
utimestamp_read > 0 as "read"
%s
FROM tmensajes tm
%s
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
AND up.id_grupo=ng.id_group
) ON tm.id_mensaje=ng.id_mensaje
%s
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
AND up.id_grupo=ng.id_group)
ON tm.id_mensaje=ng.id_mensaje
WHERE utimestamp_erased is null
AND (nu.id_user="%s" OR up.id_usuario="%s" OR ng.id_group=0)
) t
%s',
WHERE %s %s',
$source_select,
$source_sql,
$user,
$user,
$user,
$read
$read,
$source_extra
);
return (int) db_get_sql($sql);