Merge pull request #3697 from annando/new-ostatus

Rewritten OStatus inbound part
This commit is contained in:
rabuzarus 2017-09-12 10:47:29 +02:00 committed by GitHub
commit cf6874cffc
7 changed files with 656 additions and 989 deletions

View file

@ -229,8 +229,9 @@ define('PROTOCOL_UNKNOWN', 0);
define('PROTOCOL_DFRN', 1); define('PROTOCOL_DFRN', 1);
define('PROTOCOL_DIASPORA', 2); define('PROTOCOL_DIASPORA', 2);
define('PROTOCOL_OSTATUS_SALMON', 3); define('PROTOCOL_OSTATUS_SALMON', 3);
define('PROTOCOL_OSTATUS_FEED', 4); define('PROTOCOL_OSTATUS_FEED', 4); // Deprecated
define('PROTOCOL_GS_CONVERSATION', 5); define('PROTOCOL_GS_CONVERSATION', 5); // Deprecated
define('PROTOCOL_SPLITTED_CONV', 6);
/** @}*/ /** @}*/
/** /**

View file

@ -42,12 +42,6 @@ function cron_run(&$argv, &$argc){
// Expire and remove user entries // Expire and remove user entries
proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "expire_and_remove_users"); proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "expire_and_remove_users");
// Check OStatus conversations
proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_mentions");
// Check every conversation
proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_conversations");
// Call possible post update functions // Call possible post update functions
proc_run(PRIORITY_LOW, "include/cronjobs.php", "post_update"); proc_run(PRIORITY_LOW, "include/cronjobs.php", "post_update");

View file

@ -8,7 +8,6 @@ function cronjobs_run(&$argv, &$argc){
global $a; global $a;
require_once 'include/datetime.php'; require_once 'include/datetime.php';
require_once 'include/ostatus.php';
require_once 'include/post_update.php'; require_once 'include/post_update.php';
require_once 'mod/nodeinfo.php'; require_once 'mod/nodeinfo.php';
require_once 'include/photos.php'; require_once 'include/photos.php';
@ -22,19 +21,6 @@ function cronjobs_run(&$argv, &$argc){
logger("Starting cronjob ".$argv[1], LOGGER_DEBUG); logger("Starting cronjob ".$argv[1], LOGGER_DEBUG);
// Check OStatus conversations
// Check only conversations with mentions (for a longer time)
if ($argv[1] == 'ostatus_mentions') {
ostatus::check_conversations(true);
return;
}
// Check every conversation
if ($argv[1] == 'ostatus_conversations') {
ostatus::check_conversations(false);
return;
}
// Call possible post update functions // Call possible post update functions
// see include/post_update.php for more details // see include/post_update.php for more details
if ($argv[1] == 'post_update') { if ($argv[1] == 'post_update') {

View file

@ -303,7 +303,7 @@ class dfrn {
AND (NOT `contact`.`blocked` OR `contact`.`pending`) AND (NOT `contact`.`blocked` OR `contact`.`pending`)
LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`
WHERE `item`.`id` = %d AND `item`.`visible` AND NOT `item`.`moderated` AND `item`.`parent` != 0 WHERE `item`.`id` = %d AND `item`.`visible` AND NOT `item`.`moderated` AND `item`.`parent` != 0
AND `item`.`wall` AND NOT `item`.`private`", AND NOT `item`.`private`",
intval($item_id) intval($item_id)
); );
@ -330,12 +330,9 @@ class dfrn {
$alternatelink = $owner['url']; $alternatelink = $owner['url'];
$root = self::add_header($doc, $owner, 'dfrn:owner', $alternatelink, true);
$type = 'html'; $type = 'html';
$entry = self::entry($doc, $type, $item, $owner, true); $root = self::entry($doc, $type, $item, $owner, true, 0, true);
$root->appendChild($entry);
$atom = trim($doc->saveXML()); $atom = trim($doc->saveXML());
return $atom; return $atom;
@ -823,11 +820,12 @@ class dfrn {
* @param array $owner Owner record * @param array $owner Owner record
* @param bool $comment Trigger the sending of the "comment" element * @param bool $comment Trigger the sending of the "comment" element
* @param int $cid Contact ID of the recipient * @param int $cid Contact ID of the recipient
* @param bool $single If set, the entry is created as an XML document with a single "entry" element
* *
* @return object XML entry object * @return object XML entry object
* @todo Add type-hints * @todo Add type-hints
*/ */
private static function entry($doc, $type, $item, $owner, $comment = false, $cid = 0) { private static function entry($doc, $type, $item, $owner, $comment = false, $cid = 0, $single = false) {
$mentioned = array(); $mentioned = array();
@ -840,7 +838,22 @@ class dfrn {
return xml::create_element($doc, "at:deleted-entry", "", $attributes); return xml::create_element($doc, "at:deleted-entry", "", $attributes);
} }
if (!$single) {
$entry = $doc->createElement("entry"); $entry = $doc->createElement("entry");
} else {
$entry = $doc->createElementNS(NAMESPACE_ATOM1, 'entry');
$doc->appendChild($entry);
$entry->setAttribute("xmlns:thr", NAMESPACE_THREAD);
$entry->setAttribute("xmlns:at", NAMESPACE_TOMB);
$entry->setAttribute("xmlns:media", NAMESPACE_MEDIA);
$entry->setAttribute("xmlns:dfrn", NAMESPACE_DFRN);
$entry->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
$entry->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
$entry->setAttribute("xmlns:poco", NAMESPACE_POCO);
$entry->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
$entry->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
}
if ($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) { if ($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) {
$body = fix_private_photos($item['body'],$owner['uid'],$item,$cid); $body = fix_private_photos($item['body'],$owner['uid'],$item,$cid);
@ -868,10 +881,10 @@ class dfrn {
$entry->appendChild($dfrnowner); $entry->appendChild($dfrnowner);
if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) { if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) {
$parent = q("SELECT `guid` FROM `item` WHERE `id` = %d", intval($item["parent"]));
$parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']); $parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
$parent = q("SELECT `guid`,`plink` FROM `item` WHERE `uri` = '%s' AND `uid` = %d", dbesc($parent_item), intval($item['uid']));
$attributes = array("ref" => $parent_item, "type" => "text/html", $attributes = array("ref" => $parent_item, "type" => "text/html",
"href" => System::baseUrl().'/display/'.$parent[0]['guid'], "href" => $parent[0]['plink'],
"dfrn:diaspora_guid" => $parent[0]['guid']); "dfrn:diaspora_guid" => $parent[0]['guid']);
xml::add_element($doc, $entry, "thr:in-reply-to", "", $attributes); xml::add_element($doc, $entry, "thr:in-reply-to", "", $attributes);
} }

View file

@ -534,6 +534,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
} }
// Converting the plink // Converting the plink
/// @todo Check if this is really still needed
if ($arr['network'] == NETWORK_OSTATUS) { if ($arr['network'] == NETWORK_OSTATUS) {
if (isset($arr['plink'])) { if (isset($arr['plink'])) {
$arr['plink'] = ostatus::convert_href($arr['plink']); $arr['plink'] = ostatus::convert_href($arr['plink']);

File diff suppressed because it is too large Load diff

View file

@ -293,7 +293,7 @@ function display_content(App $a, $update = 0) {
} }
// We are displaying an "alternate" link if that post was public. See issue 2864 // We are displaying an "alternate" link if that post was public. See issue 2864
$is_public = dba::exists('item', array('id' => $item_id, 'private' => false, 'wall' => true)); $is_public = dba::exists('item', array('id' => $item_id, 'private' => false));
if ($is_public) { if ($is_public) {
$alternate = System::baseUrl().'/display/'.$nick.'/'.$item_id.'.atom'; $alternate = System::baseUrl().'/display/'.$nick.'/'.$item_id.'.atom';
} else { } else {