Add an option to lazy load room message at initial sync.

Reduces initial sync time. Useful if you joined a lot of rooms and have
a slow homeserver.
This commit is contained in:
Black Hat 2018-08-10 18:58:53 +08:00
parent 9a836a23fb
commit 4db5f3f355
9 changed files with 58 additions and 11 deletions

View File

@ -15,6 +15,7 @@ Page {
connection: page.connection connection: page.connection
onRoomAdded: setting.lazyLoad ? {} : room.getPreviousContent(20)
onNewMessage: trayIcon.showMessage("New message", "New message for room " + room.displayName) onNewMessage: trayIcon.showMessage("New message", "New message for room " + room.displayName)
} }

View File

@ -7,8 +7,10 @@ import "component"
import "form" import "form"
Page { Page {
property alias lazyLoad: generalForm.lazyLoad
property alias darkTheme: appearanceForm.darkTheme property alias darkTheme: appearanceForm.darkTheme
property alias miniMode: appearanceForm.miniMode property alias miniMode: appearanceForm.miniMode
property var connection property var connection
SettingAccountForm { SettingAccountForm {
@ -16,6 +18,11 @@ Page {
parent: null parent: null
} }
SettingGeneralForm {
id: generalForm
parent: null
}
SettingAppearanceForm { SettingAppearanceForm {
id: appearanceForm id: appearanceForm
parent: null parent: null
@ -36,6 +43,13 @@ Page {
onClicked: pushToStack(accountForm) onClicked: pushToStack(accountForm)
} }
ItemDelegate {
Layout.fillWidth: true
text: "General"
onClicked: pushToStack(generalForm)
}
ItemDelegate { ItemDelegate {
Layout.fillWidth: true Layout.fillWidth: true

View File

@ -43,9 +43,16 @@ Item {
Label { Label {
width: parent.width width: parent.width
horizontalAlignment: Text.AlignHCenter
text: currentRoom && currentRoom.id ? currentRoom.id : "" text: currentRoom && currentRoom.id ? currentRoom.id : ""
} }
Label {
width: parent.width
horizontalAlignment: Text.AlignHCenter
text: currentRoom && currentRoom.canonicalAlias ? currentRoom.canonicalAlias : "No Canonical Alias"
}
RowLayout { RowLayout {
width: parent.width width: parent.width
@ -109,6 +116,12 @@ Item {
color: Material.theme == Material.Light ? "#eaeaea" : "#242424" color: Material.theme == Material.Light ? "#eaeaea" : "#242424"
MouseArea {
anchors.fill: parent
onClicked: roomDrawer.open()
}
RowLayout { RowLayout {
anchors.fill: parent anchors.fill: parent
anchors.margins: 16 anchors.margins: 16
@ -122,12 +135,17 @@ Item {
displayText: currentRoom ? currentRoom.displayName : "" displayText: currentRoom ? currentRoom.displayName : ""
} }
Column { ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter
visible: parent.width > 80
Label {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
Label {
width: parent.width
text: currentRoom ? currentRoom.displayName : "" text: currentRoom ? currentRoom.displayName : ""
font.pointSize: 16 font.pointSize: 16
elide: Text.ElideRight elide: Text.ElideRight
@ -135,18 +153,14 @@ Item {
} }
Label { Label {
width: parent.width Layout.fillWidth: true
Layout.fillHeight: true
text: currentRoom ? currentRoom.topic : "" text: currentRoom ? currentRoom.topic : ""
elide: Text.ElideRight elide: Text.ElideRight
wrapMode: Text.NoWrap wrapMode: Text.NoWrap
} }
} }
ToolButton {
contentItem: MaterialIcon { icon: "\ue5d2" }
onClicked: roomDrawer.open()
}
} }
} }

View File

@ -226,5 +226,5 @@ Item {
} }
} }
onCurrentRoomChanged: if (currentRoom && !currentRoom.timelineSize) currentRoom.getPreviousContent(20) onCurrentRoomChanged: setting.lazyLoad && currentRoom && !currentRoom.timelineSize ? currentRoom.getPreviousContent(20) : {}
} }

View File

@ -0,0 +1,13 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
Page {
property alias lazyLoad: lazyLoadSwitch.checked
Column {
Switch {
id: lazyLoadSwitch
text: "Lazy Load at Initial Sync"
}
}
}

View File

@ -32,6 +32,8 @@ ApplicationWindow {
property alias userID: matriqueController.userID property alias userID: matriqueController.userID
property alias token: matriqueController.token property alias token: matriqueController.token
property alias lazyLoad: settingPage.lazyLoad
property alias darkTheme: settingPage.darkTheme property alias darkTheme: settingPage.darkTheme
property alias miniMode: settingPage.miniMode property alias miniMode: settingPage.miniMode
} }

View File

@ -29,5 +29,6 @@
<file>qml/form/SettingAppearanceForm.qml</file> <file>qml/form/SettingAppearanceForm.qml</file>
<file>qml/component/TextDelegate.qml</file> <file>qml/component/TextDelegate.qml</file>
<file>qml/component/MessageContextMenu.qml</file> <file>qml/component/MessageContextMenu.qml</file>
<file>qml/form/SettingGeneralForm.qml</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -42,6 +42,7 @@ void RoomListModel::doAddRoom(Room* r) {
if (auto* room = r) { if (auto* room = r) {
m_rooms.append(room); m_rooms.append(room);
connectRoomSignals(room); connectRoomSignals(room);
emit roomAdded(room);
} else { } else {
qCritical() << "Attempt to add nullptr to the room list"; qCritical() << "Attempt to add nullptr to the room list";
Q_ASSERT(false); Q_ASSERT(false);

View File

@ -53,6 +53,7 @@ class RoomListModel : public QAbstractListModel {
signals: signals:
void connectionChanged(); void connectionChanged();
void roomAdded(Room* room);
void newMessage(Room* room); void newMessage(Room* room);
}; };