]> git.mxchange.org Git - friendica.git/blobdiff - include/enotify.php
Merge pull request #7711 from annando/gserver-2
[friendica.git] / include / enotify.php
index f725511f5eee273cc72849e17afbc530ad09d784..6a66c8fa09a1822d7df160420e651659ce4dcb91 100644 (file)
@@ -11,8 +11,8 @@ use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
-use Friendica\Model\Contact;
 use Friendica\Model\Item;
+use Friendica\Model\User;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Emailer;
 use Friendica\Util\Strings;
@@ -33,8 +33,8 @@ function notification($params)
        $a = \get_app();
 
        // Temporary logging for finding the origin
-       if (!isset($params['language']) || !isset($params['uid'])) {
-               Logger::log('Missing parameters.' . System::callstack());
+       if (!isset($params['uid'])) {
+               Logger::notice('Missing parameters "uid".', ['params' => $params, 'callstack' => System::callstack()]);
        }
 
        // Ensure that the important fields are set at any time
@@ -42,7 +42,7 @@ function notification($params)
        $user = DBA::selectFirst('user', $fields, ['uid' => $params['uid']]);
 
        if (!DBA::isResult($user)) {
-               Logger::log('Unknown user ' . $params['uid']);
+               Logger::error('Unknown user', ['uid' =>  $params['uid']]);
                return false;
        }
 
@@ -142,7 +142,7 @@ function notification($params)
        }
 
        if ($params['type'] == NOTIFY_COMMENT || $params['type'] == NOTIFY_TAGSELF) {
-               $thread = Item::selectFirstThreadForUser($params['uid'], ['ignored'], ['iid' => $parent_id]);
+               $thread = Item::selectFirstThreadForUser($params['uid'], ['ignored'], ['iid' => $parent_id, 'deleted' => false]);
                if (DBA::isResult($thread) && $thread['ignored']) {
                        Logger::log('Thread ' . $parent_id . ' will be ignored', Logger::DEBUG);
                        L10n::popLang();
@@ -161,7 +161,7 @@ function notification($params)
                // if it's a post figure out who's post it is.
                $item = null;
                if ($params['otype'] === 'item' && $parent_id) {
-                       $item = Item::selectFirstForUser($params['uid'], Item::ITEM_FIELDLIST, ['id' => $parent_id]);
+                       $item = Item::selectFirstForUser($params['uid'], Item::ITEM_FIELDLIST, ['id' => $parent_id, 'deleted' => false]);
                }
 
                $item_post_type = Item::postType($item);
@@ -453,11 +453,20 @@ function notification($params)
                // It will be used by the system to send emails to users (like
                // password reset, invitations and so) using one look (but without
                // add a notification to the user, with could be inexistent)
-               $subject = $params['subject'];
+               if (!isset($params['subject'])) {
+                       Logger::warning('subject isn\'t set.', ['type' => $params['type']]);
+               }
+               $subject = defaults($params, 'subject', '');
 
-               $preamble = $params['preamble'];
+               if (!isset($params['preamble'])) {
+                       Logger::warning('preamble isn\'t set.', ['type' => $params['type'], 'subject' => $subject]);
+               }
+               $preamble = defaults($params, 'preamble', '');
 
-               $body =  $params['body'];
+               if (!isset($params['body'])) {
+                       Logger::warning('body isn\'t set.', ['type' => $params['type'], 'subject' => $subject, 'preamble' => $preamble]);
+               }
+               $body = defaults($params, 'body', '');
 
                $show_in_notification_page = false;
        }
@@ -774,8 +783,8 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
        $fields = ['id', 'mention', 'tag', 'parent', 'title', 'body',
                'author-link', 'author-name', 'author-avatar', 'author-id',
                'guid', 'parent-uri', 'uri', 'contact-id', 'network'];
-       $condition = ['id' => $itemid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]];
-       $item = Item::selectFirst($fields, $condition);
+       $condition = ['id' => $itemid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'deleted' => false];
+       $item = Item::selectFirstForUser($uid, $fields, $condition);
        if (!DBA::isResult($item) || in_array($item['author-id'], $contacts)) {
                return false;
        }
@@ -831,7 +840,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
 
        // Is it a post that the user had started?
        $fields = ['ignored', 'mention'];
-       $thread = Item::selectFirstThreadForUser($params['uid'], $fields, ['iid' => $item["parent"]]);
+       $thread = Item::selectFirstThreadForUser($params['uid'], $fields, ['iid' => $item["parent"], 'deleted' => false]);
 
        if ($thread['mention'] && !$thread['ignored'] && !isset($params["type"])) {
                $params["type"] = NOTIFY_COMMENT;
@@ -839,7 +848,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
        }
 
        // And now we check for participation of one of our contacts in the thread
-       $condition = ['parent' => $item["parent"], 'author-id' => $contacts];
+       $condition = ['parent' => $item["parent"], 'author-id' => $contacts, 'deleted' => false];
 
        if (!$thread['ignored'] && !isset($params["type"]) && Item::exists($condition)) {
                $params["type"] = NOTIFY_COMMENT;