2 * User menu for notifications.
4 * @author Alexander Ebert
5 * @copyright 2001-2021 WoltLab GmbH
6 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7 * @woltlabExcludeBundle tiny
9 define(["require", "exports", "tslib", "WoltLabSuite/Core/Ajax", "WoltLabSuite/Core/Ui/User/Menu/View", "WoltLabSuite/Core/Ui/User/Menu/Manager"], function (require
, exports
, tslib_1
, Ajax_1
, View_1
, Manager_1
) {
11 Object
.defineProperty(exports
, "__esModule", { value
: true });
12 exports
.setup
= void 0;
13 View_1
= tslib_1
.__importDefault(View_1
);
14 class UserMenuDataConversation
{
20 constructor(button
, options
) {
22 this.options
= options
;
23 const badge
= button
.querySelector(".badge");
25 const counter
= parseInt(badge
.textContent
.trim());
27 this.counter
= counter
;
36 if (this.options
.canStartConversation
) {
38 icon
: '<fa-icon size="24" name="plus"></fa-icon>',
39 link
: this.options
.newConversationLink
,
40 name
: "newConversation",
41 title
: this.options
.newConversationTitle
,
47 return "com.woltlab.wcf.conversation.conversations";
50 const data
= (await (0, Ajax_1
.dboAction
)("getConversations", "wcf\\data\\conversation\\ConversationAction")
51 .disableLoadingIndicator()
53 this.updateCounter(data
.totalCount
);
59 link
: this.options
.showAllLink
,
60 title
: this.options
.showAllTitle
,
64 return this.options
.title
;
67 if (this.view
=== undefined) {
68 this.view
= new View_1
.default(this);
72 getEmptyViewMessage() {
73 return this.options
.noItems
;
79 return this.counter
> 0;
85 const unreadItems
= this.getView()
87 .filter((item
) => item
.dataset
.isUnread
=== "true");
88 if (this.counter
!== unreadItems
.length
) {
93 async
markAsRead(objectId
) {
94 const response
= (await (0, Ajax_1
.dboAction
)("markAsRead", "wcf\\data\\conversation\\ConversationAction")
95 .objectIds([objectId
])
97 this.updateCounter(response
.totalCount
);
99 async
markAllAsRead() {
100 await (0, Ajax_1
.dboAction
)("markAllAsRead", "wcf\\data\\conversation\\ConversationAction").dispatch();
101 this.updateCounter(0);
103 updateCounter(counter
) {
104 let badge
= this.button
.querySelector(".badge");
105 if (badge
=== null && counter
> 0) {
106 badge
= document
.createElement("span");
107 badge
.classList
.add("badge", "badgeUpdate");
108 this.button
.querySelector("a").append(badge
);
115 badge
.textContent
= counter
.toString();
118 this.counter
= counter
;
121 let isInitialized
= false;
122 function setup(options
) {
123 if (!isInitialized
) {
124 const button
= document
.getElementById("unreadConversations");
125 if (button
!== null) {
126 const provider
= new UserMenuDataConversation(button
, options
);
127 (0, Manager_1
.registerProvider
)(provider
);
129 isInitialized
= true;
132 exports
.setup
= setup
;