aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2020-05-14 09:27:39 +0000
committerMario <mario@mariovavti.com>2020-05-14 09:27:39 +0000
commit4270e17bc4ffedd35ddc5e00f7037162e9b95725 (patch)
treed53d7ed6f8d0ef2f13efb742f5ba19c5dc1ad4a1
parent1329662edcfc9650982a770247fb52d3ab9c55a3 (diff)
downloadvolse-hubzilla-4270e17bc4ffedd35ddc5e00f7037162e9b95725.tar.gz
volse-hubzilla-4270e17bc4ffedd35ddc5e00f7037162e9b95725.tar.bz2
volse-hubzilla-4270e17bc4ffedd35ddc5e00f7037162e9b95725.zip
implement notifications for direct messages
-rw-r--r--Zotlabs/Module/Sse_bs.php75
-rw-r--r--Zotlabs/Widget/Notifications.php20
-rw-r--r--view/js/main.js4
3 files changed, 95 insertions, 4 deletions
diff --git a/Zotlabs/Module/Sse_bs.php b/Zotlabs/Module/Sse_bs.php
index 23bc3c96b..2f3567e70 100644
--- a/Zotlabs/Module/Sse_bs.php
+++ b/Zotlabs/Module/Sse_bs.php
@@ -57,6 +57,7 @@ class Sse_bs extends Controller {
$_SESSION['sse_loadtime'] = datetime_convert();
$network = false;
+ $dm = false;
$home = false;
$pubs = false;
$f = '';
@@ -66,6 +67,10 @@ class Sse_bs extends Controller {
$network = true;
$f = 'bs_network';
break;
+ case 'dm':
+ $dm = true;
+ $f = 'bs_dm';
+ break;
case 'home':
$home = true;
$f = 'bs_home';
@@ -84,6 +89,7 @@ class Sse_bs extends Controller {
$result = array_merge(
self::bs_network($network),
+ self::bs_dm($dm),
self::bs_home($home),
self::bs_notify(),
self::bs_intros(),
@@ -127,7 +133,7 @@ class Sse_bs extends Controller {
$items = q("SELECT * FROM item
WHERE uid = %d
AND created <= '%s'
- AND item_unseen = 1 AND item_wall = 0
+ AND item_unseen = 1 AND item_wall = 0 AND item_private IN (0, 1)
AND obj_type NOT IN ('Document', 'Video', 'Audio', 'Image')
AND author_xchan != '%s'
$item_normal
@@ -153,7 +159,7 @@ class Sse_bs extends Controller {
}
$r = q("SELECT count(id) as total FROM item
- WHERE uid = %d and item_unseen = 1 AND item_wall = 0
+ WHERE uid = %d and item_unseen = 1 AND item_wall = 0 AND item_private IN (0, 1)
$item_normal
$sql_extra
AND author_xchan != '%s'",
@@ -167,6 +173,71 @@ class Sse_bs extends Controller {
return $result;
}
+ function bs_dm($notifications) {
+
+ $result['dm']['notifications'] = [];
+ $result['dm']['count'] = 0;
+
+ if(! self::$uid)
+ return $result;
+
+ $limit = intval(self::$limit);
+ $offset = self::$offset;
+
+ $sql_extra = '';
+ if(! (self::$vnotify & VNOTIFY_LIKE))
+ $sql_extra = " AND verb NOT IN ('" . dbesc(ACTIVITY_LIKE) . "', '" . dbesc(ACTIVITY_DISLIKE) . "') ";
+
+ $sql_extra2 = '';
+ if(self::$xchans)
+ $sql_extra2 = " AND CASE WHEN verb = '" . ACTIVITY_SHARE . "' THEN owner_xchan ELSE author_xchan END IN (" . self::$xchans . ") ";
+
+ $item_normal = item_normal();
+
+ if ($notifications) {
+ $items = q("SELECT * FROM item
+ WHERE uid = %d
+ AND created <= '%s'
+ AND item_unseen = 1 AND item_wall = 0 AND item_private = 2
+ AND obj_type NOT IN ('Document', 'Video', 'Audio', 'Image')
+ AND author_xchan != '%s'
+ $item_normal
+ $sql_extra
+ $sql_extra2
+ ORDER BY created DESC LIMIT $limit OFFSET $offset",
+ intval(self::$uid),
+ dbescdate($_SESSION['sse_loadtime']),
+ dbesc(self::$ob_hash)
+ );
+
+ if($items) {
+ $result['dm']['offset'] = ((count($items) == $limit) ? intval($offset + $limit) : -1);
+ xchan_query($items);
+ foreach($items as $item) {
+ $result['dm']['notifications'][] = Enotify::format($item);
+ }
+ }
+ else {
+ $result['dm']['offset'] = -1;
+ }
+
+ }
+
+ $r = q("SELECT count(id) as total FROM item
+ WHERE uid = %d and item_unseen = 1 AND item_wall = 0 AND item_private = 2
+ $item_normal
+ $sql_extra
+ AND author_xchan != '%s'",
+ intval(self::$uid),
+ dbesc(self::$ob_hash)
+ );
+
+ if($r)
+ $result['dm']['count'] = intval($r[0]['total']);
+
+ return $result;
+ }
+
function bs_home($notifications) {
$result['home']['notifications'] = [];
diff --git a/Zotlabs/Widget/Notifications.php b/Zotlabs/Widget/Notifications.php
index 077949b4e..e2a543f80 100644
--- a/Zotlabs/Widget/Notifications.php
+++ b/Zotlabs/Widget/Notifications.php
@@ -28,6 +28,7 @@ class Notifications {
]
];
+
$notifications[] = [
'type' => 'home',
'icon' => 'home',
@@ -48,6 +49,25 @@ class Notifications {
];
$notifications[] = [
+ 'type' => 'dm',
+ 'icon' => 'envelope',
+ 'severity' => 'danger',
+ 'label' => t('New Direct Messages'),
+ 'title' => t('New Direct Messages Notifications'),
+ 'viewall' => [
+ 'url' => 'network/?dm=1',
+ 'label' => t('View your direct messages')
+ ],
+ 'markall' => [
+ 'label' => t('Mark all notifications read')
+ ],
+ 'filter' => [
+ 'posts_label' => t('Show new posts only'),
+ 'name_label' => t('Filter by name or address')
+ ]
+ ];
+
+ $notifications[] = [
'type' => 'mail',
'icon' => 'envelope',
'severity' => 'danger',
diff --git a/view/js/main.js b/view/js/main.js
index 49c0bed97..c172b9365 100644
--- a/view/js/main.js
+++ b/view/js/main.js
@@ -1744,7 +1744,7 @@ function sse_bs_notifications(e, replace, followup) {
function sse_handleNotifications(obj, replace, followup) {
- var primary_notifications = ['home', 'intros', 'register', 'mail', 'notify', 'files'];
+ var primary_notifications = ['dm', 'home', 'intros', 'register', 'mail', 'notify', 'files'];
var secondary_notifications = ['network', 'forums', 'all_events', 'pubs'];
var all_notifications = primary_notifications.concat(secondary_notifications);
@@ -1855,7 +1855,7 @@ function sse_updateNotifications(type, mid) {
}
function sse_setNotificationsStatus() {
- var primary_notifications = ['home', 'intros', 'register', 'mail', 'notify', 'files'];
+ var primary_notifications = ['dm', 'home', 'intros', 'register', 'mail', 'notify', 'files'];
var secondary_notifications = ['network', 'forums', 'all_events', 'pubs'];
var all_notifications = primary_notifications.concat(secondary_notifications);