Skip to content

Commit 78a86b1

Browse files
committed
Move follow button into the interaction drop down
1 parent 22c8b6e commit 78a86b1

4 files changed

Lines changed: 74 additions & 25 deletions

File tree

com.woltlab.wcf/templates/reactionSummaryDetailsListItems.tpl

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,6 @@
2323
{unsafe:$reaction->render()}
2424

2525
<div class="simpleUserList__item__interactions">
26-
{if $__wcf->user->userID && $user->userID != $__wcf->user->userID}
27-
{if !$__wcf->getUserProfileHandler()->isIgnoredByUser($user->userID)}
28-
{if $__wcf->getUserProfileHandler()->isFollowing($user->userID)}
29-
<button
30-
type="button"
31-
data-following="1"
32-
data-follow-user="{link controller='UserFollow' id=$user->userID}{/link}"
33-
class="button small jsTooltip"
34-
title="{lang}wcf.user.button.unfollow{/lang}"
35-
>{icon name='user-minus' type='solid'}</button>
36-
{else}
37-
<button
38-
type="button"
39-
data-following="0"
40-
data-follow-user="{link controller='UserFollow' id=$user->userID}{/link}"
41-
class="button small jsTooltip"
42-
title="{lang}wcf.user.button.follow{/lang}"
43-
>{icon name='user-plus' type='solid'}</button>
44-
{/if}
45-
{/if}
46-
{/if}
47-
4826
{unsafe:$view->renderInteractionContextMenuButton($reaction)}
4927
</div>
5028
</div>

wcfsetup/install/files/lib/system/interaction/user/UserProfileInteractions.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
2323
* @since 6.2
2424
*/
25-
final class UserProfileInteractions extends AbstractInteractionProvider
25+
class UserProfileInteractions extends AbstractInteractionProvider
2626
{
2727
public function __construct()
2828
{
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace wcf\system\interaction\user;
4+
5+
use wcf\action\UserFollowAction;
6+
use wcf\data\DatabaseObject;
7+
use wcf\data\user\UserProfile;
8+
use wcf\system\interaction\AbstractInteraction;
9+
use wcf\system\request\LinkHandler;
10+
use wcf\system\user\UserProfileHandler;
11+
use wcf\system\WCF;
12+
use wcf\util\StringUtil;
13+
14+
/**
15+
* Extended interaction provider for the context menu of user profiles with the option to follow users.
16+
*
17+
* @author Marcel Werk
18+
* @copyright 2001-2026 WoltLab GmbH
19+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
20+
* @since 6.3
21+
*/
22+
final class UserProfileInteractionsWithFollow extends UserProfileInteractions
23+
{
24+
public function __construct()
25+
{
26+
$this->addInteractions([
27+
new class(
28+
'follow',
29+
static fn(UserProfile $user) => !WCF::getUser()->isGuest()
30+
&& WCF::getUser()->userID !== $user->userID
31+
&& !UserProfileHandler::getInstance()->isIgnoredByUser($user->userID)
32+
) extends AbstractInteraction {
33+
#[\Override]
34+
public function render(DatabaseObject $object): string
35+
{
36+
\assert($object instanceof UserProfile);
37+
38+
$endpoint = StringUtil::encodeHTML(
39+
LinkHandler::getInstance()->getControllerLink(UserFollowAction::class, ['id' => $object->userID])
40+
);
41+
42+
if (UserProfileHandler::getInstance()->isFollowing($object->userID)) {
43+
$title = WCF::getLanguage()->get('wcf.user.button.unfollow');
44+
45+
return <<<HTML
46+
<button
47+
type="button"
48+
data-following="1"
49+
data-follow-user="{$endpoint}"
50+
data-type="button"
51+
>{$title}</button>
52+
HTML;
53+
} else {
54+
$title = WCF::getLanguage()->get('wcf.user.button.follow');
55+
56+
return <<<HTML
57+
<button
58+
type="button"
59+
data-following="0"
60+
data-follow-user="{$endpoint}"
61+
data-type="button"
62+
>{$title}</button>
63+
HTML;
64+
}
65+
}
66+
},
67+
]);
68+
69+
parent::__construct();
70+
}
71+
}

wcfsetup/install/files/lib/system/listView/user/ReactionSummaryDetailsListView.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use wcf\data\like\ViewableLike;
1010
use wcf\data\like\ViewableLikeList;
1111
use wcf\event\listView\user\ReactionSummaryDetailsListViewInitialized;
12-
use wcf\system\interaction\user\UserProfileInteractions;
12+
use wcf\system\interaction\user\UserProfileInteractionsWithFollow;
1313
use wcf\system\listView\AbstractListView;
1414
use wcf\system\listView\ListViewSortField;
1515
use wcf\system\reaction\ReactionHandler;
@@ -41,7 +41,7 @@ public function __construct(
4141
]);
4242

4343
$this->setAllowSorting(false);
44-
$this->setInteractionProvider(new UserProfileInteractions());
44+
$this->setInteractionProvider(new UserProfileInteractionsWithFollow());
4545
$this->setDefaultSortField('username');
4646
$this->setItemsPerPage(100);
4747
$this->setCssClassName('simpleUserList');

0 commit comments

Comments
 (0)