From c82b1cda825f3b84e3c3bef5474eccf8963b0475 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 14:35:43 -0400 Subject: 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(-) (limited to 'plugins') diff --git a/plugins/OStatus/actions/usersalmon.php b/plugins/OStatus/actions/usersalmon.php index 641e131ab..54715cd65 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 8905d2e21..5e318116a 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 */ -- cgit v1.2.3-54-g00ecf From 3baff9aa98005c6f72d295f681bc211102614946 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 16:16:38 -0400 Subject: 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(-) (limited to 'plugins') diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php index 6fef20d6f..fff692c82 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; + } } -- cgit v1.2.3-54-g00ecf From 2d4e0693c88bb8cad47f917db3ac5ecfacf28619 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 16:17:18 -0400 Subject: save URIs of remote profiles marked for attention --- plugins/OStatus/classes/Ostatus_profile.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index a95612a7f..fe3946d24 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; + } + } + } } /** -- cgit v1.2.3-54-g00ecf From ab88123373ce5f17b9e09ed2372f587e607cba20 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 17:05:11 -0400 Subject: correctly return oprofile from Ostatus_profile::ensureProfileURI() --- plugins/OStatus/classes/Ostatus_profile.php | 37 ++++++++++++++++++----------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'plugins') diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index fe3946d24..787712874 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; } } -- cgit v1.2.3-54-g00ecf From 27626c3abfeeb62ded71c0fa703238835b38015a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 17:10:29 -0400 Subject: 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(-) (limited to 'plugins') diff --git a/plugins/OStatus/actions/usersalmon.php b/plugins/OStatus/actions/usersalmon.php index 54715cd65..06a72bf02 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)) { -- cgit v1.2.3-54-g00ecf From bb9353f6e04f863c50bca12247d1a70cb12350d5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 17:59:49 -0400 Subject: debugging replyToID --- plugins/OStatus/actions/usersalmon.php | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins') diff --git a/plugins/OStatus/actions/usersalmon.php b/plugins/OStatus/actions/usersalmon.php index 06a72bf02..0422c68eb 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"); -- cgit v1.2.3-54-g00ecf From ebcd8644a51b66d73971d581789e7c70b82007b2 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 1 Sep 2010 18:22:54 -0400 Subject: Revert "debugging replyToID" This reverts commit bb9353f6e04f863c50bca12247d1a70cb12350d5. --- plugins/OStatus/actions/usersalmon.php | 1 - 1 file changed, 1 deletion(-) (limited to 'plugins') diff --git a/plugins/OStatus/actions/usersalmon.php b/plugins/OStatus/actions/usersalmon.php index 0422c68eb..06a72bf02 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"); -- cgit v1.2.3-54-g00ecf