From 72907a1f184864f514abec726a72d78328f6cb17 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Tue, 2 Feb 2021 01:52:09 +0100 Subject: [PATCH] Refactor and fix invitations -Move invitation handling into RoomPage and delete InvitationPage -Open the new room after accepting the invitation --- imports/NeoChat/Page/InvitationPage.qml | 50 ------------------------- imports/NeoChat/Page/RoomListPage.qml | 10 ++--- imports/NeoChat/Page/RoomPage.qml | 48 +++++++++++++++++++++++- qml/main.qml | 13 +------ res.qrc | 1 - src/neochatroom.cpp | 11 ++++++ src/neochatroom.h | 4 ++ 7 files changed, 66 insertions(+), 71 deletions(-) delete mode 100644 imports/NeoChat/Page/InvitationPage.qml diff --git a/imports/NeoChat/Page/InvitationPage.qml b/imports/NeoChat/Page/InvitationPage.qml deleted file mode 100644 index b119f3473..000000000 --- a/imports/NeoChat/Page/InvitationPage.qml +++ /dev/null @@ -1,50 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2019 Black Hat - * SPDX-FileCopyrightText: 2020 Carl Schwan - * - * SPDX-License-Identifier: GPL-3.0-only - */ -import QtQuick 2.12 -import QtQuick.Controls 2.12 -import org.kde.kirigami 2.14 as Kirigami -import QtQuick.Layouts 1.12 - -Kirigami.Page { - id: root - property var room - title: i18n("Invitation Received - %1", room.displayName) - - Kirigami.PlaceholderMessage { - anchors.centerIn: parent - text: i18n("Accept this invitation?") - RowLayout { - Button { - Layout.alignment : Qt.AlignHCenter - text: i18n("Cancel") - - onClicked: roomManager.getBack(); - } - - Button { - Layout.alignment : Qt.AlignHCenter - text: i18n("Reject") - - onClicked: { - room.forget() - roomManager.getBack(); - } - } - - Button { - Layout.alignment : Qt.AlignHCenter - text: i18n("Accept") - - onClicked: { - room.acceptInvitation(); - roomManager.enterRoom(room); - } - } - } - } -} - diff --git a/imports/NeoChat/Page/RoomListPage.qml b/imports/NeoChat/Page/RoomListPage.qml index 9a38a4263..4738b63a7 100644 --- a/imports/NeoChat/Page/RoomListPage.qml +++ b/imports/NeoChat/Page/RoomListPage.qml @@ -96,13 +96,9 @@ Kirigami.ScrollablePage { action: Kirigami.Action { id: enterRoomAction onTriggered: { - if (category === RoomType.Invited) { - roomManager.openInvitation(currentRoom); - } else { - var roomItem = roomManager.enterRoom(currentRoom) - roomListItem.KeyNavigation.right = roomItem - roomItem.focus = true; - } + var roomItem = roomManager.enterRoom(currentRoom) + roomListItem.KeyNavigation.right = roomItem + roomItem.focus = true; } } diff --git a/imports/NeoChat/Page/RoomPage.qml b/imports/NeoChat/Page/RoomPage.qml index 5352312f1..7b4095874 100644 --- a/imports/NeoChat/Page/RoomPage.qml +++ b/imports/NeoChat/Page/RoomPage.qml @@ -25,9 +25,20 @@ Kirigami.ScrollablePage { required property var currentRoom + title: currentRoom.displayName + signal switchRoomUp() signal switchRoomDown() + Connections { + target: Controller.activeConnection + function onJoinedRoom(room) { + if(room.id === invitation.id) { + roomManager.enterRoom(room); + } + } + } + Connections { target: roomManager.actionsHandler onShowMessage: { @@ -49,7 +60,38 @@ Kirigami.ScrollablePage { } } - title: currentRoom.displayName + Kirigami.PlaceholderMessage { + id: invitation + + property var id + + visible: currentRoom.isInvite + anchors.centerIn: parent + text: i18n("Accept this invitation?") + RowLayout { + QQC2.Button { + Layout.alignment : Qt.AlignHCenter + text: i18n("Reject") + + onClicked: { + page.currentRoom.forget() + roomManager.getBack(); + } + } + + QQC2.Button { + Layout.alignment : Qt.AlignHCenter + text: i18n("Accept") + + onClicked: { + currentRoom.acceptInvitation(); + invitation.id = currentRoom.id + invitation.visible = false + } + } + } + } + titleDelegate: Component { RowLayout { visible: !Kirigami.Settings.isMobile @@ -109,6 +151,8 @@ Kirigami.ScrollablePage { ListView { id: messageListView + visible: !invitation.visible + readonly property int largestVisibleIndex: count > 0 ? indexAt(contentX + (width / 2), contentY + height - 1) : -1 readonly property bool noNeedMoreContent: !currentRoom || currentRoom.eventsHistoryJob || currentRoom.allHistoryLoaded readonly property bool isLoaded: page.width * page.height > 10 @@ -577,6 +621,8 @@ Kirigami.ScrollablePage { footer: ChatTextInput { id: chatTextInput + + visible: !invitation.visible && !(messageListView.count === 0 && !currentRoom.allHistoryLoaded) Layout.fillWidth: true } diff --git a/qml/main.qml b/qml/main.qml index ebe7c4b40..c55dbe1ba 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -69,7 +69,6 @@ Kirigami.ApplicationWindow { property var currentRoom: null property alias pageStack: root.pageStack - property bool invitationOpen: false property var roomList: null property Item roomItem: null @@ -90,8 +89,7 @@ Kirigami.ApplicationWindow { } function enterRoom(room) { - let item = null; - if (currentRoom != null || invitationOpen) { + if (currentRoom != null) { roomItem.currentRoom = room; pageStack.currentIndex = pageStack.depth - 1; } else { @@ -104,15 +102,6 @@ Kirigami.ApplicationWindow { return roomItem; } - function openInvitation(room) { - if (currentRoom != null) { - currentRoom = null; - pageStack.removePage(pageStack.lastItem); - } - invitationOpen = true; - pageStack.push("qrc:/imports/NeoChat/Page/InvitationPage.qml", {"room": room}); - } - function getBack() { pageStack.replace(roomPage, { 'currentRoom': currentRoom, }); } diff --git a/res.qrc b/res.qrc index 34b1a1208..bbe5e7403 100644 --- a/res.qrc +++ b/res.qrc @@ -11,7 +11,6 @@ imports/NeoChat/Page/JoinRoomPage.qml imports/NeoChat/Page/InviteUserPage.qml imports/NeoChat/Page/SettingsPage.qml - imports/NeoChat/Page/InvitationPage.qml imports/NeoChat/Page/StartChatPage.qml imports/NeoChat/Page/ImageEditorPage.qml imports/NeoChat/Page/DevicesPage.qml diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index e9b7e3766..d921bef2e 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -75,6 +75,12 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS connect(this, &Room::aboutToAddHistoricalMessages, this, &NeoChatRoom::readMarkerLoadedChanged); connect(this, &Quotient::Room::eventsHistoryJobChanged, this, &NeoChatRoom::lastActiveTimeChanged); + + connect(this, &Room::joinStateChanged, this, [=](JoinState oldState, JoinState newState) { + if(oldState == JoinState::Invite && newState != JoinState::Invite) { + Q_EMIT isInviteChanged(); + } + }); } void NeoChatRoom::uploadFile(const QUrl &url, const QString &body) @@ -685,3 +691,8 @@ bool NeoChatRoom::readMarkerLoaded() const const auto it = findInTimeline(readMarkerEventId()); return it != timelineEdge(); } + +bool NeoChatRoom::isInvite() const +{ + return joinState() == JoinState::Invite; +} diff --git a/src/neochatroom.h b/src/neochatroom.h index 827d8f1b5..06b09e865 100644 --- a/src/neochatroom.h +++ b/src/neochatroom.h @@ -32,6 +32,7 @@ class NeoChatRoom : public Room Q_PROPERTY(QString avatarMediaId READ avatarMediaId NOTIFY avatarChanged STORED false) Q_PROPERTY(bool readMarkerLoaded READ readMarkerLoaded NOTIFY readMarkerLoadedChanged) Q_PROPERTY(QDateTime lastActiveTime READ lastActiveTime NOTIFY lastActiveTimeChanged) + Q_PROPERTY(bool isInvite READ isInvite NOTIFY isInviteChanged) public: explicit NeoChatRoom(Connection *connection, QString roomId, JoinState joinState = {}); @@ -102,6 +103,8 @@ public: Q_INVOKABLE [[nodiscard]] bool canSendEvent(const QString &eventType) const; Q_INVOKABLE [[nodiscard]] bool canSendState(const QString &eventType) const; + bool isInvite() const; + private: QString m_cachedInput; QSet highlights; @@ -128,6 +131,7 @@ Q_SIGNALS: void backgroundChanged(); void readMarkerLoadedChanged(); void lastActiveTimeChanged(); + void isInviteChanged(); public Q_SLOTS: void uploadFile(const QUrl &url, const QString &body = QString());