Don't accidentally hide relevant error banners

We use error banners for intermittent errors (failing to join a room),
along with more long-standing/important errors (like going offline.) And
due to the nature of how we manage banner visibility - for example, the
online check could accidentally hide joining rooms errors which is
pretty bad.

To fix this, each error banner is assigned an id. All errors can still
overwrite each other as they could before, but they can only hide
banners of their own kind.
This commit is contained in:
Joshua Goins
2025-09-02 19:06:43 -04:00
parent e5df412258
commit ce0014f846

View File

@@ -79,9 +79,9 @@ Kirigami.Page {
if (root.currentRoom.tagNames.includes("m.server_notice")) { if (root.currentRoom.tagNames.includes("m.server_notice")) {
banner.text = i18nc("@info", "This room contains official messages from your homeserver.") banner.text = i18nc("@info", "This room contains official messages from your homeserver.")
banner.visible = true; banner.show("message");
} else { } else {
banner.visible = false; banner.hideIf("message");
} }
} }
@@ -90,10 +90,10 @@ Kirigami.Page {
function onIsOnlineChanged() { function onIsOnlineChanged() {
if (!root.currentRoom.connection.isOnline) { if (!root.currentRoom.connection.isOnline) {
banner.text = i18nc("@info:status", "NeoChat is offline. Please check your network connection."); banner.text = i18nc("@info:status", "NeoChat is offline. Please check your network connection.");
banner.visible = true;
banner.type = Kirigami.MessageType.Error; banner.type = Kirigami.MessageType.Error;
banner.show("offline");
} else { } else {
banner.visible = false; banner.hideIf("offline");
} }
} }
} }
@@ -101,9 +101,23 @@ Kirigami.Page {
header: Kirigami.InlineMessage { header: Kirigami.InlineMessage {
id: banner id: banner
// Used to keep track of messages so we can hide the right one at the right time
property string messageId
showCloseButton: true showCloseButton: true
visible: false visible: false
position: Kirigami.InlineMessage.Position.Header position: Kirigami.InlineMessage.Position.Header
function show(msgid: string): void {
messageId = msgid;
visible = true;
}
function hideIf(msgid: string): void {
if (messageId == msgid) {
visible = false;
}
}
} }
Loader { Loader {
@@ -204,7 +218,7 @@ Kirigami.Page {
function onShowMessage(messageType, message) { function onShowMessage(messageType, message) {
banner.text = message; banner.text = message;
banner.type = messageType; banner.type = messageType;
banner.visible = true; banner.show("generic");
} }
function onShowEventSource(eventId) { function onShowEventSource(eventId) {