]> git.mxchange.org Git - friendica.git/commitdiff
Use the "contact-type" instead of "forum" or "prv"
authorMichael <heluecht@pirati.ca>
Wed, 9 Feb 2022 06:52:16 +0000 (06:52 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 9 Feb 2022 06:52:16 +0000 (06:52 +0000)
12 files changed:
database.sql
src/Content/Widget/VCard.php
src/Model/Contact.php
src/Model/Profile.php
src/Module/Contact.php
src/Module/Contact/Hovercard.php
src/Module/Contact/Profile.php
src/Module/Conversation/Network.php
src/Module/Directory.php
src/Protocol/DFRN.php
static/dbstructure.config.php
update.php

index b7a923618def59740e1d0f759fa2dd0d40c127c7..4237bcce344bd7df88f24db0f12bc1bd99e0244a 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2022.05-dev (Siberian Iris)
--- DB_UPDATE_VERSION 1450
+-- DB_UPDATE_VERSION 1451
 -- ------------------------------------------
 
 
index d230afd303109e181d0d8df48980ab13dc1af59a..7f75c6c9c0e588a9c567d30cdc1a0530007a8c8a 100644 (file)
@@ -99,7 +99,7 @@ class VCard
                        '$network_link'     => $network_link,
                        '$network_avatar'   => $network_avatar,
                        '$network'          => DI::l10n()->t('Network:'),
-                       '$account_type'     => Contact::getAccountType($contact),
+                       '$account_type'     => Contact::getAccountType($contact['contact-type']),
                        '$follow'           => DI::l10n()->t('Follow'),
                        '$follow_link'      => $follow_link,
                        '$unfollow'         => DI::l10n()->t('Unfollow'),
index 0af28a7401d4aa396d27fa8b57d2464171bf2e5e..1b39247f4efef4fdc7c5767bc99a1bd3be1b0887 100644 (file)
@@ -1457,34 +1457,11 @@ class Contact
         *
         * The function can be called with either the user or the contact array
         *
-        * @param array $contact contact or user array
+        * @param int $type type of contact or account
         * @return string
         */
-       public static function getAccountType(array $contact)
-       {
-               // There are several fields that indicate that the contact or user is a forum
-               // "page-flags" is a field in the user table,
-               // "forum" and "prv" are used in the contact table. They stand for User::PAGE_FLAGS_COMMUNITY and User::PAGE_FLAGS_PRVGROUP.
-               if ((isset($contact['page-flags']) && (intval($contact['page-flags']) == User::PAGE_FLAGS_COMMUNITY))
-                       || (isset($contact['page-flags']) && (intval($contact['page-flags']) == User::PAGE_FLAGS_PRVGROUP))
-                       || (isset($contact['forum']) && intval($contact['forum']))
-                       || (isset($contact['prv']) && intval($contact['prv']))
-                       || (isset($contact['community']) && intval($contact['community']))
-               ) {
-                       $type = self::TYPE_COMMUNITY;
-               } else {
-                       $type = self::TYPE_PERSON;
-               }
-
-               // The "contact-type" (contact table) and "account-type" (user table) are more general then the chaos from above.
-               if (isset($contact["contact-type"])) {
-                       $type = $contact["contact-type"];
-               }
-
-               if (isset($contact["account-type"])) {
-                       $type = $contact["account-type"];
-               }
-
+       public static function getAccountType(int $type)
+       {
                switch ($type) {
                        case self::TYPE_ORGANISATION:
                                $account_type = DI::l10n()->t("Organisation");
@@ -2947,7 +2924,7 @@ class Contact
         */
        public static function isForum($contactid)
        {
-               $fields = ['contact-type', 'forum', 'prv'];
+               $fields = ['contact-type'];
                $condition = ['id' => $contactid];
                $contact = DBA::selectFirst('contact', $fields, $condition);
                if (!DBA::isResult($contact)) {
@@ -2955,7 +2932,7 @@ class Contact
                }
 
                // Is it a forum?
-               return (($contact['contact-type'] == self::TYPE_COMMUNITY) || $contact['forum'] || $contact['prv']);
+               return ($contact['contact-type'] == self::TYPE_COMMUNITY);
        }
 
        /**
index cb7fa65479513f7ea99967fcbd6c491d227ee9f2..d779355202575618dac8bf2b98e593b513c92d00 100644 (file)
@@ -362,7 +362,7 @@ class Profile
                }
 
                // Fetch the account type
-               $account_type = Contact::getAccountType($profile);
+               $account_type = Contact::getAccountType($profile['account-type']);
 
                if (!empty($profile['address']) || !empty($profile['location'])) {
                        $location = DI::l10n()->t('Location:');
index d571016f199ff08b7c86ffd84b703f2ae9e212bb..c7b2870ece4c9523ac7dcd78483727aadc9bdd8f 100644 (file)
@@ -558,7 +558,7 @@ class Contact extends BaseModule
                        'details'      => $contact['location'],
                        'tags'         => $contact['keywords'],
                        'about'        => $contact['about'],
-                       'account_type' => Model\Contact::getAccountType($contact),
+                       'account_type' => Model\Contact::getAccountType($contact['contact-type']),
                        'sparkle'      => $sparkle,
                        'itemurl'      => ($contact['addr'] ?? '') ?: $contact['url'],
                        'network'      => ContactSelector::networkToName($contact['network'], $contact['url'], $contact['protocol'], $contact['gsid']),
index ec77a19cb97279cb43bbcac74e34655748f22595..cd03e2533a158d229863a7a8ca8c76fb6cd17f1d 100644 (file)
@@ -101,7 +101,7 @@ class Hovercard extends BaseModule
                                'network_link' => Strings::formatNetworkName($contact['network'], $contact['url']),
                                'tags'         => $contact['keywords'],
                                'bd'           => $contact['bd'] <= DBA::NULL_DATE ? '' : $contact['bd'],
-                               'account_type' => Contact::getAccountType($contact),
+                               'account_type' => Contact::getAccountType($contact['contact-type']),
                                'actions'      => $actions,
                        ],
                ]);
index e02a6a3dc608562dba872ac608430ec8ba99e2bb..8ab8dae60e98a4e4906b1b0eae23c70768565d48 100644 (file)
@@ -364,7 +364,7 @@ class Profile extends BaseModule
                        '$url'                       => $url,
                        '$profileurllabel'           => $this->t('Profile URL'),
                        '$profileurl'                => $contact['url'],
-                       '$account_type'              => Contact::getAccountType($contact),
+                       '$account_type'              => Contact::getAccountType($contact['contact-type']),
                        '$location'                  => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['location']),
                        '$location_label'            => $this->t('Location:'),
                        '$xmpp'                      => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['xmpp']),
index 908d0a63b4df251c7c67935d8ab75b7a7d8963ba..2978ecbb9d72dfd86ed129feb8418daebb9b4356 100644 (file)
@@ -119,7 +119,7 @@ class Network extends BaseModule
 
                        if (self::$forumContactId) {
                                // If self::$forumContactId belongs to a communitity forum or a privat goup,.add a mention to the status editor
-                               $condition = ["`id` = ? AND (`forum` OR `prv`)", self::$forumContactId];
+                               $condition = ["`id` = ? AND `contact-type` = ?", self::$forumContactId, Contact::TYPE_COMMUNITY];
                                $contact = DBA::selectFirst('contact', ['addr'], $condition);
                                if (!empty($contact['addr'])) {
                                        $content = '!' . $contact['addr'];
index 3a0a9fa34e211b74431d5f0a4523ba5c8f498db8..8d7b8611b64e1f03f09cf745f3a37b3a3297d673 100644 (file)
@@ -165,7 +165,7 @@ class Directory extends BaseModule
                        'img_hover'    => $contact['name'],
                        'name'         => $contact['name'],
                        'details'      => $details,
-                       'account_type' => Model\Contact::getAccountType($contact),
+                       'account_type' => Model\Contact::getAccountType($contact['contact-type']),
                        'profile'      => $profile,
                        'location'     => $location_e,
                        'tags'         => $contact['pub_keywords'],
index 833c616ab9b2eafaf438b305757b6844a9c99d00..94b1b1689d8c562c4803d1b5f48a6f7d3c139360 100644 (file)
@@ -925,9 +925,9 @@ class DFRN
 
                foreach ($mentioned as $mention) {
                        $condition = ['uid' => $owner["uid"], 'nurl' => Strings::normaliseLink($mention)];
-                       $contact = DBA::selectFirst('contact', ['forum', 'prv'], $condition);
+                       $contact = DBA::selectFirst('contact', ['contact-type'], $condition);
 
-                       if (DBA::isResult($contact) && ($contact["forum"] || $contact["prv"])) {
+                       if (DBA::isResult($contact) && ($contact['contact-type'] == Contact::TYPE_COMMUNITY)) {
                                XML::addElement(
                                        $doc,
                                        $entry,
index 2e1a2191c0119a5cc734eb35c37d7801b0b1efec..014185c92aa8dc53aabd8f1c2fcbf4c45e01f623 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1450);
+       define('DB_UPDATE_VERSION', 1451);
 }
 
 return [
index 7b5f6778be7df92807978de0e88126016fa10e9f..6e9c294c1fe5618fab763637fb4e5d3ccdee69bf 100644 (file)
@@ -55,6 +55,7 @@ use Friendica\Model\Notification;
 use Friendica\Model\Photo;
 use Friendica\Model\Post;
 use Friendica\Model\Profile;
+use Friendica\Model\User;
 use Friendica\Security\PermissionSet\Repository\PermissionSet;
 use Friendica\Worker\Delivery;
 
@@ -1087,3 +1088,11 @@ function update_1446()
 
        return Update::SUCCESS;
 }
+
+function update_1451()
+{
+       DBA::update('user', ['account-type' => User::ACCOUNT_TYPE_COMMUNITY], ['page-flags' => [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP]]);
+       DBA::update('contact', ['contact-type' => Contact::TYPE_COMMUNITY], ["`forum` OR `prv`"]);
+
+       return Update::SUCCESS;
+}