]> git.mxchange.org Git - friendica.git/commitdiff
First testable version
authorMichael <heluecht@pirati.ca>
Sat, 4 Jan 2020 21:45:20 +0000 (21:45 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 4 Jan 2020 21:45:20 +0000 (21:45 +0000)
src/Model/UserItem.php

index 26c42f10931caffb38da7f95584d7ba7f0c98d1e..1888906fa75e1b33e62398b9bf6382d514116de6 100644 (file)
@@ -6,7 +6,10 @@
 
 namespace Friendica\Model;
 
+use Friendica\Core\Hook;
 use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Util\Strings;
 
 class UserItem
 {
@@ -18,6 +21,66 @@ class UserItem
         */
        public static function setNotification($item, $uid)
        {
+               if (self::checkShared($item, $uid)) {
+                       echo "shared\n";
+               }
+
+               $profiles = self::getProfileForUser($uid);
+
+               if (self::checkTagged($item, $uid, $profiles)) {
+                       echo "tagged\n";
+               }
+
+               if (self::checkCommented($item, $uid, $profiles)) {
+                       echo "commented\n";
+               }
+       }
+
+       private static function getProfileForUser($uid)
+       {
+               $notification_data = ["uid" => $uid, "profiles" => []];
+               Hook::callAll('check_item_notification', $notification_data);
+
+               $profiles = $notification_data["profiles"];
+
+               $fields = ['nickname'];
+               $user = DBA::selectFirst('user', $fields, ['uid' => $uid]);
+               if (!DBA::isResult($user)) {
+                       return false;
+               }
+
+               $owner = DBA::selectFirst('contact', ['url'], ['self' => true, 'uid' => $uid]);
+               if (!DBA::isResult($owner)) {
+                       return false;
+               }
+
+               // This is our regular URL format
+               $profiles[] = $owner["url"];
+
+               // Notifications from Diaspora are often with an URL in the Diaspora format
+               $profiles[] = DI::baseUrl()."/u/".$user["nickname"];
+
+               $profiles2 = [];
+
+               foreach ($profiles AS $profile) {
+                       // Check for invalid profile urls. 13 should be the shortest possible profile length:
+                       // http://a.bc/d
+                       // Additionally check for invalid urls that would return the normalised value "http:"
+                       if ((strlen($profile) >= 13) && (Strings::normaliseLink($profile) != "http:")) {
+                               if (!in_array($profile, $profiles2))
+                                       $profiles2[] = $profile;
+
+                               $profile = Strings::normaliseLink($profile);
+                               if (!in_array($profile, $profiles2))
+                                       $profiles2[] = $profile;
+
+                               $profile = str_replace("http://", "https://", $profile);
+                               if (!in_array($profile, $profiles2))
+                                       $profiles2[] = $profile;
+                       }
+               }
+
+               return $profiles2;
        }
 
        private static function checkShared($item, $uid)
@@ -45,34 +108,33 @@ class UserItem
        }
 
        // Is the user mentioned in this post?
-       private static function checkTagged($item, $uid)
+       private static function checkTagged($item, $uid, $profiles)
        {
-               if ($item["mention"]) {
-                       return true;
-               }
-
                foreach ($profiles AS $profile) {
                        if (strpos($item["tag"], "=".$profile."]") || strpos($item["body"], "=".$profile."]"))
                                return true;
                }
 
-               if ($defaulttype == NOTIFY_TAGSELF) {
-                       return true;
-               }
-
                return false;
        }
 
-       private static function checkCommented($item, $uid)
+       // Fetch all contacts for the given profiles
+       private static function checkCommented($item, $uid, $profiles)
        {
                // Is it a post that the user had started?
                $fields = ['ignored', 'mention'];
                $thread = Item::selectFirstThreadForUser($uid, $fields, ['iid' => $item["parent"], 'deleted' => false]);
-
                if ($thread['mention'] && !$thread['ignored']) {
                        return true;
                }
 
+               $contacts = [];
+               $ret = DBA::select('contact', ['id'], ['uid' => 0, 'nurl' => $profiles]);
+               while ($contact = DBA::fetch($ret)) {
+                       $contacts[] = $contact['id'];
+               }
+               DBA::close($ret);
+
                // And now we check for participation of one of our contacts in the thread
                $condition = ['parent' => $item["parent"], 'author-id' => $contacts, 'deleted' => false];