diff options
author | Mario <mario@mariovavti.com> | 2024-07-28 18:44:07 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2024-07-28 18:44:07 +0000 |
commit | 241cc1ad634cd7999bcac882b9fc9a5e06873818 (patch) | |
tree | 007effd91b9e26a9347655c6d8534ba7e994579e /boot.php | |
parent | b26db5bde602db31bdd3016b1395fe5143d924f4 (diff) | |
download | volse-hubzilla-241cc1ad634cd7999bcac882b9fc9a5e06873818.tar.gz volse-hubzilla-241cc1ad634cd7999bcac882b9fc9a5e06873818.tar.bz2 volse-hubzilla-241cc1ad634cd7999bcac882b9fc9a5e06873818.zip |
storing info and notice messages in the session has some disadvantages if the functions are called via ajax. revert to storing them in xconfig.
Diffstat (limited to 'boot.php')
-rw-r--r-- | boot.php | 76 |
1 files changed, 75 insertions, 1 deletions
@@ -1897,6 +1897,8 @@ function can_view_public_stream() { */ function notice($s) { +/* + if (!session_id()) { return; } @@ -1914,6 +1916,42 @@ function notice($s) { if (App::$interactive) { $_SESSION['sysmsg'][] = $s; } +*/ + + $hash = get_observer_hash(); + $sse_id = false; + + if (!$hash) { + if (session_id()) { + $sse_id = true; + $hash = 'sse_id.' . session_id(); + } + else { + return; + } + } + + $x = null; + + $t = get_xconfig($hash, 'sse', 'timestamp', NULL_DATE); + + if (datetime_convert('UTC', 'UTC', $t) < datetime_convert('UTC', 'UTC', '- 30 seconds')) { + set_xconfig($hash, 'sse', 'notifications', []); + $x = []; + } + + if ($x === null) { + $x = get_xconfig($hash, 'sse', 'notifications', []); + } + + if (isset($x['notice']) && in_array($s, $x['notice']['notifications'])) { + return; + } + + if (App::$interactive) { + $x['notice']['notifications'][] = $s; + set_xconfig($hash, 'sse', 'notifications', $x); + } } @@ -1928,7 +1966,7 @@ function notice($s) { * @param string $s Text to display */ function info($s) { - +/* if (!session_id()) { return; } @@ -1946,6 +1984,42 @@ function info($s) { if (App::$interactive) { $_SESSION['sysmsg_info'][] = $s; } +*/ + + $hash = get_observer_hash(); + $sse_id = false; + + if (!$hash) { + if (session_id()) { + $sse_id = true; + $hash = 'sse_id.' . session_id(); + } + else { + return; + } + } + + $x = null; + + $t = get_xconfig($hash, 'sse', 'timestamp', NULL_DATE); + + if (datetime_convert('UTC', 'UTC', $t) < datetime_convert('UTC', 'UTC', '- 30 seconds')) { + set_xconfig($hash, 'sse', 'notifications', []); + $x = []; + } + + if ($x === null) { + $x = get_xconfig($hash, 'sse', 'notifications', []); + } + + if (isset($x['info']) && in_array($s, $x['info']['notifications'])) { + return; + } + + if (App::$interactive) { + $x['info']['notifications'][] = $s; + set_xconfig($hash, 'sse', 'notifications', $x); + } } |