streams/Code/Module/Starred.php

74 lines
1.8 KiB
PHP
Raw Normal View History

2016-04-19 03:38:38 +00:00
<?php
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2016-04-19 03:38:38 +00:00
2021-12-04 20:43:53 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Lib\Libsync;
use Code\Web\Controller;
use Code\Lib\Channel;
2016-04-19 03:38:38 +00:00
2021-12-02 22:33:36 +00:00
class Starred extends Controller
{
2016-04-19 03:38:38 +00:00
2021-12-02 23:02:31 +00:00
public function init()
2021-12-02 22:33:36 +00:00
{
2016-04-19 03:38:38 +00:00
2021-12-02 23:02:31 +00:00
if (!local_channel()) {
2021-12-02 22:33:36 +00:00
killme();
}
$message_id = ((argc() > 1) ? intval(argv(1)) : 0);
2021-12-02 23:02:31 +00:00
if (!$message_id) {
2021-12-02 22:33:36 +00:00
killme();
}
2021-12-02 23:02:31 +00:00
2021-12-02 22:33:36 +00:00
$r = q(
2021-12-04 20:43:53 +00:00
"SELECT * FROM item WHERE id = %d
and item_type in (0,6,7) and item_deleted = 0 and item_unpublished = 0
and item_delayed = 0 and item_pending_remove = 0 and item_blocked = 0 LIMIT 1",
2021-12-02 22:33:36 +00:00
intval($message_id)
);
2021-12-04 20:43:53 +00:00
// if interacting with a pubstream item,
// create a copy of the parent in your stream.
if ($r) {
2022-01-25 01:26:12 +00:00
if (! Channel::is_system(local_channel())) {
2021-12-04 20:43:53 +00:00
$r = [ copy_of_pubitem(App::get_channel(), $r[0]['mid']) ];
}
2021-12-02 22:33:36 +00:00
}
2021-12-02 23:02:31 +00:00
2021-12-04 20:43:53 +00:00
if (! $r) {
killme();
}
// reset $message_id to the fetched copy of message if applicable
$message_id = $r[0]['id'];
2021-12-02 22:33:36 +00:00
$item_starred = (intval($r[0]['item_starred']) ? 0 : 1);
2021-12-02 23:02:31 +00:00
2021-12-02 22:33:36 +00:00
$r = q(
"UPDATE item SET item_starred = %d WHERE uid = %d and id = %d",
intval($item_starred),
intval(local_channel()),
intval($message_id)
);
2021-12-02 22:33:36 +00:00
$r = q(
"select * from item where id = %d",
intval($message_id)
);
if ($r) {
xchan_query($r);
$sync_item = fetch_post_tags($r);
Libsync::build_sync_packet(local_channel(), [
'item' => [
encode_item($sync_item[0], true)
]
]);
}
2021-12-02 22:33:36 +00:00
header('Content-type: application/json');
echo json_encode(array('result' => $item_starred));
killme();
}
2016-04-19 03:38:38 +00:00
}