2020-09-24 09:57:54 +10:00
|
|
|
# Copyright Mirage authors & contributors <https://github.com/mirukana/mirage>
|
2019-12-19 22:46:16 +11:00
|
|
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-12-19 06:00:34 +11:00
|
|
|
"""`ModelItem` subclasses definitions."""
|
|
|
|
|
2020-02-13 04:04:46 +11:00
|
|
|
import json
|
2020-05-15 03:58:34 +10:00
|
|
|
from dataclasses import asdict, dataclass, field
|
2019-12-06 01:00:23 +11:00
|
|
|
from datetime import datetime, timedelta
|
2019-11-06 09:31:16 +11:00
|
|
|
from pathlib import Path
|
2019-12-02 17:57:47 +11:00
|
|
|
from typing import Any, Dict, List, Optional, Tuple, Type, Union
|
2019-12-02 20:06:21 +11:00
|
|
|
from uuid import UUID
|
2019-09-03 17:04:57 +10:00
|
|
|
|
|
|
|
import lxml # nosec
|
2019-08-29 03:23:12 +10:00
|
|
|
import nio
|
|
|
|
|
2020-07-19 08:33:57 +10:00
|
|
|
from ..presence import Presence
|
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
|
|
|
|
|
2019-12-02 17:57:47 +11:00
|
|
|
OptionalExceptionType = Union[Type[None], Type[Exception]]
|
2020-07-11 01:38:23 +10:00
|
|
|
|
|
|
|
ZERO_DATE = datetime.fromtimestamp(0)
|
|
|
|
|
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
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
class TypeSpecifier(AutoStrEnum):
|
|
|
|
"""Enum providing clarification of purpose for some matrix events."""
|
|
|
|
|
|
|
|
Unset = auto()
|
|
|
|
ProfileChange = auto()
|
|
|
|
MembershipChange = auto()
|
|
|
|
|
|
|
|
|
2020-08-19 14:17:24 +10:00
|
|
|
class PingStatus(AutoStrEnum):
|
|
|
|
"""Enum for the status of a homeserver ping operation."""
|
|
|
|
|
|
|
|
Done = auto()
|
|
|
|
Pinging = auto()
|
|
|
|
Failed = auto()
|
|
|
|
|
|
|
|
|
2020-10-17 19:22:48 +11:00
|
|
|
@dataclass(eq=False)
|
2020-08-19 14:17:24 +10:00
|
|
|
class Homeserver(ModelItem):
|
|
|
|
"""A homeserver we can connect to. The `id` field is the server's URL."""
|
|
|
|
|
2021-01-11 22:50:32 +11:00
|
|
|
id: str = field()
|
|
|
|
name: str = field()
|
|
|
|
site_url: str = field()
|
|
|
|
country: str = field()
|
|
|
|
ping: int = -1
|
|
|
|
status: PingStatus = PingStatus.Pinging
|
|
|
|
stability: float = -1
|
|
|
|
downtimes_ms: List[float] = field(default_factory=list)
|
2020-08-19 14:17:24 +10:00
|
|
|
|
|
|
|
def __lt__(self, other: "Homeserver") -> bool:
|
|
|
|
return (self.name.lower(), self.id) < (other.name.lower(), other.id)
|
|
|
|
|
|
|
|
|
2020-10-17 19:22:48 +11:00
|
|
|
@dataclass(eq=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
|
|
|
class Account(ModelItem):
|
2019-12-19 06:00:34 +11:00
|
|
|
"""A logged in matrix account."""
|
|
|
|
|
2020-06-01 09:13:19 +10:00
|
|
|
id: str = field()
|
|
|
|
order: int = -1
|
|
|
|
display_name: str = ""
|
|
|
|
avatar_url: str = ""
|
|
|
|
max_upload_size: int = 0
|
2020-07-11 01:38:23 +10:00
|
|
|
profile_updated: datetime = ZERO_DATE
|
2020-07-10 06:06:14 +10:00
|
|
|
connecting: bool = False
|
2020-06-01 09:13:19 +10:00
|
|
|
total_unread: int = 0
|
|
|
|
total_highlights: int = 0
|
2020-06-26 19:43:49 +10:00
|
|
|
local_unreads: bool = False
|
2020-06-26 19:58:43 +10:00
|
|
|
local_highlights: bool = 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
|
|
|
|
2020-07-03 10:25:24 +10:00
|
|
|
# For some reason, Account cannot inherit Presence, because QML keeps
|
|
|
|
# complaining type error on unknown file
|
2020-07-10 06:06:14 +10:00
|
|
|
presence_support: bool = False
|
2020-07-11 14:51:53 +10:00
|
|
|
save_presence: bool = True
|
2020-07-10 06:06:14 +10:00
|
|
|
presence: Presence.State = Presence.State.offline
|
|
|
|
currently_active: bool = False
|
2020-07-11 01:38:23 +10:00
|
|
|
last_active_at: datetime = ZERO_DATE
|
2020-07-10 06:06:14 +10:00
|
|
|
status_msg: str = ""
|
2020-07-02 13:27:50 +10:00
|
|
|
|
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: "Account") -> bool:
|
2020-05-14 17:33:34 +10:00
|
|
|
"""Sort by order, then by user ID."""
|
2020-10-17 19:22:48 +11:00
|
|
|
return (self.order, self.id) < (other.order, other.id)
|
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
|
|
|
|
|
|
|
|
2020-10-17 19:22:48 +11:00
|
|
|
@dataclass(eq=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
|
|
|
class Room(ModelItem):
|
2019-12-19 06:00:34 +11:00
|
|
|
"""A matrix room we are invited to, are or were member of."""
|
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
id: str = field()
|
2020-05-12 20:09:07 +10:00
|
|
|
for_account: str = ""
|
2019-12-03 07:29:29 +11:00
|
|
|
given_name: str = ""
|
|
|
|
display_name: str = ""
|
|
|
|
main_alias: str = ""
|
|
|
|
avatar_url: str = ""
|
|
|
|
plain_topic: str = ""
|
|
|
|
topic: str = ""
|
|
|
|
inviter_id: str = ""
|
|
|
|
inviter_name: str = ""
|
|
|
|
inviter_avatar: str = ""
|
|
|
|
left: bool = 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
|
|
|
typing_members: List[str] = field(default_factory=list)
|
|
|
|
|
2020-06-28 01:11:14 +10:00
|
|
|
federated: bool = True
|
|
|
|
encrypted: bool = False
|
|
|
|
unverified_devices: bool = False
|
|
|
|
invite_required: bool = True
|
|
|
|
guests_allowed: bool = True
|
2019-12-13 23:32:18 +11:00
|
|
|
|
2020-07-13 09:28:40 +10:00
|
|
|
default_power_level: int = 0
|
2020-07-14 08:44:20 +10:00
|
|
|
own_power_level: int = 0
|
2019-12-13 23:32:18 +11:00
|
|
|
can_invite: bool = False
|
2020-04-20 01:12:35 +10:00
|
|
|
can_kick: bool = False
|
2020-04-02 06:15:49 +11:00
|
|
|
can_redact_all: bool = False
|
2019-12-13 23:32:18 +11:00
|
|
|
can_send_messages: bool = False
|
|
|
|
can_set_name: bool = False
|
|
|
|
can_set_topic: bool = False
|
|
|
|
can_set_avatar: bool = False
|
|
|
|
can_set_encryption: bool = False
|
|
|
|
can_set_join_rules: bool = False
|
|
|
|
can_set_guest_access: bool = False
|
2020-07-14 08:44:20 +10:00
|
|
|
can_set_power_levels: bool = False
|
2019-12-12 03:42:59 +11:00
|
|
|
|
2020-07-11 01:38:23 +10:00
|
|
|
last_event_date: datetime = ZERO_DATE
|
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
|
|
|
|
2020-06-26 19:58:43 +10:00
|
|
|
unreads: int = 0
|
|
|
|
highlights: int = 0
|
|
|
|
local_unreads: bool = False
|
|
|
|
local_highlights: bool = False
|
2020-03-23 14:55:48 +11:00
|
|
|
|
2020-09-02 04:42:08 +10:00
|
|
|
lexical_sorting: bool = False
|
2020-10-17 08:36:59 +11:00
|
|
|
bookmarked: bool = False
|
2020-09-02 04:42:08 +10:00
|
|
|
|
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:
|
2020-06-01 09:13:19 +10:00
|
|
|
"""Sort by membership, highlights/unread events, last event date, name.
|
2019-12-19 06:00:34 +11:00
|
|
|
|
|
|
|
Invited rooms are first, then joined rooms, then left rooms.
|
2020-06-26 19:43:49 +10:00
|
|
|
Within these categories, sort by unread highlighted messages, then
|
|
|
|
unread messages, then by whether the room hasn't been read locally,
|
|
|
|
then last event date (room with recent messages are first),
|
|
|
|
then by display names or ID.
|
2019-12-19 06:00:34 +11:00
|
|
|
"""
|
|
|
|
|
2020-09-02 04:42:08 +10:00
|
|
|
if self.lexical_sorting:
|
|
|
|
return (
|
|
|
|
self.for_account,
|
2020-10-17 08:36:59 +11:00
|
|
|
other.bookmarked,
|
2020-09-02 04:42:08 +10:00
|
|
|
self.left,
|
2020-10-17 19:22:48 +11:00
|
|
|
bool(other.inviter_id),
|
2020-09-02 04:42:08 +10:00
|
|
|
(self.display_name or self.id).lower(),
|
2020-10-17 19:22:48 +11:00
|
|
|
self.id,
|
2020-09-02 04:42:08 +10:00
|
|
|
) < (
|
|
|
|
other.for_account,
|
2020-10-17 08:36:59 +11:00
|
|
|
self.bookmarked,
|
2020-09-02 04:42:08 +10:00
|
|
|
other.left,
|
2020-10-17 19:22:48 +11:00
|
|
|
bool(self.inviter_id),
|
2020-09-02 04:42:08 +10:00
|
|
|
(other.display_name or other.id).lower(),
|
2020-10-17 19:22:48 +11:00
|
|
|
other.id,
|
2020-09-02 04:42:08 +10:00
|
|
|
)
|
|
|
|
|
2019-11-27 07:17:15 +11:00
|
|
|
# Left rooms may still have an inviter_id, so check left first.
|
|
|
|
return (
|
2020-04-30 04:00:02 +10:00
|
|
|
self.for_account,
|
2020-10-17 08:36:59 +11:00
|
|
|
other.bookmarked,
|
2019-11-27 07:17:15 +11:00
|
|
|
self.left,
|
2020-10-17 19:22:48 +11:00
|
|
|
bool(other.inviter_id),
|
2020-06-01 09:13:19 +10:00
|
|
|
bool(other.highlights),
|
2020-06-26 19:58:43 +10:00
|
|
|
bool(other.local_highlights),
|
2020-04-18 08:59:17 +10:00
|
|
|
bool(other.unreads),
|
2020-06-26 19:43:49 +10:00
|
|
|
bool(other.local_unreads),
|
2019-12-03 07:29:29 +11:00
|
|
|
other.last_event_date,
|
|
|
|
(self.display_name or self.id).lower(),
|
2020-10-17 19:22:48 +11:00
|
|
|
self.id,
|
2020-04-30 04:00:02 +10:00
|
|
|
|
2019-11-27 07:17:15 +11:00
|
|
|
) < (
|
2020-04-30 04:00:02 +10:00
|
|
|
other.for_account,
|
2020-10-17 08:36:59 +11:00
|
|
|
self.bookmarked,
|
2019-11-27 07:17:15 +11:00
|
|
|
other.left,
|
2020-10-17 19:22:48 +11:00
|
|
|
bool(self.inviter_id),
|
2020-06-01 09:13:19 +10:00
|
|
|
bool(self.highlights),
|
2020-06-26 19:58:43 +10:00
|
|
|
bool(self.local_highlights),
|
2020-04-18 08:59:17 +10:00
|
|
|
bool(self.unreads),
|
2020-06-26 19:43:49 +10:00
|
|
|
bool(self.local_unreads),
|
2019-12-03 07:29:29 +11:00
|
|
|
self.last_event_date,
|
|
|
|
(other.display_name or other.id).lower(),
|
2020-10-17 19:22:48 +11:00
|
|
|
other.id,
|
2019-11-27 07:17:15 +11:00
|
|
|
)
|
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
|
|
|
|
2019-12-20 07:52:21 +11:00
|
|
|
|
2020-10-17 19:22:48 +11:00
|
|
|
@dataclass(eq=False)
|
2020-05-12 20:09:07 +10:00
|
|
|
class AccountOrRoom(Account, Room):
|
2020-05-14 17:33:34 +10:00
|
|
|
type: Union[Type[Account], Type[Room]] = Account
|
|
|
|
account_order: int = -1
|
2020-05-12 20:09:07 +10:00
|
|
|
|
|
|
|
def __lt__(self, other: "AccountOrRoom") -> bool: # type: ignore
|
2020-09-02 04:42:08 +10:00
|
|
|
if self.lexical_sorting:
|
|
|
|
return (
|
|
|
|
self.account_order,
|
|
|
|
self.id if self.type is Account else self.for_account,
|
|
|
|
other.type is Account,
|
2020-10-17 08:36:59 +11:00
|
|
|
other.bookmarked,
|
2020-09-02 04:42:08 +10:00
|
|
|
self.left,
|
2020-10-17 19:22:48 +11:00
|
|
|
bool(other.inviter_id),
|
2020-09-02 04:42:08 +10:00
|
|
|
(self.display_name or self.id).lower(),
|
2020-10-17 19:22:48 +11:00
|
|
|
self.id,
|
2020-09-02 04:42:08 +10:00
|
|
|
) < (
|
|
|
|
other.account_order,
|
|
|
|
other.id if other.type is Account else other.for_account,
|
|
|
|
self.type is Account,
|
2020-10-17 08:36:59 +11:00
|
|
|
self.bookmarked,
|
2020-09-02 04:42:08 +10:00
|
|
|
other.left,
|
2020-10-17 19:22:48 +11:00
|
|
|
bool(self.inviter_id),
|
2020-09-02 04:42:08 +10:00
|
|
|
(other.display_name or other.id).lower(),
|
2020-10-17 19:22:48 +11:00
|
|
|
other.id,
|
2020-09-02 04:42:08 +10:00
|
|
|
)
|
|
|
|
|
2020-05-12 20:09:07 +10:00
|
|
|
return (
|
2020-05-14 17:33:34 +10:00
|
|
|
self.account_order,
|
2020-05-12 20:09:07 +10:00
|
|
|
self.id if self.type is Account else self.for_account,
|
|
|
|
other.type is Account,
|
2020-10-17 08:36:59 +11:00
|
|
|
other.bookmarked,
|
2020-05-12 20:09:07 +10:00
|
|
|
self.left,
|
2020-10-17 19:22:48 +11:00
|
|
|
bool(other.inviter_id),
|
2020-06-01 09:13:19 +10:00
|
|
|
bool(other.highlights),
|
2020-06-26 19:58:43 +10:00
|
|
|
bool(other.local_highlights),
|
2020-05-12 20:09:07 +10:00
|
|
|
bool(other.unreads),
|
2020-06-26 19:43:49 +10:00
|
|
|
bool(other.local_unreads),
|
2020-05-12 20:09:07 +10:00
|
|
|
other.last_event_date,
|
|
|
|
(self.display_name or self.id).lower(),
|
2020-10-17 19:22:48 +11:00
|
|
|
self.id,
|
2020-05-12 20:09:07 +10:00
|
|
|
|
|
|
|
) < (
|
2020-05-14 17:33:34 +10:00
|
|
|
other.account_order,
|
2020-05-12 20:09:07 +10:00
|
|
|
other.id if other.type is Account else other.for_account,
|
|
|
|
self.type is Account,
|
2020-10-17 08:36:59 +11:00
|
|
|
self.bookmarked,
|
2020-05-12 20:09:07 +10:00
|
|
|
other.left,
|
2020-10-17 19:22:48 +11:00
|
|
|
bool(self.inviter_id),
|
2020-06-01 09:13:19 +10:00
|
|
|
bool(self.highlights),
|
2020-06-26 19:58:43 +10:00
|
|
|
bool(self.local_highlights),
|
2020-05-12 20:09:07 +10:00
|
|
|
bool(self.unreads),
|
2020-06-26 19:43:49 +10:00
|
|
|
bool(self.local_unreads),
|
2020-05-12 20:09:07 +10:00
|
|
|
self.last_event_date,
|
|
|
|
(other.display_name or other.id).lower(),
|
2020-10-17 19:22:48 +11:00
|
|
|
other.id,
|
2020-05-12 20:09:07 +10:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-10-17 19:22:48 +11:00
|
|
|
@dataclass(eq=False)
|
2020-07-10 06:06:14 +10:00
|
|
|
class Member(ModelItem):
|
2019-12-19 06:00:34 +11:00
|
|
|
"""A member in a matrix room."""
|
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
id: str = field()
|
|
|
|
display_name: str = ""
|
|
|
|
avatar_url: str = ""
|
|
|
|
typing: bool = False
|
|
|
|
power_level: int = 0
|
|
|
|
invited: bool = False
|
2020-07-11 01:38:23 +10:00
|
|
|
profile_updated: datetime = ZERO_DATE
|
2020-05-31 14:38:48 +10:00
|
|
|
last_read_event: 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
|
|
|
|
2020-07-10 06:06:14 +10:00
|
|
|
presence: Presence.State = Presence.State.offline
|
|
|
|
currently_active: bool = False
|
2020-07-11 01:38:23 +10:00
|
|
|
last_active_at: datetime = ZERO_DATE
|
2020-07-10 06:06:14 +10:00
|
|
|
status_msg: 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
|
|
|
def __lt__(self, other: "Member") -> bool:
|
2020-07-02 06:55:03 +10:00
|
|
|
"""Sort by presence, power level, then by display name/user ID."""
|
2019-12-19 06:00:34 +11:00
|
|
|
|
2019-12-13 01:03:39 +11:00
|
|
|
|
|
|
|
return (
|
2020-07-02 06:55:03 +10:00
|
|
|
self.invited,
|
|
|
|
other.power_level,
|
2020-07-10 09:53:25 +10:00
|
|
|
self.presence,
|
2020-10-17 19:22:48 +11:00
|
|
|
(self.display_name or self.id[1:]).lower(),
|
|
|
|
self.id,
|
2019-12-13 01:03:39 +11:00
|
|
|
) < (
|
2020-07-02 06:55:03 +10:00
|
|
|
other.invited,
|
|
|
|
self.power_level,
|
2020-07-10 09:53:25 +10:00
|
|
|
other.presence,
|
2020-10-17 19:22:48 +11:00
|
|
|
(other.display_name or other.id[1:]).lower(),
|
|
|
|
other.id,
|
2019-12-13 01:03:39 +11:00
|
|
|
)
|
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
|
|
|
|
|
|
|
|
2019-11-06 09:31:16 +11:00
|
|
|
class UploadStatus(AutoStrEnum):
|
2019-12-19 06:00:34 +11:00
|
|
|
"""Enum describing the status of an upload operation."""
|
|
|
|
|
2020-07-17 06:00:11 +10:00
|
|
|
Preparing = auto()
|
2019-12-07 07:44:25 +11:00
|
|
|
Uploading = auto()
|
|
|
|
Caching = auto()
|
|
|
|
Error = auto()
|
2019-11-06 09:31:16 +11:00
|
|
|
|
|
|
|
|
2020-10-17 19:22:48 +11:00
|
|
|
@dataclass(eq=False)
|
2020-03-08 20:24:07 +11:00
|
|
|
class Upload(ModelItem):
|
2019-12-19 06:00:34 +11:00
|
|
|
"""Represent a running or failed file upload operation."""
|
|
|
|
|
2020-03-08 20:24:07 +11:00
|
|
|
id: UUID = field()
|
2020-07-17 06:00:11 +10:00
|
|
|
filepath: Path = Path("-")
|
2019-12-06 01:00:23 +11:00
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
total_size: int = 0
|
|
|
|
uploaded: int = 0
|
|
|
|
speed: float = 0
|
|
|
|
time_left: timedelta = timedelta(0)
|
2020-03-08 20:24:07 +11:00
|
|
|
paused: bool = False
|
2019-12-06 01:00:23 +11:00
|
|
|
|
2020-07-17 06:00:11 +10:00
|
|
|
status: UploadStatus = UploadStatus.Preparing
|
2019-12-02 17:57:47 +11:00
|
|
|
error: OptionalExceptionType = type(None)
|
|
|
|
error_args: Tuple[Any, ...] = ()
|
2019-11-06 09:31:16 +11:00
|
|
|
|
|
|
|
start_date: datetime = field(init=False, default_factory=datetime.now)
|
|
|
|
|
|
|
|
|
|
|
|
def __lt__(self, other: "Upload") -> bool:
|
2019-12-19 06:00:34 +11:00
|
|
|
"""Sort by the start date, from newest upload to oldest."""
|
|
|
|
|
2020-10-17 19:22:48 +11:00
|
|
|
return (self.start_date, self.id) > (other.start_date, other.id)
|
2019-11-06 09:31:16 +11:00
|
|
|
|
|
|
|
|
2020-10-17 19:22:48 +11:00
|
|
|
@dataclass(eq=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
|
|
|
class Event(ModelItem):
|
2019-12-19 06:00:34 +11:00
|
|
|
"""A matrix state event or message."""
|
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
id: str = field()
|
2019-09-14 13:02:11 +10:00
|
|
|
event_id: str = field()
|
2020-02-12 21:27:21 +11:00
|
|
|
event_type: Type[nio.Event] = field()
|
2019-09-14 13:02:11 +10:00
|
|
|
date: datetime = field()
|
|
|
|
sender_id: str = field()
|
|
|
|
sender_name: str = field()
|
|
|
|
sender_avatar: str = field()
|
2020-05-20 17:42:40 +10:00
|
|
|
fetch_profile: bool = 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
|
|
|
|
2020-05-20 20:37:50 +10:00
|
|
|
content: str = ""
|
|
|
|
inline_content: str = ""
|
|
|
|
reason: str = ""
|
|
|
|
links: List[str] = field(default_factory=list)
|
|
|
|
mentions: List[Tuple[str, str]] = field(default_factory=list)
|
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
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
type_specifier: TypeSpecifier = TypeSpecifier.Unset
|
2019-08-16 15:51:42 +10:00
|
|
|
|
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 = ""
|
2020-04-03 04:54:06 +11:00
|
|
|
redacter_id: str = ""
|
|
|
|
redacter_name: 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
|
|
|
|
2020-09-06 06:47:34 +10:00
|
|
|
# {user_id: server_timestamp} - QML can't parse dates from JSONified dicts
|
|
|
|
last_read_by: Dict[str, int] = field(default_factory=dict)
|
2020-09-15 01:33:16 +10:00
|
|
|
read_by_count: int = 0
|
2020-09-06 06:47:34 +10:00
|
|
|
|
2020-02-12 23:10:59 +11:00
|
|
|
is_local_echo: bool = False
|
|
|
|
source: Optional[nio.Event] = 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
|
|
|
|
2020-07-21 12:58:02 +10:00
|
|
|
media_url: str = ""
|
2020-07-21 13:09:28 +10:00
|
|
|
media_http_url: str = ""
|
2020-07-21 12:58:02 +10:00
|
|
|
media_title: str = ""
|
|
|
|
media_width: int = 0
|
|
|
|
media_height: int = 0
|
|
|
|
media_duration: int = 0
|
|
|
|
media_size: int = 0
|
|
|
|
media_mime: str = ""
|
|
|
|
media_crypt_dict: Dict[str, Any] = field(default_factory=dict)
|
|
|
|
media_local_path: Union[str, Path] = ""
|
2019-11-05 05:37:25 +11:00
|
|
|
|
|
|
|
thumbnail_url: str = ""
|
2020-03-10 03:06:58 +11:00
|
|
|
thumbnail_mime: str = ""
|
2019-11-05 05:37:25 +11:00
|
|
|
thumbnail_width: int = 0
|
|
|
|
thumbnail_height: int = 0
|
|
|
|
thumbnail_crypt_dict: Dict[str, Any] = field(default_factory=dict)
|
2019-09-14 12:34:20 +10:00
|
|
|
|
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: "Event") -> bool:
|
2019-12-19 06:00:34 +11:00
|
|
|
"""Sort by date in descending order, from newest to oldest."""
|
|
|
|
|
2020-10-17 19:22:48 +11:00
|
|
|
return (self.date, self.id) > (other.date, other.id)
|
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
|
|
|
|
2020-02-12 08:32:22 +11:00
|
|
|
@staticmethod
|
2020-02-12 21:27:21 +11:00
|
|
|
def parse_links(text: str) -> List[str]:
|
2020-02-12 08:32:22 +11:00
|
|
|
"""Return list of URLs (`<a href=...>` tags) present in the text."""
|
2019-11-07 00:43:05 +11:00
|
|
|
|
2020-07-22 12:45:26 +10:00
|
|
|
ignore = []
|
|
|
|
|
|
|
|
if "<mx-reply>" in text:
|
|
|
|
parser = lxml.html.etree.HTMLParser()
|
|
|
|
tree = lxml.etree.fromstring(text, parser) # nosec
|
|
|
|
xpath = "//mx-reply/blockquote/a[count(preceding-sibling::*)<=1]"
|
|
|
|
ignore = [lxml.etree.tostring(el) for el in tree.xpath(xpath)]
|
|
|
|
|
2020-02-12 08:32:22 +11:00
|
|
|
if not text.strip():
|
|
|
|
return []
|
2019-09-03 17:04:57 +10:00
|
|
|
|
2020-07-22 12:45:26 +10:00
|
|
|
return [
|
|
|
|
url for el, attrib, url, pos in lxml.html.iterlinks(text)
|
|
|
|
if lxml.etree.tostring(el) not in ignore
|
|
|
|
]
|
2019-09-03 17:04:57 +10:00
|
|
|
|
2020-10-17 19:22:48 +11:00
|
|
|
def serialized_field(self, field: str) -> Any:
|
2020-02-12 23:10:59 +11:00
|
|
|
if field == "source":
|
2020-05-15 04:47:32 +10:00
|
|
|
source_dict = asdict(self.source) if self.source else {}
|
2020-02-13 04:04:46 +11:00
|
|
|
return json.dumps(source_dict)
|
2020-02-12 23:10:59 +11:00
|
|
|
|
2020-10-17 19:22:48 +11:00
|
|
|
return super().serialized_field(field)
|