From 1a81356622dba7bcbf75de6eb10f28170e972b96 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 17 Dec 2010 17:37:43 -0500 Subject: I'm still not sure when it's useful to reset a notice's author --- lib/activityimporter.php | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/lib/activityimporter.php b/lib/activityimporter.php index e936449c8..28c371e4d 100644 --- a/lib/activityimporter.php +++ b/lib/activityimporter.php @@ -72,7 +72,7 @@ class ActivityImporter extends QueueHandler $this->joinGroup($user, $activity); break; case ActivityVerb::POST: - $this->postNote($user, $activity); + $this->postNote($user, $author, $activity); break; default: throw new Exception("Unknown verb: {$activity->verb}"); @@ -141,13 +141,17 @@ class ActivityImporter extends QueueHandler if (empty($group)) { $oprofile = Ostatus_profile::ensureActivityObjectProfile($activity->objects[0]); if (!$oprofile->isGroup()) { - throw new Exception("Remote profile is not a group!"); + throw new ClientException("Remote profile is not a group!"); } $group = $oprofile->localGroup(); } assert(!empty($group)); + if ($user->isMember($group)) { + throw new ClientException("User is already a member of this group."); + } + if (Event::handle('StartJoinGroup', array($group, $user))) { Group_member::join($group->id, $user->id); Event::handle('EndJoinGroup', array($group, $user)); @@ -156,7 +160,7 @@ class ActivityImporter extends QueueHandler // XXX: largely cadged from Ostatus_profile::processNote() - function postNote($user, $activity) + function postNote($user, $author, $activity) { $note = $activity->objects[0]; @@ -165,11 +169,27 @@ class ActivityImporter extends QueueHandler $notice = Notice::staticGet('uri', $sourceUri); if (!empty($notice)) { - // This is weird. - $orig = clone($notice); - $notice->profile_id = $user->id; - $notice->update($orig); - return; + + common_log(LOG_INFO, "Notice {$sourceUri} already exists."); + + if ($this->trusted) { + + $profile = $notice->getProfile(); + + $uri = $profile->getUri(); + + if ($uri == $author->id) { + common_log(LOG_INFO, "Updating notice author from $author->id to $user->uri"); + $orig = clone($notice); + $notice->profile_id = $user->id; + $notice->update($orig); + return; + } else { + throw new ClientException(sprintf(_("Already know about notice %s and ". + " it's got a different author %s."), + $sourceUri, $uri)); + } + } } // Use summary as fallback for content @@ -199,7 +219,8 @@ class ActivityImporter extends QueueHandler 'replies' => array(), 'groups' => array(), 'tags' => array(), - 'urls' => array()); + 'urls' => array(), + 'distribute' => false); // Check for optional attributes... @@ -251,6 +272,8 @@ class ActivityImporter extends QueueHandler $options['urls'][] = $href; } + common_log(LOG_INFO, "Saving notice {$options['uri']}"); + $saved = Notice::saveNew($user->id, $content, 'restore', // TODO: restore the actual source -- cgit v1.2.3