Issue 14231: Automatically add the relay owner as contact person

This commit is contained in:
Michael 2024-06-16 17:04:43 +00:00
parent eb6297c472
commit a27d55f6cf
7 changed files with 341 additions and 271 deletions

View file

@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 2024.06-rc (Yellow Archangel)
-- DB_UPDATE_VERSION 1565
-- DB_UPDATE_VERSION 1566
-- ------------------------------------------

View file

@ -622,8 +622,10 @@ class Profile
$bd_format = DI::l10n()->t('g A l F d'); // 8 AM Friday January 18
$classtoday = '';
$condition = ["`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ?",
$uid, DateTimeFormat::utc('now + 7 days'), DateTimeFormat::utc('now - 1 days')];
$condition = [
"`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ?",
$uid, DateTimeFormat::utc('now + 7 days'), DateTimeFormat::utc('now - 1 days')
];
$s = DBA::select('event', [], $condition, ['order' => ['start']]);
$r = [];
@ -633,9 +635,11 @@ class Profile
$total = 0;
while ($rr = DBA::fetch($s)) {
$condition = ['parent-uri' => $rr['uri'], 'uid' => $rr['uid'], 'author-id' => $pcid,
$condition = [
'parent-uri' => $rr['uri'], 'uid' => $rr['uid'], 'author-id' => $pcid,
'vid' => [Verb::getID(Activity::ATTEND), Verb::getID(Activity::ATTENDMAYBE)],
'visible' => true, 'deleted' => false];
'visible' => true, 'deleted' => false
];
if (!Post::exists($condition)) {
continue;
}
@ -724,7 +728,8 @@ class Profile
if (!empty($search)) {
$publish = (DI::config()->get('system', 'publish_all') ? '' : "AND `publish` ");
$searchTerm = '%' . $search . '%';
$condition = ["`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`
$condition = [
"`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`
$publish
AND ((`name` LIKE ?) OR
(`nickname` LIKE ?) OR
@ -735,7 +740,8 @@ class Profile
(`pub_keywords` LIKE ?) OR
(`prv_keywords` LIKE ?))",
$searchTerm, $searchTerm, $searchTerm, $searchTerm,
$searchTerm, $searchTerm, $searchTerm, $searchTerm];
$searchTerm, $searchTerm, $searchTerm, $searchTerm
];
} else {
$condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
if (!DI::config()->get('system', 'publish_all')) {
@ -838,4 +844,44 @@ class Profile
DBA::delete('profile', ['id' => $profile['id']]);
}
}
/**
* Get "about" field with the added responsible relay contact if appropriate.
*
* @param string $about
* @param integer|null $parent_uid
* @param integer $account_type
* @param string $language
* @return string
*/
public static function addResponsibleRelayContact(string $about, int $parent_uid = null, int $account_type, string $language): string
{
if (($account_type != User::ACCOUNT_TYPE_RELAY) || empty($parent_uid)) {
return $about;
}
$parent = User::getOwnerDataById($parent_uid);
if (strpos($about, $parent['addr']) || strpos($about, $parent['url'])) {
return $about;
}
$l10n = DI::l10n()->withLang($language);
return $about .= "\n" . $l10n->t('Responsible account: %s', $parent['addr']);
}
/**
* Set "about" field with the added responsible relay contact if appropriate.
*
* @param integer $uid
* @return void
*/
public static function setResponsibleRelayContact(int $uid)
{
$owner = User::getOwnerDataById($uid);
$about = self::addResponsibleRelayContact($owner['about'], $owner['parent-uid'], $owner['account-type'], $owner['language']);
if ($about != $owner['about']) {
self::update(['about' => $about], $uid);
}
}
}

View file

@ -330,6 +330,11 @@ class Account extends BaseSettings
}
User::setCommunityUserSettings(DI::userSession()->getLocalUserId());
if ($account_type == User::ACCOUNT_TYPE_RELAY) {
Profile::setResponsibleRelayContact(DI::userSession()->getLocalUserId());
}
DI::baseUrl()->redirect($redirectUrl);
}
@ -425,7 +430,7 @@ class Account extends BaseSettings
$user['account-type'] = User::ACCOUNT_TYPE_COMMUNITY;
}
if (DI::config()->get('system', 'allow_relay_channels')) {
if (!empty($user['parent-uid']) && DI::config()->get('system', 'allow_relay_channels')) {
$account_relay = [
'account-type',
DI::l10n()->t('Channel Relay'),

View file

@ -133,10 +133,13 @@ class Index extends BaseSettings
$homepage = 'http://' . $homepage;
}
$user = User::getById($this->session->getLocalUserId());
$about = Profile::addResponsibleRelayContact($about, $user['parent-uid'], $user['account-type'], $user['language']);
$profileFieldsNew = $this->getProfileFieldsFromInput(
$this->session->getLocalUserId(),
$request['profile_field'],
$request['profile_field_order']
(array)$request['profile_field'],
(array)$request['profile_field_order']
);
$this->profileFieldRepo->saveCollectionForUser($this->session->getLocalUserId(), $profileFieldsNew);
@ -187,6 +190,8 @@ class Index extends BaseSettings
throw new HTTPException\NotFoundException();
}
$owner['about'] = Profile::addResponsibleRelayContact($owner['about'], $owner['parent-uid'], $owner['account-type'], $owner['language']);
$this->page->registerFooterScript('view/asset/es-jquery-sortable/source/js/jquery-sortable-min.js');
$this->page->registerFooterScript(Theme::getPathForFile('js/module/settings/profile/index.js'));

View file

@ -56,7 +56,7 @@ use Friendica\Database\DBA;
// This file is required several times during the test in DbaDefinition which justifies this condition
if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1565);
define('DB_UPDATE_VERSION', 1566);
}
return [

View file

@ -1477,4 +1477,13 @@ function update_1564()
DBA::close($users);
return Update::SUCCESS;
}
function update_1566()
{
$users = DBA::select('user', ['uid'], ["`account-type` = ? AND `verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired` AND `uid` > ?", User::ACCOUNT_TYPE_RELAY, 0]);
while ($user = DBA::fetch($users)) {
Profile::setResponsibleRelayContact($user['uid']);
}
DBA::close($users);
}

File diff suppressed because it is too large Load diff