Optimize model upsert, ensure right type for roles

This commit is contained in:
miruka
2019-07-04 18:37:15 -04:00
parent 6b83d79f16
commit 07438150db
8 changed files with 65 additions and 44 deletions

View File

@@ -81,10 +81,24 @@ SortFilterProxyModel {
return model.get(model.count)
}
if (update_if_exist != false) {
model.set(indices[0], new_item)
}
return model.get(indices[0])
var existing = model.get(indices[0])
if (update_if_exist == false) { 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() != new_item[role].getTime()) {
model.set(indices[0], new_item)
return existing
}
} else {
if (existing[role] != new_item[role]) {
model.set(indices[0], new_item)
return existing
}
}
}
return existing
}
function pop(index) {

View File

@@ -35,7 +35,7 @@ HColumnLayout {
RoomHeader {
id: roomHeader
displayName: roomInfo.displayName
topic: roomInfo.topic || ""
topic: roomInfo.topic
Layout.fillWidth: true
Layout.preferredHeight: HStyle.avatar.size

View File

@@ -72,7 +72,7 @@ function onTimelineEventReceived(
"isLocalEcho": is_local_echo,
"showNameLine": show_name_line,
"translatable": translatable,
"targetUserId": target_user_id || "",
"targetUserId": target_user_id,
}
// Replace any matching local echo

View File

@@ -6,7 +6,6 @@ function onAccountDeleted(user_id) {
accounts.popWhere({"userId": user_id}, 1)
}
// TODO: get updated from nio rooms
function onUserUpdated(user_id, display_name, avatar_url, status_message) {
users.upsert({"userId": user_id}, {
"userId": user_id,

View File

@@ -40,7 +40,7 @@ Column {
HTextField {
id: statusEdit
text: user.statusMessage || ""
text: user.statusMessage
placeholderText: qsTr("Set status message")
font.pixelSize: HStyle.fontSize.small
background: null