Refactor and fix invitations

-Move invitation handling into RoomPage and delete InvitationPage
-Open the new room after accepting the invitation
This commit is contained in:
Tobias Fella
2021-02-02 01:52:09 +01:00
parent 465334e23f
commit 72907a1f18
7 changed files with 66 additions and 71 deletions

View File

@@ -1,50 +0,0 @@
/**
* SPDX-FileCopyrightText: 2019 Black Hat <bhat@encom.eu.org>
* SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
*
* 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);
}
}
}
}
}

View File

@@ -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;
}
}

View File

@@ -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
}

View File

@@ -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, });
}

View File

@@ -11,7 +11,6 @@
<file>imports/NeoChat/Page/JoinRoomPage.qml</file>
<file>imports/NeoChat/Page/InviteUserPage.qml</file>
<file>imports/NeoChat/Page/SettingsPage.qml</file>
<file>imports/NeoChat/Page/InvitationPage.qml</file>
<file>imports/NeoChat/Page/StartChatPage.qml</file>
<file>imports/NeoChat/Page/ImageEditorPage.qml</file>
<file>imports/NeoChat/Page/DevicesPage.qml</file>

View File

@@ -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;
}

View File

@@ -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<const Quotient::RoomEvent *> 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());