]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/classes/Ostatus_profile.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / OStatus / classes / Ostatus_profile.php
index c63bf84dd155d5d1bc15eb901cc2b407bb8cbcab..ddd1a2a38dfe145ba881e3f6d94e9ea254edcb8e 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-if (!defined('STATUSNET')) {
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * @package OStatusPlugin
- * @maintainer Brion Vibber <brion@status.net>
+ * @author Brion Vibber <brion@status.net>
+ * @maintainer Mikael Nordfeldth <mmn@hethane.se>
  */
 class Ostatus_profile extends Managed_DataObject
 {
@@ -692,8 +691,8 @@ class Ostatus_profile extends Managed_DataObject
                                      $options);
             if ($saved instanceof Notice) {
                 Ostatus_source::saveNew($saved, $this, $method);
-                if (!empty($attachment)) {
-                    File_to_post::processNew($attachment->id, $saved->id);
+                if ($attachment instanceof File) {
+                    File_to_post::processNew($attachment, $saved);
                 }
             }
         } catch (Exception $e) {
@@ -1005,11 +1004,13 @@ class Ostatus_profile extends Managed_DataObject
             }
         }
 
+        $obj = ActivityUtils::getFeedAuthor($feedEl);
+
         // @todo FIXME: We should check whether this feed has elements
         // with different <author> or <dc:creator> elements, and... I dunno.
         // Do something about that.
 
-        $obj = ActivityObject::fromRssChannel($feedEl);
+        if(empty($obj)) { $obj = ActivityObject::fromRssChannel($feedEl); }
 
         return self::ensureActivityObjectProfile($obj, $hints);
     }
@@ -1747,11 +1748,8 @@ class Ostatus_profile extends Managed_DataObject
             throw new Exception(_m('Not a valid webfinger address.'));
         }
 
-        $hints = array('webfinger' => $addr);
-
-        $dhints = DiscoveryHints::fromXRD($xrd);
-
-        $hints = array_merge($hints, $dhints);
+        $hints = array_merge(array('webfinger' => $addr),
+                             DiscoveryHints::fromXRD($xrd));
 
         // If there's an Hcard, let's grab its info
         if (array_key_exists('hcard', $hints)) {
@@ -1982,6 +1980,38 @@ class Ostatus_profile extends Managed_DataObject
 
         return $oprofile->localProfile();
     }
+
+    public function updateUriKeys($profile_uri, array $hints=array())
+    {
+        $orig = clone($this);
+
+        common_debug('URIFIX These identities both say they are each other: "'.$orig->uri.'" and "'.$profile_uri.'"');
+        $this->uri = $profile_uri;
+
+        if (array_key_exists('feedurl', $hints)) {
+            if (!empty($this->feeduri)) {
+                common_debug('URIFIX Changing FeedSub ['.$feedsub->id.'] feeduri "'.$feedsub->uri.'" to "'.$hints['feedurl']);
+                $feedsub = FeedSub::getKV('uri', $this->feeduri);
+                $feedorig = clone($feedsub);
+                $feedsub->uri = $hints['feedurl'];
+                $feedsub->updateWithKeys($feedorig);
+            } else {
+                common_debug('URIFIX Old Ostatus_profile did not have feedurl set, ensuring feed: '.$hints['feedurl']);
+                FeedSub::ensureFeed($hints['feedurl']);
+            }
+            $this->feeduri = $hints['feedurl'];
+        }
+        if (array_key_exists('salmon', $hints)) {
+            common_debug('URIFIX Changing Ostatus_profile salmonuri from "'.$this->salmonuri.'" to "'.$hints['salmon'].'"');
+            $this->salmonuri = $hints['salmon'];
+        }
+
+        common_debug('URIFIX Updating Ostatus_profile URI for '.$orig->uri.' to '.$this->uri);
+        $this->updateWithKeys($orig, 'uri');    // 'uri' is the primary key column
+
+        common_debug('URIFIX Subscribing/renewing feedsub for Ostatus_profile '.$this->uri);
+        $this->subscribe();
+    }
 }
 
 /**