Dedicated circle name for groups

pull/13235/head
Michael 2023-06-25 20:37:11 +00:00
parent 9f9898d47a
commit e562dbd59c
9 changed files with 274 additions and 234 deletions

View File

@ -177,7 +177,7 @@ class Circle
public static function countUnseen()
{
$stmt = DBA::p("SELECT `circle`.`id`, `circle`.`name`,
(SELECT COUNT(*) FROM `post-user`
(SELECT COUNT(*) FROM `post-user-view`
WHERE `uid` = ?
AND `unseen`
AND `contact-id` IN
@ -481,12 +481,13 @@ class Circle
* Returns a templated circle selection list
*
* @param int $uid User id
* @param int $gid An optional pre-selected circle
* @param string $label An optional label of the list
* @param int $gid A pre-selected circle
* @param string $id The id of the option group
* @param string $label The label of the option group
* @return string
* @throws \Exception
*/
public static function getSelectorHTML(int $uid, int $gid = 0, string $label = ''): string
public static function getSelectorHTML(int $uid, int $gid, string $id, string $label): string
{
$display_circles = [
[
@ -508,11 +509,8 @@ class Circle
Logger::info('Got circles', $display_circles);
if ($label == '') {
$label = DI::l10n()->t('Default privacy circle for new contacts');
}
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('circle_selection.tpl'), [
'$id' => $id,
'$label' => $label,
'$circles' => $display_circles
]);

View File

@ -3100,29 +3100,30 @@ class Contact
self::insert([
'uid' => $uid,
'created' => DateTimeFormat::utcNow(),
'url' => $ret['url'],
'nurl' => Strings::normaliseLink($ret['url']),
'addr' => $ret['addr'],
'alias' => $ret['alias'],
'batch' => $ret['batch'],
'notify' => $ret['notify'],
'poll' => $ret['poll'],
'poco' => $ret['poco'],
'name' => $ret['name'],
'nick' => $ret['nick'],
'network' => $ret['network'],
'baseurl' => $ret['baseurl'],
'gsid' => $ret['gsid'] ?? null,
'protocol' => $protocol,
'pubkey' => $ret['pubkey'],
'rel' => $new_relation,
'priority' => $ret['priority'],
'writable' => $writeable,
'hidden' => $hidden,
'blocked' => 0,
'readonly' => 0,
'pending' => $pending,
'subhub' => $subhub
'url' => $ret['url'],
'nurl' => Strings::normaliseLink($ret['url']),
'addr' => $ret['addr'],
'alias' => $ret['alias'],
'batch' => $ret['batch'],
'notify' => $ret['notify'],
'poll' => $ret['poll'],
'poco' => $ret['poco'],
'name' => $ret['name'],
'nick' => $ret['nick'],
'network' => $ret['network'],
'baseurl' => $ret['baseurl'],
'gsid' => $ret['gsid'] ?? null,
'contact-type' => $ret['account-type'] ?? self::TYPE_PERSON,
'protocol' => $protocol,
'pubkey' => $ret['pubkey'],
'rel' => $new_relation,
'priority' => $ret['priority'],
'writable' => $writeable,
'hidden' => $hidden,
'blocked' => 0,
'readonly' => 0,
'pending' => $pending,
'subhub' => $subhub
]);
}
@ -3135,7 +3136,11 @@ class Contact
$contact_id = $contact['id'];
$result['cid'] = $contact_id;
Circle::addMember(User::getDefaultCircle($uid), $contact_id);
if ($contact['contact-type'] == self::TYPE_COMMUNITY) {
Circle::addMember(User::getDefaultGroupCircle($uid), $contact_id);
} else {
Circle::addMember(User::getDefaultCircle($uid), $contact_id);
}
// Update the avatar
self::updateAvatar($contact_id, $ret['photo']);
@ -3265,7 +3270,7 @@ class Contact
Post\UserNotification::insertNotification($pub_contact['id'], Activity::FOLLOW, $importer['uid']);
$contact_record = DBA::selectFirst('contact', ['id', 'network', 'name', 'url', 'photo'], ['id' => $contact_id]);
$contact_record = DBA::selectFirst('contact', ['id', 'network', 'name', 'url', 'photo', 'contact-type'], ['id' => $contact_id]);
/// @TODO Encapsulate this into a function/method
$fields = ['uid', 'username', 'email', 'page-flags', 'notify-flags', 'language'];
@ -3281,7 +3286,11 @@ class Contact
DI::intro()->save($intro);
}
Circle::addMember(User::getDefaultCircle($importer['uid']), $contact_record['id']);
if ($contact_record['contact-type'] == self::TYPE_COMMUNITY) {
Circle::addMember(User::getDefaultGroupCircle($importer['uid']), $contact_record['id']);
} else {
Circle::addMember(User::getDefaultCircle($importer['uid']), $contact_record['id']);
}
if (($user['notify-flags'] & Notification\Type::INTRO) && $user['page-flags'] == User::PAGE_FLAGS_NORMAL) {
DI::notify()->createFromArray([

View File

@ -483,7 +483,7 @@ class User
}
/**
* Returns the default circle for a given user and network
* Returns the default circle for a given user
*
* @param int $uid User id
*
@ -502,6 +502,24 @@ class User
return $default_circle;
}
/**
* Returns the default circle for groups for a given user
*
* @param int $uid User id
*
* @return int circle id
* @throws Exception
*/
public static function getDefaultGroupCircle(int $uid): int
{
$default_circle = DI::pConfig()->get($uid, 'system', 'default-group-gid');
if (empty($default_circle)) {
$default_circle = self::getDefaultCircle($uid);
}
return $default_circle;
}
/**
* Authenticate a user with a clear text password
*
@ -1208,6 +1226,11 @@ class User
DBA::update('user', $fields, ['uid' => $uid]);
$def_gid_groups = Circle::create($uid, DI::l10n()->t('Groups'));
if (!$def_gid_groups) {
DI::pConfig()->set($uid, 'system', 'default-group-gid', $def_gid_groups);
}
// if we have no OpenID photo try to look up an avatar
if (!strlen($photo)) {
$photo = Network::lookupAvatarByEmail($email);

View File

@ -305,9 +305,9 @@ class Network extends BaseModule
protected function parseRequest(array $get)
{
self::$circleId = $this->parameters['circle_id'] ?? 0;
self::$circleId = (int)($this->parameters['circle_id'] ?? 0);
self::$groupContactId = $this->parameters['contact_id'] ?? 0;
self::$groupContactId = (int)($this->parameters['contact_id'] ?? 0);
self::$selectedTab = self::getTimelineOrderBySession(DI::userSession(), DI::pConfig());

View File

@ -173,6 +173,7 @@ class Account extends BaseSettings
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'unlisted', !empty($request['unlisted']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'accessible-photos', !empty($request['accessible-photos']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'default-group-gid', intval($request['circle-selection-group'] ?? $def_gid));
$fields = [
'allow_cid' => $str_contact_allow,
@ -592,7 +593,8 @@ class Account extends BaseSettings
'$blocktags' => ['blocktags', DI::l10n()->t('Allow friends to tag your posts?'), (intval($user['blocktags']) ? '0' : '1'), DI::l10n()->t('Your contacts can add additional tags to your posts.')],
'$unkmail' => ['unkmail', DI::l10n()->t('Permit unknown people to send you private mail?'), $unkmail, DI::l10n()->t('Friendica network users may send you private messages even if they are not in your contact list.')],
'$cntunkmail' => ['cntunkmail', DI::l10n()->t('Maximum private messages per day from unknown people:'), $cntunkmail, DI::l10n()->t("(to prevent spam abuse)")],
'$circle_select' => Circle::getSelectorHTML(DI::userSession()->getLocalUserId(), $user['def_gid']),
'$circle_select' => Circle::getSelectorHTML(DI::userSession()->getLocalUserId(), $user['def_gid'], 'circle-selection', DI::l10n()->t('Default privacy circle for new contacts')),
'$circle_select_group' => Circle::getSelectorHTML(DI::userSession()->getLocalUserId(), DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'default-group-gid', $user['def_gid']), 'circle-selection-group', DI::l10n()->t('Default privacy circle for new group contacts')),
'$permissions' => DI::l10n()->t('Default Post Permissions'),
'$aclselect' => ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId()),

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
<div class="field custom">
<label for="circle-selection" id="circle-selection-lbl">{{$label}}</label>
<select name="circle-selection" id="circle-selection">
<label for="{{$id}}" id="circle-selection-lbl">{{$label}}</label>
<select name="{{$id}}" id="{{$id}}">
{{foreach $circles as $circle}}
<option value="{{$circle.id}}"{{if $circle.selected}} selected="selected"{{/if}}>{{$circle.name}}</option>
{{/foreach}}

View File

@ -60,6 +60,7 @@
{{include file="field_input.tpl" field=$cntunkmail}}
{{$circle_select nofilter}}
{{$circle_select_group nofilter}}
{{if not $is_community}}
<h3>{{$permissions}}</h3>

View File

@ -93,6 +93,8 @@
{{$circle_select nofilter}}
{{$circle_select_group nofilter}}
{{if not $is_community}}
<h3>{{$permissions}}</h3>