return self::receiveConversation($importer, $msg, $fields);
case "like":
- return self::receiveLike($importer, $sender, $fields);
+ return self::receiveLike($importer, $sender, $fields, $fetched);
case "message":
if (!$private) {
Logger::log('Message with type ' . $type . ' is not private, quitting.');
return false;
}
- return self::receiveParticipation($importer, $fields);
+ return self::receiveParticipation($importer, $fields, $fetched);
case "photo": // Not implemented
return self::receivePhoto($importer, $fields);
return self::receiveProfile($importer, $fields);
case "reshare":
- return self::receiveReshare($importer, $fields, $msg["message"]);
+ return self::receiveReshare($importer, $fields, $msg["message"], $fetched);
case "retraction":
return self::receiveRetraction($importer, $sender, $fields);
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- private static function plink($addr, $guid, $parent_guid = '')
+ private static function plink(string $addr, string $guid, string $parent_guid = '')
{
$contact = Contact::getByURL($addr);
if (empty($contact)) {
$datarray["protocol"] = Conversation::PARCEL_DIASPORA;
$datarray["source"] = $xml;
+ $datarray["direction"] = $fetched ? Conversation::PULL : Conversation::PUSH;
$datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at;
$datarray['diaspora_signed_text'] = json_encode($data);
}
+ if (Item::isTooOld($datarray)) {
+ Logger::info('Comment is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
+ return false;
+ }
+
$message_id = Item::insert($datarray);
if ($message_id <= 0) {
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- private static function receiveLike(array $importer, $sender, $data)
+ private static function receiveLike(array $importer, $sender, $data, bool $fetched)
{
$author = Strings::escapeTags(XML::unescape($data->author));
$guid = Strings::escapeTags(XML::unescape($data->guid));
$datarray = [];
$datarray["protocol"] = Conversation::PARCEL_DIASPORA;
+ $datarray["direction"] = $fetched ? Conversation::PULL : Conversation::PUSH;
$datarray["uid"] = $importer["uid"];
$datarray["contact-id"] = $author_contact["cid"];
$datarray['diaspora_signed_text'] = json_encode($data);
}
+ if (Item::isTooOld($datarray)) {
+ Logger::info('Like is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
+ return false;
+ }
+
$message_id = Item::insert($datarray);
if ($message_id <= 0) {
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- private static function receiveParticipation(array $importer, $data)
+ private static function receiveParticipation(array $importer, $data, bool $fetched)
{
$author = strtolower(Strings::escapeTags(XML::unescape($data->author)));
$guid = Strings::escapeTags(XML::unescape($data->guid));
$datarray = [];
$datarray["protocol"] = Conversation::PARCEL_DIASPORA;
+ $datarray["direction"] = $fetched ? Conversation::PULL : Conversation::PUSH;
$datarray["uid"] = $importer["uid"];
$datarray["contact-id"] = $author_contact["cid"];
// Diaspora doesn't provide a date for a participation
$datarray["changed"] = $datarray["created"] = $datarray["edited"] = DateTimeFormat::utcNow();
+ if (Item::isTooOld($datarray)) {
+ Logger::info('Participation is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
+ return false;
+ }
+
$message_id = Item::insert($datarray);
Logger::info('Participation stored', ['id' => $message_id, 'guid' => $guid, 'parent_guid' => $parent_guid, 'author' => $author]);
$datarray['object-type'] = Activity\ObjectType::NOTE;
$datarray['protocol'] = $item['protocol'];
+ $datarray['source'] = $item['source'];
+ $datarray['direction'] = $item['direction'];
$datarray['plink'] = self::plink($author, $datarray['guid']);
$datarray['private'] = $item['private'];
$datarray['changed'] = $datarray['created'] = $datarray['edited'] = $item['created'];
+ if (Item::isTooOld($datarray)) {
+ Logger::info('Reshare activity is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
+ return false;
+ }
+
$message_id = Item::insert($datarray);
if ($message_id) {
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- private static function receiveReshare(array $importer, $data, $xml)
+ private static function receiveReshare(array $importer, $data, $xml, bool $fetched)
{
$author = Strings::escapeTags(XML::unescape($data->author));
$guid = Strings::escapeTags(XML::unescape($data->guid));
return false;
}
+ if (empty($original_item['plink'])) {
+ $original_item['plink'] = self::plink($root_author, $root_guid);
+ }
+
$datarray = [];
$datarray["uid"] = $importer["uid"];
$datarray["protocol"] = Conversation::PARCEL_DIASPORA;
$datarray["source"] = $xml;
+ $datarray["direction"] = $fetched ? Conversation::PULL : Conversation::PUSH;
/// @todo Copy tag data from original post
$datarray["object-type"] = $original_item["object-type"];
self::fetchGuid($datarray);
+
+ if (Item::isTooOld($datarray)) {
+ Logger::info('Reshare is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
+ return false;
+ }
+
$message_id = Item::insert($datarray);
self::sendParticipation($contact, $datarray);
$datarray["protocol"] = Conversation::PARCEL_DIASPORA;
$datarray["source"] = $xml;
+ $datarray["direction"] = $fetched ? Conversation::PULL : Conversation::PUSH;
if ($fetched) {
$datarray["post-type"] = Item::PT_FETCHED;
}
self::fetchGuid($datarray);
+
+ if (Item::isTooOld($datarray)) {
+ Logger::info('Status is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
+ return false;
+ }
+
$message_id = Item::insert($datarray);
self::sendParticipation($contact, $datarray);
}
if ($item['author-link'] != $item['owner-link']) {
- require_once 'mod/share.php';
$body = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'],
$item['plink'], $item['created']) . $body . '[/share]';
}