From 12dfb8e5cfb63070cf14322fc0753656da4233ed Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 30 Dec 2018 01:04:20 -0500 Subject: [PATCH 1/6] Make NOTIFY_* constant values human-readable --- boot.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/boot.php b/boot.php index eb8176b83d..be217eadfc 100644 --- a/boot.php +++ b/boot.php @@ -164,21 +164,21 @@ define('MAX_LIKERS', 75); * Email notification options * @{ */ -define('NOTIFY_INTRO', 0x0001); -define('NOTIFY_CONFIRM', 0x0002); -define('NOTIFY_WALL', 0x0004); -define('NOTIFY_COMMENT', 0x0008); -define('NOTIFY_MAIL', 0x0010); -define('NOTIFY_SUGGEST', 0x0020); -define('NOTIFY_PROFILE', 0x0040); -define('NOTIFY_TAGSELF', 0x0080); -define('NOTIFY_TAGSHARE', 0x0100); -define('NOTIFY_POKE', 0x0200); -define('NOTIFY_SHARE', 0x0400); +define('NOTIFY_INTRO', 1); +define('NOTIFY_CONFIRM', 2); +define('NOTIFY_WALL', 4); +define('NOTIFY_COMMENT', 8); +define('NOTIFY_MAIL', 16); +define('NOTIFY_SUGGEST', 32); +define('NOTIFY_PROFILE', 64); +define('NOTIFY_TAGSELF', 128); +define('NOTIFY_TAGSHARE', 256); +define('NOTIFY_POKE', 512); +define('NOTIFY_SHARE', 1024); -define('SYSTEM_EMAIL', 0x4000); +define('SYSTEM_EMAIL', 16384); -define('NOTIFY_SYSTEM', 0x8000); +define('NOTIFY_SYSTEM', 32768); /* @}*/ From d838e6d0ecf2af14735da11f6e16a8831af01269 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 30 Dec 2018 01:04:52 -0500 Subject: [PATCH 2/6] Fix unread message conversation title display --- mod/message.php | 3 +-- view/theme/frio/templates/mail_list.tpl | 11 ++++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/mod/message.php b/mod/message.php index 9ef55fbfe8..f36b3ffa3b 100644 --- a/mod/message.php +++ b/mod/message.php @@ -499,7 +499,6 @@ function render_messages(array $msg, $t) $participants = L10n::t("%s and You", $rr['from-name']); } - $subject_e = (($rr['mailseen']) ? $rr['title'] : '' . $rr['title'] . ''); $body_e = $rr['body']; $to_name_e = $rr['name']; @@ -517,7 +516,7 @@ function render_messages(array $msg, $t) '$from_addr' => defaults($contact, 'addr', ''), '$sparkle' => ' sparkle', '$from_photo' => ProxyUtils::proxifyUrl($from_photo, false, ProxyUtils::SIZE_THUMB), - '$subject' => $subject_e, + '$subject' => $rr['title'], '$delete' => L10n::t('Delete conversation'), '$body' => $body_e, '$to_name' => $to_name_e, diff --git a/view/theme/frio/templates/mail_list.tpl b/view/theme/frio/templates/mail_list.tpl index 4a797d47c0..bfc21aabaf 100644 --- a/view/theme/frio/templates/mail_list.tpl +++ b/view/theme/frio/templates/mail_list.tpl @@ -12,7 +12,16 @@
{{$ago}}

{{$from_name}}

- + From 5abc22f6c536b4fea7a5becd53561959ba0e7512 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 30 Dec 2018 01:08:51 -0500 Subject: [PATCH 3/6] Replace q() with DBA methods, fix code style - Remove unused variables - Fix doc block - Fix indentation --- mod/message.php | 60 ++++++++++++++++++------------- mod/ping.php | 13 ++----- src/Protocol/Diaspora.php | 76 +++++++++++++++++++-------------------- 3 files changed, 74 insertions(+), 75 deletions(-) diff --git a/mod/message.php b/mod/message.php index f36b3ffa3b..0a80773c73 100644 --- a/mod/message.php +++ b/mod/message.php @@ -303,41 +303,51 @@ function message_content(App $a) $o .= $header; - $r = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb` - FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id` - WHERE `mail`.`uid` = %d AND `mail`.`id` = %d LIMIT 1", - intval(local_user()), - intval($a->argv[1]) + $message = DBA::fetchFirst(" + SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb` + FROM `mail` + LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id` + WHERE `mail`.`uid` = ? AND `mail`.`id` = ? + LIMIT 1", + local_user(), + $a->argv[1] ); - if (DBA::isResult($r)) { - $contact_id = $r[0]['contact-id']; - $convid = $r[0]['convid']; + if (DBA::isResult($message)) { + $contact_id = $message['contact-id']; - $sql_extra = sprintf(" and `mail`.`parent-uri` = '%s' ", DBA::escape($r[0]['parent-uri'])); - if ($convid) - $sql_extra = sprintf(" and ( `mail`.`parent-uri` = '%s' OR `mail`.`convid` = '%d' ) ", - DBA::escape($r[0]['parent-uri']), - intval($convid) - ); + $params = [ + local_user(), + $message['parent-uri'] + ]; - $messages = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb` - FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id` - WHERE `mail`.`uid` = %d $sql_extra ORDER BY `mail`.`created` ASC", - intval(local_user()) + if ($message['convid']) { + $sql_extra = "AND (`mail`.`parent-uri` = ? OR `mail`.`convid` = ?)"; + $params[] = $message['convid']; + } else { + $sql_extra = "AND `mail`.`parent-uri` = ?"; + } + $messages_stmt = DBA::p(" + SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb` + FROM `mail` + LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id` + WHERE `mail`.`uid` = ? + $sql_extra + ORDER BY `mail`.`created` ASC", + ...$params ); + + $messages = DBA::toArray($messages_stmt); + + DBA::update('mail', ['seen' => 1], ['parent-uri' => $message['parent-uri'], 'uid' => local_user()]); } else { $messages = false; } + if (!DBA::isResult($messages)) { notice(L10n::t('Message not available.') . EOL); return $o; } - $r = q("UPDATE `mail` SET `seen` = 1 WHERE `parent-uri` = '%s' AND `uid` = %d", - DBA::escape($r[0]['parent-uri']), - intval(local_user()) - ); - $tpl = Renderer::getMarkupTemplate('msg-header.tpl'); $a->page['htmlhead'] .= Renderer::replaceMacros($tpl, [ '$baseurl' => System::baseUrl(true), @@ -350,8 +360,10 @@ function message_content(App $a) $unknown = false; foreach ($messages as $message) { - if ($message['unknown']) + if ($message['unknown']) { $unknown = true; + } + if ($message['from-url'] == $myprofile) { $from_url = $myprofile; $sparkle = ''; diff --git a/mod/ping.php b/mod/ping.php index b315ecf4b9..2783b83ddb 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -64,14 +64,7 @@ function ping_init(App $a) $format = 'json'; } - $tags = []; - $comments = []; - $likes = []; - $dislikes = []; - $friends = []; - $posts = []; $regs = []; - $mails = []; $notifications = []; $intro_count = 0; @@ -427,8 +420,6 @@ function ping_get_notifications($uid) $order = "DESC"; $quit = false; - $a = get_app(); - do { $r = q( "SELECT `notify`.*, `item`.`visible`, `item`.`deleted` @@ -505,8 +496,8 @@ function ping_get_notifications($uid) * @param array $notifs Complete list of notification * @param array $sysmsgs List of system notice messages * @param array $sysmsgs_info List of system info messages - * @param int $groups_unseen Number of unseen group items - * @param int $forums_unseen Number of unseen forum items + * @param array $groups_unseen List of unseen group messages + * @param array $forums_unseen List of unseen forum messages * * @return array XML-transform ready data array */ diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 64009581b5..fb851e3356 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -1807,31 +1807,28 @@ class Diaspora return false; } - q( - "INSERT INTO `mail` (`uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`) - VALUES (%d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')", - intval($importer["uid"]), - DBA::escape($msg_guid), - intval($conversation["id"]), - DBA::escape($person["name"]), - DBA::escape($person["photo"]), - DBA::escape($person["url"]), - intval($contact["id"]), - DBA::escape($subject), - DBA::escape($body), - 0, - 0, - DBA::escape($message_uri), - DBA::escape($author.":".$guid), - DBA::escape($msg_created_at) - ); + DBA::insert('mail', [ + 'uid' => $importer['uid'], + 'guid' => $msg_guid, + 'convid' => $conversation['id'], + 'from-name' => $person['name'], + 'from-photo' => $person['photo'], + 'from-url' => $person['url'], + 'contact-id' => $contact['id'], + 'title' => $subject, + 'body' => $body, + 'seen' => 0, + 'reply' => 0, + 'uri' => $message_uri, + 'parent-uri' => $author . ':' . $guid, + 'created' => $msg_created_at + ]); DBA::unlock(); DBA::update('conv', ['updated' => DateTimeFormat::utcNow()], ['id' => $conversation["id"]]); - notification( - [ + notification([ "type" => NOTIFY_MAIL, "notify_flags" => $importer["notify-flags"], "language" => $importer["language"], @@ -1843,8 +1840,9 @@ class Diaspora "source_link" => $person["url"], "source_photo" => $person["photo"], "verb" => ACTIVITY_POST, - "otype" => "mail"] - ); + "otype" => "mail" + ]); + return true; } @@ -2066,24 +2064,22 @@ class Diaspora return false; } - q( - "INSERT INTO `mail` (`uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`) - VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')", - intval($importer["uid"]), - DBA::escape($guid), - intval($conversation["id"]), - DBA::escape($person["name"]), - DBA::escape($person["photo"]), - DBA::escape($person["url"]), - intval($contact["id"]), - DBA::escape($conversation["subject"]), - DBA::escape($body), - 0, - 1, - DBA::escape($message_uri), - DBA::escape($author.":".$conversation["guid"]), - DBA::escape($created_at) - ); + DBA::insert('mail', [ + 'uid' => $importer['uid'], + 'guid' => $guid, + 'convid' => $conversation['id'], + 'from-name' => $person['name'], + 'from-photo' => $person['photo'], + 'from-url' => $person['url'], + 'contact-id' => $contact['id'], + 'title' => $conversation['subject'], + 'body' => $body, + 'seen' => 0, + 'reply' => 1, + 'uri' => $message_uri, + 'parent-uri' => $author.":".$conversation['guid'], + 'created' => $created_at + ]); DBA::unlock(); From 3095d4aa706ff6047862f9bde366df70dcee382d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 30 Dec 2018 01:10:10 -0500 Subject: [PATCH 4/6] Add parent to private message notifications - Fix item id for Diaspora private message notification --- src/Protocol/DFRN.php | 1 + src/Protocol/Diaspora.php | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index c3366f5bcc..f8405ee92b 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -1870,6 +1870,7 @@ class DFRN "to_email" => $importer["email"], "uid" => $importer["importer_uid"], "item" => $msg, + "parent" => $msg["parent-uri"], "source_name" => $msg["from-name"], "source_link" => $importer["url"], "source_photo" => $importer["thumb"], diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index fb851e3356..b4e494121a 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -1824,6 +1824,8 @@ class Diaspora 'created' => $msg_created_at ]); + $message_id = DBA::lastInsertId(); + DBA::unlock(); DBA::update('conv', ['updated' => DateTimeFormat::utcNow()], ['id' => $conversation["id"]]); @@ -1834,8 +1836,9 @@ class Diaspora "language" => $importer["language"], "to_name" => $importer["username"], "to_email" => $importer["email"], - "uid" =>$importer["uid"], - "item" => ["id" => $conversation["id"], "title" => $subject, "subject" => $subject, "body" => $body], + "uid" => $importer["uid"], + "item" => ["id" => $message_id, "title" => $subject, "subject" => $subject, "body" => $body], + "parent" => $conversation["id"], "source_name" => $person["name"], "source_link" => $person["url"], "source_photo" => $person["photo"], @@ -2081,9 +2084,28 @@ class Diaspora 'created' => $created_at ]); + $message_id = DBA::lastInsertId(); + DBA::unlock(); DBA::update('conv', ['updated' => DateTimeFormat::utcNow()], ['id' => $conversation["id"]]); + + notification([ + "type" => NOTIFY_MAIL, + "notify_flags" => $importer["notify-flags"], + "language" => $importer["language"], + "to_name" => $importer["username"], + "to_email" => $importer["email"], + "uid" => $importer["uid"], + "item" => ["id" => $message_id, "title" => $conversation["subject"], "subject" => $conversation["subject"], "body" => $body], + "parent" => $conversation["id"], + "source_name" => $person["name"], + "source_link" => $person["url"], + "source_photo" => $person["photo"], + "verb" => ACTIVITY_POST, + "otype" => "mail" + ]); + return true; } From 36f995ed20e94c89661f324fc720d8e5c7be6b65 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 30 Dec 2018 01:11:02 -0500 Subject: [PATCH 5/6] Add notification clear on private message display --- mod/message.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mod/message.php b/mod/message.php index 0a80773c73..85ede744b9 100644 --- a/mod/message.php +++ b/mod/message.php @@ -339,6 +339,13 @@ function message_content(App $a) $messages = DBA::toArray($messages_stmt); DBA::update('mail', ['seen' => 1], ['parent-uri' => $message['parent-uri'], 'uid' => local_user()]); + + if ($message['convid']) { + // Clear Diaspora private message notifications + DBA::update('notify', ['seen' => 1], ['type' => NOTIFY_MAIL, 'parent' => $message['convid'], 'uid' => local_user()]); + } + // Clear DFRN private message notifications + DBA::update('notify', ['seen' => 1], ['type' => NOTIFY_MAIL, 'parent' => $message['parent-uri'], 'uid' => local_user()]); } else { $messages = false; } From e9b05bd13f1bf3f74c63202f6f9f9fa2f65f19f1 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 30 Dec 2018 01:11:30 -0500 Subject: [PATCH 6/6] Remove fake private message notifications from ping output --- mod/ping.php | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/mod/ping.php b/mod/ping.php index 2783b83ddb..18b126cce5 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -275,22 +275,6 @@ function ping_init(App $a) } } - if (DBA::isResult($mails)) { - foreach ($mails as $mail) { - $notif = [ - 'id' => 0, - 'href' => System::baseUrl() . '/message/' . $mail['id'], - 'name' => $mail['from-name'], - 'url' => $mail['from-url'], - 'photo' => $mail['from-photo'], - 'date' => $mail['created'], - 'seen' => false, - 'message' => L10n::t('{0} sent you a message'), - ]; - $notifs[] = $notif; - } - } - if (DBA::isResult($regs)) { foreach ($regs as $reg) { $notif = [ @@ -377,7 +361,7 @@ function ping_init(App $a) if ($format == 'json') { $data['groups'] = $groups_unseen; $data['forums'] = $forums_unseen; - $data['notify'] = $sysnotify_count + $intro_count + $mail_count + $register_count; + $data['notify'] = $sysnotify_count + $intro_count + $register_count; $data['notifications'] = $notifications; $data['sysmsgs'] = [ 'notice' => $sysmsgs,