2016-06-03 03:31:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Zotlabs\Module;
|
|
|
|
|
2019-04-30 02:29:11 +00:00
|
|
|
use Zotlabs\Web\Controller;
|
|
|
|
use Zotlabs\Lib\Activity;
|
|
|
|
use Zotlabs\Daemon\Master;
|
2016-06-03 03:31:34 +00:00
|
|
|
|
2019-04-30 02:29:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
class React extends Controller {
|
2016-06-03 03:31:34 +00:00
|
|
|
|
|
|
|
function get() {
|
2017-11-27 02:29:24 +00:00
|
|
|
|
2016-06-03 03:31:34 +00:00
|
|
|
if(! local_channel())
|
|
|
|
return;
|
|
|
|
|
2017-11-27 02:29:24 +00:00
|
|
|
$sys = get_sys_channel();
|
|
|
|
$channel = \App::get_channel();
|
|
|
|
|
2016-06-03 03:31:34 +00:00
|
|
|
$postid = $_REQUEST['postid'];
|
|
|
|
|
|
|
|
if(! $postid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
$emoji = $_REQUEST['emoji'];
|
2017-11-27 02:29:24 +00:00
|
|
|
|
|
|
|
|
2016-06-03 03:31:34 +00:00
|
|
|
if($_REQUEST['emoji']) {
|
|
|
|
|
|
|
|
$i = q("select * from item where id = %d and uid = %d",
|
|
|
|
intval($postid),
|
|
|
|
intval(local_channel())
|
|
|
|
);
|
|
|
|
|
2017-11-27 02:29:24 +00:00
|
|
|
if(! $i) {
|
|
|
|
$i = q("select * from item where id = %d and uid = %d",
|
|
|
|
intval($postid),
|
|
|
|
intval($sys['channel_id'])
|
|
|
|
);
|
|
|
|
|
|
|
|
if($i) {
|
|
|
|
$i = [ copy_of_pubitem($channel, $i[0]['mid']) ];
|
|
|
|
$postid = (($i) ? $i[0]['id'] : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(! $i) {
|
2016-06-03 03:31:34 +00:00
|
|
|
return;
|
2017-11-27 02:29:24 +00:00
|
|
|
}
|
2016-06-03 03:31:34 +00:00
|
|
|
|
2019-05-03 02:39:08 +00:00
|
|
|
$item = array_shift($i);
|
2016-06-03 03:31:34 +00:00
|
|
|
|
2019-04-30 02:29:11 +00:00
|
|
|
$n = [] ;
|
2016-06-03 03:31:34 +00:00
|
|
|
$n['aid'] = $channel['channel_account_id'];
|
|
|
|
$n['uid'] = $channel['channel_id'];
|
2016-06-04 01:46:59 +00:00
|
|
|
$n['item_origin'] = true;
|
2019-05-03 02:39:08 +00:00
|
|
|
$n['item_type'] = $item['item_type'];
|
2016-06-03 03:31:34 +00:00
|
|
|
$n['parent'] = $postid;
|
2019-05-03 02:39:08 +00:00
|
|
|
$n['parent_mid'] = $item['mid'];
|
2019-02-19 22:59:22 +00:00
|
|
|
$n['uuid'] = new_uuid();
|
|
|
|
$n['mid'] = z_root() . '/item/' . $n['uuid'];
|
2019-05-03 02:39:08 +00:00
|
|
|
$n['verb'] = 'emojiReaction';
|
|
|
|
$n['body'] = "\n\n[size=48]" . '&#x' . $emoji . ';[/size]' . "\n\n";
|
2016-06-03 03:31:34 +00:00
|
|
|
$n['author_xchan'] = $channel['channel_hash'];
|
|
|
|
|
2019-05-03 02:39:08 +00:00
|
|
|
$n['obj'] = Activity::fetch_item( [ 'id' => $item['mid'] ] );
|
|
|
|
$n['obj_type'] = ((array_path_exists('obj/type',$n)) ? $n['obj']['type'] : EMPTY_STR);
|
|
|
|
// This needs more work to provide an ActivityPub compatible object, if that is ever desired
|
|
|
|
$n['target'] = [ 'name' => $emoji ];
|
|
|
|
|
2016-06-03 03:31:34 +00:00
|
|
|
$x = item_store($n);
|
2017-07-11 03:18:33 +00:00
|
|
|
|
2017-11-27 02:29:24 +00:00
|
|
|
retain_item($postid);
|
2017-07-11 03:18:33 +00:00
|
|
|
|
2016-06-03 03:31:34 +00:00
|
|
|
if($x['success']) {
|
|
|
|
$nid = $x['item_id'];
|
2019-04-30 02:29:11 +00:00
|
|
|
Master::Summon( [ 'Notifier', 'like', $nid ] );
|
2016-06-03 03:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|