aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2025-05-09 20:24:25 +0000
committerMario <mario@mariovavti.com>2025-05-09 20:24:25 +0000
commit4fa9f301897aeecf0506e9289658dc3002f3e4a2 (patch)
tree47f48cca9d7445a11930f561d2465a2d7cbd050d
parent57ae3325e0a205916392f63dd58b80ae82ab0a83 (diff)
downloadvolse-hubzilla-4fa9f301897aeecf0506e9289658dc3002f3e4a2.tar.gz
volse-hubzilla-4fa9f301897aeecf0506e9289658dc3002f3e4a2.tar.bz2
volse-hubzilla-4fa9f301897aeecf0506e9289658dc3002f3e4a2.zip
cleanup, add some doco an add missing counts of observer event rsvps
-rw-r--r--Zotlabs/Lib/ThreadItem.php10
-rw-r--r--include/items.php76
2 files changed, 69 insertions, 17 deletions
diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php
index b8239df48..315e30668 100644
--- a/Zotlabs/Lib/ThreadItem.php
+++ b/Zotlabs/Lib/ThreadItem.php
@@ -474,7 +474,15 @@ class ThreadItem {
'reactions_allowed' => $reactions_allowed,
'reaction_str' => [t('Add yours'), t('Remove yours')],
'is_contained' => $this->is_toplevel() && str_contains($item['tgt_type'], 'Collection'),
- 'observer_activity' => ['like' => intval($item['observer_liked'] ?? 0), 'dislike' => intval($item['observer_disliked'] ?? 0), 'announce' => intval($item['observer_announced'] ?? 0), 'comment' => intval($item['observer_commented'] ?? 0)],
+ 'observer_activity' => [
+ 'like' => intval($item['observer_liked'] ?? 0),
+ 'dislike' => intval($item['observer_disliked'] ?? 0),
+ 'announce' => intval($item['observer_announced'] ?? 0),
+ 'comment' => intval($item['observer_commented'] ?? 0),
+ 'attendyes' => intval($item['observer_accepted'] ?? 0),
+ 'attendno' => intval($item['observer_rejected'] ?? 0),
+ 'attendmaybe' => intval($item['observer_tentativelyaccepted'] ?? 0)
+ ],
'threaded' => $this->threaded,
'blog_mode' => $blog_mode
);
diff --git a/include/items.php b/include/items.php
index c0948b7dc..9d9394118 100644
--- a/include/items.php
+++ b/include/items.php
@@ -5361,12 +5361,17 @@ function set_activity_mid($string) {
return str_replace(z_root() . '/item/', z_root() . '/activity/', $string);
}
+/**
+ * @brief returns SQL which counts activities for an item and
+ * if there is an observer also count activities authored by observer.
+ * @param string $prefix (optional)
+ */
+
function item_activity_sql($prefix = 'c') {
$item_normal_c = item_normal(prefix: $prefix);
$sql = '';
$observer = get_observer_hash();
- $observer_sql = '';
$thread_allow = ((local_channel()) ? PConfig::Get(local_channel(), 'system', 'thread_allow', true) : Config::Get('system', 'thread_allow', true));
@@ -5375,6 +5380,9 @@ function item_activity_sql($prefix = 'c') {
COUNT(CASE WHEN $prefix.verb = 'Like' AND $prefix.author_xchan = '$observer' $item_normal_c THEN 1 END) AS observer_liked,
COUNT(CASE WHEN $prefix.verb = 'Dislike' AND $prefix.author_xchan = '$observer' $item_normal_c THEN 1 END) AS observer_disliked,
COUNT(CASE WHEN $prefix.verb = 'Announce' AND $prefix.author_xchan = '$observer' $item_normal_c THEN 1 END) AS observer_announced,
+ COUNT(CASE WHEN $prefix.verb = 'Accept' AND $prefix.author_xchan = '$observer' $item_normal_c THEN 1 END) AS observer_accepted,
+ COUNT(CASE WHEN $prefix.verb = 'Reject' AND $prefix.author_xchan = '$observer' $item_normal_c THEN 1 END) AS observer_rejected,
+ COUNT(CASE WHEN $prefix.verb = 'TentativeAccept' AND $prefix.author_xchan = '$observer' $item_normal_c THEN 1 END) AS observer_tentativelyaccepted,
SQL;
if ($thread_allow) {
@@ -5400,7 +5408,14 @@ function item_activity_sql($prefix = 'c') {
}
-function item_by_item_id($id, $sql_extra = '') {
+/**
+ * @brief returns an item by id belonging to local_channel()
+ * including activity counts.
+ * @param int $id
+ */
+
+function item_by_item_id(int $id): array
+{
$item_normal = item_normal();
$item_normal_c = item_normal(prefix: 'c');
$activity_sql = item_activity_sql('c');
@@ -5421,10 +5436,20 @@ function item_by_item_id($id, $sql_extra = '') {
);
return $ret;
-
}
-function items_by_parent_ids($ids, $thr_parents = '', $blog_mode = false) {
+/**
+ * @brief returns an array of items by ids
+ * ATTENTION: no permissions are checked here!!!
+ * Permissions MUST be checked by the function which returns the ids.
+ * @param string $ids - a string with ids separated by comma
+ * @param string $thr_parents (optional) - a string with thr_parent mids separated by comma
+ * which will be included
+ * @param bool $blog_mode (optional) - if set to yes only the parent items will be returned
+ */
+
+function items_by_parent_ids(string $ids, string $thr_parents = '', bool $blog_mode = false): array
+{
$item_normal = item_normal();
$item_normal_c = item_normal(prefix: 'c');
$activity_sql = item_activity_sql('c');
@@ -5460,7 +5485,16 @@ function items_by_parent_ids($ids, $thr_parents = '', $blog_mode = false) {
return $ret;
}
-function items_by_thr_parent($mid, $parent, $sql_extra = '') {
+
+/**
+ * @brief returns an array of items by thr_parent mid of a parent
+
+ * @param string $mid
+ * @param int $parent
+ */
+
+function items_by_thr_parent(string $mid, int $parent): array
+{
$parent_item = q("SELECT uid FROM item WHERE id = %d",
intval($parent)
);
@@ -5495,13 +5529,8 @@ function items_by_thr_parent($mid, $parent, $sql_extra = '') {
}
if (!$ret) {
-
- $x = q("SELECT uid FROM item WHERE id = %d",
- intval($parent)
- );
-
$observer_hash = get_observer_hash();
- $sql_extra = item_permissions_sql($x[0]['uid'], $observer_hash);
+ $sql_extra = item_permissions_sql($owner_uid, $observer_hash);
$ret = q(
"SELECT item.*,
@@ -5520,14 +5549,23 @@ function items_by_thr_parent($mid, $parent, $sql_extra = '') {
GROUP BY item.id
ORDER BY item.created",
dbesc($mid),
- intval($x[0]['uid'])
+ intval($owner_uid)
);
}
return $ret;
}
-function item_activity_xchans($mid, $parent, $verb) {
+/**
+ * @brief returns an array of xchan entries (partly) for activities of an item by mid of a parent.
+ * Also checks if observer is allowed to add activities to the item.
+ * @param string $mid
+ * @param int $parent
+ * @param string $verb
+ */
+
+function item_activity_xchans(string $mid, int $parent, string $verb): array
+{
$observer_hash = get_observer_hash();
$parent_item = q("SELECT * FROM item WHERE id = %d",
intval($parent)
@@ -5576,9 +5614,15 @@ function item_activity_xchans($mid, $parent, $verb) {
return $ret;
}
-// Find the thr_parents we need to show when we need to show a nested comment
-// TODO: can this be improved or maybe implemented differently in the UI?
-function get_recursive_thr_parents(array $item) : array {
+
+/**
+ * @brief find and return thr_parents we need to show when displaying a nested comment.
+ * TODO: can this be improved or maybe implemented differently in the UI?
+ * @param array $item
+ */
+
+function get_recursive_thr_parents(array $item): array
+{
$thr_parents[] = $item['thr_parent'];
$mid = $item['thr_parent'];