From 7c6f334dbfaf9fec41b9e1fbcbaa22a5bea29d09 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 11 Feb 2022 19:27:45 +0100 Subject: [PATCH] components/app: close notifications when switching buffer --- components/app.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/components/app.js b/components/app.js index 56a3d42..034a46a 100644 --- a/components/app.js +++ b/components/app.js @@ -201,6 +201,7 @@ export default class App extends Component { * confirmation for security reasons. */ autoOpenURL = null; + messageNotifications = new Set(); constructor(props) { super(props); @@ -450,8 +451,15 @@ export default class App extends Component { this.buffer.current.focus(); } + let client = this.clients.get(buf.server); + + for (let notif of this.messageNotifications) { + if (client.cm(notif.data.bufferName) === client.cm(buf.name)) { + notif.close(); + } + } + if (buf.messages.length > 0) { - let client = this.clients.get(buf.server); let lastMsg = buf.messages[buf.messages.length - 1]; let stored = { name: buf.name, @@ -523,12 +531,17 @@ export default class App extends Component { body: stripANSI(text), requireInteraction: true, tag: "msg,server=" + serverID + ",from=" + msg.prefix.name + ",to=" + bufName, + data: { bufferName: bufName, message: msg }, }); if (notif) { notif.addEventListener("click", () => { // TODO: scroll to message this.switchBuffer({ server: serverID, name: bufName }); }); + notif.addEventListener("close", () => { + this.messageNotifications.delete(notif); + }); + this.messageNotifications.add(notif); } } }