Merge pull request #4788 from annando/more-relay
Relay: Avoid empty tags / Always use the "relay account"
This commit is contained in:
commit
66bcbe210a
2 changed files with 19 additions and 15 deletions
|
@ -46,8 +46,10 @@ function wk_social_relay()
|
||||||
$server_tags = Config::get('system', 'relay_server_tags');
|
$server_tags = Config::get('system', 'relay_server_tags');
|
||||||
$tagitems = explode(",", $server_tags);
|
$tagitems = explode(",", $server_tags);
|
||||||
|
|
||||||
|
/// @todo Check if it was better to use "strtolower" on the tags
|
||||||
foreach ($tagitems AS $tag) {
|
foreach ($tagitems AS $tag) {
|
||||||
$tags[trim($tag, "# ")] = trim($tag, "# ");
|
$tag = trim($tag, "# ");
|
||||||
|
$tags[$tag] = $tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config::get('system', 'relay_user_tags')) {
|
if (Config::get('system', 'relay_user_tags')) {
|
||||||
|
@ -62,8 +64,10 @@ function wk_social_relay()
|
||||||
|
|
||||||
$taglist = [];
|
$taglist = [];
|
||||||
foreach ($tags AS $tag) {
|
foreach ($tags AS $tag) {
|
||||||
|
if (!empty($tag)) {
|
||||||
$taglist[] = $tag;
|
$taglist[] = $tag;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$relay = [
|
$relay = [
|
||||||
"subscribe" => $subscribe,
|
"subscribe" => $subscribe,
|
||||||
|
|
|
@ -123,30 +123,30 @@ class Diaspora
|
||||||
{
|
{
|
||||||
$batch = $server_url . '/receive/public';
|
$batch = $server_url . '/receive/public';
|
||||||
|
|
||||||
$fields = ['batch', 'id', 'name', 'network', 'nick',
|
$fields = ['batch', 'id', 'name', 'network', 'archive', 'blocked'];
|
||||||
'url', 'archive', 'blocked', 'contact-type'];
|
|
||||||
// Fetch the first unarchived, unblocked account
|
|
||||||
$condition = ['uid' => 0, 'network' => NETWORK_DIASPORA, 'batch' => $batch,
|
|
||||||
'archive' => false, 'blocked' => false];
|
|
||||||
$contact = dba::selectFirst('contact', $fields, $condition);
|
|
||||||
|
|
||||||
// If there is nothing found, we check if there is already a relay account
|
// Fetch the relay contact
|
||||||
if (!DBM::is_result($contact)) {
|
|
||||||
$condition = ['uid' => 0, 'network' => NETWORK_DIASPORA, 'batch' => $batch,
|
$condition = ['uid' => 0, 'network' => NETWORK_DIASPORA, 'batch' => $batch,
|
||||||
'contact-type' => ACCOUNT_TYPE_RELAY];
|
'contact-type' => ACCOUNT_TYPE_RELAY];
|
||||||
$contact = dba::selectFirst('contact', $fields, $condition);
|
$contact = dba::selectFirst('contact', $fields, $condition);
|
||||||
|
|
||||||
|
// If there is nothing found, we check if there is some unmarked relay
|
||||||
|
// This code segment can be removed before the release 2018-05
|
||||||
|
if (!DBM::is_result($contact)) {
|
||||||
|
$condition = ['uid' => 0, 'network' => NETWORK_DIASPORA, 'batch' => $batch,
|
||||||
|
'name' => 'relay', 'nick' => 'relay', 'url' => $server_url];
|
||||||
|
$contact = dba::selectFirst('contact', $fields, $condition);
|
||||||
|
|
||||||
|
if (DBM::is_result($contact)) {
|
||||||
|
// Mark the relay account as a relay account
|
||||||
|
$fields = ['contact-type' => ACCOUNT_TYPE_RELAY];
|
||||||
|
dba::update('contact', $fields, ['id' => $contact['id']]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (DBM::is_result($contact)) {
|
if (DBM::is_result($contact)) {
|
||||||
if ($contact['archive'] || $contact['blocked']) {
|
if ($contact['archive'] || $contact['blocked']) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark relay accounts as a relay, if this hadn't been the case before
|
|
||||||
if (($contact['url'] == $server_url) && ($contact['nick'] == 'relay') &&
|
|
||||||
($contact['name'] == 'relay') && ($contact['contact-type'] != ACCOUNT_TYPE_RELAY)) {
|
|
||||||
$fields = ['contact-type' => ACCOUNT_TYPE_RELAY];
|
|
||||||
dba::update('contact', $fields, ['id' => $contact['id']]);
|
|
||||||
}
|
|
||||||
return $contact;
|
return $contact;
|
||||||
} else {
|
} else {
|
||||||
$fields = ['uid' => 0, 'created' => DateTimeFormat::utcNow(),
|
$fields = ['uid' => 0, 'created' => DateTimeFormat::utcNow(),
|
||||||
|
|
Loading…
Reference in a new issue