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.
2019-08-11 22:01:22 +10:00
|
|
|
from dataclasses import dataclass, field
|
|
|
|
from datetime import datetime
|
|
|
|
from typing import Any, Dict, List, Optional
|
|
|
|
|
|
|
|
from ..html_filter import HTML_FILTER
|
2019-08-16 15:51:42 +10:00
|
|
|
from ..utils import AutoStrEnum, auto
|
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.
2019-08-11 22:01:22 +10:00
|
|
|
from .model_item import ModelItem
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Account(ModelItem):
|
|
|
|
main_key = "user_id"
|
|
|
|
|
|
|
|
user_id: str = field()
|
|
|
|
display_name: str = ""
|
|
|
|
avatar_url: str = ""
|
|
|
|
profile_updated: datetime = field(default_factory=datetime.now)
|
|
|
|
|
|
|
|
def __lt__(self, other: "Account") -> bool:
|
|
|
|
name = self.display_name or self.user_id[1:]
|
|
|
|
other_name = other.display_name or other.user_id[1:]
|
|
|
|
return name < other_name
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Room(ModelItem):
|
|
|
|
main_key = "room_id"
|
|
|
|
|
|
|
|
room_id: str = field()
|
|
|
|
display_name: str = ""
|
|
|
|
avatar_url: str = ""
|
|
|
|
topic: str = ""
|
|
|
|
inviter_id: str = ""
|
2019-08-16 02:13:41 +10:00
|
|
|
inviter_name: str = ""
|
|
|
|
inviter_avatar: str = ""
|
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.
2019-08-11 22:01:22 +10:00
|
|
|
left: bool = False
|
|
|
|
filter_string: str = ""
|
|
|
|
typing_members: List[str] = field(default_factory=list)
|
|
|
|
|
2019-08-15 23:57:58 +10:00
|
|
|
# Event __dict__
|
|
|
|
last_event: Optional[Dict[str, Any]] = field(default=None, repr=False)
|
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.
2019-08-11 22:01:22 +10:00
|
|
|
|
|
|
|
def __lt__(self, other: "Room") -> bool:
|
|
|
|
# Left rooms may still have an inviter_id, check left first.
|
|
|
|
if self.left and not other.left:
|
|
|
|
return True
|
|
|
|
|
|
|
|
if other.inviter_id and not self.inviter_id:
|
|
|
|
return True
|
|
|
|
|
|
|
|
name = self.display_name or self.room_id
|
|
|
|
other_name = other.display_name or other.room_id
|
|
|
|
return name < other_name
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Member(ModelItem):
|
|
|
|
main_key = "user_id"
|
|
|
|
|
|
|
|
user_id: str = field()
|
|
|
|
display_name: str = ""
|
|
|
|
avatar_url: str = ""
|
|
|
|
typing: bool = False
|
|
|
|
power_level: int = 0
|
|
|
|
filter_string: str = ""
|
|
|
|
|
|
|
|
def __lt__(self, other: "Member") -> bool:
|
|
|
|
name = self.display_name or self.user_id[1:]
|
|
|
|
other_name = other.display_name or other.user_id[1:]
|
|
|
|
return name < other_name
|
|
|
|
|
|
|
|
|
2019-08-16 15:51:42 +10:00
|
|
|
class TypeSpecifier(AutoStrEnum):
|
|
|
|
none = auto()
|
|
|
|
profile_change = auto()
|
|
|
|
membership_change = auto()
|
|
|
|
|
|
|
|
|
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.
2019-08-11 22:01:22 +10:00
|
|
|
@dataclass
|
|
|
|
class Event(ModelItem):
|
|
|
|
main_key = "event_id"
|
|
|
|
|
|
|
|
client_id: str = field()
|
|
|
|
event_id: str = field()
|
|
|
|
event_type: str = field() # Type[nio.Event]
|
|
|
|
content: str = field()
|
|
|
|
inline_content: str = field()
|
|
|
|
date: datetime = field()
|
|
|
|
|
|
|
|
sender_id: str = field()
|
|
|
|
sender_name: str = field()
|
|
|
|
sender_avatar: str = field()
|
|
|
|
|
2019-08-16 15:51:42 +10:00
|
|
|
type_specifier: TypeSpecifier = TypeSpecifier.none
|
|
|
|
|
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.
2019-08-11 22:01:22 +10:00
|
|
|
target_id: str = ""
|
|
|
|
target_name: str = ""
|
|
|
|
target_avatar: str = ""
|
|
|
|
|
|
|
|
is_local_echo: bool = False
|
|
|
|
|
|
|
|
def __post_init__(self) -> None:
|
|
|
|
self.inline_content = HTML_FILTER.filter_inline(self.content)
|
|
|
|
|
|
|
|
|
|
|
|
def __lt__(self, other: "Event") -> bool:
|
|
|
|
# Sort events from newest to oldest. return True means return False.
|
|
|
|
# Local echoes always stay first.
|
|
|
|
if self.is_local_echo and not other.is_local_echo:
|
|
|
|
return True
|
|
|
|
|
|
|
|
if other.is_local_echo and not self.is_local_echo:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return self.date > other.date
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Device(ModelItem):
|
|
|
|
main_key = "device_id"
|
|
|
|
|
|
|
|
device_id: str = field()
|
|
|
|
ed25519_key: str = field()
|
|
|
|
trusted: bool = False
|
|
|
|
blacklisted: bool = False
|
|
|
|
display_name: str = ""
|
|
|
|
last_seen_ip: str = ""
|
|
|
|
last_seen_date: str = ""
|