add new connections to default group (if any)

This commit is contained in:
friendica 2013-03-27 19:35:34 -07:00
parent 8148b7c32f
commit 810a60b912
5 changed files with 47 additions and 62 deletions

View File

@ -41,7 +41,7 @@ require_once('include/features.php');
define ( 'FRIENDICA_PLATFORM', 'Friendica Red'); define ( 'FRIENDICA_PLATFORM', 'Friendica Red');
define ( 'FRIENDICA_VERSION', trim(file_get_contents('version.inc')) . 'R'); define ( 'FRIENDICA_VERSION', trim(file_get_contents('version.inc')) . 'R');
define ( 'ZOT_REVISION', 1 ); define ( 'ZOT_REVISION', 1 );
define ( 'DB_UPDATE_VERSION', 1039 ); define ( 'DB_UPDATE_VERSION', 1040 );
define ( 'EOL', '<br />' . "\r\n" ); define ( 'EOL', '<br />' . "\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );

View File

@ -111,7 +111,10 @@ function new_contact($uid,$url,$channel,$interactive = false) {
if((local_user()) && $uid == local_user()) { if((local_user()) && $uid == local_user()) {
$aid = get_account_id(); $aid = get_account_id();
$hash = $a->observer['xchan_hash']; $hash = get_observer_hash();
$ch = $a->get_channel();
$default_group = $ch['channel_default_group'];
} }
else { else {
$r = q("select * from channel where channel_id = %d limit 1", $r = q("select * from channel where channel_id = %d limit 1",
@ -123,6 +126,7 @@ function new_contact($uid,$url,$channel,$interactive = false) {
} }
$aid = $r[0]['channel_account_id']; $aid = $r[0]['channel_account_id'];
$hash = $r[0]['channel_hash']; $hash = $r[0]['channel_hash'];
$default_group = $r[0]['channel_default_group'];
} }
if($hash == $xchan_hash) { if($hash == $xchan_hash) {
@ -163,59 +167,16 @@ function new_contact($uid,$url,$channel,$interactive = false) {
if($r) if($r)
$result['abook'] = $r[0]; $result['abook'] = $r[0];
// Then send a ping/message to the other side /** If there is a default group for this channel, add this member to it */
if($default_group) {
/*
$r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `batch`, `notify`, `poll`, `poco`, `name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`,
`writable`, `hidden`, `blocked`, `readonly`, `pending` )
VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, 0, 0, 0) ",
intval($uid),
dbesc(datetime_convert()),
dbesc($ret['url']),
dbesc(normalise_link($ret['url'])),
dbesc($ret['addr']),
dbesc($ret['alias']),
dbesc($ret['batch']),
dbesc($ret['notify']),
dbesc($ret['poll']),
dbesc($ret['poco']),
dbesc($ret['name']),
dbesc($ret['nick']),
dbesc($ret['photo']),
dbesc($ret['network']),
dbesc($ret['pubkey']),
intval($new_relation),
intval($ret['priority']),
intval($writeable),
intval($hidden)
);
}
$r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
dbesc($ret['url']),
intval($uid)
);
if(! count($r)) {
$result['message'] .= t('Unable to retrieve contact information.') . EOL;
return $result;
}
$contact = $r[0];
$contact_id = $r[0]['id'];
$g = q("select def_gid from user where uid = %d limit 1",
intval($uid)
);
if($g && intval($g[0]['def_gid'])) {
require_once('include/group.php'); require_once('include/group.php');
group_add_member($uid,'',$contact_id,$g[0]['def_gid']); $g = group_rec_byhash($uid,$default_group);
if($g)
group_add_member($uid,'',$xchan_hash,$g['id']);
} }
*/ // Then send a ping/message to the other side
$result['success'] = true; $result['success'] = true;

View File

@ -52,40 +52,43 @@ function group_add($uid,$name) {
function group_rmv($uid,$name) { function group_rmv($uid,$name) {
$ret = false; $ret = false;
if(x($uid) && x($name)) { if(x($uid) && x($name)) {
$r = q("SELECT id FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1", $r = q("SELECT id, hash FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
intval($uid), intval($uid),
dbesc($name) dbesc($name)
); );
if(count($r)) if($r) {
$group_id = $r[0]['id']; $group_id = $r[0]['id'];
$group_hash = $r[0]['hash'];
}
if(! $group_id) if(! $group_id)
return false; return false;
// remove group from default posting lists // remove group from default posting lists
$r = q("SELECT channel_default_gid, channel_allow_gid, channel_deny_gid FROM channel WHERE channel_id = %d LIMIT 1", $r = q("SELECT channel_default_group, channel_allow_gid, channel_deny_gid FROM channel WHERE channel_id = %d LIMIT 1",
intval($uid) intval($uid)
); );
if($r) { if($r) {
$user_info = $r[0]; $user_info = $r[0];
$change = false; $change = false;
if($user_info['channel_default_gid'] == $group_id) { if($user_info['channel_default_group'] == $group_hash) {
$user_info['channel_default_gid'] = 0; $user_info['channel_default_group'] = '';
$change = true; $change = true;
} }
if(strpos($user_info['channel_allow_gid'], '<' . $group_id . '>') !== false) { if(strpos($user_info['channel_allow_gid'], '<' . $group_id . '>') !== false) {
$user_info['channel_allow_gid'] = str_replace('<' . $group_id . '>', '', $user_info['channel_allow_gid']); $user_info['channel_allow_gid'] = str_replace('<' . $group_hash . '>', '', $user_info['channel_allow_gid']);
$change = true; $change = true;
} }
if(strpos($user_info['channel_deny_gid'], '<' . $group_id . '>') !== false) { if(strpos($user_info['channel_deny_gid'], '<' . $group_id . '>') !== false) {
$user_info['channel_deny_gid'] = str_replace('<' . $group_id . '>', '', $user_info['channel_deny_gid']); $user_info['channel_deny_gid'] = str_replace('<' . $group_hash . '>', '', $user_info['channel_deny_gid']);
$change = true; $change = true;
} }
if($change) { if($change) {
q("UPDATE channel SET channel_default_gid = %d, channel_allow_gid = '%s', channel_deny_gid = '%s' q("UPDATE channel SET channel_default_group = '%s', channel_allow_gid = '%s', channel_deny_gid = '%s'
WHERE channel_id = %d", WHERE channel_id = %d",
intval($user_info['channel_default_gid']), intval($user_info['channel_default_group']),
dbesc($user_info['channel_allow_gid']), dbesc($user_info['channel_allow_gid']),
dbesc($user_info['channel_deny_gid']), dbesc($user_info['channel_deny_gid']),
intval($uid) intval($uid)
@ -124,6 +127,19 @@ function group_byname($uid,$name) {
return false; return false;
} }
function group_rec_byhash($uid,$hash) {
if((! $uid) || (! strlen($hash)))
return false;
$r = q("SELECT * FROM `group` WHERE `uid` = %d AND `hash` = '%s' LIMIT 1",
intval($uid),
dbesc($hash)
);
if($r)
return $r[0];
return false;
}
function group_rmv_member($uid,$name,$member) { function group_rmv_member($uid,$name,$member) {
$gid = group_byname($uid,$name); $gid = group_byname($uid,$name);
if(! $gid) if(! $gid)

View File

@ -160,7 +160,7 @@ CREATE TABLE IF NOT EXISTS `channel` (
`channel_max_friend_req` int(10) unsigned NOT NULL DEFAULT '10', `channel_max_friend_req` int(10) unsigned NOT NULL DEFAULT '10',
`channel_expire_days` int(11) NOT NULL DEFAULT '0', `channel_expire_days` int(11) NOT NULL DEFAULT '0',
`channel_passwd_reset` char(255) NOT NULL DEFAULT '', `channel_passwd_reset` char(255) NOT NULL DEFAULT '',
`channel_default_gid` int(10) unsigned NOT NULL DEFAULT '0', `channel_default_group` char(255) NOT NULL DEFAULT '',
`channel_allow_cid` mediumtext NOT NULL, `channel_allow_cid` mediumtext NOT NULL,
`channel_allow_gid` mediumtext NOT NULL, `channel_allow_gid` mediumtext NOT NULL,
`channel_deny_cid` mediumtext NOT NULL, `channel_deny_cid` mediumtext NOT NULL,

View File

@ -1,6 +1,6 @@
<?php <?php
define( 'UPDATE_VERSION' , 1039 ); define( 'UPDATE_VERSION' , 1040 );
/** /**
* *
@ -505,3 +505,11 @@ function update_r1038() {
} }
function update_r1039() {
$r = q("ALTER TABLE `channel` CHANGE `channel_default_gid` `channel_default_group` CHAR( 255 ) NOT NULL DEFAULT ''");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}