forked from GNUsocial/gnu-social
distribute flag for Notice::saveNew()
This commit is contained in:
parent
2e2519afee
commit
39804809dd
@ -234,6 +234,8 @@ class Notice extends Memcached_DataObject
|
|||||||
* in place of extracting # tags from content
|
* in place of extracting # tags from content
|
||||||
* array 'urls' list of attached/referred URLs to save with the
|
* array 'urls' list of attached/referred URLs to save with the
|
||||||
* notice in place of extracting links from content
|
* notice in place of extracting links from content
|
||||||
|
* boolean 'distribute' whether to distribute the notice, default true
|
||||||
|
*
|
||||||
* @fixme tag override
|
* @fixme tag override
|
||||||
*
|
*
|
||||||
* @return Notice
|
* @return Notice
|
||||||
@ -243,7 +245,8 @@ class Notice extends Memcached_DataObject
|
|||||||
$defaults = array('uri' => null,
|
$defaults = array('uri' => null,
|
||||||
'url' => null,
|
'url' => null,
|
||||||
'reply_to' => null,
|
'reply_to' => null,
|
||||||
'repeat_of' => null);
|
'repeat_of' => null,
|
||||||
|
'distribute' => true);
|
||||||
|
|
||||||
if (!empty($options)) {
|
if (!empty($options)) {
|
||||||
$options = $options + $defaults;
|
$options = $options + $defaults;
|
||||||
@ -426,8 +429,10 @@ class Notice extends Memcached_DataObject
|
|||||||
$notice->saveUrls();
|
$notice->saveUrls();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare inbox delivery, may be queued to background.
|
if ($distribute) {
|
||||||
$notice->distribute();
|
// Prepare inbox delivery, may be queued to background.
|
||||||
|
$notice->distribute();
|
||||||
|
}
|
||||||
|
|
||||||
return $notice;
|
return $notice;
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,8 @@ if (!defined('STATUSNET')) {
|
|||||||
|
|
||||||
class AccountRestorer
|
class AccountRestorer
|
||||||
{
|
{
|
||||||
|
private $_trusted = false;
|
||||||
|
|
||||||
function loadXML($xml)
|
function loadXML($xml)
|
||||||
{
|
{
|
||||||
$dom = DOMDocument::loadXML($xml);
|
$dom = DOMDocument::loadXML($xml);
|
||||||
@ -72,29 +74,22 @@ class AccountRestorer
|
|||||||
|
|
||||||
if (!empty($subjectEl)) {
|
if (!empty($subjectEl)) {
|
||||||
$subject = new ActivityObject($subjectEl);
|
$subject = new ActivityObject($subjectEl);
|
||||||
// TRANS: Commandline script output. %1$s is the subject ID, %2$s is the subject nickname.
|
|
||||||
printfv(_("Backup file for user %1$s (%2$s)")."\n", $subject->id, Ostatus_profile::getActivityObjectNickname($subject));
|
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("Feed doesn't have an <activity:subject> element.");
|
throw new Exception("Feed doesn't have an <activity:subject> element.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($user)) {
|
if (is_null($user)) {
|
||||||
// TRANS: Commandline script output.
|
|
||||||
printfv(_("No user specified; using backup user.")."\n");
|
|
||||||
$user = $this->userFromSubject($subject);
|
$user = $this->userFromSubject($subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
$entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry');
|
$entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry');
|
||||||
|
|
||||||
// TRANS: Commandline script output. %d is the number of entries in the activity stream in backup; used for plural.
|
$activities = $this->entriesToActivities($entries, $feed);
|
||||||
printfv(_m("%d entry in backup.","%d entries in backup.",$entries->length)."\n", $entries->length);
|
|
||||||
|
|
||||||
for ($i = $entries->length - 1; $i >= 0; $i--) {
|
// XXX: sort entries here
|
||||||
|
|
||||||
|
foreach ($activities as $activity) {
|
||||||
try {
|
try {
|
||||||
$entry = $entries->item($i);
|
|
||||||
|
|
||||||
$activity = new Activity($entry, $feed);
|
|
||||||
|
|
||||||
switch ($activity->verb) {
|
switch ($activity->verb) {
|
||||||
case ActivityVerb::FOLLOW:
|
case ActivityVerb::FOLLOW:
|
||||||
$this->subscribeProfile($user, $subject, $activity);
|
$this->subscribeProfile($user, $subject, $activity);
|
||||||
@ -109,7 +104,7 @@ class AccountRestorer
|
|||||||
throw new Exception("Unknown verb: {$activity->verb}");
|
throw new Exception("Unknown verb: {$activity->verb}");
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
print $e->getMessage()."\n";
|
common_log(LOG_WARNING, $e->getMessage());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,19 +115,22 @@ class AccountRestorer
|
|||||||
$profile = $user->getProfile();
|
$profile = $user->getProfile();
|
||||||
|
|
||||||
if ($activity->objects[0]->id == $subject->id) {
|
if ($activity->objects[0]->id == $subject->id) {
|
||||||
|
if (!$this->_trusted) {
|
||||||
$other = $activity->actor;
|
throw new Exception("Skipping a pushed subscription.");
|
||||||
$otherUser = User::staticGet('uri', $other->id);
|
|
||||||
|
|
||||||
if (!empty($otherUser)) {
|
|
||||||
$otherProfile = $otherUser->getProfile();
|
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("Can't force remote user to subscribe.");
|
$other = $activity->actor;
|
||||||
}
|
$otherUser = User::staticGet('uri', $other->id);
|
||||||
// XXX: don't do this for untrusted input!
|
|
||||||
Subscription::start($otherProfile, $profile);
|
|
||||||
|
|
||||||
} else if (empty($activity->actor) || $activity->actor->id == $subject->id) {
|
if (!empty($otherUser)) {
|
||||||
|
$otherProfile = $otherUser->getProfile();
|
||||||
|
} else {
|
||||||
|
throw new Exception("Can't force remote user to subscribe.");
|
||||||
|
}
|
||||||
|
// XXX: don't do this for untrusted input!
|
||||||
|
Subscription::start($otherProfile, $profile);
|
||||||
|
}
|
||||||
|
} else if (empty($activity->actor)
|
||||||
|
|| $activity->actor->id == $subject->id) {
|
||||||
|
|
||||||
$other = $activity->objects[0];
|
$other = $activity->objects[0];
|
||||||
$otherUser = User::staticGet('uri', $other->id);
|
$otherUser = User::staticGet('uri', $other->id);
|
||||||
|
Loading…
Reference in New Issue
Block a user