]> git.mxchange.org Git - friendica.git/blobdiff - include/enotify.php
Merge pull request #9444 from annando/update
[friendica.git] / include / enotify.php
index e89857b4041cc75d2bedd024ff739d52625a5f76..b7fe18a18fe4b6cb9e154f9b68e20dbd592b7cce 100644 (file)
@@ -87,12 +87,15 @@ function notification($params)
        }
        $nickname = $user["nickname"];
 
+       // Creates a new email builder for the notification email
+       $emailBuilder = DI::emailer()->newNotifyMail();
+
        // with $params['show_in_notification_page'] == false, the notification isn't inserted into
        // the database, and an email is sent if applicable.
        // default, if not specified: true
        $show_in_notification_page = isset($params['show_in_notification_page']) ? $params['show_in_notification_page'] : true;
 
-       $additional_mail_header = "X-Friendica-Account: <".$nickname."@".$hostname.">\n";
+       $emailBuilder->setHeader('X-Friendica-Account', '<' . $nickname . '@' . $hostname . '>');
 
        if (array_key_exists('item', $params)) {
                $title = $params['item']['title'];
@@ -509,7 +512,8 @@ function notification($params)
                Logger::log('sending notification email');
 
                if (isset($params['parent']) && (intval($params['parent']) != 0)) {
-                       $id_for_parent = $params['parent'] . "@" . $hostname;
+                       $parent = Item::selectFirst(['guid'], ['id' => $params['parent']]);
+                       $message_id = "<" . $parent['guid'] . "@" . gethostname() . ">";
 
                        // Is this the first email notification for this parent item and user?
                        if (!DBA::exists('notify-threads', ['master-parent-item' => $params['parent'], 'receiver-uid' => $params['uid']])) {
@@ -520,13 +524,14 @@ function notification($params)
                                        'receiver-uid' => $params['uid'], 'parent-item' => 0];
                                DBA::insert('notify-threads', $fields);
 
-                               $additional_mail_header .= "Message-ID: <${id_for_parent}>\n";
+                               $emailBuilder->setHeader('Message-ID', $message_id);
                                $log_msg                = "include/enotify: No previous notification found for this parent:\n" .
                                                          "  parent: ${params['parent']}\n" . "  uid   : ${params['uid']}\n";
                                Logger::log($log_msg, Logger::DEBUG);
                        } else {
                                // If not, just "follow" the thread.
-                               $additional_mail_header .= "References: <${id_for_parent}>\nIn-Reply-To: <${id_for_parent}>\n";
+                               $emailBuilder->setHeader('References', $message_id);
+                               $emailBuilder->setHeader('In-Reply-To', $message_id);
                                Logger::log("There's already a notification for this parent.", Logger::DEBUG);
                        }
                }
@@ -545,14 +550,13 @@ function notification($params)
                        'title'        => $title,
                        'body'         => $body,
                        'subject'      => $subject,
-                       'headers'      => $additional_mail_header,
+                       'headers'      => $emailBuilder->getHeaders(),
                ];
 
                Hook::callAll('enotify_mail', $datarray);
 
-               $builder = DI::emailer()
-                       ->newNotifyMail()
-                       ->addHeaders($datarray['headers'])
+               $emailBuilder
+                       ->withHeaders($datarray['headers'])
                        ->withRecipient($params['to_email'])
                        ->forUser([
                                'uid' => $datarray['uid'],
@@ -564,13 +568,13 @@ function notification($params)
 
                // If a photo is present, add it to the email
                if (!empty($datarray['source_photo'])) {
-                       $builder->withPhoto(
+                       $emailBuilder->withPhoto(
                                $datarray['source_photo'],
                                $datarray['source_link'] ?? $sitelink,
                                $datarray['source_name'] ?? $sitename);
                }
 
-               $email = $builder->build();
+               $email = $emailBuilder->build();
 
                // use the Emailer class to send the message
                return DI::emailer()->send($email);
@@ -645,6 +649,11 @@ function check_item_notification($itemid, $uid, $notification_type) {
                if ($item['gravity'] == GRAVITY_ACTIVITY) {
                        $parent_item = Item::selectFirst($fields, ['uri-id' => $item['thr-parent-id'], 'uid' => [$uid, 0]]);
                        if (DBA::isResult($parent_item)) {
+                               // Don't notify on own entries
+                               if (User::getIdForURL($parent_item['author-link']) == $uid) {
+                                       return false;
+                               }
+
                                $params['origin_name'] = $parent_item['author-name'];
                                $params['origin_link'] = $parent_item['author-link'];
                                $params['origin_photo'] = $parent_item['author-avatar'];