Merge Backend and QMLModels
Backend.models.accounts → Backend.accounts Backend.models.roomEvents → Backend.roomEvents
This commit is contained in:
parent
047225fded
commit
52d538e995
|
@ -2,13 +2,12 @@
|
|||
# This file is part of harmonyqml, licensed under GPLv3.
|
||||
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from typing import Dict, Sequence, Set
|
||||
from typing import Deque, Dict, Sequence, Set
|
||||
|
||||
from PyQt5.QtCore import QObject, pyqtProperty, pyqtSlot
|
||||
|
||||
from .html_filter import HtmlFilter
|
||||
from .model.items import RoomEvent
|
||||
from .model.qml_models import QMLModels
|
||||
from .model import ListModel, ListModelMap
|
||||
from .pyqt_future import futurize
|
||||
|
||||
|
||||
|
@ -22,10 +21,13 @@ class Backend(QObject):
|
|||
self.past_tokens: Dict[str, str] = {}
|
||||
self.fully_loaded_rooms: Set[str] = set()
|
||||
|
||||
self._html_filter: HtmlFilter = HtmlFilter(self)
|
||||
|
||||
from .client_manager import ClientManager
|
||||
self._client_manager: ClientManager = ClientManager(self)
|
||||
self._models: QMLModels = QMLModels(self)
|
||||
self._html_filter: HtmlFilter = HtmlFilter(self)
|
||||
|
||||
self._accounts: ListModel = ListModel(parent=parent)
|
||||
self._room_events: ListModelMap = ListModelMap(Deque, parent)
|
||||
|
||||
from .signal_manager import SignalManager
|
||||
self._signal_manager: SignalManager = SignalManager(self)
|
||||
|
@ -33,17 +35,21 @@ class Backend(QObject):
|
|||
self.clientManager.configLoad()
|
||||
|
||||
|
||||
@pyqtProperty("QVariant", constant=True)
|
||||
def htmlFilter(self):
|
||||
return self._html_filter
|
||||
|
||||
@pyqtProperty("QVariant", constant=True)
|
||||
def clientManager(self):
|
||||
return self._client_manager
|
||||
|
||||
@pyqtProperty("QVariant", constant=True)
|
||||
def models(self):
|
||||
return self._models
|
||||
def accounts(self):
|
||||
return self._accounts
|
||||
|
||||
@pyqtProperty("QVariant", constant=True)
|
||||
def htmlFilter(self):
|
||||
return self._html_filter
|
||||
def roomEvents(self):
|
||||
return self._room_events
|
||||
|
||||
|
||||
@pyqtSlot(str, result="QVariant")
|
||||
|
|
|
@ -4,4 +4,3 @@
|
|||
from . import items
|
||||
from .list_model import ListModel
|
||||
from .list_model_map import ListModelMap
|
||||
from .qml_models import QMLModels
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
# Copyright 2019 miruka
|
||||
# This file is part of harmonyqml, licensed under GPLv3.
|
||||
|
||||
from typing import Deque
|
||||
|
||||
from PyQt5.QtCore import QObject, pyqtProperty
|
||||
|
||||
from .list_model import ListModel
|
||||
from .list_model_map import ListModelMap
|
||||
|
||||
|
||||
class QMLModels(QObject):
|
||||
def __init__(self, parent: QObject) -> None:
|
||||
super().__init__(parent)
|
||||
self._accounts: ListModel = ListModel(parent=parent)
|
||||
self._room_events: ListModelMap = ListModelMap(Deque, parent)
|
||||
|
||||
|
||||
@pyqtProperty(ListModel, constant=True)
|
||||
def accounts(self):
|
||||
return self._accounts
|
||||
|
||||
|
||||
@pyqtProperty("QVariant", constant=True)
|
||||
def roomEvents(self):
|
||||
return self._room_events
|
|
@ -11,8 +11,7 @@ from nio.rooms import MatrixRoom
|
|||
|
||||
from .backend import Backend
|
||||
from .client import Client
|
||||
from .model.items import Account, Room, RoomCategory, RoomEvent
|
||||
from .model.list_model import ListModel
|
||||
from .model.items import Account, ListModel, Room, RoomCategory, RoomEvent
|
||||
|
||||
Inviter = Optional[Dict[str, str]]
|
||||
LeftEvent = Optional[Dict[str, str]]
|
||||
|
@ -36,7 +35,7 @@ class SignalManager(QObject):
|
|||
def onClientAdded(self, client: Client) -> None:
|
||||
self.connectClient(client)
|
||||
|
||||
self.backend.models.accounts.append(Account(
|
||||
self.backend.accounts.append(Account(
|
||||
userId = client.userId,
|
||||
roomCategories = ListModel([
|
||||
RoomCategory("Invites", ListModel()),
|
||||
|
@ -48,7 +47,7 @@ class SignalManager(QObject):
|
|||
|
||||
|
||||
def onClientDeleted(self, user_id: str) -> None:
|
||||
del self.backend.models.accounts[user_id]
|
||||
del self.backend.accounts[user_id]
|
||||
|
||||
|
||||
def connectClient(self, client: Client) -> None:
|
||||
|
@ -79,7 +78,7 @@ class SignalManager(QObject):
|
|||
inviter: Inviter = None) -> None:
|
||||
|
||||
nio_room = client.nio.invited_rooms[room_id]
|
||||
categories = self.backend.models.accounts[client.userId].roomCategories
|
||||
categories = self.backend.accounts[client.userId].roomCategories
|
||||
|
||||
categories["Rooms"].rooms.pop(room_id, None)
|
||||
categories["Left"].rooms.pop(room_id, None)
|
||||
|
@ -94,7 +93,7 @@ class SignalManager(QObject):
|
|||
|
||||
def onRoomJoined(self, client: Client, room_id: str) -> None:
|
||||
nio_room = client.nio.rooms[room_id]
|
||||
categories = self.backend.models.accounts[client.userId].roomCategories
|
||||
categories = self.backend.accounts[client.userId].roomCategories
|
||||
|
||||
categories["Invites"].rooms.pop(room_id, None)
|
||||
categories["Left"].rooms.pop(room_id, None)
|
||||
|
@ -110,7 +109,7 @@ class SignalManager(QObject):
|
|||
client: Client,
|
||||
room_id: str,
|
||||
left_event: LeftEvent = None) -> None:
|
||||
categories = self.backend.models.accounts[client.userId].roomCategories
|
||||
categories = self.backend.accounts[client.userId].roomCategories
|
||||
|
||||
previous = categories["Rooms"].rooms.pop(room_id, None)
|
||||
previous = previous or categories["Invites"].rooms.pop(room_id, None)
|
||||
|
@ -155,7 +154,7 @@ class SignalManager(QObject):
|
|||
|
||||
self.last_room_events.appendleft(edict["event_id"])
|
||||
|
||||
model = self.backend.models.roomEvents[room_id]
|
||||
model = self.backend.roomEvents[room_id]
|
||||
date_time = QDateTime\
|
||||
.fromMSecsSinceEpoch(edict["server_timestamp"])
|
||||
new_event = RoomEvent(type=etype, dateTime=date_time, dict=edict)
|
||||
|
@ -218,7 +217,7 @@ class SignalManager(QObject):
|
|||
client: Client,
|
||||
room_id: str,
|
||||
users: List[str]) -> None:
|
||||
categories = self.backend.models.accounts[client.userId].roomCategories
|
||||
categories = self.backend.accounts[client.userId].roomCategories
|
||||
for categ in categories:
|
||||
try:
|
||||
categ.rooms[room_id].typingUsers = users
|
||||
|
@ -233,7 +232,7 @@ class SignalManager(QObject):
|
|||
content: Dict[str, str]) -> None:
|
||||
|
||||
with self._lock:
|
||||
model = self.backend.models.roomEvents[room_id]
|
||||
model = self.backend.roomEvents[room_id]
|
||||
nio_event = nio.events.RoomMessage.parse_event({
|
||||
"event_id": "",
|
||||
"sender": client.userId,
|
||||
|
@ -252,9 +251,9 @@ class SignalManager(QObject):
|
|||
|
||||
|
||||
def onRoomAboutToBeForgotten(self, client: Client, room_id: str) -> None:
|
||||
categories = self.backend.models.accounts[client.userId].roomCategories
|
||||
categories = self.backend.accounts[client.userId].roomCategories
|
||||
|
||||
for categ in categories:
|
||||
categ.rooms.pop(room_id, None)
|
||||
|
||||
self.backend.models.roomEvents[room_id].clear()
|
||||
self.backend.roomEvents[room_id].clear()
|
||||
|
|
|
@ -10,8 +10,9 @@ HColumnLayout {
|
|||
property string roomId: ""
|
||||
|
||||
readonly property var roomInfo:
|
||||
Backend.models.accounts.get(userId)
|
||||
.roomCategories.get(category).rooms.get(roomId)
|
||||
Backend.accounts.get(userId)
|
||||
.roomCategories.get(category)
|
||||
.rooms.get(roomId)
|
||||
|
||||
property bool canLoadPastEvents: true
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ HGlassRectangle {
|
|||
ListView {
|
||||
id: roomEventListView
|
||||
delegate: RoomEventDelegate {}
|
||||
model: Backend.models.roomEvents.get(chatPage.roomId)
|
||||
model: Backend.roomEvents.get(chatPage.roomId)
|
||||
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: space
|
||||
|
|
|
@ -9,6 +9,6 @@ ListView {
|
|||
topMargin: spacing
|
||||
bottomMargin: topMargin
|
||||
|
||||
model: Backend.models.accounts
|
||||
model: Backend.accounts
|
||||
delegate: AccountDelegate {}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,6 @@ ListView {
|
|||
property string userId: ""
|
||||
|
||||
id: roomCategoriesList
|
||||
model: Backend.models.accounts.get(userId).roomCategories
|
||||
model: Backend.accounts.get(userId).roomCategories
|
||||
delegate: RoomCategoryDelegate {}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ MouseArea {
|
|||
}
|
||||
|
||||
Connections {
|
||||
target: Backend.models.roomEvents.get(roomId)
|
||||
target: Backend.roomEvents.get(roomId)
|
||||
onChanged: subtitleLabel.text = subtitleLabel.getText()
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,6 @@ ListView {
|
|||
|
||||
id: roomList
|
||||
spacing: accountList.spacing
|
||||
model: Backend.models.accounts.get(userId).roomCategories.get(category).rooms
|
||||
model: Backend.accounts.get(userId).roomCategories.get(category).rooms
|
||||
delegate: RoomDelegate {}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
|
||||
function getLastRoomEventText(roomId, accountId) {
|
||||
var eventsModel = Backend.models.roomEvents.get(roomId)
|
||||
var eventsModel = Backend.roomEvents.get(roomId)
|
||||
if (eventsModel.count < 1) { return "" }
|
||||
var ev = eventsModel.get(0)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user