Move models to their own files
This commit is contained in:
parent
990770dd38
commit
fde7f4aee6
@ -6,7 +6,7 @@ Banner {
|
||||
|
||||
color: HStyle.chat.inviteBanner.background
|
||||
|
||||
// TODO: get disp name from models.users, inviter = userid now
|
||||
// TODO: get disp name from users, inviter = userid now
|
||||
avatar.name: inviter ? inviter.displayname : ""
|
||||
//avatar.imageUrl: inviter ? inviter.avatar_url : ""
|
||||
|
||||
|
@ -10,12 +10,12 @@ HColumnLayout {
|
||||
property string category: ""
|
||||
property string roomId: ""
|
||||
|
||||
readonly property var roomInfo: models.rooms.getWhere(
|
||||
readonly property var roomInfo: rooms.getWhere(
|
||||
{"userId": userId, "roomId": roomId, "category": category}, 1
|
||||
)[0]
|
||||
|
||||
readonly property var sender:
|
||||
models.users.getWhere({"userId": userId}, 1)[0]
|
||||
users.getWhere({"userId": userId}, 1)[0]
|
||||
|
||||
readonly property bool hasUnknownDevices: false
|
||||
//category == "Rooms" ?
|
||||
|
@ -22,7 +22,7 @@ Column {
|
||||
onReloadPreviousItem: previousItem = getPreviousItem()
|
||||
|
||||
property var senderInfo: null
|
||||
Component.onCompleted: senderInfo = models.users.getUser(model.senderId)
|
||||
Component.onCompleted: senderInfo = users.getUser(model.senderId)
|
||||
|
||||
readonly property bool isOwn: chatPage.userId === model.senderId
|
||||
|
||||
|
@ -12,7 +12,7 @@ HRectangle {
|
||||
clip: true
|
||||
|
||||
model: HListModel {
|
||||
sourceModel: models.timelines
|
||||
sourceModel: timelines
|
||||
|
||||
filters: ValueFilter {
|
||||
roleName: "roomId"
|
||||
|
@ -1,13 +1,11 @@
|
||||
function onRoomUpdated(user_id, category, room_id, display_name, avatar_url,
|
||||
topic, inviter, left_event) {
|
||||
|
||||
models.roomCategories.upsert({"userId": user_id, "name": category}, {
|
||||
roomCategories.upsert({"userId": user_id, "name": category}, {
|
||||
"userId": user_id,
|
||||
"name": category
|
||||
})
|
||||
|
||||
var rooms = models.rooms
|
||||
|
||||
function roles(for_category) {
|
||||
return {"userId": user_id, "roomId": room_id, "category": for_category}
|
||||
}
|
||||
@ -47,7 +45,7 @@ function onRoomUpdated(user_id, category, room_id, display_name, avatar_url,
|
||||
|
||||
function onRoomDeleted(user_id, category, room_id) {
|
||||
var roles = {"userId": user_id, "roomId": room_id, "category": category}
|
||||
models.rooms.popWhere(roles, 1)
|
||||
rooms.popWhere(roles, 1)
|
||||
}
|
||||
|
||||
|
||||
@ -78,19 +76,19 @@ function onTimelineEventReceived(
|
||||
}
|
||||
|
||||
// Replace any matching local echo
|
||||
var found = models.timelines.getIndices({
|
||||
var found = timelines.getIndices({
|
||||
"roomId": room_id,
|
||||
"senderId": sender_id,
|
||||
"content": content,
|
||||
"isLocalEcho": true
|
||||
}, 1, 500)
|
||||
if (found.length > 0) {
|
||||
models.timelines.set(found[0], item)
|
||||
timelines.set(found[0], item)
|
||||
return
|
||||
}
|
||||
|
||||
// Multiple clients will emit duplicate events with the same eventId
|
||||
models.timelines.upsert({"eventId": event_id}, item, true, 500)
|
||||
timelines.upsert({"eventId": event_id}, item, true, 500)
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
function onAccountUpdated(user_id) {
|
||||
models.accounts.append({"userId": user_id})
|
||||
accounts.append({"userId": user_id})
|
||||
}
|
||||
|
||||
function onAccountDeleted(user_id) {
|
||||
models.accounts.popWhere({"userId": user_id}, 1)
|
||||
accounts.popWhere({"userId": user_id}, 1)
|
||||
}
|
||||
|
||||
// TODO: get updated from nio rooms
|
||||
function onUserUpdated(user_id, display_name, avatar_url, status_message) {
|
||||
models.users.upsert({"userId": user_id}, {
|
||||
users.upsert({"userId": user_id}, {
|
||||
"userId": user_id,
|
||||
"displayName": display_name,
|
||||
"avatarUrl": avatar_url,
|
||||
|
@ -1,58 +0,0 @@
|
||||
import QtQuick 2.7
|
||||
import SortFilterProxyModel 0.2
|
||||
import "Base"
|
||||
|
||||
QtObject {
|
||||
property HListModel accounts: HListModel {
|
||||
sorters: StringSorter {
|
||||
roleName: "userId"
|
||||
numericMode: true // human numeric sort
|
||||
}
|
||||
}
|
||||
|
||||
property HListModel users: HListModel {
|
||||
function getUser(user_id) {
|
||||
var found = users.getWhere({"userId": user_id}, 1)
|
||||
if (found.length > 0) { return found[0] }
|
||||
|
||||
users.append({
|
||||
"userId": user_id,
|
||||
"displayName": "",
|
||||
"avatarUrl": "",
|
||||
"statusMessage": ""
|
||||
})
|
||||
|
||||
py.callCoro("request_user_update_event", [user_id])
|
||||
|
||||
return users.getWhere({"userId": user_id}, 1)[0]
|
||||
}
|
||||
}
|
||||
|
||||
property HListModel devices: HListModel {}
|
||||
|
||||
property HListModel roomCategories: HListModel {
|
||||
sorters: FilterSorter {
|
||||
ValueFilter { roleName: "name"; value: "Invites" }
|
||||
ValueFilter { roleName: "name"; value: "Rooms" }
|
||||
ValueFilter { roleName: "name"; value: "Left" }
|
||||
}
|
||||
}
|
||||
|
||||
property HListModel rooms: HListModel {}
|
||||
|
||||
property HListModel timelines: HListModel {
|
||||
function lastEventOf(room_id) {
|
||||
// Return an event item or undefined if none found
|
||||
|
||||
for (var i = 0; i < timelines.count; i++) {
|
||||
var item = timelines.get(i) // TODO: standardize
|
||||
if (item.roomId == room_id) { return item }
|
||||
}
|
||||
}
|
||||
|
||||
sorters: RoleSorter {
|
||||
roleName: "date"
|
||||
sortOrder: Qt.DescendingOrder
|
||||
}
|
||||
}
|
||||
}
|
10
src/qml/Models/Accounts.qml
Normal file
10
src/qml/Models/Accounts.qml
Normal file
@ -0,0 +1,10 @@
|
||||
import QtQuick 2.7
|
||||
import SortFilterProxyModel 0.2
|
||||
import "../Base"
|
||||
|
||||
HListModel {
|
||||
sorters: StringSorter {
|
||||
roleName: "userId"
|
||||
numericMode: true // human numeric sort
|
||||
}
|
||||
}
|
5
src/qml/Models/Devices.qml
Normal file
5
src/qml/Models/Devices.qml
Normal file
@ -0,0 +1,5 @@
|
||||
import QtQuick 2.7
|
||||
import SortFilterProxyModel 0.2
|
||||
import "../Base"
|
||||
|
||||
HListModel {}
|
11
src/qml/Models/RoomCategories.qml
Normal file
11
src/qml/Models/RoomCategories.qml
Normal file
@ -0,0 +1,11 @@
|
||||
import QtQuick 2.7
|
||||
import SortFilterProxyModel 0.2
|
||||
import "../Base"
|
||||
|
||||
HListModel {
|
||||
sorters: FilterSorter {
|
||||
ValueFilter { roleName: "name"; value: "Invites" }
|
||||
ValueFilter { roleName: "name"; value: "Rooms" }
|
||||
ValueFilter { roleName: "name"; value: "Left" }
|
||||
}
|
||||
}
|
5
src/qml/Models/Rooms.qml
Normal file
5
src/qml/Models/Rooms.qml
Normal file
@ -0,0 +1,5 @@
|
||||
import QtQuick 2.7
|
||||
import SortFilterProxyModel 0.2
|
||||
import "../Base"
|
||||
|
||||
HListModel {}
|
19
src/qml/Models/Timelines.qml
Normal file
19
src/qml/Models/Timelines.qml
Normal file
@ -0,0 +1,19 @@
|
||||
import QtQuick 2.7
|
||||
import SortFilterProxyModel 0.2
|
||||
import "../Base"
|
||||
|
||||
HListModel {
|
||||
function lastEventOf(room_id) {
|
||||
// Return an event item or undefined if none found
|
||||
|
||||
for (var i = 0; i < count; i++) {
|
||||
var item = get(i) // TODO: standardize
|
||||
if (item.roomId == room_id) { return item }
|
||||
}
|
||||
}
|
||||
|
||||
sorters: RoleSorter {
|
||||
roleName: "date"
|
||||
sortOrder: Qt.DescendingOrder
|
||||
}
|
||||
}
|
21
src/qml/Models/Users.qml
Normal file
21
src/qml/Models/Users.qml
Normal file
@ -0,0 +1,21 @@
|
||||
import QtQuick 2.7
|
||||
import SortFilterProxyModel 0.2
|
||||
import "../Base"
|
||||
|
||||
HListModel {
|
||||
function getUser(user_id) {
|
||||
var found = getWhere({"userId": user_id}, 1)
|
||||
if (found.length > 0) { return found[0] }
|
||||
|
||||
append({
|
||||
"userId": user_id,
|
||||
"displayName": "",
|
||||
"avatarUrl": "",
|
||||
"statusMessage": ""
|
||||
})
|
||||
|
||||
py.callCoro("request_user_update_event", [user_id])
|
||||
|
||||
return getWhere({"userId": user_id}, 1)[0]
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ Column {
|
||||
|
||||
// Avoid binding loop by using Component.onCompleted
|
||||
property var user: null
|
||||
Component.onCompleted: user = models.users.getUser(userId)
|
||||
Component.onCompleted: user = users.getUser(userId)
|
||||
|
||||
property string roomCategoriesListUserId: userId
|
||||
property bool expanded: true
|
||||
|
@ -6,6 +6,6 @@ HListView {
|
||||
id: accountList
|
||||
clip: true
|
||||
|
||||
model: models.accounts
|
||||
model: accounts
|
||||
delegate: AccountDelegate {}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ HListView {
|
||||
id: roomCategoriesList
|
||||
|
||||
model: SortFilterProxyModel {
|
||||
sourceModel: models.roomCategories
|
||||
sourceModel: roomCategories
|
||||
filters: ValueFilter {
|
||||
roleName: "userId"
|
||||
value: userId
|
||||
|
@ -37,11 +37,7 @@ MouseArea {
|
||||
}
|
||||
|
||||
HRichLabel {
|
||||
id: subtitleLabel
|
||||
visible: Boolean(text)
|
||||
textFormat: Text.StyledText
|
||||
text: {
|
||||
var ev = models.timelines.lastEventOf(model.roomId)
|
||||
function getText(ev) {
|
||||
if (! ev) { return "" }
|
||||
|
||||
if (! Utils.eventIsMessage(ev)) {
|
||||
@ -49,11 +45,16 @@ MouseArea {
|
||||
}
|
||||
|
||||
return Utils.coloredNameHtml(
|
||||
models.users.getUser(ev.senderId).displayName,
|
||||
users.getUser(ev.senderId).displayName,
|
||||
ev.senderId
|
||||
) + ": " + py.callSync("inlinify", [ev.content])
|
||||
}
|
||||
|
||||
id: subtitleLabel
|
||||
visible: Boolean(text)
|
||||
textFormat: Text.StyledText
|
||||
text: getText(timelines.lastEventOf(model.roomId))
|
||||
|
||||
font.pixelSize: HStyle.fontSize.small
|
||||
elide: Text.ElideRight
|
||||
maximumLineCount: 1
|
||||
|
@ -11,7 +11,7 @@ HListView {
|
||||
spacing: sidePane.normalSpacing
|
||||
|
||||
model: SortFilterProxyModel {
|
||||
sourceModel: models.rooms
|
||||
sourceModel: rooms
|
||||
filters: AllOf {
|
||||
ValueFilter {
|
||||
roleName: "category"
|
||||
|
@ -16,7 +16,7 @@ Item {
|
||||
}
|
||||
|
||||
property bool accountsPresent:
|
||||
models.accounts.count > 0 || py.loadingAccounts
|
||||
accounts.count > 0 || py.loadingAccounts
|
||||
|
||||
HImage {
|
||||
id: mainUIBackground
|
||||
|
@ -1,6 +1,7 @@
|
||||
import QtQuick 2.7
|
||||
import QtQuick.Controls 2.2
|
||||
import "Base"
|
||||
import "Models"
|
||||
|
||||
ApplicationWindow {
|
||||
id: window
|
||||
@ -20,13 +21,14 @@ ApplicationWindow {
|
||||
window.ready = true
|
||||
}
|
||||
|
||||
Python {
|
||||
id: py
|
||||
}
|
||||
Python { id: py }
|
||||
|
||||
Models {
|
||||
id: models
|
||||
}
|
||||
Accounts { id: accounts }
|
||||
Devices { id: devices }
|
||||
RoomCategories { id: roomCategories }
|
||||
Rooms { id: rooms }
|
||||
Timelines { id: timelines }
|
||||
Users { id: users }
|
||||
|
||||
LoadingScreen {
|
||||
id: loadingScreen
|
||||
|
@ -63,16 +63,16 @@ function eventIsMessage(ev) {
|
||||
|
||||
|
||||
function translatedEventContent(ev) {
|
||||
// ev: models.timelines item
|
||||
// ev: timelines item
|
||||
if (ev.translatable == false) { return ev.content }
|
||||
|
||||
// %S → sender display name
|
||||
var name = models.users.getUser(ev.senderId).displayName
|
||||
var name = users.getUser(ev.senderId).displayName
|
||||
var text = ev.content.replace("%S", coloredNameHtml(name, ev.senderId))
|
||||
|
||||
// %T → target (event state_key) display name
|
||||
if (ev.targetUserId) {
|
||||
var tname = models.users.getUser(ev.targetUserId).displayName
|
||||
var tname = users.getUser(ev.targetUserId).displayName
|
||||
text = text.replace("%T", coloredNameHtml(tname, ev.targetUserId))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user