aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Lib/XConfig.php2
-rw-r--r--Zotlabs/Module/Admin/Channels.php2
-rw-r--r--Zotlabs/Module/Sse.php51
-rw-r--r--boot.php28
4 files changed, 36 insertions, 47 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++;
+
}
}
diff --git a/boot.php b/boot.php
index 52c222b0a..88482cf2d 100644
--- a/boot.php
+++ b/boot.php
@@ -1928,19 +1928,11 @@ function notice($s) {
}
}
- $t = get_xconfig($hash, 'sse', 'timestamp', NULL_DATE);
+ $x = get_xconfig($hash, 'sse', 'notifications', []);
- if (datetime_convert('UTC', 'UTC', $t) < datetime_convert('UTC', 'UTC', '- 30 seconds')) {
- set_xconfig($hash, 'sse', 'notifications', []);
- }
-
- $x = get_xconfig($hash, 'sse', 'notifications');
-
- if ($x === false)
- $x = [];
-
- if (isset($x['notice']) && in_array($s, $x['notice']['notifications']))
+ if (isset($x['notice']) && in_array($s, $x['notice']['notifications'])) {
return;
+ }
if (App::$interactive) {
$x['notice']['notifications'][] = $s;
@@ -1988,19 +1980,11 @@ function info($s) {
}
}
- $t = get_xconfig($hash, 'sse', 'timestamp', NULL_DATE);
+ $x = get_xconfig($hash, 'sse', 'notifications', []);
- if (datetime_convert('UTC', 'UTC', $t) < datetime_convert('UTC', 'UTC', '- 30 seconds')) {
- set_xconfig($hash, 'sse', 'notifications', []);
- }
-
- $x = get_xconfig($hash, 'sse', 'notifications');
-
- if ($x === false)
- $x = [];
-
- if (isset($x['info']) && in_array($s, $x['info']['notifications']))
+ if (isset($x['info']) && in_array($s, $x['info']['notifications'])) {
return;
+ }
if (App::$interactive) {
$x['info']['notifications'][] = $s;