From 4f03272a5f4c33f6c893b6f56f43fe5e839173b3 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 1 Jul 2023 11:03:26 +0000 Subject: unify code for selecting deliverable abook xchans --- include/connections.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'include/connections.php') 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", -- cgit v1.2.3