Big performance refactoring & various improvements
Instead of passing all sorts of events for the JS to handle and manually add to different data models, we now handle everything we can in Python. For any change, the python models send a sync event with their contents (no more than 4 times per second) to JS, and the QSyncable library's JsonListModel takes care of converting it to a QML ListModel and sending the appropriate signals. The SortFilterProxyModel library is not used anymore, the only case where we need to filter/sort something now is when the user interacts with the "Filter rooms" or "Filter members" fields. These cases are handled by a simple JS function. We now keep separated room and timeline models for different accounts, the previous approach of sharing all the data we could between accounts created a lot of complications (local echoes, decrypted messages replacing others, etc). The users's own account profile changes are now hidden in the timeline. On startup, if all events for a room were only own profile changes, more events will be loaded. Any kind of image format supported by Qt is now handled by the pyotherside image provider, instead of just PNG/JPG. SVGs which previously caused errors are supported as well. The typing members bar paddings/margins are fixed. The behavior of the avatar/"upload a profile picture" overlay is fixed. Config files read from disk are now cached (TODO: make them reloadable again). Pylint is not used anymore because of all its annoying false warnings and lack of understanding for dataclasses, it is replaced by flake8 with a custom config and various plugins. Debug mode is now considered on if the program was compiled with the right option, instead of taking an argument from CLI. When on, C++ will set a flag in the Window QML component. The loading screen is now unloaded after the UI is ready, where previously it just stayed in the background invisible and wasted CPU. The overall refactoring and improvements make us now able to handle rooms with thousand of members and no lazy-loading, where previously everything would freeze and simply scrolling up to load past events in any room would block the UI for a few seconds.
This commit is contained in:
@@ -35,7 +35,7 @@ HRectangle {
|
||||
text: name ? name.charAt(0) : "?"
|
||||
font.pixelSize: parent.height / 1.4
|
||||
|
||||
color: Utils.hsla(
|
||||
color: Utils.hsluv(
|
||||
name ? Utils.hueFrom(name) : 0,
|
||||
name ? theme.controls.avatar.letter.saturation : 0,
|
||||
theme.controls.avatar.letter.lightness,
|
||||
|
@@ -2,124 +2,14 @@
|
||||
// This file is part of harmonyqml, licensed under LGPLv3.
|
||||
|
||||
import QtQuick 2.12
|
||||
import SortFilterProxyModel 0.2
|
||||
import QSyncable 1.0
|
||||
|
||||
SortFilterProxyModel {
|
||||
// To initialize a HListModel with items,
|
||||
// use `Component.onCompleted: extend([{"foo": 1, "bar": 2}, ...])`
|
||||
JsonListModel {
|
||||
id: model
|
||||
source: []
|
||||
Component.onCompleted: if (! keyField) { throw "keyField not set" }
|
||||
|
||||
id: sortFilteredModel
|
||||
|
||||
property ListModel model: ListModel {}
|
||||
sourceModel: model // Can't assign a "ListModel {}" directly here
|
||||
|
||||
function append(dict) { return model.append(dict) }
|
||||
function clear() { return model.clear() }
|
||||
function insert(index, dict) { return model.inset(index, dict) }
|
||||
function move(from, to, n=1) { return model.move(from, to, n) }
|
||||
function remove(index, count=1) { return model.remove(index, count) }
|
||||
function set(index, dict) { return model.set(index, dict) }
|
||||
function sync() { return model.sync() }
|
||||
function setProperty(index, prop, value) {
|
||||
return model.setProperty(index, prop, value)
|
||||
}
|
||||
|
||||
function extend(newItems) {
|
||||
for (let item of newItems) { model.append(item) }
|
||||
}
|
||||
|
||||
function getIndices(whereRolesAre, maxResults=null, maxTries=null) {
|
||||
// maxResults, maxTries: null or int
|
||||
let results = []
|
||||
|
||||
for (let i = 0; i < model.count; i++) {
|
||||
let item = model.get(i)
|
||||
let include = true
|
||||
|
||||
for (let role in whereRolesAre) {
|
||||
if (item[role] != whereRolesAre[role]) {
|
||||
include = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (include) {
|
||||
results.push(i)
|
||||
if (maxResults && results.length >= maxResults) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (maxTries && i >= maxTries) {
|
||||
break
|
||||
}
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
function getWhere(rolesAre, maxResults=null, maxTries=null) {
|
||||
let items = []
|
||||
|
||||
for (let indice of getIndices(rolesAre, maxResults, maxTries)) {
|
||||
items.push(model.get(indice))
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
function forEachWhere(rolesAre, func, maxResults=null, maxTries=null) {
|
||||
for (let item of getWhere(rolesAre, maxResults, maxTries)) {
|
||||
func(item)
|
||||
}
|
||||
}
|
||||
|
||||
function upsert(
|
||||
whereRolesAre, newItem, updateIfExist=true, maxTries=null
|
||||
) {
|
||||
let indices = getIndices(whereRolesAre, 1, maxTries)
|
||||
|
||||
if (indices.length == 0) {
|
||||
model.append(newItem)
|
||||
return model.get(model.count)
|
||||
}
|
||||
|
||||
let existing = model.get(indices[0])
|
||||
if (! updateIfExist) { return existing }
|
||||
|
||||
// Really update only if existing and new item have a difference
|
||||
for (var role in existing) {
|
||||
if (Boolean(existing[role].getTime)) {
|
||||
if (existing[role].getTime() != newItem[role].getTime()) {
|
||||
model.set(indices[0], newItem)
|
||||
return existing
|
||||
}
|
||||
} else {
|
||||
if (existing[role] != newItem[role]) {
|
||||
model.set(indices[0], newItem)
|
||||
return existing
|
||||
}
|
||||
}
|
||||
}
|
||||
return existing
|
||||
}
|
||||
|
||||
function pop(index) {
|
||||
let item = model.get(index)
|
||||
model.remove(index)
|
||||
return item
|
||||
}
|
||||
|
||||
function popWhere(rolesAre, maxResults=null, maxTries=null) {
|
||||
let items = []
|
||||
|
||||
for (let indice of getIndices(rolesAre, maxResults, maxTries)) {
|
||||
items.push(model.get(indice))
|
||||
model.remove(indice)
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
|
||||
function toObject(itemList=sortFilteredModel) {
|
||||
function toObject(itemList=listModel) {
|
||||
let objList = []
|
||||
|
||||
for (let item of itemList) {
|
||||
|
@@ -8,6 +8,7 @@ import "../SidePane"
|
||||
|
||||
SwipeView {
|
||||
default property alias columnChildren: contentColumn.children
|
||||
|
||||
property alias page: innerPage
|
||||
property alias header: innerPage.header
|
||||
property alias footer: innerPage.header
|
||||
@@ -81,7 +82,6 @@ SwipeView {
|
||||
|
||||
HColumnLayout {
|
||||
id: contentColumn
|
||||
spacing: theme.spacing
|
||||
width: innerFlickable.width
|
||||
height: innerFlickable.height
|
||||
}
|
||||
|
@@ -4,16 +4,13 @@
|
||||
import QtQuick 2.12
|
||||
|
||||
HAvatar {
|
||||
property string userId: ""
|
||||
property string roomId: ""
|
||||
property string displayName: ""
|
||||
property string avatarUrl: ""
|
||||
|
||||
readonly property var roomInfo: rooms.getWhere({userId, roomId}, 1)[0]
|
||||
name: displayName[0] == "#" && displayName.length > 1 ?
|
||||
displayName.substring(1) :
|
||||
displayName
|
||||
|
||||
// Avoid error messages when a room is forgotten
|
||||
readonly property var dname: roomInfo ? roomInfo.displayName : ""
|
||||
readonly property var avUrl: roomInfo ? roomInfo.avatarUrl : ""
|
||||
|
||||
name: dname[0] == "#" && dname.length > 1 ? dname.substring(1) : dname
|
||||
imageUrl: avUrl ? ("image://python/" + avUrl) : null
|
||||
toolTipImageUrl: avUrl ? ("image://python/" + avUrl) : null
|
||||
imageUrl: avatarUrl ? ("image://python/" + avatarUrl) : null
|
||||
toolTipImageUrl: avatarUrl ? ("image://python/" + avatarUrl) : null
|
||||
}
|
||||
|
@@ -26,9 +26,8 @@ TextField {
|
||||
border.color: field.activeFocus ? focusedBorderColor : borderColor
|
||||
border.width: bordered ? theme.controls.textField.borderWidth : 0
|
||||
|
||||
Behavior on color { HColorAnimation { factor: 0.5 } }
|
||||
Behavior on border.color { HColorAnimation { factor: 0.5 } }
|
||||
Behavior on border.width { HNumberAnimation { factor: 0.5 } }
|
||||
Behavior on color { HColorAnimation { factor: 0.25 } }
|
||||
Behavior on border.color { HColorAnimation { factor: 0.25 } }
|
||||
}
|
||||
|
||||
selectByMouse: true
|
||||
|
@@ -5,23 +5,16 @@ import QtQuick 2.12
|
||||
|
||||
HAvatar {
|
||||
property string userId: ""
|
||||
readonly property var userInfo: userId ? users.find(userId) : ({})
|
||||
property string displayName: ""
|
||||
property string avatarUrl: ""
|
||||
|
||||
readonly property var defaultImageUrl:
|
||||
userInfo.avatarUrl ? ("image://python/" + userInfo.avatarUrl) : null
|
||||
avatarUrl ? ("image://python/" + avatarUrl) : null
|
||||
|
||||
readonly property var defaultToolTipImageUrl:
|
||||
userInfo.avatarUrl ? ("image://python/" + userInfo.avatarUrl) : null
|
||||
avatarUrl ? ("image://python/" + avatarUrl) : null
|
||||
|
||||
name: userInfo.displayName || userId.substring(1) // no leading @
|
||||
name: displayName || userId.substring(1) // no leading @
|
||||
imageUrl: defaultImageUrl
|
||||
toolTipImageUrl:defaultToolTipImageUrl
|
||||
|
||||
//HImage {
|
||||
//id: status
|
||||
//anchors.right: parent.right
|
||||
//anchors.bottom: parent.bottom
|
||||
//source: "../../icons/status.svg"
|
||||
//sourceSize.width: 12
|
||||
//}
|
||||
}
|
||||
|
Reference in New Issue
Block a user