Added update ball notifications

Former-commit-id: 60c253a1b64d1084ae732e88e0a6fb1f98cf8a12
This commit is contained in:
fermin831 2019-02-11 14:44:14 +01:00
parent 1223ce69da
commit 17c012cd83
2 changed files with 25 additions and 5 deletions

View File

@ -425,7 +425,22 @@ config_check();
"last_id": last_id "last_id": last_id
}, },
function (data, status) { function (data, status) {
// TODO if(!data.has_new_notifications) return;
// Substitute the ball
var new_ball = atob(data.new_ball);
var ball_wrapper = document
.getElementById('notification-ball-header')
.parentElement;
if (ball_wrapper === null) {
console.error('Cannot update notification ball');
return;
}
ball_wrapper.innerHTML = new_ball;
// Show the toasts
//TODO
}, },
"json" "json"
) )

View File

@ -98,15 +98,20 @@ if (get_parameter('check_new_notifications', 0)) {
$last_id_ui = (int) get_parameter('last_id', 0); $last_id_ui = (int) get_parameter('last_id', 0);
$counters = notifications_get_counters(); $counters = notifications_get_counters();
if ((int) $last_id_ui === (int) $counters['last_id']) { if ((int) $last_id_ui === (int) $counters['last_id']) {
echo json_encode(['new_notifications' => []]); echo json_encode(['has_new_notifications' => false]);
return; return;
} }
// If there is new messages, get the info. // If there is new messages, get the info.
echo json_encode( echo json_encode(
[ [
'notifications' => $counters['notifications'], 'has_new_notifications' => true,
'last_id' => $counters['last_id'], 'new_ball' => base64_encode(
notifications_print_ball(
$counters['notifications'],
$counters['last_id']
)
),
'new_notifications' => messages_get_overview( 'new_notifications' => messages_get_overview(
'timestamp', 'timestamp',
'ASC', 'ASC',