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:
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -96,13 +96,9 @@ Kirigami.ScrollablePage {
|
|||||||
action: Kirigami.Action {
|
action: Kirigami.Action {
|
||||||
id: enterRoomAction
|
id: enterRoomAction
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
if (category === RoomType.Invited) {
|
var roomItem = roomManager.enterRoom(currentRoom)
|
||||||
roomManager.openInvitation(currentRoom);
|
roomListItem.KeyNavigation.right = roomItem
|
||||||
} else {
|
roomItem.focus = true;
|
||||||
var roomItem = roomManager.enterRoom(currentRoom)
|
|
||||||
roomListItem.KeyNavigation.right = roomItem
|
|
||||||
roomItem.focus = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,9 +25,20 @@ Kirigami.ScrollablePage {
|
|||||||
|
|
||||||
required property var currentRoom
|
required property var currentRoom
|
||||||
|
|
||||||
|
title: currentRoom.displayName
|
||||||
|
|
||||||
signal switchRoomUp()
|
signal switchRoomUp()
|
||||||
signal switchRoomDown()
|
signal switchRoomDown()
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: Controller.activeConnection
|
||||||
|
function onJoinedRoom(room) {
|
||||||
|
if(room.id === invitation.id) {
|
||||||
|
roomManager.enterRoom(room);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: roomManager.actionsHandler
|
target: roomManager.actionsHandler
|
||||||
onShowMessage: {
|
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 {
|
titleDelegate: Component {
|
||||||
RowLayout {
|
RowLayout {
|
||||||
visible: !Kirigami.Settings.isMobile
|
visible: !Kirigami.Settings.isMobile
|
||||||
@@ -109,6 +151,8 @@ Kirigami.ScrollablePage {
|
|||||||
ListView {
|
ListView {
|
||||||
id: messageListView
|
id: messageListView
|
||||||
|
|
||||||
|
visible: !invitation.visible
|
||||||
|
|
||||||
readonly property int largestVisibleIndex: count > 0 ? indexAt(contentX + (width / 2), contentY + height - 1) : -1
|
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 noNeedMoreContent: !currentRoom || currentRoom.eventsHistoryJob || currentRoom.allHistoryLoaded
|
||||||
readonly property bool isLoaded: page.width * page.height > 10
|
readonly property bool isLoaded: page.width * page.height > 10
|
||||||
@@ -577,6 +621,8 @@ Kirigami.ScrollablePage {
|
|||||||
|
|
||||||
footer: ChatTextInput {
|
footer: ChatTextInput {
|
||||||
id: chatTextInput
|
id: chatTextInput
|
||||||
|
|
||||||
|
visible: !invitation.visible && !(messageListView.count === 0 && !currentRoom.allHistoryLoaded)
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
qml/main.qml
13
qml/main.qml
@@ -69,7 +69,6 @@ Kirigami.ApplicationWindow {
|
|||||||
|
|
||||||
property var currentRoom: null
|
property var currentRoom: null
|
||||||
property alias pageStack: root.pageStack
|
property alias pageStack: root.pageStack
|
||||||
property bool invitationOpen: false
|
|
||||||
property var roomList: null
|
property var roomList: null
|
||||||
property Item roomItem: null
|
property Item roomItem: null
|
||||||
|
|
||||||
@@ -90,8 +89,7 @@ Kirigami.ApplicationWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function enterRoom(room) {
|
function enterRoom(room) {
|
||||||
let item = null;
|
if (currentRoom != null) {
|
||||||
if (currentRoom != null || invitationOpen) {
|
|
||||||
roomItem.currentRoom = room;
|
roomItem.currentRoom = room;
|
||||||
pageStack.currentIndex = pageStack.depth - 1;
|
pageStack.currentIndex = pageStack.depth - 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -104,15 +102,6 @@ Kirigami.ApplicationWindow {
|
|||||||
return roomItem;
|
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() {
|
function getBack() {
|
||||||
pageStack.replace(roomPage, { 'currentRoom': currentRoom, });
|
pageStack.replace(roomPage, { 'currentRoom': currentRoom, });
|
||||||
}
|
}
|
||||||
|
|||||||
1
res.qrc
1
res.qrc
@@ -11,7 +11,6 @@
|
|||||||
<file>imports/NeoChat/Page/JoinRoomPage.qml</file>
|
<file>imports/NeoChat/Page/JoinRoomPage.qml</file>
|
||||||
<file>imports/NeoChat/Page/InviteUserPage.qml</file>
|
<file>imports/NeoChat/Page/InviteUserPage.qml</file>
|
||||||
<file>imports/NeoChat/Page/SettingsPage.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/StartChatPage.qml</file>
|
||||||
<file>imports/NeoChat/Page/ImageEditorPage.qml</file>
|
<file>imports/NeoChat/Page/ImageEditorPage.qml</file>
|
||||||
<file>imports/NeoChat/Page/DevicesPage.qml</file>
|
<file>imports/NeoChat/Page/DevicesPage.qml</file>
|
||||||
|
|||||||
@@ -75,6 +75,12 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
|
|||||||
connect(this, &Room::aboutToAddHistoricalMessages, this, &NeoChatRoom::readMarkerLoadedChanged);
|
connect(this, &Room::aboutToAddHistoricalMessages, this, &NeoChatRoom::readMarkerLoadedChanged);
|
||||||
|
|
||||||
connect(this, &Quotient::Room::eventsHistoryJobChanged, this, &NeoChatRoom::lastActiveTimeChanged);
|
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)
|
void NeoChatRoom::uploadFile(const QUrl &url, const QString &body)
|
||||||
@@ -685,3 +691,8 @@ bool NeoChatRoom::readMarkerLoaded() const
|
|||||||
const auto it = findInTimeline(readMarkerEventId());
|
const auto it = findInTimeline(readMarkerEventId());
|
||||||
return it != timelineEdge();
|
return it != timelineEdge();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NeoChatRoom::isInvite() const
|
||||||
|
{
|
||||||
|
return joinState() == JoinState::Invite;
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class NeoChatRoom : public Room
|
|||||||
Q_PROPERTY(QString avatarMediaId READ avatarMediaId NOTIFY avatarChanged STORED false)
|
Q_PROPERTY(QString avatarMediaId READ avatarMediaId NOTIFY avatarChanged STORED false)
|
||||||
Q_PROPERTY(bool readMarkerLoaded READ readMarkerLoaded NOTIFY readMarkerLoadedChanged)
|
Q_PROPERTY(bool readMarkerLoaded READ readMarkerLoaded NOTIFY readMarkerLoadedChanged)
|
||||||
Q_PROPERTY(QDateTime lastActiveTime READ lastActiveTime NOTIFY lastActiveTimeChanged)
|
Q_PROPERTY(QDateTime lastActiveTime READ lastActiveTime NOTIFY lastActiveTimeChanged)
|
||||||
|
Q_PROPERTY(bool isInvite READ isInvite NOTIFY isInviteChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit NeoChatRoom(Connection *connection, QString roomId, JoinState joinState = {});
|
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 canSendEvent(const QString &eventType) const;
|
||||||
Q_INVOKABLE [[nodiscard]] bool canSendState(const QString &eventType) const;
|
Q_INVOKABLE [[nodiscard]] bool canSendState(const QString &eventType) const;
|
||||||
|
|
||||||
|
bool isInvite() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_cachedInput;
|
QString m_cachedInput;
|
||||||
QSet<const Quotient::RoomEvent *> highlights;
|
QSet<const Quotient::RoomEvent *> highlights;
|
||||||
@@ -128,6 +131,7 @@ Q_SIGNALS:
|
|||||||
void backgroundChanged();
|
void backgroundChanged();
|
||||||
void readMarkerLoadedChanged();
|
void readMarkerLoadedChanged();
|
||||||
void lastActiveTimeChanged();
|
void lastActiveTimeChanged();
|
||||||
|
void isInviteChanged();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void uploadFile(const QUrl &url, const QString &body = QString());
|
void uploadFile(const QUrl &url, const QString &body = QString());
|
||||||
|
|||||||
Reference in New Issue
Block a user