make item_normal() deal with various item types and add missing reactions modal

This commit is contained in:
Mario
2025-08-07 22:36:35 +00:00
parent 9343f00918
commit 51c79aecac
4 changed files with 39 additions and 18 deletions

View File

@@ -53,12 +53,12 @@ class Item extends Controller {
if (argc() > 1 && argv(1) !== 'drop') {
$x = q("select uid, item_wall, llink, uuid from item where uuid = '%s' order by item_wall desc",
$x = q("select uid, item_wall, item_type, llink, uuid from item where uuid = '%s' order by item_wall desc",
dbesc(argv(1))
);
if ($x) {
if ($x[0]['item_wall']) {
if ($x[0]['item_wall'] && $x[0]['item_type'] === ITEM_TYPE_POST) {
$c = channelx_by_n($x[0]['uid']);
if ($c) {
goaway(z_root() . '/channel/' . $c['channel_address'] . '?mid=' . $x[0]['uuid']);

View File

@@ -67,7 +67,7 @@ class Like extends Controller {
$items = conv_sort($items, 'commented');
}
else {
$item = item_by_item_id($arr['item']['id'], $arr['item']['parent']);
$item = item_by_item_id($arr['item']['id'], $arr['item']['parent'], type: $arr['item']['item_type']);
xchan_query($item, true);
$item = fetch_post_tags($item, true);
}
@@ -127,7 +127,7 @@ class Like extends Controller {
$extended_like = false;
$object = $target = null;
$post_type = EMPTY_STR;
$obj_type = EMPTY_STR;
$obj_type = EMPTY_STR;
if (argc() == 3) {
@@ -305,8 +305,6 @@ class Like extends Controller {
// parent, copy that as well.
if ($r) {
$obj_type = $r[0]['obj_type'];
if ($r[0]['uid'] === $sys_channel['channel_id'] && local_channel()) {
$r = [copy_of_pubitem(App::get_channel(), $r[0]['mid'])];
}
@@ -322,6 +320,8 @@ class Like extends Controller {
$item = $r[0];
$owner_uid = $r[0]['uid'];
$owner_aid = $r[0]['aid'];
$obj_type = $r[0]['obj_type'];
$item_type = $r[0]['item_type'];
if ((array_key_exists('owner', $item)) && intval($item['owner']['abook_self']))
$can_comment = perm_is_allowed($item['uid'], $observer['xchan_hash'], 'post_comments');
@@ -362,7 +362,7 @@ class Like extends Controller {
$multi_undo = true;
}
$item_normal = item_normal();
$item_normal = item_normal(type: $item_type);
$r = q("SELECT id, parent, uid, verb FROM item WHERE verb in ( $verbs ) $item_normal
AND author_xchan = '%s' AND thr_parent = '%s' and uid = %d ",

View File

@@ -240,7 +240,7 @@ function comments_are_now_closed($item) {
return false;
}
function item_normal($profile_uid = null, $prefix = 'item') {
function item_normal($profile_uid = null, $prefix = 'item', $type = ITEM_TYPE_POST) {
if ($profile_uid === null) {
$profile_uid = App::$profile['profile_uid'] ?? App::$profile_uid ?? null;
}
@@ -248,7 +248,7 @@ function item_normal($profile_uid = null, $prefix = 'item') {
$uid = local_channel();
$is_owner = ($uid && intval($profile_uid) === $uid);
$sql = " and $prefix.item_hidden = 0 and $prefix.item_type = 0 and $prefix.item_deleted = 0
$sql = " and $prefix.item_hidden = 0 and $prefix.item_type = $type and $prefix.item_deleted = 0
and $prefix.item_unpublished = 0 and $prefix.item_pending_remove = 0";
if ($is_owner) {
@@ -5360,17 +5360,18 @@ function set_activity_mid($string) {
* including activity counts.
* @param int $id
* @param int $parent
* @param int $type (optional) - defaults to ITEM_TYPE_POST
*/
function item_by_item_id(int $id, int $parent): array
function item_by_item_id(int $id, int $parent, int $type = ITEM_TYPE_POST): array
{
if (!$id && !$parent && !local_channel()) {
return [];
}
$item_normal_sql = item_normal();
$item_normal_sql = item_normal(type: $type);
$reaction = item_reaction_sql($parent);
$reaction = item_reaction_sql($parent, type: $type);
$reaction_cte_sql = $reaction['cte'];
$reaction_select_sql = $reaction['select'];
$reaction_join_sql = $reaction['join'];
@@ -5401,9 +5402,10 @@ function item_by_item_id(int $id, int $parent): array
* @param null|array $thr_parents (optional) - thr_parent mids which will be included
* @param string $permission_sql (optional) - SQL as provided by item_permission_sql() from the calling module
* @param bool $blog_mode (optional) - if set to yes only the parent items will be returned
* @param int $type (optional) - defaults to ITEM_TYPE_POST
*/
function items_by_parent_ids(array $parents, null|array $thr_parents = null, string $permission_sql = '', bool $blog_mode = false): array
function items_by_parent_ids(array $parents, null|array $thr_parents = null, string $permission_sql = '', bool $blog_mode = false, int $type = ITEM_TYPE_POST): array
{
if (!$parents) {
return [];
@@ -5411,7 +5413,7 @@ function items_by_parent_ids(array $parents, null|array $thr_parents = null, str
$ids = ids_to_querystr($parents, 'item_id');
$thread_allow = ((local_channel()) ? PConfig::Get(local_channel(), 'system', 'thread_allow', true) : Config::Get('system', 'thread_allow', true));
$item_normal_sql = item_normal();
$item_normal_sql = item_normal(type: $type);
$limit = $thread_allow ? 3 : 1000;
$thr_parent_sql = (($thread_allow) ? " AND item.thr_parent = item.parent_mid " : '');
@@ -5421,7 +5423,7 @@ function items_by_parent_ids(array $parents, null|array $thr_parents = null, str
$thr_parent_sql = " AND item.thr_parent IN (" . protect_sprintf($thr_parent_str) . ") ";
}
$reaction = item_reaction_sql($ids, $permission_sql, 'final_selection', $blog_mode);
$reaction = item_reaction_sql($ids, $permission_sql, 'final_selection', $blog_mode, $type);
$reaction_cte_sql = $reaction['cte'];
$reaction_select_sql = $reaction['select'];
$reaction_join_sql = $reaction['join'];
@@ -5499,11 +5501,12 @@ function items_by_parent_ids(array $parents, null|array $thr_parents = null, str
* @param string $ids
* @param string $permission_sql (optional) - SQL provided by item_permission_sql()
* @param string $join_prefix (optional) - prefix for the join part defaults to 'item'
* @param int $type (optional) - defaults to ITEM_TYPE_POST
*/
function item_reaction_sql(string $ids, string $permission_sql = '', string $join_prefix = 'item', bool $blog_mode = false): array
function item_reaction_sql(string $ids, string $permission_sql = '', string $join_prefix = 'item', bool $blog_mode = false, int $type = ITEM_TYPE_POST): array
{
$item_normal_sql = item_normal();
$item_normal_sql = item_normal(type: $type);
$observer = get_observer_hash();
$verbs = [
@@ -5686,7 +5689,7 @@ function item_activity_xchans(string $mid, int $parent, string $verb): array
);
$owner_uid = intval($parent_item[0]['uid']);
$item_normal = item_normal($owner_uid);
$item_normal = item_normal($owner_uid, type: $parent_item[0]['item_type']);
if (local_channel() === $owner_uid) {
$ret = q("SELECT item.id, item.item_blocked, xchan.xchan_hash, xchan.xchan_name as name, xchan.xchan_url as url, xchan.xchan_photo_s as photo FROM item

View File

@@ -23,4 +23,22 @@
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<div class="modal" id="reactions" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="reactions_title"></h3>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-hidden="true"></button>
</div>
<div class="modal-header" id="reactions_action">
</div>
<div class="modal-body list-group" id="reactions_body">
{{$wait}}
</div>
<div class="ps-3 pe-3" id="reactions_extra_top"></div>
<div class="ps-3 pe-3" id="reactions_extra_middle"></div>
<div class="ps-3 pe-3" id="reactions_extra_bottom"></div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
{{/if}}