From b033597ada02ef045bc9fbdb2237f81935b73e47 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 11 Nov 2019 21:30:38 +0100 Subject: sse notifications --- boot.php | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'boot.php') diff --git a/boot.php b/boot.php index a9d93b5ae..9588d2c2a 100755 --- a/boot.php +++ b/boot.php @@ -1811,6 +1811,8 @@ function can_view_public_stream() { * @param string $s Text to display */ function notice($s) { + +/* if(! session_id()) return; @@ -1826,6 +1828,34 @@ function notice($s) { if(App::$interactive) { $_SESSION['sysmsg'][] = $s; } +*/ + + $hash = get_observer_hash(); + + if (! $hash) + return; + + + $t = get_xconfig($hash, 'sse', 'timestamp'); + + if(datetime_convert('UTC', 'UTC', $t) < datetime_convert('UTC', 'UTC', '- 30 seconds')) { + del_xconfig($hash, 'sse', 'notifications'); + } + + $x = get_xconfig($hash, 'sse', 'notifications'); + + if ($x === false) + $x = []; + + if (isset($x['notice']) && in_array($s, $x['notice']['notifications'])) + return; + + if (App::$interactive) { + $x['notice']['notifications'][] = $s; + set_xconfig($hash, 'sse', 'timestamp', datetime_convert()); + set_xconfig($hash, 'sse', 'notifications', $x); + } + } /** @@ -1839,8 +1869,11 @@ function notice($s) { * @param string $s Text to display */ function info($s) { + +/* if(! session_id()) return; + if(! x($_SESSION, 'sysmsg_info')) $_SESSION['sysmsg_info'] = array(); @@ -1849,6 +1882,33 @@ function info($s) { if(App::$interactive) $_SESSION['sysmsg_info'][] = $s; +*/ + + $hash = get_observer_hash(); + + if (! $hash) + return; + + $t = get_xconfig($hash, 'sse', 'timestamp'); + + if(datetime_convert('UTC', 'UTC', $t) < datetime_convert('UTC', 'UTC', '- 30 seconds')) { + del_xconfig($hash, 'sse', 'notifications'); + } + + $x = get_xconfig($hash, 'sse', 'notifications'); + + if($x === false) + $x = []; + + if(isset($x['info']) && in_array($s, $x['info']['notifications'])) + return; + + if(App::$interactive) { + $x['info']['notifications'][] = $s; + set_xconfig($hash, 'sse', 'timestamp', datetime_convert()); + set_xconfig($hash, 'sse', 'notifications', $x); + } + } /** -- cgit v1.2.3