]> git.mxchange.org Git - friendica.git/commitdiff
Use first word as platform / improvements for registered users
authorMichael <heluecht@pirati.ca>
Sun, 6 Feb 2022 05:59:47 +0000 (05:59 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 6 Feb 2022 05:59:47 +0000 (05:59 +0000)
src/Model/GServer.php

index 26c36d6a996db35d99e63d0fbec073314d5c16b7..4db851571b1635b3dad2b9a01cabf6b91a8a1120 100644 (file)
@@ -496,19 +496,19 @@ class GServer
                $serverdata['url'] = $url;
                $serverdata['nurl'] = Strings::normaliseLink($url);
 
-               // We take the highest number that we do find
-               $registeredUsers = $serverdata['registered-users'] ?? 0;
-
-               // On an active server there has to be at least a single user
-               if (($serverdata['network'] != Protocol::PHANTOM) && ($registeredUsers == 0)) {
-                       $registeredUsers = 1;
-               }
-
                if ($serverdata['network'] == Protocol::PHANTOM) {
-                       $serverdata['registered-users'] = max($registeredUsers, 1);
                        $serverdata = self::detectNetworkViaContacts($url, $serverdata);
                }
 
+               $serverdata['registered-users'] = $serverdata['registered-users'] ?? 0;
+
+               // On an active server there has to be at least a single user
+               if (!in_array($serverdata['network'], [Protocol::PHANTOM, Protocol::FEED]) && ($serverdata['registered-users'] == 0)) {
+                       $serverdata['registered-users'] = 1;
+               } elseif (in_array($serverdata['network'], [Protocol::PHANTOM, Protocol::FEED])) {
+                       $serverdata['registered-users'] = 0;
+               }
+
                $serverdata['next_contact'] = self::getNextUpdateDate(true);
 
                $serverdata['last_contact'] = DateTimeFormat::utcNow();
@@ -520,11 +520,6 @@ class GServer
                        $ret = DBA::insert('gserver', $serverdata);
                        $id = DBA::lastInsertId();
                } else {
-                       // Don't override the network with 'unknown' when there had been a valid entry before
-                       if (($serverdata['network'] == Protocol::PHANTOM) && !empty($gserver['network'])) {
-                               unset($serverdata['network']);
-                       }
-
                        $ret = DBA::update('gserver', $serverdata, ['nurl' => $serverdata['nurl']]);
                        $gserver = DBA::selectFirst('gserver', ['id'], ['nurl' => $serverdata['nurl']]);
                        if (DBA::isResult($gserver)) {
@@ -532,11 +527,12 @@ class GServer
                        }
                }
 
-               if (!empty($serverdata['network']) && !empty($id) && ($serverdata['network'] != Protocol::PHANTOM)) {
+               // Count the number of known contacts from this server
+               if (!empty($id) && !in_array($serverdata['network'], [Protocol::PHANTOM, Protocol::FEED])) {
                        $apcontacts = DBA::count('apcontact', ['gsid' => $id]);
-                       $contacts = DBA::count('contact', ['uid' => 0, 'gsid' => $id]);
-                       $max_users = max($apcontacts, $contacts, $registeredUsers, 1);
-                       if ($max_users > $registeredUsers) {
+                       $contacts = DBA::count('contact', ['uid' => 0, 'gsid' => $id, 'failed' => false]);
+                       $max_users = max($apcontacts, $contacts);
+                       if ($max_users > $serverdata['registered-users']) {
                                Logger::info('Update registered users', ['id' => $id, 'url' => $serverdata['nurl'], 'registered-users' => $max_users]);
                                DBA::update('gserver', ['registered-users' => $max_users], ['id' => $id]);
                        }
@@ -1056,14 +1052,12 @@ class GServer
 
                foreach ($contacts as $contact) {
                        $probed = Contact::getByURL($contact);
-                       if (!empty($probed) && in_array($probed['network'], Protocol::FEDERATED)) {
+                       if (!empty($probed) && !$probed['failed'] && in_array($probed['network'], Protocol::FEDERATED)) {
                                $serverdata['network'] = $probed['network'];
                                break;
                        }
                }
 
-               $serverdata['registered-users'] = max($serverdata['registered-users'], count($contacts), 1);
-
                return $serverdata;
        }
 
@@ -1598,7 +1592,8 @@ class GServer
                                }
                        }
 
-                       if (!in_array(strtolower($attr['content']), $valid_platforms)) {
+                       $platform = explode(' ', strtolower($attr['content']));
+                       if (!in_array($platform[0], $valid_platforms)) {
                                continue;
                        }
 
@@ -1661,7 +1656,8 @@ class GServer
                                }
                        }
 
-                       if (!in_array(strtolower($attr['content']), $valid_platforms)) {
+                       $platform = explode(' ', strtolower($attr['content']));
+                       if (!in_array($platform[0], $valid_platforms)) {
                                continue;
                        }