moment/harmonyqml/backend/model/items.py

97 lines
2.9 KiB
Python
Raw Normal View History

from enum import Enum
from typing import Any, Dict, List, Optional
2019-05-16 05:59:43 +10:00
from PyQt5.QtCore import QDateTime
from ..pyqt_future import PyQtFuture
from .list_item import ListItem
from .list_model import ListModel
2019-05-16 05:59:43 +10:00
from .sort_filter_proxy import SortFilterProxy
2019-05-10 10:17:24 +10:00
class Account(ListItem):
_required_init_values = {"userId", "roomCategories"}
_constant = {"userId", "roomCategories"}
userId: str = ""
roomCategories: ListModel = ListModel()
2019-05-10 10:17:24 +10:00
class RoomCategory(ListItem):
_required_init_values = {"name", "rooms", "sortedRooms"}
_constant = {"name", "rooms", "sortedRooms"}
2019-05-10 10:17:24 +10:00
2019-05-16 05:59:43 +10:00
name: str = ""
rooms: ListModel = ListModel()
sortedRooms: SortFilterProxy = SortFilterProxy(ListModel(), "", "")
class Room(ListItem):
2019-05-16 05:59:43 +10:00
_required_init_values = {"roomId", "displayName", "members",
"sortedMembers"}
_constant = {"roomId", "members", "sortedMembers"}
roomId: str = ""
displayName: str = ""
topic: Optional[str] = None
lastEventDateTime: Optional[QDateTime] = None
typingMembers: List[str] = []
2019-05-16 05:59:43 +10:00
members: ListModel = ListModel()
sortedMembers: SortFilterProxy = SortFilterProxy(ListModel(), "", "")
inviter: Optional[Dict[str, str]] = None
leftEvent: Optional[Dict[str, str]] = None
class RoomMember(ListItem):
_required_init_values = {"userId"}
_constant = {"userId"}
userId: str = ""
2019-05-10 10:17:24 +10:00
class RoomEvent(ListItem):
_required_init_values = {"eventId", "type", "dict", "dateTime"}
2019-05-10 10:17:24 +10:00
_constant = {"type"}
eventId: str = ""
2019-05-10 10:17:24 +10:00
type: str = ""
dict: Dict[str, Any] = {}
dateTime: QDateTime = QDateTime()
2019-05-10 10:17:24 +10:00
isLocalEcho: bool = False
2019-05-10 10:17:24 +10:00
# ----------
class User(ListItem):
_required_init_values = {"userId", "devices"}
_constant = {"userId", "devices"}
# Use PyQtFutures because the info might or might not need a request
# to be fetched, and we don't want to block the UI in any case.
# QML's property binding ability is used on the PyQtFuture.value
userId: str = ""
displayName: Optional[PyQtFuture] = None
avatarUrl: Optional[PyQtFuture] = None
statusMessage: Optional[PyQtFuture] = None
devices: ListModel = ListModel()
class Trust(Enum):
blacklisted = -1
undecided = 0
trusted = 1
class Device(ListItem):
_required_init_values = {"deviceId", "ed25519Key"}
_constant = {"deviceId", "ed25519Key"}
2019-05-10 04:22:50 +10:00
deviceId: str = ""
ed25519Key: str = ""
displayName: Optional[str] = None
trust: Trust = Trust.undecided
lastSeenIp: Optional[str] = None
lastSeenDate: Optional[QDateTime] = None