aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-07-08 20:35:08 +0000
committerMario <mario@mariovavti.com>2024-07-08 20:35:08 +0000
commit5cbae0fb81078a60c9fa507be9c725856d7ecb29 (patch)
tree32bcec63c1b3d13feb1576f4512e73ba1cca14ef /Zotlabs
parent2ddc0875128e17a9e36393974d721f19ccbe64e3 (diff)
downloadvolse-hubzilla-5cbae0fb81078a60c9fa507be9c725856d7ecb29.tar.gz
volse-hubzilla-5cbae0fb81078a60c9fa507be9c725856d7ecb29.tar.bz2
volse-hubzilla-5cbae0fb81078a60c9fa507be9c725856d7ecb29.zip
improve handling of sse especially in relation with page reloads
Diffstat (limited to 'Zotlabs')
-rw-r--r--Zotlabs/Lib/XConfig.php2
-rw-r--r--Zotlabs/Module/Admin/Channels.php2
-rw-r--r--Zotlabs/Module/Sse.php51
3 files changed, 30 insertions, 25 deletions
diff --git a/Zotlabs/Lib/XConfig.php b/Zotlabs/Lib/XConfig.php
index 76ac8dc7a..5eed9224e 100644
--- a/Zotlabs/Lib/XConfig.php
+++ b/Zotlabs/Lib/XConfig.php
@@ -83,7 +83,7 @@ class XConfig {
return $default;
if(! array_key_exists($xchan, \App::$config))
- load_xconfig($xchan);
+ self::Load($xchan);
if((! array_key_exists($family, \App::$config[$xchan])) || (! array_key_exists($key, \App::$config[$xchan][$family])))
return $default;
diff --git a/Zotlabs/Module/Admin/Channels.php b/Zotlabs/Module/Admin/Channels.php
index 52b661420..cd1d2b6fe 100644
--- a/Zotlabs/Module/Admin/Channels.php
+++ b/Zotlabs/Module/Admin/Channels.php
@@ -126,7 +126,7 @@ class Channels {
goaway(z_root() . '/admin/channels' );
}
- $key = (($_REQUEST['key']) ? dbesc($_REQUEST['key']) : 'channel_id');
+ $key = ((isset($_REQUEST['key']) && $_REQUEST['key']) ? dbesc($_REQUEST['key']) : 'channel_id');
$dir = 'asc';
if(array_key_exists('dir',$_REQUEST))
$dir = ((intval($_REQUEST['dir'])) ? 'asc' : 'desc');
diff --git a/Zotlabs/Module/Sse.php b/Zotlabs/Module/Sse.php
index 5baa90128..41ff24352 100644
--- a/Zotlabs/Module/Sse.php
+++ b/Zotlabs/Module/Sse.php
@@ -31,13 +31,14 @@ class Sse extends Controller {
// this is important!
session_write_close();
+ ignore_user_abort(true);
self::$uid = local_channel();
self::$ob_hash = get_observer_hash();
self::$sse_id = false;
self::$vnotify = -1;
- if(! self::$ob_hash) {
+ if (!self::$ob_hash) {
if(session_id()) {
self::$sse_id = true;
self::$ob_hash = 'sse_id.' . session_id();
@@ -55,7 +56,7 @@ class Sse extends Controller {
self::$sse_enabled = Config::Get('system', 'sse_enabled', 0);
- if(self::$sse_enabled) {
+ if (self::$sse_enabled) {
// Server Sent Events
@@ -73,7 +74,7 @@ class Sse extends Controller {
$i = 0;
}
- if(!self::$sse_id && $i === 0) {
+ if (!self::$sse_id && $i === 0) {
// Update chat presence indication about once per minute
$r = q("select cp_id, cp_room from chatpresence where cp_xchan = '%s' and cp_client = '%s' and cp_room = 0 limit 1",
dbesc(self::$ob_hash),
@@ -82,7 +83,7 @@ class Sse extends Controller {
$basic_presence = false;
- if($r) {
+ if ($r) {
$basic_presence = true;
q("update chatpresence set cp_last = '%s' where cp_id = %d",
dbesc(datetime_convert()),
@@ -90,7 +91,7 @@ class Sse extends Controller {
);
}
- if(!$basic_presence) {
+ if (!$basic_presence) {
q("insert into chatpresence ( cp_xchan, cp_last, cp_status, cp_client)
values( '%s', '%s', '%s', '%s' ) ",
dbesc(self::$ob_hash),
@@ -101,16 +102,17 @@ class Sse extends Controller {
}
}
- XConfig::Load(self::$ob_hash);
$result = [];
+
+ XConfig::Load(self::$ob_hash);
+
$lock = XConfig::Get(self::$ob_hash, 'sse', 'lock');
if (!$lock) {
$result = XConfig::Get(self::$ob_hash, 'sse', 'notifications', []);
}
-
// 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'))) {
@@ -119,35 +121,38 @@ class Sse extends Controller {
}
}
- if($result) {
+ if ($result) {
echo "event: notifications\n";
echo 'data: ' . json_encode($result);
echo "\n\n";
-
- XConfig::Set(self::$ob_hash, 'sse', 'notifications', []);
- unset($result);
+ }
+ else {
+ // if no result we will send a heartbeat to keep connected
+ echo "event: heartbeat\n";
+ echo 'data: {}';
+ echo "\n\n";
}
- // always send heartbeat to detect disconnected clients
- echo "event: heartbeat\n";
- echo 'data: {}';
- echo "\n\n";
-
- if(ob_get_length() > 0)
+ if (connection_status() != CONNECTION_NORMAL || connection_aborted()) {
ob_end_flush();
+ flush();
- flush();
-
- if(connection_status() != CONNECTION_NORMAL || connection_aborted()) {
- //TODO: this does not seem to be triggered
XConfig::Set(self::$ob_hash, 'sse', 'timestamp', NULL_DATE);
- break;
+
+ exit;
}
- $i++;
+ ob_flush();
+ flush();
+
+ if ($result) {
+ XConfig::Set(self::$ob_hash, 'sse', 'notifications', []);
+ }
usleep($sleep);
+ $i++;
+
}
}