From c82b1cda825f3b84e3c3bef5474eccf8963b0475 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 14:35:43 -0400 Subject: [PATCH 01/10] send a salmon slap to mentioned person when we reply to a notice --- plugins/OStatus/actions/usersalmon.php | 6 ++++-- plugins/OStatus/lib/ostatusqueuehandler.php | 13 ++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/plugins/OStatus/actions/usersalmon.php b/plugins/OStatus/actions/usersalmon.php index 641e131abc..54715cd657 100644 --- a/plugins/OStatus/actions/usersalmon.php +++ b/plugins/OStatus/actions/usersalmon.php @@ -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($notice->getReplies(), $this->user->id)) { + 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) && diff --git a/plugins/OStatus/lib/ostatusqueuehandler.php b/plugins/OStatus/lib/ostatusqueuehandler.php index 8905d2e210..5e318116a6 100644 --- a/plugins/OStatus/lib/ostatusqueuehandler.php +++ b/plugins/OStatus/lib/ostatusqueuehandler.php @@ -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 */ From 7bec455a2120607a0aacb8be03cd60372cc5d0c1 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 16:15:22 -0400 Subject: [PATCH 02/10] Static method to get a profile based on an URI --- classes/Profile.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/classes/Profile.php b/classes/Profile.php index d7617f0b74..87cfab0e01 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -960,4 +960,24 @@ 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)); + } + + } } From a2de30b767e23ae848d15a3ce1d3ed9d16fd1df9 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 16:15:51 -0400 Subject: [PATCH 03/10] Notice::saveReplies() uses Profile::fromURI() to handle remote profiles too --- classes/Notice.php | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index 0eeebfadf3..93456011ad 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1014,25 +1014,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; - } - - $reply = new Reply(); - - $reply->notice_id = $this->id; - $reply->profile_id = $user->id; - common_log(LOG_INFO, __METHOD__ . ": saving reply: notice $this->id to profile $user->id"); - - $id = $reply->insert(); + if (empty($profile)) { + common_log(LOG_WARNING, "Unable to determine profile for URI '$uri'"); + continue; } + + 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 = new Reply(); + + $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; From 3baff9aa98005c6f72d295f681bc211102614946 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 16:16:38 -0400 Subject: [PATCH 04/10] Handle profile-from-uri hook to return ostatus profile if there's a match --- plugins/OStatus/OStatusPlugin.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php index 6fef20d6f5..fff692c82b 100644 --- a/plugins/OStatus/OStatusPlugin.php +++ b/plugins/OStatus/OStatusPlugin.php @@ -492,7 +492,7 @@ class OStatusPlugin extends Plugin * Tell the FeedSub infrastructure whether we have any active OStatus * usage for the feed; if not it'll be able to garbage-collect the * feed subscription. - * + * * @param FeedSub $feedsub * @param integer $count in/out * @return mixed hook return code @@ -995,4 +995,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; + } } From 2d4e0693c88bb8cad47f917db3ac5ecfacf28619 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 16:17:18 -0400 Subject: [PATCH 05/10] save URIs of remote profiles marked for attention --- plugins/OStatus/classes/Ostatus_profile.php | 28 +++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index a95612a7ff..fe3946d249 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -699,14 +699,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; } @@ -1763,6 +1765,28 @@ class Ostatus_profile extends Memcached_DataObject return $file; } + + static function ensureProfileURI($uri) + { + $oprofile = null; + + 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; + } + } + } } /** From 974ac48771915406527b4f2e5670c7e7cb5aa314 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 16:55:16 -0400 Subject: [PATCH 06/10] bug in Profile::fromURI() wasn't returning profile --- classes/Profile.php | 1 + 1 file changed, 1 insertion(+) diff --git a/classes/Profile.php b/classes/Profile.php index 87cfab0e01..8f86795504 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -979,5 +979,6 @@ class Profile extends Memcached_DataObject Event::handle('EndGetProfileFromURI', array($uri, $profile)); } + return $profile; } } From ab88123373ce5f17b9e09ed2372f587e607cba20 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 17:05:11 -0400 Subject: [PATCH 07/10] correctly return oprofile from Ostatus_profile::ensureProfileURI() --- plugins/OStatus/classes/Ostatus_profile.php | 37 +++++++++++++-------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index fe3946d249..7877128745 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -1770,22 +1770,31 @@ class Ostatus_profile extends Memcached_DataObject { $oprofile = null; - 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; + // 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; } } From 27626c3abfeeb62ded71c0fa703238835b38015a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 17:10:29 -0400 Subject: [PATCH 08/10] Correctly check for user's id in replies in user salmon post --- plugins/OStatus/actions/usersalmon.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/OStatus/actions/usersalmon.php b/plugins/OStatus/actions/usersalmon.php index 54715cd657..06a72bf024 100644 --- a/plugins/OStatus/actions/usersalmon.php +++ b/plugins/OStatus/actions/usersalmon.php @@ -81,7 +81,7 @@ class UsersalmonAction extends SalmonAction throw new ClientException("In reply to unknown notice"); } if ($notice->profile_id != $this->user->id && - !in_array($notice->getReplies(), $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)) { From bb9353f6e04f863c50bca12247d1a70cb12350d5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 17:59:49 -0400 Subject: [PATCH 09/10] debugging replyToID --- plugins/OStatus/actions/usersalmon.php | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/OStatus/actions/usersalmon.php b/plugins/OStatus/actions/usersalmon.php index 06a72bf024..0422c68ebd 100644 --- a/plugins/OStatus/actions/usersalmon.php +++ b/plugins/OStatus/actions/usersalmon.php @@ -76,6 +76,7 @@ class UsersalmonAction extends SalmonAction $context = $this->activity->context; if (!empty($context->replyToID)) { + common_log(LOG_DEBUG, "Got a notice in reply to '{$context->replyToID}' ({$context->replyToUrl})"); $notice = Notice::staticGet('uri', $context->replyToID); if (empty($notice)) { throw new ClientException("In reply to unknown notice"); From ebcd8644a51b66d73971d581789e7c70b82007b2 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 18:22:54 -0400 Subject: [PATCH 10/10] Revert "debugging replyToID" This reverts commit bb9353f6e04f863c50bca12247d1a70cb12350d5. --- plugins/OStatus/actions/usersalmon.php | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/OStatus/actions/usersalmon.php b/plugins/OStatus/actions/usersalmon.php index 0422c68ebd..06a72bf024 100644 --- a/plugins/OStatus/actions/usersalmon.php +++ b/plugins/OStatus/actions/usersalmon.php @@ -76,7 +76,6 @@ class UsersalmonAction extends SalmonAction $context = $this->activity->context; if (!empty($context->replyToID)) { - common_log(LOG_DEBUG, "Got a notice in reply to '{$context->replyToID}' ({$context->replyToUrl})"); $notice = Notice::staticGet('uri', $context->replyToID); if (empty($notice)) { throw new ClientException("In reply to unknown notice");