From: Alexander Ebert Date: Thu, 30 Jun 2022 17:18:49 +0000 (+0200) Subject: Update the unread badge using the server-side data X-Git-Tag: 5.5.0_RC_3~4 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=05e725ccf48c3781ae7bb5fb1a531c0da05d428e;p=GitHub%2FWoltLab%2Fcom.woltlab.wcf.conversation.git Update the unread badge using the server-side data The previous implementation relied on the number of unread items currently visible in the user menu. This caused an incorrect number shown for >10 unread items. Notice: This is a last-minute API change to report the correct number from the server-side. See WoltLab/WCF#4886 --- diff --git a/files/js/WoltLabSuite/Core/Conversation/Ui/User/Menu/Data/Conversation.js b/files/js/WoltLabSuite/Core/Conversation/Ui/User/Menu/Data/Conversation.js index d20e0e4..75e79ac 100644 --- a/files/js/WoltLabSuite/Core/Conversation/Ui/User/Menu/Data/Conversation.js +++ b/files/js/WoltLabSuite/Core/Conversation/Ui/User/Menu/Data/Conversation.js @@ -49,10 +49,9 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Ajax", "WoltLabSuite/C const data = (await (0, Ajax_1.dboAction)("getConversations", "wcf\\data\\conversation\\ConversationAction") .disableLoadingIndicator() .dispatch()); - const counter = data.filter((item) => item.isUnread).length; - this.updateCounter(counter); + this.updateCounter(data.totalCount); this.stale = false; - return data; + return data.items; } getFooter() { return { diff --git a/files/lib/data/conversation/ConversationAction.class.php b/files/lib/data/conversation/ConversationAction.class.php index 428c592..a4a163f 100644 --- a/files/lib/data/conversation/ConversationAction.class.php +++ b/files/lib/data/conversation/ConversationAction.class.php @@ -906,7 +906,7 @@ class ConversationAction extends AbstractDatabaseObjectAction implements UserStorageHandler::getInstance()->reset([WCF::getUser()->userID], 'unreadConversationCount'); } - return \array_map(static function (ViewableConversation $conversation) { + $conversations = \array_map(static function (ViewableConversation $conversation) { if ($conversation->userID === WCF::getUser()->userID) { if ($conversation->participants > 1) { $image = ''; @@ -945,6 +945,11 @@ class ConversationAction extends AbstractDatabaseObjectAction implements 'usernames' => $usernames, ]; }, $conversations); + + return [ + 'items' => $conversations, + 'totalCount' => $totalCount, + ]; } /** diff --git a/ts/WoltLabSuite/Core/Conversation/Ui/User/Menu/Data/Conversation.ts b/ts/WoltLabSuite/Core/Conversation/Ui/User/Menu/Data/Conversation.ts index 29e6595..60ce55a 100644 --- a/ts/WoltLabSuite/Core/Conversation/Ui/User/Menu/Data/Conversation.ts +++ b/ts/WoltLabSuite/Core/Conversation/Ui/User/Menu/Data/Conversation.ts @@ -28,6 +28,11 @@ type Options = { title: string; }; +type ResponseGetData = { + items: UserMenuData[]; + totalCount: number; +}; + type ResponseMarkAsRead = { markAsRead: number; totalCount: number; @@ -78,14 +83,13 @@ class UserMenuDataConversation implements UserMenuProvider { async getData(): Promise { const data = (await dboAction("getConversations", "wcf\\data\\conversation\\ConversationAction") .disableLoadingIndicator() - .dispatch()) as UserMenuData[]; + .dispatch()) as ResponseGetData; - const counter = data.filter((item) => item.isUnread).length; - this.updateCounter(counter); + this.updateCounter(data.totalCount); this.stale = false; - return data; + return data.items; } getFooter(): UserMenuFooter | null {