streams/Zotlabs/Module/Contactgroup.php

57 lines
1.1 KiB
PHP
Raw Normal View History

2016-04-19 03:38:38 +00:00
<?php
namespace Zotlabs\Module;
2019-04-17 06:31:36 +00:00
use Zotlabs\Web\Controller;
use Zotlabs\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
class Contactgroup extends Controller {
2016-04-19 03:38:38 +00:00
function get() {
2019-04-17 06:31:36 +00:00
if (! local_channel()) {
2016-04-19 03:38:38 +00:00
killme();
}
2019-04-17 06:31:36 +00:00
if ((argc() > 2) && (intval(argv(1))) && (argv(2))) {
$r = abook_by_hash(local_channel(), base64url_decode(argv(2)));
if ($r) {
$change = $r['abook_xchan'];
}
2016-04-19 03:38:38 +00:00
}
2019-04-17 06:31:36 +00:00
if ((argc() > 1) && (intval(argv(1)))) {
2016-04-19 03:38:38 +00:00
2019-04-17 06:31:36 +00:00
$group = AccessList::by_id(local_channel(),argv(1));
if (! $group) {
2016-04-19 03:38:38 +00:00
killme();
}
2019-10-02 01:29:39 +00:00
$members = AccessList::members(local_channel(),$group['id']);
2019-04-17 06:31:36 +00:00
$preselected = ids_to_array($members,'xchan_hash');
2016-04-19 03:38:38 +00:00
2019-04-17 06:31:36 +00:00
if ($change) {
if (in_array($change,$preselected)) {
AccessList::member_remove(local_channel(),$group['gname'],$change);
2016-04-19 03:38:38 +00:00
}
else {
AccessList::member_add(local_channel(),$group['gname'],$change);
2016-04-19 03:38:38 +00:00
}
}
}
killme();
}
}