aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Module/Sse.php63
-rw-r--r--boot.php76
2 files changed, 90 insertions, 49 deletions
diff --git a/Zotlabs/Module/Sse.php b/Zotlabs/Module/Sse.php
index daf344f2d..fda2f2be4 100644
--- a/Zotlabs/Module/Sse.php
+++ b/Zotlabs/Module/Sse.php
@@ -19,13 +19,14 @@ class Sse extends Controller {
function init() {
+ // This is important!
+ session_write_close();
+ ignore_user_abort(true);
+
if((observer_prohibited(true))) {
killme();
}
- // this is important!
- ignore_user_abort(true);
-
self::$uid = local_channel();
self::$ob_hash = get_observer_hash();
self::$sse_id = false;
@@ -102,19 +103,9 @@ class Sse extends Controller {
$lock = XConfig::Get(self::$ob_hash, 'sse', 'lock');
if (!$lock) {
- $result_db = XConfig::Get(self::$ob_hash, 'sse', 'notifications', []);
- }
-
- if (!empty($_SESSION['sysmsg'])) {
- $result['notice']['notifications'] = $_SESSION['sysmsg'];
+ $result = XConfig::Get(self::$ob_hash, 'sse', 'notifications', []);
}
- 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'))) {
@@ -137,8 +128,9 @@ class Sse extends Controller {
if (connection_status() != CONNECTION_NORMAL || connection_aborted()) {
- // IMPORTANT: in case the channel was changed we need to reset the
- // session here to it's current stored state.
+ // In case session_write_close() failed for some reason and
+ // the channel was changed we might need to reset the
+ // session to it's current stored state here.
// Otherwise the uid might switch back to the previous value
// in the background.
@@ -147,9 +139,6 @@ class Sse extends Controller {
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();
}
@@ -168,12 +157,7 @@ class Sse extends Controller {
usleep($sleep);
if ($result) {
- if ($result_db) {
- XConfig::Set(self::$ob_hash, 'sse', 'notifications', []);
- }
-
- $_SESSION['sysmsg'] = [];
- $_SESSION['sysmsg_info'] = [];
+ XConfig::Set(self::$ob_hash, 'sse', 'notifications', []);
}
$i++;
@@ -184,7 +168,7 @@ class Sse extends Controller {
else {
// Fallback to traditional polling
- if(! self::$sse_id) {
+ if(!self::$sse_id) {
// Update chat presence indication
@@ -193,14 +177,14 @@ class Sse extends Controller {
dbesc($_SERVER['REMOTE_ADDR'])
);
$basic_presence = false;
- if($r) {
+ if ($r) {
$basic_presence = true;
q("update chatpresence set cp_last = '%s' where cp_id = %d",
dbesc(datetime_convert()),
intval($r[0]['cp_id'])
);
}
- 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),
@@ -212,34 +196,17 @@ class Sse extends Controller {
}
$result = [];
- $result_db = [];
XConfig::Load(self::$ob_hash);
$lock = XConfig::Get(self::$ob_hash, 'sse', 'lock');
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 = XConfig::Get(self::$ob_hash, 'sse', 'notifications', []);
}
- $result = array_merge($result, $result_db);
-
- if($result) {
- if ($result_db) {
- XConfig::Set(self::$ob_hash, 'sse', 'notifications', []);
- }
-
- $_SESSION['sysmsg'] = [];
- $_SESSION['sysmsg_info'] = [];
-
+ if ($result) {
+ XConfig::Set(self::$ob_hash, 'sse', 'notifications', []);
json_return_and_die($result);
}
diff --git a/boot.php b/boot.php
index f40f5e39d..dcda705f0 100644
--- a/boot.php
+++ b/boot.php
@@ -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);
+ }
}