streams/Code/Module/Contactgroup.php

58 lines
1.4 KiB
PHP
Raw Normal View History

2016-04-19 03:38:38 +00:00
<?php
2021-12-03 03:01:39 +00:00
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2016-04-19 03:38:38 +00:00
2022-02-16 04:08:28 +00:00
use Code\Web\Controller;
use Code\Lib\AccessList;
2016-04-19 03:38:38 +00:00
2019-04-17 06:31:36 +00:00
/*
* Adds or removes a connection from an AccessList
* If the connection is already a member, they are removed.
* If they are not a member, they are added.
*
* argv[1] => AccessList['id']
* argv[2] => connection portable_id (base64url_encoded for transport)
*
*/
2016-04-19 03:38:38 +00:00
2019-04-17 06:31:36 +00:00
2021-12-02 23:02:31 +00:00
class Contactgroup extends Controller
{
public function get()
{
if (!local_channel()) {
killme();
}
if ((argc() > 2) && (intval(argv(1))) && (argv(2))) {
$r = abook_by_hash(local_channel(), base64url_decode(argv(2)));
if ($r) {
$change = $r['abook_xchan'];
}
}
if ((argc() > 1) && (intval(argv(1)))) {
$group = AccessList::by_id(local_channel(), argv(1));
if (!$group) {
killme();
}
$members = AccessList::members(local_channel(), $group['id']);
$preselected = ids_to_array($members, 'xchan_hash');
if ($change) {
if (in_array($change, $preselected)) {
AccessList::member_remove(local_channel(), $group['gname'], $change);
} else {
AccessList::member_add(local_channel(), $group['gname'], $change);
}
}
}
killme();
}
2016-04-19 03:38:38 +00:00
}