more work on channel sync

This commit is contained in:
friendica 2013-06-26 17:31:02 -07:00
parent 156cf592ee
commit b9466941e7
4 changed files with 41 additions and 8 deletions

View file

@ -1,9 +1,17 @@
<?php /** @file */
function build_sync_packet($packet = null) {
/**
* Send a zot packet to all hubs where this channel is duplicated, refreshing
* such things as personal settings, channel permissions, address book updates, etc.
*/
function build_sync_packet($uid = 0, $packet = null) {
$a = get_app();
$uid = local_user();
if(! $uid)
$uid = local_user();
if(! $uid)
return;
@ -27,6 +35,15 @@ function build_sync_packet($packet = null) {
if(! $synchubs)
return;
$r = q("select xchan_guid, xchan_guid_sig from xchan where xchan_hash = '%s' limit 1",
dbesc($channel['channel_hash'])
);
if(! $r)
return;
$env_recips = array();
$env_recips[] = array('guid' => $r[0]['xchan_guid'],'guid_sig' => $r[0]['xchan_guid_sig']);
$info = (($packet) ? $packet : array());
if(array_key_exists($uid,$a->config) && array_key_exists('transient',$a->config[$uid])) {
@ -41,10 +58,14 @@ function build_sync_packet($packet = null) {
foreach($channel as $k => $v) {
if(strpos('channel_',$k) !== 0)
continue;
if($k === 'channel_id')
continue;
if($k === 'channel_account_id')
// don't pass these elements, they should not be synchronised
$disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey');
if(in_array($k,$disallowed))
continue;
$info['channel'][$k] = $v;
}
}
@ -55,7 +76,7 @@ function build_sync_packet($packet = null) {
foreach($synchubs as $hub) {
$hash = random_string();
$n = zot_build_packet($channel,'channel_sync');
$n = zot_build_packet($channel,'channel_sync',$env_recips,$hub['hubloc_sitekey'],null,$hash);
q("insert into outq ( outq_hash, outq_account, outq_channel, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s' )",
dbesc($hash),
intval($channel['channel_account']),

View file

@ -874,8 +874,16 @@ function zot_import($arr) {
$result = process_profile_delivery($i['notify']['sender'],$arr,$deliveries);
}
elseif($i['message']['type'] === 'channel_sync') {
// $arr = get_channelsync_elements($i['message']);
$arr = $i['message'];
logger('Channel sync received: ' . print_r($arr,true), LOGGER_DATA);
logger('Channel sync recipients: ' . print_r($deliveries,true), LOGGER_DATA);
// $result = process_channelsync_delivery($i['notify']['sender'],$arr,$deliveries);
}
}
if($result)
$return = array_merge($return,$result);

View file

@ -145,7 +145,7 @@ function connections_clone(&$a) {
unset($clone['abook_account']);
unset($clone['abook_channel']);
require_once('include/settings.php');
build_sync_packet(array('abook' => array($clone)));
build_sync_packet(0 /* use the current local_user */, array('abook' => array($clone)));
}

View file

@ -177,6 +177,7 @@ function settings_post(&$a) {
check_form_security_token_redirectOnErr('/settings/featured', 'settings_featured');
call_hooks('feature_settings_post', $_POST);
build_sync_packet();
return;
}
@ -189,6 +190,7 @@ function settings_post(&$a) {
set_pconfig(local_user(),'feature',substr($k,8),((intval($v)) ? 1 : 0));
}
}
build_sync_packet();
return;
}
@ -232,6 +234,7 @@ function settings_post(&$a) {
);
call_hooks('display_settings_post', $_POST);
build_sync_packet();
goaway($a->get_baseurl(true) . '/settings/display' );
return; // NOTREACHED
}
@ -545,11 +548,12 @@ function settings_post(&$a) {
dbesc($username),
intval($channel['channel_id'])
);
// we really need to send out notifications to all our friends
}
proc_run('php','include/directory.php',local_user());
build_sync_packet();
//$_SESSION['theme'] = $theme;
if($email_changed && $a->config['system']['register_policy'] == REGISTER_VERIFY) {