From 3fca63a15f50743952ce87672974145a0c2b4abb Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 20 Jul 2024 13:08:52 +0000 Subject: Revert "Revert "more work on sse sys messages"" This reverts commit c22f633ae0d42b5a0076a11dd08952817a613342 --- Zotlabs/Module/Login.php | 2 +- Zotlabs/Module/Sse.php | 78 ++++++++++++++++++++++++++++++---------- boot.php | 94 ++++++++---------------------------------------- view/pdl/mod_home.pdl | 3 ++ view/pdl/mod_login.pdl | 6 ++++ 5 files changed, 83 insertions(+), 100 deletions(-) create mode 100644 view/pdl/mod_login.pdl diff --git a/Zotlabs/Module/Login.php b/Zotlabs/Module/Login.php index 6430939b4..721ac15ac 100644 --- a/Zotlabs/Module/Login.php +++ b/Zotlabs/Module/Login.php @@ -12,5 +12,5 @@ class Login extends \Zotlabs\Web\Controller { return login(true); } - + } diff --git a/Zotlabs/Module/Sse.php b/Zotlabs/Module/Sse.php index df4a74f7b..a5b5c7e35 100644 --- a/Zotlabs/Module/Sse.php +++ b/Zotlabs/Module/Sse.php @@ -23,14 +23,7 @@ class Sse extends Controller { killme(); } - if(! intval(Config::Get('system','open_pubstream',1))) { - if(! get_observer_hash()) { - killme(); - } - } - // this is important! - session_write_close(); ignore_user_abort(true); self::$uid = local_channel(); @@ -48,6 +41,8 @@ class Sse extends Controller { } } + + if (self::$uid) { self::$vnotify = get_pconfig(self::$uid, 'system', 'vnotify'); } @@ -102,7 +97,6 @@ class Sse extends Controller { } } - $result = []; XConfig::Load(self::$ob_hash); @@ -110,9 +104,19 @@ class Sse extends Controller { $lock = XConfig::Get(self::$ob_hash, 'sse', 'lock'); if (!$lock) { - $result = XConfig::Get(self::$ob_hash, 'sse', 'notifications', []); + $result_db = XConfig::Get(self::$ob_hash, 'sse', 'notifications', []); + } + + if (!empty($_SESSION['sysmsg'])) { + $result['notice']['notifications'] = $_SESSION['sysmsg']; + } + + if (!empty($_SESSION['sysmsg_info'])) { + $result['info']['notifications'] = $_SESSION['sysmsg_info']; } + $result = array_merge($result, $result_db); + // We do not have the local_channel in the addon. // Reset pubs here if the app is not installed. if (self::$uid && (!(self::$vnotify & VNOTIFY_PUBS) || !Apps::system_app_installed(self::$uid, 'Public Stream'))) { @@ -133,22 +137,36 @@ class Sse extends Controller { echo "\n\n"; } - if (ob_get_length() > 0) { - ob_end_flush(); - } - - flush(); - if (connection_status() != CONNECTION_NORMAL || connection_aborted()) { XConfig::Set(self::$ob_hash, 'sse', 'timestamp', NULL_DATE); XConfig::Set(self::$ob_hash, 'sse', 'notifications', []); + $_SESSION['sysmsg'] = []; + $_SESSION['sysmsg_info'] = []; + + if (ob_get_length() > 0) { + ob_end_flush(); + } + + flush(); + exit; } + if (ob_get_length() > 0) { + ob_flush(); + } + + flush(); + usleep($sleep); if ($result) { - XConfig::Set(self::$ob_hash, 'sse', 'notifications', []); + if ($result_db) { + XConfig::Set(self::$ob_hash, 'sse', 'notifications', []); + } + + $_SESSION['sysmsg'] = []; + $_SESSION['sysmsg_info'] = []; } $i++; @@ -186,13 +204,35 @@ class Sse extends Controller { } } + $result = []; + $result_db = []; + XConfig::Load(self::$ob_hash); - $result = XConfig::Get(self::$ob_hash, 'sse', 'notifications', []); $lock = XConfig::Get(self::$ob_hash, 'sse', 'lock'); - if($result && !$lock) { - XConfig::Set(self::$ob_hash, 'sse', 'notifications', []); + if (!$lock) { + $result_db = XConfig::Get(self::$ob_hash, 'sse', 'notifications', []); + } + + if (!empty($_SESSION['sysmsg'])) { + $result['notice']['notifications'] = $_SESSION['sysmsg']; + } + + if (!empty($_SESSION['sysmsg_info'])) { + $result['info']['notifications'] = $_SESSION['sysmsg_info']; + } + + $result = array_merge($result, $result_db); + + if($result) { + if ($result_db) { + XConfig::Set(self::$ob_hash, 'sse', 'notifications', []); + } + + $_SESSION['sysmsg'] = []; + $_SESSION['sysmsg_info'] = []; + json_return_and_die($result); } diff --git a/boot.php b/boot.php index 78ad668ca..2b9e8ccba 100644 --- a/boot.php +++ b/boot.php @@ -1897,57 +1897,22 @@ function can_view_public_stream() { */ function notice($s) { - /* - if(! session_id()) - return; - - if(! x($_SESSION, 'sysmsg')) $_SESSION['sysmsg'] = array(); - - // ignore duplicated error messages which haven't yet been displayed - // - typically seen as multiple 'permission denied' messages - // as a result of auto-reloading a protected page with &JS=1 - - if(in_array($s, $_SESSION['sysmsg'])) - return; - - 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; - } + if (!session_id()) { + 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 (!isset($_SESSION['sysmsg'])) { + $_SESSION['sysmsg'] = []; } - if ($x === null) { - $x = get_xconfig($hash, 'sse', 'notifications', []); - } + // ignore duplicated error messages which haven't yet been displayed - if (isset($x['notice']) && in_array($s, $x['notice']['notifications'])) { + if (in_array($s, $_SESSION['sysmsg'])) { return; } if (App::$interactive) { - $x['notice']['notifications'][] = $s; - set_xconfig($hash, 'sse', 'notifications', $x); + $_SESSION['sysmsg'][] = $s; } } @@ -1964,53 +1929,22 @@ function notice($s) { */ function info($s) { - /* - if(! session_id()) - return; - - if(! x($_SESSION, 'sysmsg_info')) - $_SESSION['sysmsg_info'] = array(); - - if(in_array($s, $_SESSION['sysmsg_info'])) - return; - - 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; - } + if (!session_id()) { + 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 (!isset($_SESSION['sysmsg_info'])) { + $_SESSION['sysmsg_info'] = []; } - if ($x === null) { - $x = get_xconfig($hash, 'sse', 'notifications', []); - } + // ignore duplicated error messages which haven't yet been displayed - if (isset($x['info']) && in_array($s, $x['info']['notifications'])) { + if (in_array($s, $_SESSION['sysmsg_info'])) { return; } if (App::$interactive) { - $x['info']['notifications'][] = $s; - set_xconfig($hash, 'sse', 'notifications', $x); + $_SESSION['sysmsg_info'][] = $s; } } diff --git a/view/pdl/mod_home.pdl b/view/pdl/mod_home.pdl index 8b3ff52f8..2660f63e0 100644 --- a/view/pdl/mod_home.pdl +++ b/view/pdl/mod_home.pdl @@ -1,3 +1,6 @@ +[region=aside] +[widget=notifications][var=sys_only]1[/var][/widget] +[/region] [region=content] $content [/region] diff --git a/view/pdl/mod_login.pdl b/view/pdl/mod_login.pdl new file mode 100644 index 000000000..3065703de --- /dev/null +++ b/view/pdl/mod_login.pdl @@ -0,0 +1,6 @@ +[region=aside] +[widget=notifications][var=sys_only]1[/var][/widget] +[/region] +[region=content] +$content +[/region] -- cgit v1.2.3