]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact.php
Replace remaining references to default banner image by api.mastodon_banner configura...
[friendica.git] / src / Model / Contact.php
index 4787eeab9e9e72e1d3edff82f05c1b8e9201b18a..d91abe9bcdb0b3070fa579b0171be4da3b4ef6e1 100644 (file)
@@ -22,7 +22,9 @@
 namespace Friendica\Model;
 
 use Friendica\Contact\Avatar;
+use Friendica\Contact\Header;
 use Friendica\Contact\Introduction\Exception\IntroductionNotFoundException;
+use Friendica\Contact\LocalRelationship\Entity\LocalRelationship;
 use Friendica\Content\Conversation as ConversationContent;
 use Friendica\Content\Pager;
 use Friendica\Content\Text\HTML;
@@ -111,10 +113,14 @@ class Contact
         * @}
         */
 
-       const MIRROR_DEACTIVATED = 0;
-       const MIRROR_FORWARDED = 1; // Deprecated, now does the same like MIRROR_OWN_POST
-       const MIRROR_OWN_POST = 2;
-       const MIRROR_NATIVE_RESHARE = 3;
+       /** @deprecated Use Entity\LocalRelationship::MIRROR_DEACTIVATED instead */
+       const MIRROR_DEACTIVATED = LocalRelationship::MIRROR_DEACTIVATED;
+       /** @deprecated Now does the same as MIRROR_OWN_POST */
+       const MIRROR_FORWARDED = 1;
+       /** @deprecated Use Entity\LocalRelationship::MIRROR_OWN_POST instead */
+       const MIRROR_OWN_POST = LocalRelationship::MIRROR_OWN_POST;
+       /** @deprecated Use Entity\LocalRelationship::MIRROR_NATIVE_RESHARE instead */
+       const MIRROR_NATIVE_RESHARE = LocalRelationship::MIRROR_NATIVE_RESHARE;
 
        /**
         * @param array $fields    Array of selected fields, empty for all
@@ -799,7 +805,7 @@ class Contact
                        return false;
                }
 
-               $fields = ['uid', 'nickname', 'page-flags', 'account-type', 'prvkey', 'pubkey'];
+               $fields = ['uid', 'username', 'nickname', 'page-flags', 'account-type', 'prvkey', 'pubkey'];
                $user = DBA::selectFirst('user', $fields, ['uid' => $uid, 'account_expired' => false]);
                if (!DBA::isResult($user)) {
                        return false;
@@ -818,7 +824,7 @@ class Contact
                $url = DI::baseUrl() . '/profile/' . $user['nickname'];
 
                $fields = [
-                       'name'         => $profile['name'],
+                       'name'         => $user['username'],
                        'nick'         => $user['nickname'],
                        'avatar-date'  => $self['avatar-date'],
                        'location'     => Profile::formatLocation($profile),
@@ -841,7 +847,6 @@ class Contact
                        'confirm'      => DI::baseUrl() . '/dfrn_confirm/' . $user['nickname'],
                ];
 
-
                $avatar = Photo::selectFirst(['resource-id', 'type'], ['uid' => $uid, 'profile' => true]);
                if (DBA::isResult($avatar)) {
                        if ($update_avatar) {
@@ -1626,7 +1631,7 @@ class Contact
                                }
                        }
 
-                       $o .= DI::conversation()->create($items, ConversationContent::MODE_CONTACTS, $update, false, 'pinned_commented', DI::userSession()->getLocalUserId());
+                       $o .= DI::conversation()->render($items, ConversationContent::MODE_CONTACTS, $update, false, 'pinned_commented', DI::userSession()->getLocalUserId());
                } else {
                        $fields = array_merge(Item::DISPLAY_FIELDLIST, ['featured']);
                        $items = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), $fields, $condition, $params));
@@ -1643,7 +1648,7 @@ class Contact
                                }
                        }
 
-                       $o .= DI::conversation()->create($items, ConversationContent::MODE_CONTACT_POSTS, $update);
+                       $o .= DI::conversation()->render($items, ConversationContent::MODE_CONTACT_POSTS, $update);
                }
 
                if (!$update) {
@@ -1895,13 +1900,7 @@ class Contact
                switch ($platform) {
                        case 'friendica':
                        case 'friendika':
-                               /**
-                                * Picture credits
-                                * @author  Lostinlight <https://mastodon.xyz/@lightone>
-                                * @license CC0 https://creativecommons.org/share-your-work/public-domain/cc0/
-                                * @link    https://gitlab.com/lostinlight/per_aspera_ad_astra/-/blob/master/friendica-404/friendica-promo-bubbles.jpg
-                                */
-                               $header = DI::baseUrl() . '/images/friendica-banner.jpg';
+                               $header = DI::baseUrl() . (new Header(DI::config()))->getMastodonBannerPath();
                                break;
                        case 'diaspora':
                                /**
@@ -2595,7 +2594,7 @@ class Contact
         * @throws HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function updateFromProbe(int $id, string $network = '')
+       public static function updateFromProbe(int $id, string $network = ''): bool
        {
                $contact = DBA::selectFirst('contact', ['uid', 'url'], ['id' => $id]);
                if (!DBA::isResult($contact)) {
@@ -2811,7 +2810,7 @@ class Contact
                }
 
                $update = false;
-               $guid = ($ret['guid'] ?? '') ?: Item::guidFromUri($ret['url'], $ret['baseurl'] ?? $ret['alias']);
+               $guid = ($ret['guid'] ?? '') ?: Item::guidFromUri($ret['url'], $ret['baseurl'] ?? $ret['alias'] ?? '');
 
                // make sure to not overwrite existing values with blank entries except some technical fields
                $keep = ['batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'baseurl'];
@@ -3098,31 +3097,32 @@ class Contact
 
                        // create contact record
                        self::insert([
-                               'uid'     => $uid,
-                               'created' => DateTimeFormat::utcNow(),
-                               'url'     => $ret['url'],
-                               'nurl'    => Strings::normaliseLink($ret['url']),
-                               'addr'    => $ret['addr'],
-                               'alias'   => $ret['alias'],
-                               'batch'   => $ret['batch'],
-                               'notify'  => $ret['notify'],
-                               'poll'    => $ret['poll'],
-                               'poco'    => $ret['poco'],
-                               'name'    => $ret['name'],
-                               'nick'    => $ret['nick'],
-                               'network' => $ret['network'],
-                               'baseurl' => $ret['baseurl'],
-                               'gsid'    => $ret['gsid'] ?? null,
-                               'protocol' => $protocol,
-                               'pubkey'  => $ret['pubkey'],
-                               'rel'     => $new_relation,
-                               'priority' => $ret['priority'],
-                               'writable' => $writeable,
-                               'hidden'  => $hidden,
-                               'blocked' => 0,
-                               'readonly' => 0,
-                               'pending' => $pending,
-                               'subhub'  => $subhub
+                               'uid'          => $uid,
+                               'created'      => DateTimeFormat::utcNow(),
+                               'url'          => $ret['url'],
+                               'nurl'         => Strings::normaliseLink($ret['url']),
+                               'addr'         => $ret['addr'],
+                               'alias'        => $ret['alias'],
+                               'batch'        => $ret['batch'],
+                               'notify'       => $ret['notify'],
+                               'poll'         => $ret['poll'],
+                               'poco'         => $ret['poco'],
+                               'name'         => $ret['name'],
+                               'nick'         => $ret['nick'],
+                               'network'      => $ret['network'],
+                               'baseurl'      => $ret['baseurl'],
+                               'gsid'         => $ret['gsid'] ?? null,
+                               'contact-type' => $ret['account-type'] ?? self::TYPE_PERSON,
+                               'protocol'     => $protocol,
+                               'pubkey'       => $ret['pubkey'],
+                               'rel'          => $new_relation,
+                               'priority'     => $ret['priority'],
+                               'writable'     => $writeable,
+                               'hidden'       => $hidden,
+                               'blocked'      => 0,
+                               'readonly'     => 0,
+                               'pending'      => $pending,
+                               'subhub'       => $subhub
                        ]);
                }
 
@@ -3135,7 +3135,11 @@ class Contact
                $contact_id = $contact['id'];
                $result['cid'] = $contact_id;
 
-               Circle::addMember(User::getDefaultCircle($uid), $contact_id);
+               if ($contact['contact-type'] == self::TYPE_COMMUNITY) {
+                       Circle::addMember(User::getDefaultGroupCircle($uid), $contact_id);
+               } else {
+                       Circle::addMember(User::getDefaultCircle($uid), $contact_id);
+               }
 
                // Update the avatar
                self::updateAvatar($contact_id, $ret['photo']);
@@ -3265,7 +3269,7 @@ class Contact
 
                        Post\UserNotification::insertNotification($pub_contact['id'], Activity::FOLLOW, $importer['uid']);
 
-                       $contact_record = DBA::selectFirst('contact', ['id', 'network', 'name', 'url', 'photo'], ['id' => $contact_id]);
+                       $contact_record = DBA::selectFirst('contact', ['id', 'network', 'name', 'url', 'photo', 'contact-type'], ['id' => $contact_id]);
 
                        /// @TODO Encapsulate this into a function/method
                        $fields = ['uid', 'username', 'email', 'page-flags', 'notify-flags', 'language'];
@@ -3281,7 +3285,11 @@ class Contact
                                        DI::intro()->save($intro);
                                }
 
-                               Circle::addMember(User::getDefaultCircle($importer['uid']), $contact_record['id']);
+                               if ($contact_record['contact-type'] == self::TYPE_COMMUNITY) {
+                                       Circle::addMember(User::getDefaultGroupCircle($importer['uid']), $contact_record['id']);
+                               } else {
+                                       Circle::addMember(User::getDefaultCircle($importer['uid']), $contact_record['id']);
+                               }
 
                                if (($user['notify-flags'] & Notification\Type::INTRO) && $user['page-flags'] == User::PAGE_FLAGS_NORMAL) {
                                        DI::notify()->createFromArray([