Merge pull request #4147 from annando/send_participation

We now send participations when receiving public posts
This commit is contained in:
Hypolite Petovan 2017-12-29 14:02:25 -06:00 committed by GitHub
commit 2f7ef735f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2688,6 +2688,8 @@ class Diaspora
self::fetchGuid($datarray);
$message_id = item_store($datarray);
self::sendParticipation($contact, $datarray);
if ($message_id) {
logger("Stored reshare ".$datarray["guid"]." with message id ".$message_id, LOGGER_DEBUG);
return true;
@ -2926,6 +2928,8 @@ class Diaspora
self::fetchGuid($datarray);
$message_id = item_store($datarray);
self::sendParticipation($contact, $datarray);
if ($message_id) {
logger("Stored item ".$datarray["guid"]." with message id ".$message_id, LOGGER_DEBUG);
return true;
@ -3215,6 +3219,49 @@ class Diaspora
return $return_code;
}
/**
* @brief sends a participation (Used to get all further updates)
*
* @param array $contact Target of the communication
* @param array $item Item array
*
* @return int The result of the transmission
*/
private static function sendParticipation($contact, $item)
{
// Don't send notifications for private postings
if ($item['private']) {
return;
}
$cachekey = "diaspora:sendParticipation:".$item['guid'];
$result = Cache::get($cachekey);
if (!is_null($result)) {
return;
}
// Fetch some user id to have a valid handle to transmit the participation.
// In fact it doesn't matter which user sends this - but it is needed by the protocol.
$condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
$first_user = dba::select('user', ['uid'], $condition, ['limit' => 1]);
$owner = User::getOwnerDataById($first_user['uid']);
$author = self::myHandle($owner);
$message = array("author" => $author,
"guid" => get_guid(32),
"parent_type" => "Post",
"parent_guid" => $item["guid"]);
logger("Send participation for ".$item["guid"]." by ".$author, LOGGER_DEBUG);
// It doesn't matter what we store, we only want to avoid sending repeated notifications for the same item
Cache::set($cachekey, $item["guid"], CACHE_QUARTER_HOUR);
return self::buildAndTransmit($owner, $contact, "participation", $message);
}
/**
* @brief sends an account migration
*