This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/plugins/chat/assets/javascripts/discourse/widgets/chat-header-icon.js
Joffrey JAFFEUX a51e5e1987
DEV: separates preferred-chat-mode service (#18883)
Also adds end to end system tests to ensure navigation scenarios are working correctly. This separation will make it easier to implement state in/out from chat.
2022-11-07 09:04:43 +01:00

84 lines
1.9 KiB
JavaScript

import getURL from "discourse-common/lib/get-url";
import { createWidget } from "discourse/widgets/widget";
import { h } from "virtual-dom";
import { iconNode } from "discourse-common/lib/icon-library";
export default createWidget("header-chat-link", {
buildKey: () => "header-chat-link",
chat: null,
tagName: "li.header-dropdown-toggle.open-chat",
title: "chat.title",
services: ["chat", "router", "chatPreferredMode", "fullPageChat"],
html() {
if (!this.chat.userCanChat) {
return;
}
if (this.currentUser.isInDoNotDisturb()) {
return this.chatLinkHtml();
}
let indicator;
if (this.chat.unreadUrgentCount) {
indicator = h(
"div.chat-channel-unread-indicator.urgent",
{},
h(
"div.number-wrap",
{},
h("div.number", {}, this.chat.unreadUrgentCount)
)
);
} else if (this.chat.hasUnreadMessages) {
indicator = h("div.chat-channel-unread-indicator");
}
return this.chatLinkHtml(indicator);
},
chatLinkHtml(indicatorNode) {
return h(
`a.icon${
this.fullPageChat.isActive || this.chat.chatOpen ? ".active" : ""
}`,
{ attributes: { tabindex: 0 } },
[iconNode("comment"), indicatorNode].filter(Boolean)
);
},
mouseUp(e) {
if (e.which === 2) {
// Middle mouse click
window.open(getURL("/chat"), "_blank").focus();
}
},
keyUp(e) {
if (e.code === "Enter") {
return this.click();
}
},
click() {
if (this.fullPageChat.isActive && !this.site.mobileView) {
return;
}
if (
this.chat.sidebarActive ||
this.site.mobileView ||
this.chatPreferredMode.isFullPage
) {
this.chatPreferredMode.setFullPage();
return this.router.transitionTo("chat");
} else {
this.appEvents.trigger("chat:toggle-open");
}
},
chatRerenderHeader() {
this.scheduleRerender();
},
});