import * as Core from "../../../../../Core";
import * as Language from "../../../../../Language";
-import { AjaxCallbackSetup, ResponseData } from "../../../../../Ajax/Data";
import * as UiNotification from "../../../../Notification";
import UiUserProfileMenuItemAbstract from "./Abstract";
+import FormBuilderDialog from "../../../../../Form/Builder/Dialog";
-interface AjaxResponse extends ResponseData {
- returnValues: {
- isIgnoredUser: 1 | 0;
- };
+interface AjaxResponse {
+ isIgnoredUser: 1 | 0;
}
class UiUserProfileMenuItemIgnore extends UiUserProfileMenuItemAbstract {
+ private readonly dialog: FormBuilderDialog;
+
constructor(userId: number, isActive: boolean) {
super(userId, isActive);
+
+ this.dialog = new FormBuilderDialog("ignoreDialog", "wcf\\data\\user\\ignore\\UserIgnoreAction", "getDialog", {
+ dialog: {
+ title: Language.get("wcf.user.button.ignore"),
+ },
+ actionParameters: {
+ userID: this._userId,
+ },
+ submitActionName: "submitDialog",
+ successCallback: (r: AjaxResponse) => this._ajaxSuccess(r),
+ destroyOnClose: true,
+ });
}
_getLabel(): string {
return Language.get("wcf.user.button." + (this._isActive ? "un" : "") + "ignore");
}
- _getAjaxActionName(): string {
- return this._isActive ? "unignore" : "ignore";
- }
-
_ajaxSuccess(data: AjaxResponse): void {
- this._isActive = !!data.returnValues.isIgnoredUser;
+ this._isActive = !!data.isIgnoredUser;
this._updateButton();
UiNotification.show();
}
- _ajaxSetup(): ReturnType<AjaxCallbackSetup> {
- return {
- data: {
- className: "wcf\\data\\user\\ignore\\UserIgnoreAction",
- },
- };
+ protected _toggle(event: MouseEvent): void {
+ event.preventDefault();
+
+ this.dialog.open();
}
}
use wcf\system\database\table\column\NotNullVarchar255DatabaseTableColumn;
use wcf\system\database\table\column\ObjectIdDatabaseTableColumn;
use wcf\system\database\table\column\TextDatabaseTableColumn;
+use wcf\system\database\table\column\TinyintDatabaseTableColumn;
use wcf\system\database\table\column\VarbinaryDatabaseTableColumn;
use wcf\system\database\table\column\VarcharDatabaseTableColumn;
use wcf\system\database\table\DatabaseTable;
DefaultFalseBooleanDatabaseTableColumn::create('requireMultifactor'),
]),
+ PartialDatabaseTable::create('wcf1_user_ignore')
+ ->columns([
+ TinyintDatabaseTableColumn::create('type')
+ ->length(1)
+ ->notNull()
+ ->defaultValue(1),
+ ]),
+
DatabaseTable::create('wcf1_user_multifactor')
->columns([
ObjectIdDatabaseTableColumn::create('setupID'),
-define(["require", "exports", "tslib", "../../../../../Core", "../../../../../Language", "../../../../Notification", "./Abstract"], function (require, exports, tslib_1, Core, Language, UiNotification, Abstract_1) {
+define(["require", "exports", "tslib", "../../../../../Core", "../../../../../Language", "../../../../Notification", "./Abstract", "../../../../../Form/Builder/Dialog"], function (require, exports, tslib_1, Core, Language, UiNotification, Abstract_1, Dialog_1) {
"use strict";
Core = tslib_1.__importStar(Core);
Language = tslib_1.__importStar(Language);
UiNotification = tslib_1.__importStar(UiNotification);
Abstract_1 = tslib_1.__importDefault(Abstract_1);
+ Dialog_1 = tslib_1.__importDefault(Dialog_1);
class UiUserProfileMenuItemIgnore extends Abstract_1.default {
constructor(userId, isActive) {
super(userId, isActive);
+ this.dialog = new Dialog_1.default("ignoreDialog", "wcf\\data\\user\\ignore\\UserIgnoreAction", "getDialog", {
+ dialog: {
+ title: Language.get("wcf.user.button.ignore"),
+ },
+ actionParameters: {
+ userID: this._userId,
+ },
+ submitActionName: "submitDialog",
+ successCallback: (r) => this._ajaxSuccess(r),
+ destroyOnClose: true,
+ });
}
_getLabel() {
return Language.get("wcf.user.button." + (this._isActive ? "un" : "") + "ignore");
}
- _getAjaxActionName() {
- return this._isActive ? "unignore" : "ignore";
- }
_ajaxSuccess(data) {
- this._isActive = !!data.returnValues.isIgnoredUser;
+ this._isActive = !!data.isIgnoredUser;
this._updateButton();
UiNotification.show();
}
- _ajaxSetup() {
- return {
- data: {
- className: "wcf\\data\\user\\ignore\\UserIgnoreAction",
- },
- };
+ _toggle(event) {
+ event.preventDefault();
+ this.dialog.open();
}
}
Core.enableLegacyInheritance(UiUserProfileMenuItemIgnore);
* @property-read int $userID id of the ignoring user
* @property-read int $ignoreUserID id of the ignored user
* @property-read int $time time at which ignore relation has been established
+ * @property-read int $type one of the TYPE_* class constants
*/
class UserIgnore extends DatabaseObject
{
+ public const TYPE_NO_IGNORE = 0;
+
+ public const TYPE_BLOCK_DIRECT_CONTACT = 1;
+
+ public const TYPE_HIDE_MESSAGES = 2;
+
/**
* Returns a UserIgnore object for given ignored user id.
*
use wcf\data\AbstractDatabaseObjectAction;
use wcf\data\user\follow\UserFollow;
use wcf\data\user\follow\UserFollowEditor;
+use wcf\data\user\User;
use wcf\system\cache\runtime\UserProfileRuntimeCache;
use wcf\system\exception\IllegalLinkException;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\exception\UserInputException;
+use wcf\system\form\builder\data\processor\CustomFormDataProcessor;
+use wcf\system\form\builder\DialogFormDocument;
+use wcf\system\form\builder\field\RadioButtonFormField;
+use wcf\system\form\builder\field\validation\FormFieldValidationError;
+use wcf\system\form\builder\field\validation\FormFieldValidator;
+use wcf\system\form\builder\IFormDocument;
use wcf\system\user\storage\UserStorageHandler;
use wcf\system\WCF;
*/
class UserIgnoreAction extends AbstractDatabaseObjectAction
{
+ protected $form;
+
/**
* Validates the 'ignore' action.
*/
if ($userProfile->getPermission('user.profile.cannotBeIgnored')) {
throw new PermissionDeniedException();
}
+
+ $this->readInteger('type', true, 'data');
+
+ if (
+ $this->parameters['data']['type']
+ && !\in_array($this->parameters['data']['type'], [
+ UserIgnore::TYPE_BLOCK_DIRECT_CONTACT,
+ UserIgnore::TYPE_HIDE_MESSAGES,
+ ])
+ ) {
+ throw new UserInputException('type', 'invalid');
+ }
}
/**
*/
public function ignore()
{
- /** @var UserIgnore $ignore */
- $ignore = UserIgnoreEditor::createOrIgnore([
- 'ignoreUserID' => $this->parameters['data']['userID'],
- 'time' => TIME_NOW,
- 'userID' => WCF::getUser()->userID,
- ]);
+ $ignore = new UserIgnoreEditor(UserIgnore::getIgnore($this->parameters['data']['userID']));
+ $type = $this->parameters['data']['type'] ?? UserIgnore::TYPE_BLOCK_DIRECT_CONTACT;
+
+ if ($ignore->ignoreID) {
+ $ignore->update([
+ 'type' => $type,
+ 'time' => TIME_NOW,
+ ]);
+ } else {
+ $ignore = UserIgnoreEditor::createOrIgnore([
+ 'ignoreUserID' => $this->parameters['data']['userID'],
+ 'type' => $type,
+ 'time' => TIME_NOW,
+ 'userID' => WCF::getUser()->userID,
+ ]);
+ }
if ($ignore !== null) {
UserStorageHandler::getInstance()->reset([WCF::getUser()->userID], 'ignoredUserIDs');
return ['isIgnoredUser' => 0];
}
+ public function validateGetDialog()
+ {
+ $this->readInteger('userID');
+
+ $userProfile = UserProfileRuntimeCache::getInstance()->getObject($this->parameters['userID']);
+ if ($userProfile === null || $userProfile->userID == WCF::getUser()->userID) {
+ throw new IllegalLinkException();
+ }
+
+ $ignore = UserIgnore::getIgnore($this->parameters['userID']);
+
+ // Check if the user is not yet ignored and cannot be ignored.
+ if (!$ignore && $userProfile->getPermission('user.profile.cannotBeIgnored')) {
+ throw new PermissionDeniedException();
+ }
+ }
+
+ public function getDialog()
+ {
+ $form = $this->getForm();
+
+ return [
+ 'dialog' => $form->getHtml(),
+ 'formId' => $form->getId(),
+ ];
+ }
+
+ public function validateSubmitDialog()
+ {
+ $this->validateGetDialog();
+
+ $this->readString('formId');
+
+ $this->getForm()->requestData($this->parameters['data'] ?? []);
+ $this->getForm()->readValues();
+ }
+
+ public function submitDialog()
+ {
+ $this->getForm()->validate();
+
+ if ($this->getForm()->hasValidationErrors()) {
+ return [
+ 'dialog' => $this->getForm()->getHtml(),
+ 'formId' => $this->getForm()->getId(),
+ ];
+ }
+
+ $formData = $this->getForm()->getData();
+
+ if ($formData['data']['type'] === UserIgnore::TYPE_NO_IGNORE) {
+ return (new self([], 'unignore', [
+ 'data' => [
+ 'userID' => $this->parameters['userID'],
+ ],
+ ]))->executeAction()['returnValues'];
+ } else {
+ return (new self([], 'ignore', [
+ 'data' => [
+ 'userID' => $this->parameters['userID'],
+ 'type' => $formData['data']['type'],
+ ],
+ ]))->executeAction()['returnValues'];
+ }
+ }
+
+ protected function getForm(): IFormDocument
+ {
+ if ($this->form === null) {
+ $id = 'userIgnore';
+ $this->form = DialogFormDocument::create($id)
+ ->ajax()
+ ->prefix($id);
+
+ $ignore = UserIgnore::getIgnore($this->parameters['userID']);
+
+ $this->form->appendChildren([
+ RadioButtonFormField::create('type')
+ ->label(WCF::getLanguage()->get('wcf.user.ignore.type'))
+ ->options([
+ UserIgnore::TYPE_NO_IGNORE => WCF::getLanguage()
+ ->get('wcf.user.ignore.type.noIgnore'),
+ UserIgnore::TYPE_BLOCK_DIRECT_CONTACT => WCF::getLanguage()
+ ->get('wcf.user.ignore.type.blockDirectContact'),
+ UserIgnore::TYPE_HIDE_MESSAGES => WCF::getLanguage()
+ ->get('wcf.user.ignore.type.hideMessages'),
+ ])
+ ->value($ignore->type ?: 0)
+ ->addValidator(new FormFieldValidator('type', function (RadioButtonFormField $formField) {
+ $userProfile = UserProfileRuntimeCache::getInstance()->getObject($this->parameters['userID']);
+ if ($userProfile->getPermission('user.profile.cannotBeIgnored')) {
+ if ($formField->getValue() != UserIgnore::TYPE_NO_IGNORE) {
+ $formField->addValidationError(
+ new FormFieldValidationError(
+ 'cannotBeIgnored',
+ 'wcf.user.ignore.error.cannotBeIgnored'
+ )
+ );
+ }
+ }
+ })),
+ ]);
+
+ $this->form->getDataHandler()->addProcessor(
+ new CustomFormDataProcessor(
+ 'type',
+ static function (IFormDocument $document, array $parameters) {
+ $parameters['data']['type'] = \intval($parameters['data']['type']);
+
+ return $parameters;
+ }
+ )
+ );
+
+ $this->form->build();
+ }
+
+ return $this->form;
+ }
+
/**
* @inheritDoc
*/
<item name="wcf.user.reauthentication.explanation"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du betrittst einen besonders geschützten Bereich. Aus Sicherheitsgründen ist es notwendig, dass du dich durch Eingabe deines Kennworts erneut authentifizierst.{else}Sie betreten einen besonders geschützten Bereich. Aus Sicherheitsgründen ist es notwendig, dass Sie sich durch Eingabe Ihres Kennworts erneut authentifizieren.{/if}]]></item>
<item name="wcf.user.reauthentication.loginAs"><![CDATA[Angemeldet als]]></item>
<item name="wcf.user.reauthentication.logoutAndChangeUser"><![CDATA[Nicht {$__wcf->user->username}? <a href="{link controller='FullLogout' application='wcf'}t={csrfToken type='url'}{/link}">Abmelden und Benutzer wechseln</a>.]]></item>
+ <item name="wcf.user.ignore.type"><![CDATA[Benutzer blockieren]]></item>
+ <item name="wcf.user.ignore.type.noIgnore"><![CDATA[Nicht Blockieren]]></item>
+ <item name="wcf.user.ignore.type.blockDirectContact"><![CDATA[Direkten Kontakt blockieren]]></item>
+ <item name="wcf.user.ignore.type.hideMessages"><![CDATA[Erstellte Inhalte ausblenden]]></item>
+ <item name="wcf.user.ignore.error.cannotBeIgnored"><![CDATA[Der Benutzer kann nicht blockiert werden.]]></item>
</category>
<category name="wcf.user.menu">
<item name="wcf.user.menu.community"><![CDATA[Community]]></item>
<item name="wcf.user.reauthentication.explanation"><![CDATA[You are entering a security-sensitive area. For security reasons it is required that you re-authenticate yourself by entering your password.]]></item>
<item name="wcf.user.reauthentication.loginAs"><![CDATA[Logged in as]]></item>
<item name="wcf.user.reauthentication.logoutAndChangeUser"><![CDATA[Not {$__wcf->user->username}? <a href="{link controller='FullLogout' application='wcf'}t={csrfToken type='url'}{/link}">Logout and change user</a>.]]></item>
+ <item name="wcf.user.ignore.type"><![CDATA[Block User]]></item>
+ <item name="wcf.user.ignore.type.noIgnore"><![CDATA[Do Not Block]]></item>
+ <item name="wcf.user.ignore.type.blockDirectContact"><![CDATA[Block Direct Contact]]></item>
+ <item name="wcf.user.ignore.type.hideMessages"><![CDATA[Hide Created Messages]]></item>
+ <item name="wcf.user.ignore.error.cannotBeIgnored"><![CDATA[The user cannot be blocked.]]></item>
</category>
<category name="wcf.user.menu">
<item name="wcf.user.menu.community"><![CDATA[Community]]></item>
userID INT(10) NOT NULL,
ignoreUserID INT(10) NOT NULL,
time INT(10) NOT NULL DEFAULT 0,
+ type TINYINT(1) NOT NULL DEFAULT 1,
UNIQUE KEY (userID, ignoreUserID)
);