Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Marks all user notifications as read.
*
* @author Olaf Braun
* @copyright 2001-2025 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.3
* @woltlabExcludeBundle tiny
*/

import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
import { fromInfallibleApiRequest } from "WoltLabSuite/Core/Api/Result";

export async function markAllUserNotificationsAsRead(): Promise<[]> {
return fromInfallibleApiRequest(() => {
return prepareRequest(`${window.WSC_RPC_API_URL}core/users/notifications/mark-all-as-read`).post().fetchAsJson();
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Marks a user notification as read.
*
* @author Olaf Braun
* @copyright 2001-2025 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.3
* @woltlabExcludeBundle tiny
*/

import { fromInfallibleApiRequest } from "WoltLabSuite/Core/Api/Result";
import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";

type Response = {
unreadNotifications: number;
};

export async function markUserNotificationAsRead(notificationId: number): Promise<Response> {
return fromInfallibleApiRequest(() => {
return prepareRequest(`${window.WSC_RPC_API_URL}core/users/notifications/${notificationId}/mark-as-read`)
.post()
.fetchAsJson();
});
}
9 changes: 4 additions & 5 deletions ts/WoltLabSuite/Core/Controller/User/Notification/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
* @woltlabExcludeBundle tiny
*/

import { dboAction } from "WoltLabSuite/Core/Ajax";
import { confirmationFactory } from "WoltLabSuite/Core/Component/Confirmation";
import { showDefaultSuccessSnackbar } from "WoltLabSuite/Core/Component/Snackbar";
import { promiseMutex } from "WoltLabSuite/Core/Helper/PromiseMutex";
import { getPhrase } from "WoltLabSuite/Core/Language";
import { markAllUserNotificationsAsRead } from "WoltLabSuite/Core/Api/Users/Notifications/MarkAllUserNotificationsAsRead";
import { markUserNotificationAsRead } from "WoltLabSuite/Core/Api/Users/Notifications/MarkUserNotificationAsRead";

function initMarkAllAsRead(): void {
document.querySelector(".jsMarkAllAsConfirmed")?.addEventListener(
Expand All @@ -29,7 +30,7 @@ async function markAllAsRead(): Promise<void> {
return;
}

await dboAction("markAllAsConfirmed", "wcf\\data\\user\\notification\\UserNotificationAction").dispatch();
await markAllUserNotificationsAsRead();

showDefaultSuccessSnackbar().addEventListener("snackbar:close", () => {
window.location.reload();
Expand All @@ -46,9 +47,7 @@ function initMarkAsRead(): void {
}

async function markAsRead(element: HTMLElement): Promise<void> {
await dboAction("markAsConfirmed", "wcf\\data\\user\\notification\\UserNotificationAction")
.objectIds([parseInt(element.dataset.objectId!)])
.dispatch();
await markUserNotificationAsRead(parseInt(element.dataset.objectId!, 10));

element.querySelector(".notificationListItem__unread")?.remove();
element.dataset.isRead = "true";
Expand Down
15 changes: 5 additions & 10 deletions ts/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { registerProvider } from "../Manager";
import * as Language from "../../../../Language";
import { enableNotifications } from "../../../../Notification/Handler";
import { registerServiceWorker, updateNotificationLastReadTime } from "../../../../Notification/ServiceWorker";
import { markUserNotificationAsRead } from "WoltLabSuite/Core/Api/Users/Notifications/MarkUserNotificationAsRead";
import { markAllUserNotificationsAsRead } from "WoltLabSuite/Core/Api/Users/Notifications/MarkAllUserNotificationsAsRead";

let originalFavicon = "";
function setFaviconCounter(counter: number): void {
Expand Down Expand Up @@ -128,11 +130,6 @@ type ResponseGetData = {
totalCount: number;
};

type ResponseMarkAsRead = {
markAsRead: number;
totalCount: number;
};

class UserMenuDataNotification implements DesktopNotifications, UserMenuProvider {
private readonly button: HTMLElement;
private readonly options: Options;
Expand Down Expand Up @@ -277,16 +274,14 @@ class UserMenuDataNotification implements DesktopNotifications, UserMenuProvider
}

async markAsRead(objectId: number): Promise<void> {
const response = (await dboAction("markAsConfirmed", "wcf\\data\\user\\notification\\UserNotificationAction")
.objectIds([objectId])
.dispatch()) as ResponseMarkAsRead;
const { unreadNotifications } = await markUserNotificationAsRead(objectId);
updateNotificationLastReadTime();

this.updateCounter(response.totalCount);
this.updateCounter(unreadNotifications);
}

async markAllAsRead(): Promise<void> {
await dboAction("markAllAsConfirmed", "wcf\\data\\user\\notification\\UserNotificationAction").dispatch();
await markAllUserNotificationsAsRead();
updateNotificationLastReadTime();

this.updateCounter(0);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions wcfsetup/install/files/lib/bootstrap/com.woltlab.wcf.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ static function (\wcf\event\endpoint\ControllerCollecting $event) {
$event->register(new \wcf\system\endpoint\controller\core\users\groups\assignment\EnableAssignment());
$event->register(new \wcf\system\endpoint\controller\core\users\groups\assignment\DisableAssignment());
$event->register(new \wcf\system\endpoint\controller\core\users\groups\DeleteGroup());
$event->register(new \wcf\system\endpoint\controller\core\users\notifications\MarkUserNotificationAsRead());
$event->register(new \wcf\system\endpoint\controller\core\users\notifications\MarkAllUserNotificationsAsRead());
$event->register(new \wcf\system\endpoint\controller\core\menus\DeleteMenu());
$event->register(new \wcf\system\endpoint\controller\core\trophies\EnableTrophy());
$event->register(new \wcf\system\endpoint\controller\core\trophies\DisableTrophy());
Expand Down
Loading