aboutsummaryrefslogtreecommitdiffstats
path: root/include/zot.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2014-07-16 21:18:28 -0700
committerfriendica <info@friendica.com>2014-07-16 21:18:28 -0700
commitfeb23fc9bcf2b942d03931cc18728427cb43f4a3 (patch)
tree0a35847313e674d3644452064bdda54e0035689c /include/zot.php
parentb0a4a48ceb4db6c49724515eac0fbdef48691a2b (diff)
downloadvolse-hubzilla-feb23fc9bcf2b942d03931cc18728427cb43f4a3.tar.gz
volse-hubzilla-feb23fc9bcf2b942d03931cc18728427cb43f4a3.tar.bz2
volse-hubzilla-feb23fc9bcf2b942d03931cc18728427cb43f4a3.zip
collection sync
Diffstat (limited to 'include/zot.php')
-rw-r--r--include/zot.php114
1 files changed, 114 insertions, 0 deletions
diff --git a/include/zot.php b/include/zot.php
index e4fb5bc56..e00f54a17 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -2226,6 +2226,7 @@ function process_channel_sync_delivery($sender,$arr,$deliveries) {
}
+
if(array_key_exists('abook',$arr) && is_array($arr['abook']) && count($arr['abook'])) {
$disallowed = array('abook_id','abook_account','abook_channel');
@@ -2292,6 +2293,119 @@ function process_channel_sync_delivery($sender,$arr,$deliveries) {
}
}
+ // sync collections (privacy groups) oh joy...
+
+ if(array_key_exists('collections',$arr) && is_array($arr['collections']) && count($arr['collections'])) {
+ $x = q("select * from groups where uid = %d",
+ intval($channel['channel_id'])
+ );
+ foreach($arr['collections'] as $cl) {
+ $found = false;
+ if($x) {
+ foreach($x as $y) {
+ if($cl['collection'] == $y['hash']) {
+ $found = true;
+ break;
+ }
+ }
+ if($found) {
+ if(($y['name'] != $cl['name'])
+ || ($y['visible'] != $cl['visible'])
+ || ($y['deleted'] != $cl['deleted'])) {
+ q("update groups set name = '%s', visible = %d, deleted = %d where hash = '%s' and uid = %d limit 1",
+ dbesc($cl['name']),
+ intval($cl['visible']),
+ intval($cl['deleted']),
+ dbesc($cl['hash']),
+ intval($channel['channel_id'])
+ );
+ }
+ if(intval($cl['deleted']) && (! intval($y['deleted']))) {
+ q("delete from group_member where gid = %d",
+ intval($y['id'])
+ );
+ }
+ }
+ }
+ if(! $found) {
+ $r = q("INSERT INTO `groups` ( hash, uid, visible, deleted, name )
+ VALUES( '%s', %d, %d, %d, '%s' ) ",
+ dbesc($cl['collection']),
+ intval($channel['channel_id']),
+ intval($cl['visible']),
+ intval($cl['deleted']),
+ dbesc($cl['name'])
+ );
+ }
+ }
+
+ // reload the group list with any updates
+ $x = q("select * from groups where uid = %d",
+ intval($channel['channel_id'])
+ );
+
+ // now sync the members
+
+ if(array_key_exists('collection_members',$arr) &&
+ is_array($arr['collection_members']) && count($arr['collection_members'])) {
+
+ // first sort into groups keyed by the group hash
+ $members = array();
+ foreach($arr['collection_members'] as $cm) {
+ if(! array_key_exists($cm['collection'],$members))
+ $members[$cm['collection']] = array();
+ $members[$cm['collection']][] = $cm['member'];
+ }
+
+ // our group list is already synchronised
+ if($x) {
+ foreach($x as $y) {
+
+ // for each group, loop on members list we just received
+ foreach($members[$y['hash']] as $member) {
+ $found = false;
+ $z = q("select xchan from group_member where gid = %d and uid = %d and xchan = '%s' limit 1",
+ intval($y['id']),
+ intval($channel['channel_id']),
+ dbesc($member)
+ );
+ if($z)
+ $found = true;
+
+ // if somebody is in the group that wasn't before - add them
+
+ if(! $found) {
+ q("INSERT INTO `group_member` (`uid`, `gid`, `xchan`)
+ VALUES( %d, %d, '%s' ) ",
+ intval($channel['channel_id']),
+ intval($y['id']),
+ dbesc($member)
+ );
+ }
+ }
+
+ // now retrieve a list of members we have on this site
+ $m = q("select xchan from group_member where gid = %d and uid = %d",
+ intval($y['id']),
+ intval($channel['channel_id'])
+ );
+ if($m) {
+ foreach($m as $mm) {
+ // if the local existing member isn't in the list we just received - remove them
+ if(! in_array($mm['xchan'],$members[$y['hash']])) {
+ q("delete from group_member where xchan = '%s' and gid = %d and uid = %d limit 1",
+ dbesc($mm['xchan']),
+ intval($y['id']),
+ intval($channel['channel_id'])
+ );
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
if(array_key_exists('profile',$arr) && is_array($arr['profile']) && count($arr['profile'])) {
$disallowed = array('id','aid','uid');