mirror of
https://github.com/friendica/friendica
synced 2024-12-22 18:00:16 +00:00
Issue 14231: Automatically add the relay owner as contact person
This commit is contained in:
parent
eb6297c472
commit
a27d55f6cf
7 changed files with 341 additions and 271 deletions
|
@ -1,6 +1,6 @@
|
||||||
-- ------------------------------------------
|
-- ------------------------------------------
|
||||||
-- Friendica 2024.06-rc (Yellow Archangel)
|
-- Friendica 2024.06-rc (Yellow Archangel)
|
||||||
-- DB_UPDATE_VERSION 1565
|
-- DB_UPDATE_VERSION 1566
|
||||||
-- ------------------------------------------
|
-- ------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -622,8 +622,10 @@ class Profile
|
||||||
$bd_format = DI::l10n()->t('g A l F d'); // 8 AM Friday January 18
|
$bd_format = DI::l10n()->t('g A l F d'); // 8 AM Friday January 18
|
||||||
$classtoday = '';
|
$classtoday = '';
|
||||||
|
|
||||||
$condition = ["`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ?",
|
$condition = [
|
||||||
$uid, DateTimeFormat::utc('now + 7 days'), DateTimeFormat::utc('now - 1 days')];
|
"`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']]);
|
$s = DBA::select('event', [], $condition, ['order' => ['start']]);
|
||||||
|
|
||||||
$r = [];
|
$r = [];
|
||||||
|
@ -633,9 +635,11 @@ class Profile
|
||||||
$total = 0;
|
$total = 0;
|
||||||
|
|
||||||
while ($rr = DBA::fetch($s)) {
|
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)],
|
'vid' => [Verb::getID(Activity::ATTEND), Verb::getID(Activity::ATTENDMAYBE)],
|
||||||
'visible' => true, 'deleted' => false];
|
'visible' => true, 'deleted' => false
|
||||||
|
];
|
||||||
if (!Post::exists($condition)) {
|
if (!Post::exists($condition)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -724,7 +728,8 @@ class Profile
|
||||||
if (!empty($search)) {
|
if (!empty($search)) {
|
||||||
$publish = (DI::config()->get('system', 'publish_all') ? '' : "AND `publish` ");
|
$publish = (DI::config()->get('system', 'publish_all') ? '' : "AND `publish` ");
|
||||||
$searchTerm = '%' . $search . '%';
|
$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
|
$publish
|
||||||
AND ((`name` LIKE ?) OR
|
AND ((`name` LIKE ?) OR
|
||||||
(`nickname` LIKE ?) OR
|
(`nickname` LIKE ?) OR
|
||||||
|
@ -735,7 +740,8 @@ class Profile
|
||||||
(`pub_keywords` LIKE ?) OR
|
(`pub_keywords` LIKE ?) OR
|
||||||
(`prv_keywords` LIKE ?))",
|
(`prv_keywords` LIKE ?))",
|
||||||
$searchTerm, $searchTerm, $searchTerm, $searchTerm,
|
$searchTerm, $searchTerm, $searchTerm, $searchTerm,
|
||||||
$searchTerm, $searchTerm, $searchTerm, $searchTerm];
|
$searchTerm, $searchTerm, $searchTerm, $searchTerm
|
||||||
|
];
|
||||||
} else {
|
} else {
|
||||||
$condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
|
$condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
|
||||||
if (!DI::config()->get('system', 'publish_all')) {
|
if (!DI::config()->get('system', 'publish_all')) {
|
||||||
|
@ -838,4 +844,44 @@ class Profile
|
||||||
DBA::delete('profile', ['id' => $profile['id']]);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -330,6 +330,11 @@ class Account extends BaseSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
User::setCommunityUserSettings(DI::userSession()->getLocalUserId());
|
User::setCommunityUserSettings(DI::userSession()->getLocalUserId());
|
||||||
|
|
||||||
|
if ($account_type == User::ACCOUNT_TYPE_RELAY) {
|
||||||
|
Profile::setResponsibleRelayContact(DI::userSession()->getLocalUserId());
|
||||||
|
}
|
||||||
|
|
||||||
DI::baseUrl()->redirect($redirectUrl);
|
DI::baseUrl()->redirect($redirectUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,7 +430,7 @@ class Account extends BaseSettings
|
||||||
$user['account-type'] = User::ACCOUNT_TYPE_COMMUNITY;
|
$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_relay = [
|
||||||
'account-type',
|
'account-type',
|
||||||
DI::l10n()->t('Channel Relay'),
|
DI::l10n()->t('Channel Relay'),
|
||||||
|
|
|
@ -133,10 +133,13 @@ class Index extends BaseSettings
|
||||||
$homepage = 'http://' . $homepage;
|
$homepage = 'http://' . $homepage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$user = User::getById($this->session->getLocalUserId());
|
||||||
|
$about = Profile::addResponsibleRelayContact($about, $user['parent-uid'], $user['account-type'], $user['language']);
|
||||||
|
|
||||||
$profileFieldsNew = $this->getProfileFieldsFromInput(
|
$profileFieldsNew = $this->getProfileFieldsFromInput(
|
||||||
$this->session->getLocalUserId(),
|
$this->session->getLocalUserId(),
|
||||||
$request['profile_field'],
|
(array)$request['profile_field'],
|
||||||
$request['profile_field_order']
|
(array)$request['profile_field_order']
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->profileFieldRepo->saveCollectionForUser($this->session->getLocalUserId(), $profileFieldsNew);
|
$this->profileFieldRepo->saveCollectionForUser($this->session->getLocalUserId(), $profileFieldsNew);
|
||||||
|
@ -187,6 +190,8 @@ class Index extends BaseSettings
|
||||||
throw new HTTPException\NotFoundException();
|
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('view/asset/es-jquery-sortable/source/js/jquery-sortable-min.js');
|
||||||
$this->page->registerFooterScript(Theme::getPathForFile('js/module/settings/profile/index.js'));
|
$this->page->registerFooterScript(Theme::getPathForFile('js/module/settings/profile/index.js'));
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ use Friendica\Database\DBA;
|
||||||
|
|
||||||
// This file is required several times during the test in DbaDefinition which justifies this condition
|
// This file is required several times during the test in DbaDefinition which justifies this condition
|
||||||
if (!defined('DB_UPDATE_VERSION')) {
|
if (!defined('DB_UPDATE_VERSION')) {
|
||||||
define('DB_UPDATE_VERSION', 1565);
|
define('DB_UPDATE_VERSION', 1566);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -1477,4 +1477,13 @@ function update_1564()
|
||||||
DBA::close($users);
|
DBA::close($users);
|
||||||
|
|
||||||
return Update::SUCCESS;
|
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
Loading…
Reference in a new issue