Merge pull request #13235 from annando/group-circle

Dedicated circle name for groups
This commit is contained in:
Hypolite Petovan 2023-06-26 07:49:20 -04:00 committed by GitHub
commit 582e05fcff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 290 additions and 241 deletions

View file

@ -537,6 +537,14 @@ class Item
$item['private'] = $private_group ? ItemModel::PRIVATE : ItemModel::UNLISTED;
if ($only_to_group) {
$cdata = Contact::getPublicAndUserContactID($group_contact['id'], $item['uid']);
if (!empty($cdata['user'])) {
$item['owner-id'] = $cdata['user'];
unset($item['owner-link']);
unset($item['owner-name']);
unset($item['owner-avatar']);
}
$item['postopts'] = '';
}

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

@ -3098,31 +3098,32 @@ class Contact
// create contact record
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
'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,
'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()),

View file

@ -421,7 +421,7 @@ class Processor
if ($activity['thread-completion'] != $item['owner-id']) {
$actor = Contact::getById($activity['thread-completion'], ['url']);
$item['causer-link'] = $actor['url'];
$item['causer-id'] = $activity['thread-completion'];
$item['causer-id'] = $activity['thread-completion'];
Logger::info('Use inherited actor as causer.', ['id' => $item['owner-id'], 'activity' => $activity['thread-completion'], 'owner' => $item['owner-link'], 'actor' => $actor['url']]);
} else {
// Store the original actor in the "causer" fields to enable the check for ignored or blocked contacts
@ -431,7 +431,7 @@ class Processor
}
$item['owner-link'] = $item['author-link'];
$item['owner-id'] = $item['author-id'];
$item['owner-id'] = $item['author-id'];
}
if (!$item['isGroup'] && !empty($activity['receiver_urls']['as:audience'])) {
@ -440,7 +440,8 @@ class Processor
if (($actor['type'] ?? 'Person') == 'Group') {
Logger::debug('Group post detected via audience.', ['audience' => $audience, 'actor' => $activity['actor'], 'author' => $activity['author']]);
$item['isGroup'] = true;
$item['group-link'] = $audience;
$item['group-link'] = $item['owner-link'] = $audience;
$item['owner-id'] = Contact::getIdForURL($audience);
}
}
} else {
@ -457,13 +458,13 @@ class Processor
if (!$item['isGroup'] && (($causer['type'] ?? 'Person') == 'Group')) {
Logger::debug('Group post detected via causer.', ['actor' => $activity['actor'], 'author' => $activity['author'], 'causer' => $item['causer-link']]);
$item['isGroup'] = true;
$item['isGroup'] = true;
$item['group-link'] = $item['causer-link'];
}
if (!empty($item['group-link']) && empty($item['causer-link'])) {
$item['causer-link'] = $item['group-link'];
$item['causer-id'] = Contact::getIdForURL($item['causer-link']);
$item['causer-id'] = Contact::getIdForURL($item['causer-link']);
}
$item['uri'] = $activity['id'];

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>