From: Michael <heluecht@pirati.ca>
Date: Sat, 12 Jan 2019 16:09:27 +0000 (+0000)
Subject: Issue 6282: Update the forum status of contacts
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=297a549590844568c21137a936ec2a2c1eafd79b;p=friendica.git

Issue 6282: Update the forum status of contacts
---

diff --git a/src/Model/APContact.php b/src/Model/APContact.php
index 5f47313dc8..2b5a5c4e7b 100644
--- a/src/Model/APContact.php
+++ b/src/Model/APContact.php
@@ -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;
 				}
 			}
 		}
diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php
index 5933ccf289..d6b0a482ec 100644
--- a/src/Protocol/DFRN.php
+++ b/src/Protocol/DFRN.php
@@ -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);
 		}
 
 
diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php
index 0579bfa245..b3b3f1c65c 100644
--- a/src/Worker/OnePoll.php
+++ b/src/Worker/OnePoll.php
@@ -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;
 		}