mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-29 06:08:48 +03:00
Redesign invites and room preview joins
This commit is contained in:
parent
c318adbf21
commit
2f08f5181c
9 changed files with 214 additions and 82 deletions
|
@ -79,6 +79,7 @@ Rectangle {
|
||||||
|
|
||||||
showBackButton: adaptiveView.singlePageMode
|
showBackButton: adaptiveView.singlePageMode
|
||||||
room: Rooms.currentRoom
|
room: Rooms.currentRoom
|
||||||
|
roomPreview: Rooms.currentRoomPreview.roomid ? Rooms.currentRoomPreview : null
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,7 +121,7 @@ Page {
|
||||||
states: [
|
states: [
|
||||||
State {
|
State {
|
||||||
name: "highlight"
|
name: "highlight"
|
||||||
when: hovered.hovered && !(Rooms.currentRoom && model.roomId == Rooms.currentRoom.roomId())
|
when: hovered.hovered && !((Rooms.currentRoom && model.roomId == Rooms.currentRoom.roomId()) || Rooms.currentRoomPreview.roomid == model.roomId)
|
||||||
|
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: roomItem
|
target: roomItem
|
||||||
|
@ -135,7 +135,7 @@ Page {
|
||||||
},
|
},
|
||||||
State {
|
State {
|
||||||
name: "selected"
|
name: "selected"
|
||||||
when: Rooms.currentRoom && model.roomId == Rooms.currentRoom.roomId()
|
when: (Rooms.currentRoom && model.roomId == Rooms.currentRoom.roomId()) || Rooms.currentRoomPreview.roomid == model.roomId
|
||||||
|
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: roomItem
|
target: roomItem
|
||||||
|
@ -268,7 +268,7 @@ Page {
|
||||||
RowLayout {
|
RowLayout {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
spacing: 0
|
spacing: 0
|
||||||
visible: !model.isInvite && !model.isSpace
|
visible: !model.isSpace
|
||||||
height: visible ? 0 : undefined
|
height: visible ? 0 : undefined
|
||||||
|
|
||||||
ElidedLabel {
|
ElidedLabel {
|
||||||
|
@ -310,60 +310,6 @@ Page {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RowLayout {
|
|
||||||
Layout.fillWidth: true
|
|
||||||
spacing: Nheko.paddingMedium
|
|
||||||
visible: model.isInvite
|
|
||||||
enabled: visible
|
|
||||||
height: visible ? 0 : undefined
|
|
||||||
|
|
||||||
ElidedLabel {
|
|
||||||
elideWidth: textContent.width / 2 - 2 * Nheko.paddingMedium
|
|
||||||
fullText: qsTr("Accept")
|
|
||||||
horizontalAlignment: Text.AlignHCenter
|
|
||||||
verticalAlignment: Text.AlignVCenter
|
|
||||||
leftPadding: Nheko.paddingMedium
|
|
||||||
rightPadding: Nheko.paddingMedium
|
|
||||||
color: Nheko.colors.brightText
|
|
||||||
|
|
||||||
TapHandler {
|
|
||||||
onSingleTapped: Rooms.acceptInvite(model.roomId)
|
|
||||||
}
|
|
||||||
|
|
||||||
background: Rectangle {
|
|
||||||
color: Nheko.theme.alternateButton
|
|
||||||
radius: height / 2
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ElidedLabel {
|
|
||||||
Layout.alignment: Qt.AlignRight
|
|
||||||
elideWidth: textContent.width / 2 - 2 * Nheko.paddingMedium
|
|
||||||
fullText: qsTr("Decline")
|
|
||||||
horizontalAlignment: Text.AlignHCenter
|
|
||||||
verticalAlignment: Text.AlignVCenter
|
|
||||||
leftPadding: Nheko.paddingMedium
|
|
||||||
rightPadding: Nheko.paddingMedium
|
|
||||||
color: Nheko.colors.brightText
|
|
||||||
|
|
||||||
TapHandler {
|
|
||||||
onSingleTapped: Rooms.declineInvite(model.roomId)
|
|
||||||
}
|
|
||||||
|
|
||||||
background: Rectangle {
|
|
||||||
color: Nheko.theme.alternateButton
|
|
||||||
radius: height / 2
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Item {
|
|
||||||
Layout.fillWidth: true
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,9 +117,11 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrollView {
|
ScrollView {
|
||||||
Layout.maximumHeight: 75
|
Layout.fillHeight: true
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
width: parent.width
|
Layout.fillWidth: true
|
||||||
|
Layout.leftMargin: Nheko.paddingLarge
|
||||||
|
Layout.rightMargin: Nheko.paddingLarge
|
||||||
|
|
||||||
TextArea {
|
TextArea {
|
||||||
text: TimelineManager.escapeEmoji(roomSettings.roomTopic)
|
text: TimelineManager.escapeEmoji(roomSettings.roomTopic)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
import "./components"
|
||||||
import "./delegates"
|
import "./delegates"
|
||||||
import "./device-verification"
|
import "./device-verification"
|
||||||
import "./emoji"
|
import "./emoji"
|
||||||
|
@ -21,10 +22,11 @@ Item {
|
||||||
id: timelineView
|
id: timelineView
|
||||||
|
|
||||||
property var room: null
|
property var room: null
|
||||||
|
property var roomPreview: null
|
||||||
property bool showBackButton: false
|
property bool showBackButton: false
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
visible: !room && !TimelineManager.isInitialSync
|
visible: !room && !TimelineManager.isInitialSync && !roomPreview
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
text: qsTr("No room open")
|
text: qsTr("No room open")
|
||||||
font.pointSize: 24
|
font.pointSize: 24
|
||||||
|
@ -132,15 +134,25 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
visible: room != null && room.isSpace
|
id: preview
|
||||||
|
|
||||||
|
property string roomName: room ? room.roomName : (roomPreview ? roomPreview.roomName : "")
|
||||||
|
property string roomTopic: room ? room.roomTopic : (roomPreview ? roomPreview.roomTopic : "")
|
||||||
|
property string avatarUrl: room ? room.roomAvatarUrl : (roomPreview ? roomPreview.roomAvatarUrl : "")
|
||||||
|
|
||||||
|
visible: room != null && room.isSpace || roomPreview != null
|
||||||
enabled: visible
|
enabled: visible
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: Nheko.paddingLarge
|
anchors.margins: Nheko.paddingLarge
|
||||||
spacing: Nheko.paddingLarge
|
spacing: Nheko.paddingLarge
|
||||||
|
|
||||||
|
Item {
|
||||||
|
Layout.fillHeight: true
|
||||||
|
}
|
||||||
|
|
||||||
Avatar {
|
Avatar {
|
||||||
url: room ? room.roomAvatarUrl.replace("mxc://", "image://MxcImage/") : ""
|
url: parent.avatarUrl.replace("mxc://", "image://MxcImage/")
|
||||||
displayName: room ? room.roomName : ""
|
displayName: parent.roomName
|
||||||
height: 130
|
height: 130
|
||||||
width: 130
|
width: 130
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
|
@ -148,22 +160,25 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
MatrixText {
|
MatrixText {
|
||||||
text: room ? room.roomName : ""
|
text: parent.roomName
|
||||||
font.pixelSize: 24
|
font.pixelSize: 24
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
MatrixText {
|
MatrixText {
|
||||||
|
visible: !!room
|
||||||
text: qsTr("%1 member(s)").arg(room ? room.roomMemberCount : 0)
|
text: qsTr("%1 member(s)").arg(room ? room.roomMemberCount : 0)
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrollView {
|
ScrollView {
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
width: timelineView.width - Nheko.paddingLarge * 2
|
Layout.fillWidth: true
|
||||||
|
Layout.leftMargin: Nheko.paddingLarge
|
||||||
|
Layout.rightMargin: Nheko.paddingLarge
|
||||||
|
|
||||||
TextArea {
|
TextArea {
|
||||||
text: TimelineManager.escapeEmoji(room ? room.roomTopic : "")
|
text: TimelineManager.escapeEmoji(preview.roomTopic)
|
||||||
wrapMode: TextEdit.WordWrap
|
wrapMode: TextEdit.WordWrap
|
||||||
textFormat: TextEdit.RichText
|
textFormat: TextEdit.RichText
|
||||||
readOnly: true
|
readOnly: true
|
||||||
|
@ -182,6 +197,32 @@ Item {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FlatButton {
|
||||||
|
visible: roomPreview && !roomPreview.isInvite
|
||||||
|
Layout.alignment: Qt.AlignHCenter
|
||||||
|
text: qsTr("join the conversation")
|
||||||
|
onClicked: Rooms.joinPreview(roomPreview.roomid)
|
||||||
|
}
|
||||||
|
|
||||||
|
FlatButton {
|
||||||
|
visible: roomPreview && roomPreview.isInvite
|
||||||
|
Layout.alignment: Qt.AlignHCenter
|
||||||
|
text: qsTr("accept invite")
|
||||||
|
onClicked: Rooms.acceptInvite(roomPreview.roomid)
|
||||||
|
}
|
||||||
|
|
||||||
|
FlatButton {
|
||||||
|
visible: roomPreview && roomPreview.isInvite
|
||||||
|
Layout.alignment: Qt.AlignHCenter
|
||||||
|
text: qsTr("decline invite")
|
||||||
|
onClicked: Rooms.declineInvite(roomPreview.roomid)
|
||||||
|
}
|
||||||
|
|
||||||
|
Item {
|
||||||
|
visible: room != null
|
||||||
|
Layout.preferredHeight: Math.ceil(fontMetrics.lineSpacing * 2)
|
||||||
|
}
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,9 @@ Rectangle {
|
||||||
id: topBar
|
id: topBar
|
||||||
|
|
||||||
property bool showBackButton: false
|
property bool showBackButton: false
|
||||||
|
property string roomName: room ? room.roomName : qsTr("No room selected")
|
||||||
|
property string avatarUrl: room ? room.roomAvatarUrl : ""
|
||||||
|
property string roomTopic: room ? room.roomTopic : ""
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
implicitHeight: topLayout.height + Nheko.paddingMedium * 2
|
implicitHeight: topLayout.height + Nheko.paddingMedium * 2
|
||||||
|
@ -20,15 +23,15 @@ Rectangle {
|
||||||
|
|
||||||
TapHandler {
|
TapHandler {
|
||||||
onSingleTapped: {
|
onSingleTapped: {
|
||||||
room.openRoomSettings();
|
if (room)
|
||||||
|
room.openRoomSettings();
|
||||||
|
|
||||||
eventPoint.accepted = true;
|
eventPoint.accepted = true;
|
||||||
}
|
}
|
||||||
gesturePolicy: TapHandler.ReleaseWithinBounds
|
gesturePolicy: TapHandler.ReleaseWithinBounds
|
||||||
}
|
}
|
||||||
|
|
||||||
GridLayout {
|
GridLayout {
|
||||||
//Layout.margins: 8
|
|
||||||
|
|
||||||
id: topLayout
|
id: topLayout
|
||||||
|
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
|
@ -59,9 +62,13 @@ Rectangle {
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
width: Nheko.avatarSize
|
width: Nheko.avatarSize
|
||||||
height: Nheko.avatarSize
|
height: Nheko.avatarSize
|
||||||
url: room ? room.roomAvatarUrl.replace("mxc://", "image://MxcImage/") : ""
|
url: avatarUrl.replace("mxc://", "image://MxcImage/")
|
||||||
displayName: room ? room.roomName : qsTr("No room selected")
|
displayName: roomName
|
||||||
onClicked: room.openRoomSettings()
|
onClicked: {
|
||||||
|
if (room) {
|
||||||
|
room.openRoomSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
|
@ -70,7 +77,7 @@ Rectangle {
|
||||||
Layout.row: 0
|
Layout.row: 0
|
||||||
color: Nheko.colors.text
|
color: Nheko.colors.text
|
||||||
font.pointSize: fontMetrics.font.pointSize * 1.1
|
font.pointSize: fontMetrics.font.pointSize * 1.1
|
||||||
text: room ? room.roomName : qsTr("No room selected")
|
text: roomName
|
||||||
maximumLineCount: 1
|
maximumLineCount: 1
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
textFormat: Text.RichText
|
textFormat: Text.RichText
|
||||||
|
@ -82,12 +89,13 @@ Rectangle {
|
||||||
Layout.row: 1
|
Layout.row: 1
|
||||||
Layout.maximumHeight: fontMetrics.lineSpacing * 2 // show 2 lines
|
Layout.maximumHeight: fontMetrics.lineSpacing * 2 // show 2 lines
|
||||||
clip: true
|
clip: true
|
||||||
text: room ? room.roomTopic : ""
|
text: roomTopic
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageButton {
|
ImageButton {
|
||||||
id: roomOptionsButton
|
id: roomOptionsButton
|
||||||
|
|
||||||
|
visible: !!room
|
||||||
Layout.column: 3
|
Layout.column: 3
|
||||||
Layout.row: 0
|
Layout.row: 0
|
||||||
Layout.rowSpan: 2
|
Layout.rowSpan: 2
|
||||||
|
|
47
resources/qml/components/FlatButton.qml
Normal file
47
resources/qml/components/FlatButton.qml
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
import QtGraphicalEffects 1.12
|
||||||
|
import QtQuick 2.9
|
||||||
|
import QtQuick.Controls 2.5
|
||||||
|
import im.nheko 1.0
|
||||||
|
|
||||||
|
Button {
|
||||||
|
id: control
|
||||||
|
|
||||||
|
implicitHeight: Math.ceil(control.contentItem.implicitHeight * 1.5)
|
||||||
|
implicitWidth: Math.ceil(control.contentItem.implicitWidth + control.contentItem.implicitHeight)
|
||||||
|
hoverEnabled: true
|
||||||
|
|
||||||
|
DropShadow {
|
||||||
|
anchors.fill: control.background
|
||||||
|
horizontalOffset: 3
|
||||||
|
verticalOffset: 3
|
||||||
|
radius: 8
|
||||||
|
samples: 17
|
||||||
|
cached: true
|
||||||
|
color: "#80000000"
|
||||||
|
source: control.background
|
||||||
|
}
|
||||||
|
|
||||||
|
contentItem: Text {
|
||||||
|
text: control.text
|
||||||
|
//font: control.font
|
||||||
|
font.capitalization: Font.AllUppercase
|
||||||
|
font.pointSize: Math.ceil(fontMetrics.font.pointSize * 1.5)
|
||||||
|
//font.capitalization: Font.AllUppercase
|
||||||
|
color: Nheko.colors.light
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
elide: Text.ElideRight
|
||||||
|
}
|
||||||
|
|
||||||
|
background: Rectangle {
|
||||||
|
//height: control.contentItem.implicitHeight * 2
|
||||||
|
//width: control.contentItem.implicitWidth * 2
|
||||||
|
radius: height / 6
|
||||||
|
color: Qt.lighter(Nheko.colors.dark, control.down ? 1.4 : (control.hovered ? 1.2 : 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -183,6 +183,7 @@
|
||||||
<file>qml/voip/VideoCall.qml</file>
|
<file>qml/voip/VideoCall.qml</file>
|
||||||
<file>qml/components/AdaptiveLayout.qml</file>
|
<file>qml/components/AdaptiveLayout.qml</file>
|
||||||
<file>qml/components/AdaptiveLayoutElement.qml</file>
|
<file>qml/components/AdaptiveLayoutElement.qml</file>
|
||||||
|
<file>qml/components/FlatButton.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
<qresource prefix="/media">
|
<qresource prefix="/media">
|
||||||
<file>media/ring.ogg</file>
|
<file>media/ring.ogg</file>
|
||||||
|
|
|
@ -16,6 +16,8 @@ RoomlistModel::RoomlistModel(TimelineViewManager *parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
, manager(parent)
|
, manager(parent)
|
||||||
{
|
{
|
||||||
|
[[maybe_unused]] static auto id = qRegisterMetaType<RoomPreview>();
|
||||||
|
|
||||||
connect(ChatPage::instance(), &ChatPage::decryptSidebarChanged, this, [this]() {
|
connect(ChatPage::instance(), &ChatPage::decryptSidebarChanged, this, [this]() {
|
||||||
auto decrypt = ChatPage::instance()->userSettings()->decryptSidebar();
|
auto decrypt = ChatPage::instance()->userSettings()->decryptSidebar();
|
||||||
QHash<QString, QSharedPointer<TimelineModel>>::iterator i;
|
QHash<QString, QSharedPointer<TimelineModel>>::iterator i;
|
||||||
|
@ -137,7 +139,7 @@ RoomlistModel::data(const QModelIndex &index, int role) const
|
||||||
case Roles::RoomName:
|
case Roles::RoomName:
|
||||||
return QString::fromStdString(room.name);
|
return QString::fromStdString(room.name);
|
||||||
case Roles::LastMessage:
|
case Roles::LastMessage:
|
||||||
return QString();
|
return tr("Pending invite.");
|
||||||
case Roles::Time:
|
case Roles::Time:
|
||||||
return QString();
|
return QString();
|
||||||
case Roles::Timestamp:
|
case Roles::Timestamp:
|
||||||
|
@ -434,9 +436,11 @@ void
|
||||||
RoomlistModel::sync(const mtx::responses::Rooms &rooms)
|
RoomlistModel::sync(const mtx::responses::Rooms &rooms)
|
||||||
{
|
{
|
||||||
for (const auto &[room_id, room] : rooms.join) {
|
for (const auto &[room_id, room] : rooms.join) {
|
||||||
|
auto qroomid = QString::fromStdString(room_id);
|
||||||
|
|
||||||
// addRoom will only add the room, if it doesn't exist
|
// addRoom will only add the room, if it doesn't exist
|
||||||
addRoom(QString::fromStdString(room_id));
|
addRoom(qroomid);
|
||||||
const auto &room_model = models.value(QString::fromStdString(room_id));
|
const auto &room_model = models.value(qroomid);
|
||||||
room_model->sync(room);
|
room_model->sync(room);
|
||||||
// room_model->addEvents(room.timeline);
|
// room_model->addEvents(room.timeline);
|
||||||
connect(room_model.data(),
|
connect(room_model.data(),
|
||||||
|
@ -465,14 +469,20 @@ RoomlistModel::sync(const mtx::responses::Rooms &rooms)
|
||||||
|
|
||||||
for (const auto &[room_id, room] : rooms.leave) {
|
for (const auto &[room_id, room] : rooms.leave) {
|
||||||
(void)room;
|
(void)room;
|
||||||
auto idx = this->roomidToIndex(QString::fromStdString(room_id));
|
auto qroomid = QString::fromStdString(room_id);
|
||||||
|
|
||||||
|
if ((currentRoom_ && currentRoom_->roomId() == qroomid) ||
|
||||||
|
(currentRoomPreview_ && currentRoomPreview_->roomid() == qroomid))
|
||||||
|
resetCurrentRoom();
|
||||||
|
|
||||||
|
auto idx = this->roomidToIndex(qroomid);
|
||||||
if (idx != -1) {
|
if (idx != -1) {
|
||||||
beginRemoveRows(QModelIndex(), idx, idx);
|
beginRemoveRows(QModelIndex(), idx, idx);
|
||||||
roomids.erase(roomids.begin() + idx);
|
roomids.erase(roomids.begin() + idx);
|
||||||
if (models.contains(QString::fromStdString(room_id)))
|
if (models.contains(qroomid))
|
||||||
models.remove(QString::fromStdString(room_id));
|
models.remove(qroomid);
|
||||||
else if (invites.contains(QString::fromStdString(room_id)))
|
else if (invites.contains(qroomid))
|
||||||
invites.remove(QString::fromStdString(room_id));
|
invites.remove(qroomid);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -529,6 +539,19 @@ RoomlistModel::clear()
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
RoomlistModel::joinPreview(QString roomid, QString parentSpace)
|
||||||
|
{
|
||||||
|
if (previewedRooms.contains(roomid)) {
|
||||||
|
auto child = cache::client()->getStateEvent<mtx::events::state::space::Child>(
|
||||||
|
parentSpace.toStdString(), roomid.toStdString());
|
||||||
|
ChatPage::instance()->joinRoomVia(roomid.toStdString(),
|
||||||
|
(child && child->content.via)
|
||||||
|
? child->content.via.value()
|
||||||
|
: std::vector<std::string>{},
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
}
|
||||||
void
|
void
|
||||||
RoomlistModel::acceptInvite(QString roomid)
|
RoomlistModel::acceptInvite(QString roomid)
|
||||||
{
|
{
|
||||||
|
@ -581,6 +604,31 @@ RoomlistModel::setCurrentRoom(QString roomid)
|
||||||
nhlog::ui()->debug("Trying to switch to: {}", roomid.toStdString());
|
nhlog::ui()->debug("Trying to switch to: {}", roomid.toStdString());
|
||||||
if (models.contains(roomid)) {
|
if (models.contains(roomid)) {
|
||||||
currentRoom_ = models.value(roomid);
|
currentRoom_ = models.value(roomid);
|
||||||
|
currentRoomPreview_.reset();
|
||||||
|
emit currentRoomChanged();
|
||||||
|
nhlog::ui()->debug("Switched to: {}", roomid.toStdString());
|
||||||
|
} else if (invites.contains(roomid) || previewedRooms.contains(roomid)) {
|
||||||
|
currentRoom_ = nullptr;
|
||||||
|
std::optional<RoomInfo> i;
|
||||||
|
|
||||||
|
RoomPreview p;
|
||||||
|
|
||||||
|
if (invites.contains(roomid)) {
|
||||||
|
i = invites.value(roomid);
|
||||||
|
p.isInvite_ = true;
|
||||||
|
} else {
|
||||||
|
i = previewedRooms.value(roomid);
|
||||||
|
p.isInvite_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i) {
|
||||||
|
p.roomid_ = roomid;
|
||||||
|
p.roomName_ = QString::fromStdString(i->name);
|
||||||
|
p.roomTopic_ = QString::fromStdString(i->topic);
|
||||||
|
p.roomAvatarUrl_ = QString::fromStdString(i->avatar_url);
|
||||||
|
currentRoomPreview_ = std::move(p);
|
||||||
|
}
|
||||||
|
|
||||||
emit currentRoomChanged();
|
emit currentRoomChanged();
|
||||||
nhlog::ui()->debug("Switched to: {}", roomid.toStdString());
|
nhlog::ui()->debug("Switched to: {}", roomid.toStdString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,35 @@
|
||||||
|
|
||||||
class TimelineViewManager;
|
class TimelineViewManager;
|
||||||
|
|
||||||
|
class RoomPreview
|
||||||
|
{
|
||||||
|
Q_GADGET
|
||||||
|
Q_PROPERTY(QString roomid READ roomid CONSTANT)
|
||||||
|
Q_PROPERTY(QString roomName READ roomName CONSTANT)
|
||||||
|
Q_PROPERTY(QString roomTopic READ roomTopic CONSTANT)
|
||||||
|
Q_PROPERTY(QString roomAvatarUrl READ roomAvatarUrl CONSTANT)
|
||||||
|
Q_PROPERTY(bool isInvite READ isInvite CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
RoomPreview() {}
|
||||||
|
|
||||||
|
QString roomid() const { return roomid_; }
|
||||||
|
QString roomName() const { return roomName_; }
|
||||||
|
QString roomTopic() const { return roomTopic_; }
|
||||||
|
QString roomAvatarUrl() const { return roomAvatarUrl_; }
|
||||||
|
bool isInvite() const { return isInvite_; }
|
||||||
|
|
||||||
|
QString roomid_, roomName_, roomAvatarUrl_, roomTopic_;
|
||||||
|
bool isInvite_ = false;
|
||||||
|
};
|
||||||
|
|
||||||
class RoomlistModel : public QAbstractListModel
|
class RoomlistModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(TimelineModel *currentRoom READ currentRoom NOTIFY currentRoomChanged RESET
|
Q_PROPERTY(TimelineModel *currentRoom READ currentRoom NOTIFY currentRoomChanged RESET
|
||||||
resetCurrentRoom)
|
resetCurrentRoom)
|
||||||
|
Q_PROPERTY(RoomPreview currentRoomPreview READ currentRoomPreview NOTIFY currentRoomChanged
|
||||||
|
RESET resetCurrentRoom)
|
||||||
public:
|
public:
|
||||||
enum Roles
|
enum Roles
|
||||||
{
|
{
|
||||||
|
@ -72,14 +96,20 @@ public slots:
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
void joinPreview(QString roomid, QString parentSpace);
|
||||||
void acceptInvite(QString roomid);
|
void acceptInvite(QString roomid);
|
||||||
void declineInvite(QString roomid);
|
void declineInvite(QString roomid);
|
||||||
void leave(QString roomid);
|
void leave(QString roomid);
|
||||||
TimelineModel *currentRoom() const { return currentRoom_.get(); }
|
TimelineModel *currentRoom() const { return currentRoom_.get(); }
|
||||||
|
RoomPreview currentRoomPreview() const
|
||||||
|
{
|
||||||
|
return currentRoomPreview_.value_or(RoomPreview{});
|
||||||
|
}
|
||||||
void setCurrentRoom(QString roomid);
|
void setCurrentRoom(QString roomid);
|
||||||
void resetCurrentRoom()
|
void resetCurrentRoom()
|
||||||
{
|
{
|
||||||
currentRoom_ = nullptr;
|
currentRoom_ = nullptr;
|
||||||
|
currentRoomPreview_.reset();
|
||||||
emit currentRoomChanged();
|
emit currentRoomChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,6 +133,7 @@ private:
|
||||||
QHash<QString, std::optional<RoomInfo>> previewedRooms;
|
QHash<QString, std::optional<RoomInfo>> previewedRooms;
|
||||||
|
|
||||||
QSharedPointer<TimelineModel> currentRoom_;
|
QSharedPointer<TimelineModel> currentRoom_;
|
||||||
|
std::optional<RoomPreview> currentRoomPreview_;
|
||||||
|
|
||||||
friend class FilteredRoomlistModel;
|
friend class FilteredRoomlistModel;
|
||||||
};
|
};
|
||||||
|
@ -112,6 +143,8 @@ class FilteredRoomlistModel : public QSortFilterProxyModel
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(TimelineModel *currentRoom READ currentRoom NOTIFY currentRoomChanged RESET
|
Q_PROPERTY(TimelineModel *currentRoom READ currentRoom NOTIFY currentRoomChanged RESET
|
||||||
resetCurrentRoom)
|
resetCurrentRoom)
|
||||||
|
Q_PROPERTY(RoomPreview currentRoomPreview READ currentRoomPreview NOTIFY currentRoomChanged
|
||||||
|
RESET resetCurrentRoom)
|
||||||
public:
|
public:
|
||||||
FilteredRoomlistModel(RoomlistModel *model, QObject *parent = nullptr);
|
FilteredRoomlistModel(RoomlistModel *model, QObject *parent = nullptr);
|
||||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
|
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
|
||||||
|
@ -123,12 +156,17 @@ public slots:
|
||||||
return mapFromSource(roomlistmodel->index(roomlistmodel->roomidToIndex(roomid)))
|
return mapFromSource(roomlistmodel->index(roomlistmodel->roomidToIndex(roomid)))
|
||||||
.row();
|
.row();
|
||||||
}
|
}
|
||||||
|
void joinPreview(QString roomid)
|
||||||
|
{
|
||||||
|
roomlistmodel->joinPreview(roomid, filterType == FilterBy::Space ? filterStr : "");
|
||||||
|
}
|
||||||
void acceptInvite(QString roomid) { roomlistmodel->acceptInvite(roomid); }
|
void acceptInvite(QString roomid) { roomlistmodel->acceptInvite(roomid); }
|
||||||
void declineInvite(QString roomid) { roomlistmodel->declineInvite(roomid); }
|
void declineInvite(QString roomid) { roomlistmodel->declineInvite(roomid); }
|
||||||
void leave(QString roomid) { roomlistmodel->leave(roomid); }
|
void leave(QString roomid) { roomlistmodel->leave(roomid); }
|
||||||
void toggleTag(QString roomid, QString tag, bool on);
|
void toggleTag(QString roomid, QString tag, bool on);
|
||||||
|
|
||||||
TimelineModel *currentRoom() const { return roomlistmodel->currentRoom(); }
|
TimelineModel *currentRoom() const { return roomlistmodel->currentRoom(); }
|
||||||
|
RoomPreview currentRoomPreview() const { return roomlistmodel->currentRoomPreview(); }
|
||||||
void setCurrentRoom(QString roomid) { roomlistmodel->setCurrentRoom(std::move(roomid)); }
|
void setCurrentRoom(QString roomid) { roomlistmodel->setCurrentRoom(std::move(roomid)); }
|
||||||
void resetCurrentRoom() { roomlistmodel->resetCurrentRoom(); }
|
void resetCurrentRoom() { roomlistmodel->resetCurrentRoom(); }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue