OStatus: Mentions should work now

This commit is contained in:
Michael Vogel 2015-06-26 10:41:11 +02:00
parent b1ddf28520
commit 58b624f877

View File

@ -421,11 +421,9 @@ function ostatus_import($xml,$importer,&$contact, &$hub) {
logger("Item was stored with id ".$item_id, LOGGER_DEBUG); logger("Item was stored with id ".$item_id, LOGGER_DEBUG);
$item["id"] = $item_id; $item["id"] = $item_id;
if (!isset($item["parent"]) OR ($item["parent"] == 0))
$item["parent"] = $item_id;
if ($mention) { if ($mention) {
$u = q("SELECT `notify-flags`, `language`, `username`, `email` FROM user WHERE uid = %d LIMIT 1", intval($item['uid'])); $u = q("SELECT `notify-flags`, `language`, `username`, `email` FROM user WHERE uid = %d LIMIT 1", intval($item['uid']));
$r = q("SELECT `parent` FROM `item` WHERE `id` = %d", intval($item_id));
notification(array( notification(array(
'type' => NOTIFY_TAGSELF, 'type' => NOTIFY_TAGSELF,
@ -435,13 +433,13 @@ function ostatus_import($xml,$importer,&$contact, &$hub) {
'to_email' => $u[0]["email"], 'to_email' => $u[0]["email"],
'uid' => $item["uid"], 'uid' => $item["uid"],
'item' => $item, 'item' => $item,
'link' => $a->get_baseurl().'/display/'.urlencode(get_item_guid($item["id"])), 'link' => $a->get_baseurl().'/display/'.urlencode(get_item_guid($item_id)),
'source_name' => $item["author-name"], 'source_name' => $item["author-name"],
'source_link' => $item["author-link"], 'source_link' => $item["author-link"],
'source_photo' => $item["author-avatar"], 'source_photo' => $item["author-avatar"],
'verb' => ACTIVITY_TAG, 'verb' => ACTIVITY_TAG,
'otype' => 'item', 'otype' => 'item',
'parent' => $item["parent"] 'parent' => $r[0]["parent"]
)); ));
} }
} }
@ -510,6 +508,8 @@ function check_conversations($override = false) {
function ostatus_completion($conversation_url, $uid, $item = array()) { function ostatus_completion($conversation_url, $uid, $item = array()) {
$a = get_app();
$item_stored = -1; $item_stored = -1;
$conversation_url = ostatus_convert_href($conversation_url); $conversation_url = ostatus_convert_href($conversation_url);
@ -600,12 +600,16 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
$items = array_reverse($items); $items = array_reverse($items);
$r = q("SELECT `nurl` FROM `contact` WHERE `uid` = %d AND `self`", intval($uid));
$importer = $r[0];
foreach ($items as $single_conv) { foreach ($items as $single_conv) {
// Test - remove before flight // Test - remove before flight
//$tempfile = tempnam(get_temppath(), "conversation"); //$tempfile = tempnam(get_temppath(), "conversation");
//file_put_contents($tempfile, json_encode($single_conv)); //file_put_contents($tempfile, json_encode($single_conv));
$mention = false;
if (isset($single_conv->object->id)) if (isset($single_conv->object->id))
$single_conv->id = $single_conv->object->id; $single_conv->id = $single_conv->object->id;
@ -718,6 +722,11 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
continue; continue;
} }
if (is_array($single_conv->to))
foreach($single_conv->to AS $to)
if ($importer["nurl"] == normalise_link($to->id))
$mention = true;
$actor = $single_conv->actor->id; $actor = $single_conv->actor->id;
if (isset($single_conv->actor->url)) if (isset($single_conv->actor->url))
$actor = $single_conv->actor->url; $actor = $single_conv->actor->url;
@ -858,6 +867,28 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
// Add the conversation entry (but don't fetch the whole conversation) // Add the conversation entry (but don't fetch the whole conversation)
ostatus_store_conversation($newitem, $conversation_url); ostatus_store_conversation($newitem, $conversation_url);
if ($mention) {
$u = q("SELECT `notify-flags`, `language`, `username`, `email` FROM user WHERE uid = %d LIMIT 1", intval($uid));
$r = q("SELECT `parent` FROM `item` WHERE `id` = %d", intval($newitem));
notification(array(
'type' => NOTIFY_TAGSELF,
'notify_flags' => $u[0]["notify-flags"],
'language' => $u[0]["language"],
'to_name' => $u[0]["username"],
'to_email' => $u[0]["email"],
'uid' => $uid,
'item' => $arr,
'link' => $a->get_baseurl().'/display/'.urlencode(get_item_guid($newitem)),
'source_name' => $arr["author-name"],
'source_link' => $arr["author-link"],
'source_photo' => $arr["author-avatar"],
'verb' => ACTIVITY_TAG,
'otype' => 'item',
'parent' => $r[0]["parent"]
));
}
// If the newly created item is the top item then change the parent settings of the thread // If the newly created item is the top item then change the parent settings of the thread
// This shouldn't happen anymore. This is supposed to be absolote. // This shouldn't happen anymore. This is supposed to be absolote.
if ($arr["uri"] == $first_id) { if ($arr["uri"] == $first_id) {