aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2023-07-01 11:03:26 +0000
committerMario <mario@mariovavti.com>2023-07-01 11:03:26 +0000
commit4f03272a5f4c33f6c893b6f56f43fe5e839173b3 (patch)
tree98c13a7fabccf9aa1dbe164532db68703d7d6dbf
parent7755936a2ef31d8ad9976d6fe80eb85f0b816f70 (diff)
downloadvolse-hubzilla-4f03272a5f4c33f6c893b6f56f43fe5e839173b3.tar.gz
volse-hubzilla-4f03272a5f4c33f6c893b6f56f43fe5e839173b3.tar.bz2
volse-hubzilla-4f03272a5f4c33f6c893b6f56f43fe5e839173b3.zip
unify code for selecting deliverable abook xchans
-rw-r--r--include/connections.php29
-rw-r--r--include/items.php23
-rw-r--r--include/text.php18
3 files changed, 45 insertions, 25 deletions
diff --git a/include/connections.php b/include/connections.php
index e8415bb25..9a6ee7d8d 100644
--- a/include/connections.php
+++ b/include/connections.php
@@ -67,6 +67,35 @@ function rconnect_url($channel_id,$xchan) {
}
+function deliverable_abook_xchans($channel_id, $filter = [], $flatten = true) {
+ $filter_sql = '';
+
+ if ($filter) {
+ $filter_sql = " AND abook_xchan IN (" . protect_sprintf(stringify_array($filter, true)) . ") ";
+ }
+
+ $r = q("SELECT abook_xchan, xchan_network FROM abook LEFT JOIN xchan ON abook_xchan = xchan_hash WHERE
+ abook_channel = %d $filter_sql
+ AND abook_self = 0
+ AND abook_pending = 0
+ AND abook_archived = 0
+ AND abook_not_here = 0
+ AND xchan_network NOT IN ('anon', 'token', 'rss')",
+ intval($channel_id)
+ );
+
+ if (!$r) {
+ return [];
+ }
+
+ if ($flatten) {
+ return ids_to_array($r, 'abook_xchan');
+ }
+
+ return $r;
+}
+
+
function abook_connections($channel_id, $sql_conditions = '') {
$r = q("select * from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d
and abook_self = 0 $sql_conditions",
diff --git a/include/items.php b/include/items.php
index c6aeaa0ed..c832a3075 100644
--- a/include/items.php
+++ b/include/items.php
@@ -53,35 +53,28 @@ function collect_recipients($item, &$private_envelope,$include_groups = true) {
$allow_groups = [];
}
- $recipients = array_unique(array_merge($allow_people,$allow_groups));
+ $raw_recipients = array_unique(array_merge($allow_people, $allow_groups));
+ $recipients = deliverable_abook_xchans($item['uid'], $raw_recipients);
// if you specifically deny somebody but haven't allowed anybody, we'll allow everybody in your
// address book minus the denied connections. The post is still private and can't be seen publicly
// as that would allow the denied person to see the post by logging out.
- if((! $item['allow_cid']) && (! $item['allow_gid'])) {
- $r = q("select * from abook where abook_channel = %d and abook_self = 0 and abook_pending = 0 and abook_archived = 0 ",
- intval($item['uid'])
- );
-
- if($r) {
- foreach($r as $rr) {
- $recipients[] = $rr['abook_xchan'];
- }
- }
+ if(!$item['allow_cid'] && !$item['allow_gid']) {
+ $recipients = deliverable_abook_xchans($item['uid']);
}
$deny_people = expand_acl($item['deny_cid']);
$deny_groups = AccessList::expand(expand_acl($item['deny_gid']));
- $deny = array_unique(array_merge($deny_people,$deny_groups));
+ $deny = array_unique(array_merge($deny_people, $deny_groups));
// Don't deny anybody if nobody was allowed (e.g. they were all filtered out)
// That would lead to array_diff doing the wrong thing.
// This will result in a private post that won't be delivered to anybody.
if($recipients && $deny)
- $recipients = array_diff($recipients,$deny);
+ $recipients = array_diff($recipients, $deny);
$private_envelope = true;
}
@@ -112,9 +105,7 @@ function collect_recipients($item, &$private_envelope,$include_groups = true) {
if ($hookinfo['recipients']) {
$r = $hookinfo['recipients'];
} else {
- $r = q("select abook_xchan, xchan_network from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_self = 0 and abook_pending = 0 and abook_archived = 0 and abook_not_here = 0 and xchan_network not in ('anon', 'token', 'rss')",
- intval($item['uid'])
- );
+ $r = deliverable_abook_xchans($item['uid'], [], false);
}
if($r) {
diff --git a/include/text.php b/include/text.php
index dcf0980c5..c038d3d3d 100644
--- a/include/text.php
+++ b/include/text.php
@@ -2529,26 +2529,26 @@ function check_webbie($arr) {
return '';
}
-function ids_to_array($arr,$idx = 'id') {
- $t = array();
+function ids_to_array($arr, $idx = 'id') {
+ $t = [];
if($arr) {
foreach($arr as $x) {
- if(array_key_exists($idx,$x) && strlen($x[$idx]) && (! in_array($x[$idx],$t))) {
+ if(array_key_exists($idx, $x) && strlen($x[$idx]) && (! in_array($x[$idx], $t))) {
$t[] = $x[$idx];
}
}
}
- return($t);
+ return $t;
}
-function ids_to_querystr($arr,$idx = 'id',$quote = false) {
- $t = array();
+function ids_to_querystr($arr, $idx = 'id', $quote = false) {
+ $t = [];
if($arr) {
foreach($arr as $x) {
- if(! in_array($x[$idx],$t)) {
+ if(!in_array($x[$idx], $t)) {
if($quote)
$t[] = "'" . dbesc($x[$idx]) . "'";
else
@@ -2556,7 +2556,7 @@ function ids_to_querystr($arr,$idx = 'id',$quote = false) {
}
}
}
- return(implode(',', $t));
+ return implode(',', $t);
}
/**
@@ -2700,7 +2700,7 @@ function stringify_array_elms(&$arr, $escape = false) {
function stringify_array($arr, $escape = false) {
if($arr) {
stringify_array_elms($arr, $escape);
- return(implode(',',$arr));
+ return(implode(',', $arr));
}
return EMPTY_STR;
}