diff --git a/src/config/settings.py b/src/config/settings.py index d1c7f894..e0d67c09 100644 --- a/src/config/settings.py +++ b/src/config/settings.py @@ -390,10 +390,9 @@ class Keys: # Can also be done by clicking on current tab button at the top right. hide_room_pane = ["Alt+Ctrl+R"] - # Invite new members, leave or forget the current chat. + # Invite new members or leave the current chat. invite = ["Alt+I"] leave = ["Alt+Escape"] - forget = ["Alt+Shift+Escape"] # Open the file picker to upload files in the current chat. send_file = ["Alt+S"] diff --git a/src/gui/MainPane/RoomDelegate.qml b/src/gui/MainPane/RoomDelegate.qml index 9488b61e..2d327fa6 100644 --- a/src/gui/MainPane/RoomDelegate.qml +++ b/src/gui/MainPane/RoomDelegate.qml @@ -227,11 +227,17 @@ HTile { } HMenuItemPopupSpawner { - visible: invited || joined - icon.name: invited ? "invite-decline" : "room-leave" - icon.color: theme.colors.negativeBackground - text: invited ? qsTr("Decline invite") : qsTr("Leave") enabled: accountModel.presence !== "offline" + icon.color: theme.colors.negativeBackground + icon.name: + parted ? "room-forget" : + invited ? "invite-decline" : + "room-leave" + + text: + parted ? qsTr("Forget history") : + invited ? qsTr("Decline invite") : + qsTr("Leave") popup: "Popups/LeaveRoomPopup.qml" properties: ({ @@ -239,21 +245,7 @@ HTile { roomId: model.id, roomName: model.display_name, inviterId: model.inviter_id, - }) - } - - HMenuItemPopupSpawner { - icon.name: "room-forget" - icon.color: theme.colors.negativeBackground - text: qsTr("Forget") - enabled: accountModel.presence !== "offline" - - popup: "Popups/ForgetRoomPopup.qml" - autoDestruct: false - properties: ({ - userId: model.for_account, - roomId: model.id, - roomName: model.display_name, + left: model.left, }) } } diff --git a/src/gui/Pages/Chat/Banners/LeftBanner.qml b/src/gui/Pages/Chat/Banners/LeftBanner.qml index 76289bf0..0949d221 100644 --- a/src/gui/Pages/Chat/Banners/LeftBanner.qml +++ b/src/gui/Pages/Chat/Banners/LeftBanner.qml @@ -25,11 +25,13 @@ Banner { buttonCallbacks: ({ forget: button => { window.makePopup( - "Popups/ForgetRoomPopup.qml", + "Popups/LeaveRoomPopup.qml", { - userId: chat.userId, - roomId: chat.roomId, - roomName: chat.roomInfo.display_name, + userId: chat.userId, + roomId: chat.roomId, + roomName: chat.roomInfo.display_name, + inviterId: chat.roomInfo.inviter_id, + left: true, }, obj => { obj.onOk.connect(() => { button.loading = true }) // FIXME diff --git a/src/gui/Pages/Chat/Chat.qml b/src/gui/Pages/Chat/Chat.qml index 7f71f453..5226187e 100644 --- a/src/gui/Pages/Chat/Chat.qml +++ b/src/gui/Pages/Chat/Chat.qml @@ -59,19 +59,11 @@ Item { roomId, roomName: roomInfo.display_name, inviterId: roomInfo.inviter_id, + left: roomInfo.left, }, ) } - HShortcut { - sequences: window.settings.Keys.Chat.forget - active: userInfo && userInfo.presence !== "offline" - onActivated: window.makePopup( - "Popups/ForgetRoomPopup.qml", - {userId, roomId, roomName: roomInfo.display_name}, - ) - } - Timer { interval: 300 running: ! ready diff --git a/src/gui/Popups/ForgetRoomPopup.qml b/src/gui/Popups/ForgetRoomPopup.qml deleted file mode 100644 index 1f085def..00000000 --- a/src/gui/Popups/ForgetRoomPopup.qml +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright Mirage authors & contributors -// SPDX-License-Identifier: LGPL-3.0-or-later - -import QtQuick 2.12 -import "../Base" -import "../Base/Buttons" - -HFlickableColumnPopup { - id: popup - - property string userId: "" - property string roomId: "" - property string roomName: "" - - property bool canDestroy: false - - function forget() { - py.callClientCoro(userId, "room_forget", [roomId], () => { - if (window.uiState.page === "Pages/Chat/Chat.qml" && - window.uiState.pageProperties.userRoomId[0] === userId && - window.uiState.pageProperties.userRoomId[1] === roomId) - { - window.mainUI.pageLoader.showPrevious() || - window.mainUI.pageLoader.show("Pages/Default.qml") - - Qt.callLater(popup.destroy) - } - }) - } - - page.footer: AutoDirectionLayout { - ApplyButton { - id: forgetButton - text: qsTr("Forget") - icon.name: "room-forget" - onClicked: forget() - } - - CancelButton { - onClicked: { - canDestroy = true - popup.close() - } - } - } - - onOpened: forgetButton.forceActiveFocus() - onClosed: if (canDestroy) Qt.callLater(popup.destroy) - - SummaryLabel { - text: qsTr("Leave %1 and lose the history?").arg( - utils.htmlColorize(roomName, theme.colors.accentText), - ) - textFormat: Text.StyledText - } - - DetailsLabel { - text: qsTr( - "You will not be able to see the messages you received in " + - "this room anymore.\n\n" + - - "If all members forget the room, it will be removed from the " + - "servers." - ) - } -} diff --git a/src/gui/Popups/LeaveRoomPopup.qml b/src/gui/Popups/LeaveRoomPopup.qml index 35a83421..07df78e3 100644 --- a/src/gui/Popups/LeaveRoomPopup.qml +++ b/src/gui/Popups/LeaveRoomPopup.qml @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-or-later import QtQuick 2.12 +import QtQuick.Layouts 1.12 import "../Base" import "../Base/Buttons" @@ -12,18 +13,40 @@ HFlickableColumnPopup { property string roomId: "" property string roomName: "" property string inviterId: "" - property var leftCallback: null + property bool left: false + + function forget() { + py.callClientCoro(userId, "room_forget", [roomId], () => { + if (window.uiState.page === "Pages/Chat/Chat.qml" && + window.uiState.pageProperties.userRoomId[0] === userId && + window.uiState.pageProperties.userRoomId[1] === roomId) + { + window.mainUI.pageLoader.showPrevious() || + window.mainUI.pageLoader.show("Pages/Default.qml") + + Qt.callLater(popup.destroy) + } + }) + } + + function leave() { + py.callClientCoro(userId, "room_leave", [roomId]) + popup.close() + } page.footer: AutoDirectionLayout { ApplyButton { id: leaveButton - icon.name: "room-leave" - text: inviterId ? qsTr("Decline") : qsTr("Leave") + icon.name: popup.left ? "room-forget" : "room-leave" + text: + popup.left ? qsTr("Forget") : + popup.inviterId ? qsTr("Decline") : + qsTr("Leave") - onClicked: { - py.callClientCoro(userId, "room_leave", [roomId], leftCallback) - popup.close() - } + onClicked: + forgetCheck.checked || popup.left ? + popup.forget() : + popup.leave() } CancelButton { @@ -35,19 +58,34 @@ HFlickableColumnPopup { SummaryLabel { readonly property string roomText: - utils.htmlColorize(roomName, theme.colors.accentText) + utils.htmlColorize(popup.roomName, theme.colors.accentText) textFormat: Text.StyledText text: - inviterId ? - qsTr("Decline invite to %1?").arg(roomText) : + popup.left ? qsTr("Forget the history for %1?").arg(roomText) : + popup.inviterId ? qsTr("Decline invite to %1?").arg(roomText) : qsTr("Leave %1?").arg(roomText) } DetailsLabel { - visible: inviterId === "" - text: qsTr( - "If this room is private, you will not be able to rejoin it." + text: + popup.left ? + forgetCheck.subtitle.text : + qsTr( + "If this room is private, you will not be able to rejoin it " + + "without a new invite." + ) + } + + HCheckBox { + id: forgetCheck + visible: ! popup.left + text: qsTr("Forget this room's history") + subtitle.text: qsTr( + "You will lose access to any previously received messages.\n" + + "If all members forget a room, servers will erase it." ) + + Layout.fillWidth: true } }