streams/Zotlabs/Module/React.php

85 lines
1.7 KiB
PHP
Raw Normal View History

2016-06-03 03:31:34 +00:00
<?php
namespace Zotlabs\Module;
use Zotlabs\Web\Controller;
use Zotlabs\Lib\Activity;
use Zotlabs\Daemon\Master;
2016-06-03 03:31:34 +00:00
class React extends Controller {
2016-06-03 03:31:34 +00:00
function get() {
2016-06-03 03:31:34 +00:00
if(! local_channel())
return;
$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'];
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())
);
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;
}
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
$n = [] ;
2016-06-03 03:31:34 +00:00
$n['aid'] = $channel['channel_account_id'];
$n['uid'] = $channel['channel_id'];
$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);
retain_item($postid);
2016-06-03 03:31:34 +00:00
if($x['success']) {
$nid = $x['item_id'];
Master::Summon( [ 'Notifier', 'like', $nid ] );
2016-06-03 03:31:34 +00:00
}
}
}
}