Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 37 additions & 18 deletions files/lib/bootstrap/com.woltlab.wcf.conversation.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

use wcf\form\ConversationAddForm;
use wcf\data\DatabaseObject;
use wcf\data\user\UserProfile;
use wcf\system\event\EventHandler;
use wcf\system\request\LinkHandler;
use wcf\system\view\user\profile\UserProfileHeaderViewInteractionOption;
use wcf\system\WCF;
use wcf\util\StringUtil;

return static function (): void {
$eventHandler = EventHandler::getInstance();
Expand All @@ -18,23 +19,41 @@ static function (\wcf\event\worker\RebuildWorkerCollecting $event) {
}
);

$eventHandler->register(
\wcf\event\user\profile\UserProfileHeaderInteractionOptionCollecting::class,
static function (\wcf\event\user\profile\UserProfileHeaderInteractionOptionCollecting $event) {
if (
MODULE_CONVERSATION
&& WCF::getUser()->userID
&& WCF::getSession()->getPermission('user.conversation.canUseConversation')
&& WCF::getSession()->getPermission('user.conversation.canStartConversation')
&& WCF::getUser()->userID != $event->user->userID
) {
$event->register(UserProfileHeaderViewInteractionOption::forLink(
WCF::getLanguage()->get('wcf.conversation.button.add'),
LinkHandler::getInstance()->getControllerLink(ConversationAddForm::class, ['userID' => $event->user->userID])
));
if (
\MODULE_CONVERSATION
&& WCF::getUser()->userID
&& WCF::getSession()->getPermission('user.conversation.canUseConversation')
&& WCF::getSession()->getPermission('user.conversation.canStartConversation')
) {
$eventHandler->register(
\wcf\event\interaction\user\UserProfileInteractionCollecting::class,
static function (\wcf\event\interaction\user\UserProfileInteractionCollecting $event) {
$event->provider->addInteraction(
new class(
'start-conversation',
isAvailableCallback: static fn(UserProfile $user) => WCF::getUser()->userID !== $user->userID
) extends \wcf\system\interaction\AbstractInteraction {
#[\Override]
public function render(DatabaseObject $object): string
{
\assert($object instanceof UserProfile);

return \sprintf(
'<a href="%s">%s</a>',
StringUtil::encodeHTML(
LinkHandler::getInstance()->getControllerLink(
\wcf\form\ConversationAddForm::class,
['userID' => $object->userID]
)
),
WCF::getLanguage()->get('wcf.conversation.button.add')
);
}
}
);
}
}
);
);
}

$eventHandler->register(
\wcf\event\endpoint\ControllerCollecting::class,
Expand Down
11 changes: 5 additions & 6 deletions templateListener.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
<eventname>buttons</eventname>
<templatecode><![CDATA[{include file='__userInformationStartConversation'}]]></templatecode>
</templatelistener>
<templatelistener name="userCardConversationButton">
<environment>user</environment>
<templatename>userCard</templatename>
<eventname>buttons</eventname>
<templatecode><![CDATA[{include file='userCard_buttons_conversationButton'}]]></templatecode>
</templatelistener>

<templatelistener name="searchAreaConversationSettings">
<environment>user</environment>
Expand Down Expand Up @@ -52,5 +46,10 @@
<eventname>menuInteraction</eventname>
<templatecode><![CDATA[{include file='__userProfileStartConversation'}]]></templatecode>
</templatelistener>
<templatelistener name="userCardConversationButton">
<environment>user</environment>
<templatename>userCard</templatename>
<eventname>buttons</eventname>
</templatelistener>
</delete>
</data>
3 changes: 0 additions & 3 deletions templates/userCard_buttons_conversationButton.tpl

This file was deleted.