]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch 'swat0' into 0.9.x
authorEvan Prodromou <evan@status.net>
Thu, 2 Sep 2010 20:58:55 +0000 (16:58 -0400)
committerEvan Prodromou <evan@status.net>
Thu, 2 Sep 2010 20:58:55 +0000 (16:58 -0400)
classes/Notice.php
classes/Profile.php
plugins/OStatus/OStatusPlugin.php
plugins/OStatus/actions/usersalmon.php
plugins/OStatus/classes/Ostatus_profile.php
plugins/OStatus/lib/ostatusqueuehandler.php

index 5a70f70b6461c16b888301fc53d1213590e57d57..14477b1b53a2c17122e2baafe7891c304eb678e7 100644 (file)
@@ -1019,25 +1019,31 @@ class Notice extends Memcached_DataObject
         if (empty($uris)) {
             return;
         }
+
         $sender = Profile::staticGet($this->profile_id);
 
         foreach (array_unique($uris) as $uri) {
 
-            $user = User::staticGet('uri', $uri);
+            $profile = Profile::fromURI($uri);
 
-            if (!empty($user)) {
-                if ($user->hasBlocked($sender)) {
-                    continue;
-                }
+            if (empty($profile)) {
+                common_log(LOG_WARNING, "Unable to determine profile for URI '$uri'");
+                continue;
+            }
 
-                $reply = new Reply();
+            if ($profile->hasBlocked($sender)) {
+                common_log(LOG_INFO, "Not saving reply to profile {$profile->id} ($uri) from sender {$sender->id} because of a block.");
+                continue;
+            }
 
-                $reply->notice_id  = $this->id;
-                $reply->profile_id = $user->id;
-                common_log(LOG_INFO, __METHOD__ . ": saving reply: notice $this->id to profile $user->id");
+            $reply = new Reply();
 
-                $id = $reply->insert();
-            }
+            $reply->notice_id  = $this->id;
+            $reply->profile_id = $profile->id;
+
+            common_log(LOG_INFO, __METHOD__ . ": saving reply: notice $this->id to profile $profile->id");
+
+            $id = $reply->insert();
         }
 
         return;
index d7617f0b74c0a27afbbd67ee20bb1ef7c03d1bf4..8f867955044b0d2ff454157f827cba0af9d353a2 100644 (file)
@@ -960,4 +960,25 @@ class Profile extends Memcached_DataObject
 
         return $feed;
     }
+
+    static function fromURI($uri)
+    {
+        $profile = null;
+
+        if (Event::handle('StartGetProfileFromURI', array($uri, &$profile))) {
+            // Get a local user or remote (OMB 0.1) profile
+            $user = User::staticGet('uri', $uri);
+            if (!empty($user)) {
+                $profile = $user->getProfile();
+            } else {
+                $remote_profile = Remote_profile::staticGet('uri', $uri);
+                if (!empty($remote_profile)) {
+                    $profile = Profile::staticGet('id', $remote_profile->profile_id);
+                }
+            }
+            Event::handle('EndGetProfileFromURI', array($uri, $profile));
+        }
+
+        return $profile;
+    }
 }
index 76ffd511b54d5baf3e67418cad9a2bbd1e4b6d04..f9a8782faa119284f8414d508e8a637185b92c31 100644 (file)
@@ -984,4 +984,18 @@ class OStatusPlugin extends Plugin
         $feed = $oprofile->feeduri;
         return false;
     }
+
+    function onStartGetProfileFromURI($uri, &$profile) {
+
+        // XXX: do discovery here instead (OStatus_profile::ensureProfileURI($uri))
+
+        $oprofile = Ostatus_profile::staticGet('uri', $uri);
+
+        if (!empty($oprofile) && !$oprofile->isGroup()) {
+            $profile = $oprofile->localProfile();
+            return false;
+        }
+
+        return true;
+    }
 }
index 641e131abc1d5c32e9894c8f2c7e515b59f6c6bf..06a72bf0244331be868a790eb38b6bd3f7697ae3 100644 (file)
@@ -71,6 +71,7 @@ class UsersalmonAction extends SalmonAction
 
         // Notice must either be a) in reply to a notice by this user
         // or b) to the attention of this user
+        // or c) in reply to a notice to the attention of this user
 
         $context = $this->activity->context;
 
@@ -79,8 +80,9 @@ class UsersalmonAction extends SalmonAction
             if (empty($notice)) {
                 throw new ClientException("In reply to unknown notice");
             }
-            if ($notice->profile_id != $this->user->id) {
-                throw new ClientException("In reply to a notice not by this user");
+            if ($notice->profile_id != $this->user->id &&
+                !in_array($this->user->id, $notice->getReplies())) {
+                throw new ClientException("In reply to a notice not by this user and not mentioning this user");
             }
         } else if (!empty($context->attention)) {
             if (!in_array($this->user->uri, $context->attention) &&
index cc4307b14f119c625e56ee606d2207c5a134c925..898c63e83e438fe08970a1bf8e8dc6e14fb9bbef 100644 (file)
@@ -700,14 +700,16 @@ class Ostatus_profile extends Memcached_DataObject
             }
 
             // Is the recipient a remote group?
-            $oprofile = Ostatus_profile::staticGet('uri', $recipient);
+            $oprofile = Ostatus_profile::ensureProfileURI($recipient);
+
             if ($oprofile) {
                 if ($oprofile->isGroup()) {
                     // Deliver to local members of this remote group.
                     // @fixme sender verification?
                     $groups[] = $oprofile->group_id;
                 } else {
-                    common_log(LOG_DEBUG, "Skipping reply to remote profile $recipient");
+                    // may be canonicalized or something
+                    $replies[] = $oprofile->uri;
                 }
                 continue;
             }
@@ -1764,6 +1766,37 @@ class Ostatus_profile extends Memcached_DataObject
 
         return $file;
     }
+
+    static function ensureProfileURI($uri)
+    {
+        $oprofile = null;
+
+        // First, try to query it
+
+        $oprofile = Ostatus_profile::staticGet('uri', $uri);
+
+        // If unfound, do discovery stuff
+
+        if (empty($oprofile)) {
+            if (preg_match("/^(\w+)\:(.*)/", $uri, $match)) {
+                $protocol = $match[1];
+                switch ($protocol) {
+                case 'http':
+                case 'https':
+                    $oprofile = Ostatus_profile::ensureProfileURL($uri);
+                    break;
+                case 'acct':
+                case 'mailto':
+                    $rest = $match[2];
+                    $oprofile = Ostatus_profile::ensureWebfinger($rest);
+                default:
+                    common_log("Unrecognized URI protocol for profile: $protocol ($uri)");
+                    break;
+                }
+            }
+        }
+        return $oprofile;
+    }
 }
 
 /**
index 8905d2e21069f22851c81c208b20ba650fbc2fd6..5e318116a6e1a3d479d5ffd379cb655a71009be7 100644 (file)
@@ -67,6 +67,17 @@ class OStatusQueueHandler extends QueueHandler
             }
         }
 
+        if (!empty($this->notice->reply_to)) {
+            $replyTo = Notice::staticGet('id', $this->notice->reply_to);
+            if (!empty($replyTo)) {
+                foreach($replyTo->getReplies() as $profile_id) {
+                    $oprofile = Ostatus_profile::staticGet('profile_id', $profile_id);
+                    if ($oprofile) {
+                        $this->pingReply($oprofile);
+                    }
+                }
+            }
+        }
         return true;
     }
 
@@ -161,7 +172,7 @@ class OStatusQueueHandler extends QueueHandler
      * Queue up direct feed update pushes to subscribers on our internal hub.
      * If there are a large number of subscriber sites, intermediate bulk
      * distribution triggers may be queued.
-     * 
+     *
      * @param string $atom update feed, containing only new/changed items
      * @param HubSub $sub open query of subscribers
      */