]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #6433 from annando/issue-6282
authorHypolite Petovan <hypolite@mrpetovan.com>
Sat, 12 Jan 2019 19:46:04 +0000 (14:46 -0500)
committerGitHub <noreply@github.com>
Sat, 12 Jan 2019 19:46:04 +0000 (14:46 -0500)
Issue 6282: Update the forum status of contacts

src/Model/APContact.php
src/Protocol/DFRN.php
src/Worker/OnePoll.php

index 5f47313dc8d86f382c26ee633ec1f253b766f76e..2b5a5c4e7b15015636170933b764d82e31071b75 100644 (file)
@@ -157,8 +157,9 @@ class APContact extends BaseObject
 
                $apcontact['pubkey'] = trim(JsonLD::fetchElement($compacted, 'w3id:publicKey', 'w3id:publicKeyPem'));
 
+               $manually_approve = JsonLD::fetchElement($compacted, 'as:manuallyApprovesFollowers');
+
                // To-Do
-               // manuallyApprovesFollowers
 
                // Unhandled
                // @context, tag, attachment, image, nomadicLocations, signature, following, followers, featured, movedTo, liked
@@ -197,10 +198,14 @@ class APContact extends BaseObject
                        if (is_int($contact_type)) {
                                $contact_fields['contact-type'] = $contact_type;
 
-                               // Resetting the 'forum' and 'prv' field when it isn't a forum
                                if ($contact_fields['contact-type'] != Contact::ACCOUNT_TYPE_COMMUNITY) {
+                                       // Resetting the 'forum' and 'prv' field when it isn't a forum
                                        $contact_fields['forum'] = false;
                                        $contact_fields['prv'] = false;
+                               } else {
+                                       // Otherwise set the corresponding forum type
+                                       $contact_fields['forum'] = !$manually_approve;
+                                       $contact_fields['prv'] = $manually_approve;
                                }
                        }
                }
index 5933ccf2891114e3d8579d4050c68bc10c924ee7..d6b0a482ec94c439734b6b49436913346d7a07df 100644 (file)
@@ -2850,19 +2850,41 @@ class DFRN
 
                // The account type is new since 3.5.1
                if ($xpath->query("/atom:feed/dfrn:account_type")->length > 0) {
+                       // Hint: We are using separate update calls for uid=0 and uid!=0 since a combined call is bad for the database performance
+
                        $accounttype = intval(XML::getFirstNodeValue($xpath, "/atom:feed/dfrn:account_type/text()"));
 
                        if ($accounttype != $importer["contact-type"]) {
-                               DBA::update('contact', ['contact-type' => $accounttype], ['id' => $importer["id"]]);
+                               DBA::update('contact', ['contact-type' => $accounttype], ['id' => $importer['id']]);
+
+                               // Updating the public contact as well
+                               DBA::update('contact', ['contact-type' => $accounttype], ['uid' => 0, 'nurl' => $importer['nurl']]);
                        }
                        // A forum contact can either have set "forum" or "prv" - but not both
-                       if (($accounttype == Contact::ACCOUNT_TYPE_COMMUNITY) && (($forum != $importer["forum"]) || ($forum == $importer["prv"]))) {
-                               $condition = ['(`forum` != ? OR `prv` != ?) AND `id` = ?', $forum, !$forum, $importer["id"]];
+                       if ($accounttype == Contact::ACCOUNT_TYPE_COMMUNITY) {
+                               // It's a forum, so either set the public or private forum flag
+                               $condition = ['(`forum` != ? OR `prv` != ?) AND `id` = ?', $forum, !$forum, $importer['id']];
+                               DBA::update('contact', ['forum' => $forum, 'prv' => !$forum], $condition);
+
+                               // Updating the public contact as well
+                               $condition = ['(`forum` != ? OR `prv` != ?) AND `uid` = 0 AND `nurl` = ?', $forum, !$forum, $importer['nurl']];
                                DBA::update('contact', ['forum' => $forum, 'prv' => !$forum], $condition);
+                       } else {
+                               // It's not a forum, so remove the flags
+                               $condition = ['(`forum` OR `prv`) AND `id` = ?', $importer['id']];
+                               DBA::update('contact', ['forum' => false, 'prv' => false], $condition);
+
+                               // Updating the public contact as well
+                               $condition = ['(`forum` OR `prv`) AND `uid` = 0 AND `nurl` = ?', $importer['nurl']];
+                               DBA::update('contact', ['forum' => false, 'prv' => false], $condition);
                        }
                } elseif ($forum != $importer["forum"]) { // Deprecated since 3.5.1
                        $condition = ['`forum` != ? AND `id` = ?', $forum, $importer["id"]];
                        DBA::update('contact', ['forum' => $forum], $condition);
+
+                       // Updating the public contact as well
+                       $condition = ['`forum` != ? AND `uid` = 0 AND `nurl` = ?', $forum, $importer['nurl']];
+                       DBA::update('contact', ['forum' => $forum], $condition);
                }
 
 
index 0579bfa24505f8979dd6fd5534cf32f5950bbdb2..b3b3f1c65c1585550c79d0bbe51884a3bf9b92f1 100644 (file)
@@ -11,6 +11,7 @@ use Friendica\Core\Logger;
 use Friendica\Core\PConfig;
 use Friendica\Core\Protocol;
 use Friendica\Database\DBA;
+use Friendica\Model\APContact;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Protocol\ActivityPub;
@@ -60,7 +61,12 @@ class OnePoll
                        $contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
                }
 
-               // We currently don't do anything with AP here
+               // These three networks can be able to speak AP, so we are trying to fetch AP profile data here
+               if (in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::DFRN])) {
+                       APContact::getByURL($contact['url']);
+               }
+
+               // We currently don't do anything more with AP here
                if ($contact['network'] === Protocol::ACTIVITYPUB) {
                        return;
                }