components/app: make showNotification return null on error
We'll do more involved stuff with notifications soon, and don't want to deal with buggy notification objects.
This commit is contained in:
parent
bb42ff6a07
commit
7ddd783150
1 changed files with 25 additions and 21 deletions
|
@ -120,7 +120,7 @@ function fillConnectParams(params) {
|
||||||
|
|
||||||
function showNotification(title, options) {
|
function showNotification(title, options) {
|
||||||
if (!window.Notification || Notification.permission !== "granted") {
|
if (!window.Notification || Notification.permission !== "granted") {
|
||||||
return new EventTarget();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This can still fail due to:
|
// This can still fail due to:
|
||||||
|
@ -129,7 +129,7 @@ function showNotification(title, options) {
|
||||||
return new Notification(title, options);
|
return new Notification(title, options);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to show notification: ", err);
|
console.error("Failed to show notification: ", err);
|
||||||
return new EventTarget();
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -524,10 +524,12 @@ export default class App extends Component {
|
||||||
requireInteraction: true,
|
requireInteraction: true,
|
||||||
tag: "msg,server=" + serverID + ",from=" + msg.prefix.name + ",to=" + bufName,
|
tag: "msg,server=" + serverID + ",from=" + msg.prefix.name + ",to=" + bufName,
|
||||||
});
|
});
|
||||||
notif.addEventListener("click", () => {
|
if (notif) {
|
||||||
// TODO: scroll to message
|
notif.addEventListener("click", () => {
|
||||||
this.switchBuffer({ server: serverID, name: bufName });
|
// TODO: scroll to message
|
||||||
});
|
this.switchBuffer({ server: serverID, name: bufName });
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (msg.command === "INVITE" && client.isMyNick(msg.params[0])) {
|
if (msg.command === "INVITE" && client.isMyNick(msg.params[0])) {
|
||||||
|
@ -543,22 +545,24 @@ export default class App extends Component {
|
||||||
title: "Accept",
|
title: "Accept",
|
||||||
}],
|
}],
|
||||||
});
|
});
|
||||||
notif.addEventListener("click", (event) => {
|
if (notif) {
|
||||||
if (event.action === "accept") {
|
notif.addEventListener("click", (event) => {
|
||||||
let stored = {
|
if (event.action === "accept") {
|
||||||
name: bufName,
|
let stored = {
|
||||||
server: client.params,
|
name: bufName,
|
||||||
receipts: { [ReceiptType.READ]: receiptFromMessage(msg) },
|
server: client.params,
|
||||||
};
|
receipts: { [ReceiptType.READ]: receiptFromMessage(msg) },
|
||||||
if (this.bufferStore.put(stored)) {
|
};
|
||||||
this.sendReadReceipt(client, stored);
|
if (this.bufferStore.put(stored)) {
|
||||||
|
this.sendReadReceipt(client, stored);
|
||||||
|
}
|
||||||
|
this.open(channel, serverID);
|
||||||
|
} else {
|
||||||
|
// TODO: scroll to message
|
||||||
|
this.switchBuffer({ server: serverID, name: bufName });
|
||||||
}
|
}
|
||||||
this.open(channel, serverID);
|
});
|
||||||
} else {
|
}
|
||||||
// TODO: scroll to message
|
|
||||||
this.switchBuffer({ server: serverID, name: bufName });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open a new buffer if the message doesn't come from me or is a
|
// Open a new buffer if the message doesn't come from me or is a
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue