]> git.mxchange.org Git - friendica.git/blobdiff - mod/message.php
Merge remote-tracking branch 'upstream/develop' into contact-tabs
[friendica.git] / mod / message.php
index 06203b8394525da5e539a66970417de5818d502d..f04bdaecd72dfb4284ce5cd7e68169655e93da7b 100644 (file)
@@ -1,6 +1,22 @@
 <?php
 /**
- * @file mod/message.php
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
  */
 
 use Friendica\App;
@@ -8,15 +24,14 @@ use Friendica\Content\Nav;
 use Friendica\Content\Pager;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\ACL;
-use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Mail;
+use Friendica\Model\Notify\Type;
 use Friendica\Module\Security\Login;
 use Friendica\Util\DateTimeFormat;
-use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
 
@@ -52,7 +67,7 @@ function message_init(App $a)
 function message_post(App $a)
 {
        if (!local_user()) {
-               notice(DI::l10n()->t('Permission denied.') . EOL);
+               notice(DI::l10n()->t('Permission denied.'));
                return;
        }
 
@@ -66,20 +81,18 @@ function message_post(App $a)
 
        switch ($ret) {
                case -1:
-                       notice(DI::l10n()->t('No recipient selected.') . EOL);
+                       notice(DI::l10n()->t('No recipient selected.'));
                        $norecip = true;
                        break;
                case -2:
-                       notice(DI::l10n()->t('Unable to locate contact information.') . EOL);
+                       notice(DI::l10n()->t('Unable to locate contact information.'));
                        break;
                case -3:
-                       notice(DI::l10n()->t('Message could not be sent.') . EOL);
+                       notice(DI::l10n()->t('Message could not be sent.'));
                        break;
                case -4:
-                       notice(DI::l10n()->t('Message collection failure.') . EOL);
+                       notice(DI::l10n()->t('Message collection failure.'));
                        break;
-               default:
-                       info(DI::l10n()->t('Message sent.') . EOL);
        }
 
        // fake it to go back to the input form if no recipient listed
@@ -97,7 +110,7 @@ function message_content(App $a)
        Nav::setSelected('messages');
 
        if (!local_user()) {
-               notice(DI::l10n()->t('Permission denied.') . EOL);
+               notice(DI::l10n()->t('Permission denied.'));
                return Login::form();
        }
 
@@ -162,17 +175,16 @@ function message_content(App $a)
                if ($cmd === 'drop') {
                        $message = DBA::selectFirst('mail', ['convid'], ['id' => $a->argv[2], 'uid' => local_user()]);
                        if(!DBA::isResult($message)){
-                               info(DI::l10n()->t('Conversation not found.') . EOL);
+                               notice(DI::l10n()->t('Conversation not found.'));
                                DI::baseUrl()->redirect('message');
                        }
 
-                       if (DBA::delete('mail', ['id' => $a->argv[2], 'uid' => local_user()])) {
-                               info(DI::l10n()->t('Message deleted.') . EOL);
+                       if (!DBA::delete('mail', ['id' => $a->argv[2], 'uid' => local_user()])) {
+                               notice(DI::l10n()->t('Message was not deleted.'));
                        }
 
                        $conversation = DBA::selectFirst('mail', ['id'], ['convid' => $message['convid'], 'uid' => local_user()]);
                        if(!DBA::isResult($conversation)){
-                               info(DI::l10n()->t('Conversation removed.') . EOL);
                                DI::baseUrl()->redirect('message');
                        }
 
@@ -185,8 +197,8 @@ function message_content(App $a)
                        if (DBA::isResult($r)) {
                                $parent = $r[0]['parent-uri'];
 
-                               if (DBA::delete('mail', ['parent-uri' => $parent, 'uid' => local_user()])) {
-                                       info(DI::l10n()->t('Conversation removed.') . EOL);
+                               if (!DBA::delete('mail', ['parent-uri' => $parent, 'uid' => local_user()])) {
+                                       notice(DI::l10n()->t('Conversation was not removed.'));
                                }
                        }
                        DI::baseUrl()->redirect('message');
@@ -280,12 +292,12 @@ function message_content(App $a)
                        $total = $r[0]['total'];
                }
 
-               $pager = new Pager(DI::args()->getQueryString());
+               $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
 
                $r = get_messages(local_user(), $pager->getStart(), $pager->getItemsPerPage());
 
                if (!DBA::isResult($r)) {
-                       info(DI::l10n()->t('No messages.') . EOL);
+                       notice(DI::l10n()->t('No messages.'));
                        return $o;
                }
 
@@ -336,19 +348,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()]);
+                       DBA::update('notify', ['seen' => 1], ['type' => Type::MAIL, 'parent' => $message['id'], 'uid' => local_user()]);
                } else {
                        $messages = false;
                }
 
                if (!DBA::isResult($messages)) {
-                       notice(DI::l10n()->t('Message not available.') . EOL);
+                       notice(DI::l10n()->t('Message not available.'));
                        return $o;
                }
 
@@ -386,12 +392,8 @@ function message_content(App $a)
                        $body_e = BBCode::convert($message['body']);
                        $to_name_e = $message['name'];
 
-                       $contact = Contact::getDetailsByURL($message['from-url']);
-                       if (isset($contact["thumb"])) {
-                               $from_photo = $contact["thumb"];
-                       } else {
-                               $from_photo = $message['from-photo'];
-                       }
+                       $contact = Contact::getByURL($message['from-url'], false, ['thumb', 'addr', 'id', 'avatar']);
+                       $from_photo = Contact::getThumb($contact, $message['from-photo']);
 
                        $mails[] = [
                                'id' => $message['id'],
@@ -399,7 +401,7 @@ function message_content(App $a)
                                'from_url' => $from_url,
                                'from_addr' => $contact['addr'],
                                'sparkle' => $sparkle,
-                               'from_photo' => ProxyUtils::proxifyUrl($from_photo, false, ProxyUtils::SIZE_THUMB),
+                               'from_photo' => $from_photo,
                                'subject' => $subject_e,
                                'body' => $body_e,
                                'delete' => DI::l10n()->t('Delete message'),
@@ -518,12 +520,8 @@ function render_messages(array $msg, $t)
                $body_e = $rr['body'];
                $to_name_e = $rr['name'];
 
-               $contact = Contact::getDetailsByURL($rr['url']);
-               if (isset($contact["thumb"])) {
-                       $from_photo = $contact["thumb"];
-               } else {
-                       $from_photo = (($rr['thumb']) ? $rr['thumb'] : $rr['from-photo']);
-               }
+               $contact = Contact::getByURL($rr['url'], false, ['thumb', 'addr', 'id', 'avatar']);
+               $from_photo = Contact::getThumb($contact, $rr['thumb'] ?: $rr['from-photo']);
 
                $rslt .= Renderer::replaceMacros($tpl, [
                        '$id' => $rr['id'],
@@ -531,7 +529,7 @@ function render_messages(array $msg, $t)
                        '$from_url' => Contact::magicLink($rr['url']),
                        '$from_addr' => $contact['addr'] ?? '',
                        '$sparkle' => ' sparkle',
-                       '$from_photo' => ProxyUtils::proxifyUrl($from_photo, false, ProxyUtils::SIZE_THUMB),
+                       '$from_photo' => $from_photo,
                        '$subject' => $rr['title'],
                        '$delete' => DI::l10n()->t('Delete conversation'),
                        '$body' => $body_e,
@@ -539,7 +537,7 @@ function render_messages(array $msg, $t)
                        '$date' => DateTimeFormat::local($rr['mailcreated'], DI::l10n()->t('D, d M Y - g:i A')),
                        '$ago' => Temporal::getRelativeDate($rr['mailcreated']),
                        '$seen' => $rr['mailseen'],
-                       '$count' => L10n::tt('%d message', '%d messages', $rr['count']),
+                       '$count' => DI::l10n()->tt('%d message', '%d messages', $rr['count']),
                ]);
        }