whenFirstSeen("woltlab-core-comment-response", () => {
void import("./Component/Comment/Response/woltlab-core-comment-response");
});
+ whenFirstSeen("[data-follow-user]", () => {
+ void import("./Component/User/Follow").then(({ setup }) => setup());
+ });
}
*/
import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
+import { promiseMutex } from "WoltLabSuite/Core/Helper/PromiseMutex";
+import { wheneverFirstSeen } from "WoltLabSuite/Core/Helper/Selector";
import { getPhrase } from "WoltLabSuite/Core/Language";
+import * as UiNotification from "WoltLabSuite/Core/Ui/Notification";
-function toggleFollow(button: HTMLButtonElement): void {
- if (button.dataset.following != "1") {
- button.dataset.following = "1";
- button.dataset.tooltip = getPhrase("wcf.user.button.unfollow");
- button.querySelector("fa-icon")?.setIcon("circle-minus");
- void prepareRequest(button.dataset.endpoint!)
+async function toggleFollow(button: HTMLElement): Promise<void> {
+ if (button.dataset.following !== "1") {
+ await prepareRequest(button.dataset.followUser!)
.post({
action: "follow",
})
.fetchAsResponse();
+
+ button.dataset.following = "1";
+ button.dataset.tooltip = getPhrase("wcf.user.button.unfollow");
+ button.querySelector("fa-icon")?.setIcon("circle-minus");
} else {
- button.dataset.following = "0";
- button.dataset.tooltip = getPhrase("wcf.user.button.follow");
- button.querySelector("fa-icon")?.setIcon("circle-plus");
- void prepareRequest(button.dataset.endpoint!)
+ await prepareRequest(button.dataset.followUser!)
.post({
action: "unfollow",
})
.fetchAsResponse();
+
+ button.dataset.following = "0";
+ button.dataset.tooltip = getPhrase("wcf.user.button.follow");
+ button.querySelector("fa-icon")?.setIcon("circle-plus");
}
+
+ UiNotification.show();
}
export function setup(): void {
- document.querySelectorAll<HTMLButtonElement>(".jsFollowButton").forEach((button) => {
- button.addEventListener("click", () => {
- toggleFollow(button);
- });
+ wheneverFirstSeen("[data-follow-user]", (button) => {
+ button.addEventListener(
+ "click",
+ promiseMutex(() => toggleFollow(button)),
+ );
});
}
(0, LazyLoader_1.whenFirstSeen)("woltlab-core-comment-response", () => {
void new Promise((resolve_4, reject_4) => { require(["./Component/Comment/Response/woltlab-core-comment-response"], resolve_4, reject_4); }).then(tslib_1.__importStar);
});
+ (0, LazyLoader_1.whenFirstSeen)("[data-follow-user]", () => {
+ void new Promise((resolve_5, reject_5) => { require(["./Component/User/Follow"], resolve_5, reject_5); }).then(tslib_1.__importStar).then(({ setup }) => setup());
+ });
}
exports.setup = setup;
});
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.1
*/
-define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "WoltLabSuite/Core/Language"], function (require, exports, Backend_1, Language_1) {
+define(["require", "exports", "tslib", "WoltLabSuite/Core/Ajax/Backend", "WoltLabSuite/Core/Helper/PromiseMutex", "WoltLabSuite/Core/Helper/Selector", "WoltLabSuite/Core/Language", "WoltLabSuite/Core/Ui/Notification"], function (require, exports, tslib_1, Backend_1, PromiseMutex_1, Selector_1, Language_1, UiNotification) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setup = void 0;
- function toggleFollow(button) {
- if (button.dataset.following != "1") {
- button.dataset.following = "1";
- button.dataset.tooltip = (0, Language_1.getPhrase)("wcf.user.button.unfollow");
- button.querySelector("fa-icon")?.setIcon("circle-minus");
- void (0, Backend_1.prepareRequest)(button.dataset.endpoint)
+ UiNotification = tslib_1.__importStar(UiNotification);
+ async function toggleFollow(button) {
+ if (button.dataset.following !== "1") {
+ await (0, Backend_1.prepareRequest)(button.dataset.followUser)
.post({
action: "follow",
})
.fetchAsResponse();
+ button.dataset.following = "1";
+ button.dataset.tooltip = (0, Language_1.getPhrase)("wcf.user.button.unfollow");
+ button.querySelector("fa-icon")?.setIcon("circle-minus");
}
else {
- button.dataset.following = "0";
- button.dataset.tooltip = (0, Language_1.getPhrase)("wcf.user.button.follow");
- button.querySelector("fa-icon")?.setIcon("circle-plus");
- void (0, Backend_1.prepareRequest)(button.dataset.endpoint)
+ await (0, Backend_1.prepareRequest)(button.dataset.followUser)
.post({
action: "unfollow",
})
.fetchAsResponse();
+ button.dataset.following = "0";
+ button.dataset.tooltip = (0, Language_1.getPhrase)("wcf.user.button.follow");
+ button.querySelector("fa-icon")?.setIcon("circle-plus");
}
+ UiNotification.show();
}
function setup() {
- document.querySelectorAll(".jsFollowButton").forEach((button) => {
- button.addEventListener("click", () => {
- toggleFollow(button);
- });
+ (0, Selector_1.wheneverFirstSeen)("[data-follow-user]", (button) => {
+ button.addEventListener("click", (0, PromiseMutex_1.promiseMutex)(() => toggleFollow(button)));
});
}
exports.setup = setup;
EOT
);
- if ($bodyParameters['action'] == 'follow') {
+ if ($bodyParameters['action'] === 'follow') {
$this->assertUserIsNotIgnored($user);
$command = new Follow(WCF::getUser(), $user);
private function assertUserIsNotIgnored(User $target): void
{
$sql = "SELECT ignoreID
- FROM wcf" . WCF_N . "_user_ignore
+ FROM wcf1_user_ignore
WHERE userID = ?
AND ignoreUserID = ?";
- $statement = WCF::getDB()->prepareStatement($sql);
+ $statement = WCF::getDB()->prepare($sql);
$statement->execute([
$target->userID,
WCF::getUser()->userID,
$event->preload('wcf.user.language');
$event->preload('wcf.user.panel.settings');
$event->preload('wcf.user.panel.showAll');
+ $event->preload('wcf.user.button.follow');
+ $event->preload('wcf.user.button.unfollow');
}
}