Skip to content

Commit

Permalink
Merge pull request #12638 from annando/collapse
Browse files Browse the repository at this point in the history
Posts from contacts can now be collapsed
  • Loading branch information
MrPetovan committed Jan 9, 2023
2 parents 0ae7a53 + 83dd49a commit e6f6087
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 147 deletions.
2 changes: 1 addition & 1 deletion database.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 2023.03-dev (Giant Rhubarb)
-- DB_UPDATE_VERSION 1509
-- DB_UPDATE_VERSION 1510
-- ------------------------------------------


Expand Down
12 changes: 7 additions & 5 deletions src/Content/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,11 @@ public function photoMenu(array $item, string $formSecurityToken): string
}

if (!empty($pcid)) {
$contact_url = 'contact/' . $pcid;
$posts_link = $contact_url . '/posts';
$block_link = $item['self'] ? '' : $contact_url . '/block?t=' . $formSecurityToken;
$ignore_link = $item['self'] ? '' : $contact_url . '/ignore?t=' . $formSecurityToken;
$contact_url = 'contact/' . $pcid;
$posts_link = $contact_url . '/posts';
$block_link = $item['self'] ? '' : $contact_url . '/block?t=' . $formSecurityToken;
$ignore_link = $item['self'] ? '' : $contact_url . '/ignore?t=' . $formSecurityToken;
$collapse_link = $item['self'] ? '' : $contact_url . '/collapse?t=' . $formSecurityToken;
}

if ($cid && !$item['self']) {
Expand All @@ -423,7 +424,8 @@ public function photoMenu(array $item, string $formSecurityToken): string
$this->l10n->t('View Contact') => $contact_url,
$this->l10n->t('Send PM') => $pm_url,
$this->l10n->t('Block') => $block_link,
$this->l10n->t('Ignore') => $ignore_link
$this->l10n->t('Ignore') => $ignore_link,
$this->l10n->t('Collapse') => $collapse_link
];

if (!empty($item['language'])) {
Expand Down
4 changes: 4 additions & 0 deletions src/Model/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -3048,6 +3048,10 @@ public static function prepareBody(array &$item, bool $attach = false, bool $is_
// Compile eventual content filter reasons
$filter_reasons = [];
if (!$is_preview && DI::userSession()->getPublicContactId() != $item['author-id']) {
if (Contact\User::isCollapsed($item['author-id'], $item['uid'])) {
$filter_reasons[] = DI::l10n()->t('Content from %s is collapsed', $item['author-name']);
}

if (!empty($item['content-warning']) && (!DI::userSession()->getLocalUserId() || !DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'disable_cw', false))) {
$filter_reasons[] = DI::l10n()->t('Content warning: %s', $item['content-warning']);
}
Expand Down
48 changes: 40 additions & 8 deletions src/Module/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ private static function batchActions()
self::toggleIgnoreContact($cdata['public']);
$count_actions++;
}

if (!empty($_POST['contacts_batch_collapse'])) {
self::toggleCollapseContact($cdata['public']);
$count_actions++;
}
}
if ($count_actions > 0) {
DI::sysmsg()->addInfo(DI::l10n()->tt('%d contact edited.', '%d contacts edited.', $count_actions));
Expand Down Expand Up @@ -165,6 +170,18 @@ private static function toggleIgnoreContact(int $contact_id)
Model\Contact\User::setIgnored($contact_id, DI::userSession()->getLocalUserId(), $ignored);
}

/**
* Toggles the collapsed status of a contact identified by id.
*
* @param int $contact_id Id of the contact with uid = 0
* @throws \Exception
*/
private static function toggleCollapseContact(int $contact_id)
{
$collapsed = !Model\Contact\User::isCollapsed($contact_id, DI::userSession()->getLocalUserId());
Model\Contact\User::setCollapsed($contact_id, DI::userSession()->getLocalUserId(), $collapsed);
}

protected function content(array $request = []): string
{
if (!DI::userSession()->getLocalUserId()) {
Expand Down Expand Up @@ -230,6 +247,11 @@ protected function content(array $request = []): string
// This makes the query look for contact.uid = 0
array_unshift($sql_values, 0);
break;
case 'collapsed':
$sql_extra = " AND `id` IN (SELECT `cid` FROM `user-contact` WHERE `user-contact`.`uid` = ? AND `user-contact`.`collapsed`)";
// This makes the query look for contact.uid = 0
array_unshift($sql_values, 0);
break;
case 'archived':
$sql_extra = " AND `archive` AND NOT `blocked` AND NOT `pending`";
break;
Expand Down Expand Up @@ -345,6 +367,14 @@ protected function content(array $request = []): string
'id' => 'showignored-tab',
'accesskey' => 'i',
],
[
'label' => DI::l10n()->t('Collapsed'),
'url' => 'contact/collapsed',
'sel' => $type == 'collapsed' ? 'active' : '',
'title' => DI::l10n()->t('Only show collapsed contacts'),
'id' => 'showcollapsed-tab',
'accesskey' => 'c',
],
[
'label' => DI::l10n()->t('Archived'),
'url' => 'contact/archived',
Expand Down Expand Up @@ -382,11 +412,12 @@ protected function content(array $request = []): string
}

switch ($type) {
case 'pending': $header .= ' - ' . DI::l10n()->t('Pending'); break;
case 'blocked': $header .= ' - ' . DI::l10n()->t('Blocked'); break;
case 'hidden': $header .= ' - ' . DI::l10n()->t('Hidden'); break;
case 'ignored': $header .= ' - ' . DI::l10n()->t('Ignored'); break;
case 'archived': $header .= ' - ' . DI::l10n()->t('Archived'); break;
case 'pending': $header .= ' - ' . DI::l10n()->t('Pending'); break;
case 'blocked': $header .= ' - ' . DI::l10n()->t('Blocked'); break;
case 'hidden': $header .= ' - ' . DI::l10n()->t('Hidden'); break;
case 'ignored': $header .= ' - ' . DI::l10n()->t('Ignored'); break;
case 'collapsed': $header .= ' - ' . DI::l10n()->t('Collapsed'); break;
case 'archived': $header .= ' - ' . DI::l10n()->t('Archived'); break;
}

$header .= $nets ? ' - ' . ContactSelector::networkToName($nets) : '';
Expand All @@ -405,9 +436,10 @@ protected function content(array $request = []): string
'$form_security_token' => BaseModule::getFormSecurityToken('contact_batch_actions'),
'multiselect' => 1,
'$batch_actions' => [
'contacts_batch_update' => DI::l10n()->t('Update'),
'contacts_batch_block' => DI::l10n()->t('Block') . '/' . DI::l10n()->t('Unblock'),
'contacts_batch_ignore' => DI::l10n()->t('Ignore') . '/' . DI::l10n()->t('Unignore'),
'contacts_batch_update' => DI::l10n()->t('Update'),
'contacts_batch_block' => DI::l10n()->t('Block') . '/' . DI::l10n()->t('Unblock'),
'contacts_batch_ignore' => DI::l10n()->t('Ignore') . '/' . DI::l10n()->t('Unignore'),
'contacts_batch_collapse' => DI::l10n()->t('Collapse') . '/' . DI::l10n()->t('Uncollapse'),
],
'$h_batch_actions' => DI::l10n()->t('Batch Actions'),
'$paginate' => $pager->renderFull($total),
Expand Down
25 changes: 25 additions & 0 deletions src/Module/Contact/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,23 @@ protected function content(array $request = []): string
Contact\User::setIgnored($contact['id'], DI::userSession()->getLocalUserId(), true);
$message = $this->t('Contact has been ignored');
}

// @TODO: add $this->localRelationship->save($localRelationship);
DI::sysmsg()->addInfo($message);
}

if ($cmd === 'collapse') {
if ($localRelationship->collapsed) {
// @TODO Backward compatibility, replace with $localRelationship->unblock()
Contact\User::setCollapsed($contact['id'], DI::userSession()->getLocalUserId(), false);

$message = $this->t('Contact has been uncollapsed');
} else {
// @TODO Backward compatibility, replace with $localRelationship->block()
Contact\User::setCollapsed($contact['id'], DI::userSession()->getLocalUserId(), true);
$message = $this->t('Contact has been collapsed');
}

// @TODO: add $this->localRelationship->save($localRelationship);
DI::sysmsg()->addInfo($message);
}
Expand Down Expand Up @@ -352,6 +368,7 @@ protected function content(array $request = []): string
'$cinfo' => ['info', '', $localRelationship->info, ''],
'$blocked' => ($contact['blocked'] ? $this->t('Currently blocked') : ''),
'$ignored' => ($contact['readonly'] ? $this->t('Currently ignored') : ''),
'$collapsed' => (Contact\User::isCollapsed($contact['id'], DI::userSession()->getLocalUserId()) ? $this->t('Currently collapsed') : ''),
'$archived' => ($contact['archive'] ? $this->t('Currently archived') : ''),
'$pending' => ($contact['pending'] ? $this->t('Awaiting connection acknowledge') : ''),
'$hidden' => ['hidden', $this->t('Hide this contact from others'), $localRelationship->hidden, $this->t('Replies/likes to your public posts <strong>may</strong> still be visible')],
Expand Down Expand Up @@ -479,6 +496,14 @@ private function getContactActions(array $contact, Entity\LocalRelationship $loc
'id' => 'toggle-ignore',
];

$contact_actions['collapse'] = [
'label' => $localRelationship->collapsed ? $this->t('Uncollapse') : $this->t('Collapse'),
'url' => 'contact/' . $contact['id'] . '/collapse?t=' . $formSecurityToken,
'title' => $this->t('Toggle Collapsed status'),
'sel' => $localRelationship->collapsed ? 'active' : '',
'id' => 'toggle-collapse',
];

if (Protocol::supportsRevokeFollow($contact['network']) && in_array($localRelationship->rel, [Contact::FOLLOWER, Contact::FRIEND])) {
$contact_actions['revoke_follow'] = [
'label' => $this->t('Revoke Follow'),
Expand Down
2 changes: 1 addition & 1 deletion static/dbstructure.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
use Friendica\Database\DBA;

if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1509);
define('DB_UPDATE_VERSION', 1510);
}

return [
Expand Down
3 changes: 2 additions & 1 deletion static/routes.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@
'/contact' => [
'[/]' => [Module\Contact::class, [R::GET]],
'/{id:\d+}[/]' => [Module\Contact\Profile::class, [R::GET, R::POST]],
'/{id:\d+}/{action:block|ignore|update|updateprofile}'
'/{id:\d+}/{action:block|ignore|collapse|update|updateprofile}'
=> [Module\Contact\Profile::class, [R::GET]],
'/{id:\d+}/advanced' => [Module\Contact\Advanced::class, [R::GET, R::POST]],
'/{id:\d+}/conversations' => [Module\Contact\Conversations::class, [R::GET]],
Expand All @@ -401,6 +401,7 @@
'/hidden' => [Module\Contact::class, [R::GET]],
'/hovercard' => [Module\Contact\Hovercard::class, [R::GET]],
'/ignored' => [Module\Contact::class, [R::GET]],
'/collapsed' => [Module\Contact::class, [R::GET]],
'/match' => [Module\Contact\MatchInterests::class, [R::GET]],
'/pending' => [Module\Contact::class, [R::GET]],
'/redir/{id:\d+}' => [Module\Contact\Redir::class, [R::GET]],
Expand Down
15 changes: 15 additions & 0 deletions update.php
Original file line number Diff line number Diff line change
Expand Up @@ -1212,3 +1212,18 @@ function update_1509()

return Update::SUCCESS;
}

function update_1510()
{
$blocks = DBA::select('pconfig', ['uid', 'v'], ['cat' => 'blockem', 'k' => 'words']);
while ($block = DBA::fetch($blocks)) {
foreach (explode(',', $block['v']) as $account) {
$id = Contact::getIdForURL(trim($account), 0, false);
if (empty($id)) {
continue;
}
Contact\User::setCollapsed($id, $block['uid'], true);
}
}
return Update::SUCCESS;
}

0 comments on commit e6f6087

Please sign in to comment.