use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Model\Profile;
-use Friendica\Model\Queue;
use Friendica\Model\User;
use Friendica\Network\Probe;
use Friendica\Util\Crypto;
if ($no_exit) {
return false;
} else {
- System::httpExit(400);
+ throw new \Friendica\Network\HTTPException\BadRequestException();
}
}
if ($no_exit) {
return false;
} else {
- System::httpExit(400);
+ throw new \Friendica\Network\HTTPException\BadRequestException();
}
}
if ($no_exit) {
return false;
} else {
- System::httpExit(400);
+ throw new \Friendica\Network\HTTPException\BadRequestException();
}
}
if ($no_exit) {
return false;
} else {
- System::httpExit(400);
+ throw new \Friendica\Network\HTTPException\BadRequestException();
}
}
if ($no_exit) {
return false;
} else {
- System::httpExit(400);
+ throw new \Friendica\Network\HTTPException\BadRequestException();
}
}
if (!$base) {
Logger::log('unable to locate salmon data in xml');
- System::httpExit(400);
+ throw new \Friendica\Network\HTTPException\BadRequestException();
}
if (!$author_link) {
Logger::log('Could not retrieve author URI.');
- System::httpExit(400);
+ throw new \Friendica\Network\HTTPException\BadRequestException();
}
// Once we have the author URI, go to the web and try to find their public key
// (first this will look it up locally if it is in the fcontact cache)
if (!$key) {
Logger::log('Could not retrieve author key.');
- System::httpExit(400);
+ throw new \Friendica\Network\HTTPException\BadRequestException();
}
$verify = Crypto::rsaVerify($signed_data, $signature, $key);
if (!$verify) {
Logger::log('Message did not verify. Discarding.');
- System::httpExit(400);
+ throw new \Friendica\Network\HTTPException\BadRequestException();
}
Logger::log('Message verified.');
return false;
}
+ /**
+ * @brief Stores a reshare activity
+ *
+ * @param array $item Array of reshare post
+ * @param integer $parent_message_id Id of the parent post
+ * @param string $guid GUID string of reshare action
+ * @param string $author Author handle
+ */
+ private static function addReshareActivity($item, $parent_message_id, $guid, $author)
+ {
+ $parent = Item::selectFirst(['uri', 'guid'], ['id' => $parent_message_id]);
+
+ $datarray = [];
+
+ $datarray['uid'] = $item['uid'];
+ $datarray['contact-id'] = $item['contact-id'];
+ $datarray['network'] = $item['network'];
+
+ $datarray['author-link'] = $item['author-link'];
+ $datarray['author-id'] = $item['author-id'];
+
+ $datarray['owner-link'] = $datarray['author-link'];
+ $datarray['owner-id'] = $datarray['author-id'];
+
+ $datarray['guid'] = $parent['guid'] . '-' . $guid;
+ $datarray['uri'] = self::getUriFromGuid($author, $datarray['guid']);
+ $datarray['parent-uri'] = $parent['uri'];
+
+ $datarray['verb'] = $datarray['body'] = ACTIVITY2_ANNOUNCE;
+ $datarray['gravity'] = GRAVITY_ACTIVITY;
+ $datarray['object-type'] = ACTIVITY_OBJ_NOTE;
+
+ $datarray['protocol'] = $item['protocol'];
+
+ $datarray['plink'] = self::plink($author, $datarray['guid']);
+ $datarray['private'] = $item['private'];
+ $datarray['changed'] = $datarray['created'] = $datarray['edited'] = $item['created'];
+
+ $message_id = Item::insert($datarray);
+
+ if ($message_id) {
+ Logger::info('Stored reshare activity.', ['guid' => $guid, 'id' => $message_id]);
+ if ($datarray['uid'] == 0) {
+ Item::distribute($message_id);
+ }
+ }
+ }
+
/**
* @brief Processes a reshare message
*
self::sendParticipation($contact, $datarray);
+ $root_message_id = self::messageExists($importer["uid"], $root_guid);
+ if ($root_message_id) {
+ self::addReshareActivity($datarray, $root_message_id, $guid, $author);
+ }
+
if ($message_id) {
Logger::log("Stored reshare ".$datarray["guid"]." with message id ".$message_id, Logger::DEBUG);
if ($datarray['uid'] == 0) {
* @param array $contact Target of the communication
* @param string $envelope The message that is to be transmitted
* @param bool $public_batch Is it a public post?
- * @param bool $queue_run Is the transmission called from the queue?
* @param string $guid message guid
+ * @param bool $no_defer Don't defer a failing delivery
*
- * @param bool $no_queue
* @return int Result of the transmission
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function transmit(array $owner, array $contact, $envelope, $public_batch, $queue_run = false, $guid = "", $no_queue = false)
+ public static function transmit(array $owner, array $contact, $envelope, $public_batch, $guid = "", $no_defer = false)
{
$enabled = intval(Config::get("system", "diaspora_enabled"));
if (!$enabled) {
Logger::log("transmit: ".$logid."-".$guid." ".$dest_url);
- if (!$queue_run && Queue::wasDelayed($contact["id"])) {
- $return_code = 0;
- } else {
- if (!intval(Config::get("system", "diaspora_test"))) {
- $content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json");
+ if (!intval(Config::get("system", "diaspora_test"))) {
+ $content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json");
- $postResult = Network::post($dest_url."/", $envelope, ["Content-Type: ".$content_type]);
- $return_code = $postResult->getReturnCode();
- } else {
- Logger::log("test_mode");
- return 200;
- }
+ $postResult = Network::post($dest_url."/", $envelope, ["Content-Type: ".$content_type]);
+ $return_code = $postResult->getReturnCode();
+ } else {
+ Logger::log("test_mode");
+ return 200;
}
Logger::log("transmit: ".$logid."-".$guid." to ".$dest_url." returns: ".$return_code);
if (!$return_code || (($return_code == 503) && (stristr($postResult->getHeader(), "retry-after")))) {
- if (!$no_queue && !empty($contact['contact-type']) && ($contact['contact-type'] != Contact::TYPE_RELAY)) {
- Logger::log("queue message");
- // queue message for redelivery
- Queue::add($contact["id"], Protocol::DIASPORA, $envelope, $public_batch, $guid);
+ if (!$no_defer && !empty($contact['contact-type']) && ($contact['contact-type'] != Contact::TYPE_RELAY)) {
+ Logger::info('defer message', ['log' => $logid, 'guid' => $guid, 'destination' => $dest_url]);
+ // defer message for redelivery
+ Worker::defer();
}
// The message could not be delivered. We mark the contact as "dead"
* @param array $message The message data
* @param bool $public_batch Is it a public post?
* @param string $guid message guid
- * @param bool $spool Should the transmission be spooled or transmitted?
+ * @param bool $no_defer Don't defer a failing delivery
*
* @return int Result of the transmission
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- private static function buildAndTransmit(array $owner, array $contact, $type, $message, $public_batch = false, $guid = "", $spool = false)
+ private static function buildAndTransmit(array $owner, array $contact, $type, $message, $public_batch = false, $guid = "", $no_defer = false)
{
$msg = self::buildPostXml($type, $message);
$envelope = self::buildMessage($msg, $owner, $contact, $owner['uprvkey'], $contact['pubkey'], $public_batch);
- if ($spool) {
- Queue::add($contact['id'], Protocol::DIASPORA, $envelope, $public_batch, $guid);
- return true;
- } else {
- $return_code = self::transmit($owner, $contact, $envelope, $public_batch, false, $guid);
- }
+ $return_code = self::transmit($owner, $contact, $envelope, $public_batch, $guid, $no_defer);
Logger::log("guid: ".$guid." result ".$return_code, Logger::DEBUG);
foreach ($recips as $recip) {
Logger::log("Send updated profile data for user ".$uid." to contact ".$recip["id"], Logger::DEBUG);
- self::buildAndTransmit($owner, $recip, "profile", $message, false, "", false);
+ self::buildAndTransmit($owner, $recip, "profile", $message, false, '', true);
}
}