]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Output proper remote info on WebFinger notice resources
authorMikael Nordfeldth <mmn@hethane.se>
Sun, 27 Mar 2016 12:56:27 +0000 (14:56 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 27 Mar 2016 12:56:27 +0000 (14:56 +0200)
plugins/OStatus/OStatusPlugin.php
plugins/WebFinger/lib/webfingerresource/notice.php

index 78ced64b5dd96ab099a510c1bb904a13b189605e..72f246d68f4e821837309ceca78c38f47edacec2 100644 (file)
@@ -1307,10 +1307,23 @@ class OStatusPlugin extends Plugin
 
     function onEndWebFingerNoticeLinks(XML_XRD $xrd, Notice $target)
     {
-        $author = $target->getProfile();
-        $profiletype = $this->profileTypeString($author);
-        $salmon_url = common_local_url("{$profiletype}salmon", array('id' => $author->id));
-        $xrd->links[] = new XML_XRD_Element_Link(Salmon::REL_SALMON, $salmon_url);
+        $salmon_url = null;
+        $actor = $target->getProfile();
+        if ($actor->isLocal()) {
+            $profiletype = $this->profileTypeString($actor);
+            $salmon_url = common_local_url("{$profiletype}salmon", array('id' => $actor->getID()));
+        } else {
+            try {
+                $oprofile = Ostatus_profile::fromProfile($actor);
+                $salmon_url = $oprofile->salmonuri;
+            } catch (Exception $e) {
+                // Even though it's not a local user, we couldn't get an Ostatus_profile?!
+            }
+        }
+        // Ostatus_profile salmon URL may be empty
+        if (!empty($salmon_url)) {
+            $xrd->links[] = new XML_XRD_Element_Link(Salmon::REL_SALMON, $salmon_url);
+        }
         return true;
     }
 
index b967bd9e1c15ff000b516ad80de8635392e185b9..295a856f36c8ba4b6056b5c018db2022c51c0bc8 100644 (file)
@@ -20,17 +20,27 @@ class WebFingerResource_Notice extends WebFingerResource
     public function updateXRD(XML_XRD $xrd)
     {
         if (Event::handle('StartWebFingerNoticeLinks', array($xrd, $this->object))) {
-            $xrd->links[] = new XML_XRD_Element_Link('alternate',
+            if ($this->object->isLocal()) {
+                $xrd->links[] = new XML_XRD_Element_Link('alternate',
                                     common_local_url('ApiStatusesShow',
                                         array('id'=>$this->object->id,
                                               'format'=>'atom')),
                                     'application/atom+xml');
 
-            $xrd->links[] = new XML_XRD_Element_Link('alternate',
+                $xrd->links[] = new XML_XRD_Element_Link('alternate',
                                     common_local_url('ApiStatusesShow',
                                         array('id'=>$this->object->id,
                                               'format'=>'json')),
                                     'application/json');
+            } else {
+                try {
+                    $xrd->links[] = new XML_XRD_Element_Link('alternate',
+                                        $this->object->getUrl(),
+                                        'text/html');
+                } catch (InvalidUrlException $e) {
+                    // don't do a fallback in webfinger
+                }
+            }
             Event::handle('EndWebFingerNoticeLinks', array($xrd, $this->object));
         }
     }