2019-12-19 22:46:16 +11:00
|
|
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Matrix client and related classes."""
|
|
|
|
|
2019-07-03 03:59:52 +10:00
|
|
|
import asyncio
|
2019-07-03 12:22:29 +10:00
|
|
|
import html
|
2019-10-30 07:42:56 +11:00
|
|
|
import io
|
2019-07-03 03:59:52 +10:00
|
|
|
import logging as log
|
|
|
|
import platform
|
2019-11-10 00:52:16 +11:00
|
|
|
import re
|
2020-04-27 03:49:44 +10:00
|
|
|
import sys
|
2019-10-31 02:10:40 +11:00
|
|
|
import traceback
|
2019-07-03 03:59:52 +10:00
|
|
|
from contextlib import suppress
|
2020-03-08 03:35:12 +11:00
|
|
|
from copy import copy
|
2020-03-10 08:36:47 +11:00
|
|
|
from datetime import datetime, timedelta
|
2019-12-13 23:32:18 +11:00
|
|
|
from functools import partial
|
2019-07-16 06:14:08 +10:00
|
|
|
from pathlib import Path
|
2019-11-05 06:18:01 +11:00
|
|
|
from typing import (
|
2020-02-12 07:22:05 +11:00
|
|
|
TYPE_CHECKING, Any, DefaultDict, Dict, List, NamedTuple, Optional, Set,
|
|
|
|
Tuple, Type, Union,
|
2019-11-05 06:18:01 +11:00
|
|
|
)
|
2019-11-10 00:52:16 +11:00
|
|
|
from urllib.parse import urlparse
|
2019-12-02 20:06:21 +11:00
|
|
|
from uuid import UUID, uuid4
|
2019-07-03 03:59:52 +10:00
|
|
|
|
2019-11-06 22:50:31 +11:00
|
|
|
import cairosvg
|
2020-03-21 04:51:32 +11:00
|
|
|
from PIL import Image as PILImage
|
|
|
|
from pymediainfo import MediaInfo
|
|
|
|
|
2019-11-05 06:18:01 +11:00
|
|
|
import nio
|
2019-11-18 04:31:00 +11:00
|
|
|
from nio.crypto import AsyncDataT as UploadData
|
|
|
|
from nio.crypto import async_generator_from_data
|
2019-11-05 06:18:01 +11:00
|
|
|
|
2019-12-26 23:16:04 +11:00
|
|
|
from . import __app_name__, __display_name__, utils
|
2019-11-12 23:38:43 +11:00
|
|
|
from .errors import (
|
2019-12-05 00:59:14 +11:00
|
|
|
BadMimeType, InvalidUserId, InvalidUserInContext, MatrixError,
|
2020-03-10 01:23:08 +11:00
|
|
|
MatrixNotFound, MatrixTooLarge, UneededThumbnail,
|
|
|
|
UserFromOtherServerDisallowed,
|
2019-11-12 23:38:43 +11:00
|
|
|
)
|
2019-12-19 00:33:22 +11:00
|
|
|
from .html_markdown import HTML_PROCESSOR as HTML
|
2020-02-12 07:22:05 +11:00
|
|
|
from .media_cache import Media, Thumbnail
|
2020-03-17 03:36:39 +11:00
|
|
|
from .models.items import Event, Member, Room, Upload, UploadStatus, ZeroDate
|
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 .models.model_store import ModelStore
|
2020-02-12 07:22:05 +11:00
|
|
|
from .nio_callbacks import NioCallbacks
|
2020-03-10 04:08:09 +11:00
|
|
|
from .pyotherside_events import AlertRequested, LoopException
|
2019-07-03 03:59:52 +10:00
|
|
|
|
2020-02-12 07:22:05 +11:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from .backend import Backend
|
|
|
|
|
2020-04-27 03:49:44 +10:00
|
|
|
if sys.version_info >= (3, 7):
|
|
|
|
current_task = asyncio.current_task
|
|
|
|
else:
|
|
|
|
current_task = asyncio.Task.current_task
|
|
|
|
|
2019-11-18 04:31:00 +11:00
|
|
|
CryptDict = Dict[str, Any]
|
|
|
|
|
|
|
|
|
|
|
|
class UploadReturn(NamedTuple):
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Details for an uploaded file."""
|
|
|
|
|
2019-11-18 04:31:00 +11:00
|
|
|
mxc: str
|
|
|
|
mime: str
|
|
|
|
decryption_dict: Dict[str, Any]
|
|
|
|
|
|
|
|
|
|
|
|
class MatrixImageInfo(NamedTuple):
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Image informations to be passed for Matrix file events."""
|
|
|
|
|
|
|
|
width: int
|
|
|
|
height: int
|
|
|
|
mime: str
|
|
|
|
size: int
|
|
|
|
|
|
|
|
def as_dict(self) -> Dict[str, Union[int, str]]:
|
|
|
|
"""Return a dict ready to be included in a Matrix file events."""
|
|
|
|
|
|
|
|
return {
|
|
|
|
"w": self.width,
|
|
|
|
"h": self.height,
|
|
|
|
"mimetype": self.mime,
|
|
|
|
"size": self.size,
|
|
|
|
}
|
2019-11-05 06:18:01 +11:00
|
|
|
|
2019-07-03 03:59:52 +10:00
|
|
|
|
|
|
|
class MatrixClient(nio.AsyncClient):
|
2019-12-19 04:16:15 +11:00
|
|
|
"""A client for an account to interact with a matrix homeserver."""
|
|
|
|
|
2019-12-12 03:42:59 +11:00
|
|
|
user_id_regex = re.compile(r"^@.+:.+")
|
|
|
|
room_id_or_alias_regex = re.compile(r"^[#!].+:.+")
|
|
|
|
http_s_url = re.compile(r"^https?://")
|
|
|
|
|
2019-12-19 04:16:15 +11:00
|
|
|
|
2019-07-03 03:59:52 +10:00
|
|
|
def __init__(self,
|
2019-07-05 09:11:22 +10:00
|
|
|
backend,
|
2019-07-03 03:59:52 +10:00
|
|
|
user: str,
|
|
|
|
homeserver: str = "https://matrix.org",
|
|
|
|
device_id: Optional[str] = None) -> None:
|
2019-07-05 09:49:55 +10:00
|
|
|
|
2019-11-13 00:13:45 +11:00
|
|
|
if not urlparse(homeserver).scheme:
|
|
|
|
raise ValueError(
|
|
|
|
f"homeserver is missing scheme (e.g. https://): {homeserver}",
|
|
|
|
)
|
|
|
|
|
2019-12-18 21:44:18 +11:00
|
|
|
store = Path(backend.appdirs.user_data_dir) / "encryption"
|
2019-07-25 10:00:01 +10:00
|
|
|
store.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
2019-07-09 03:08:46 +10:00
|
|
|
super().__init__(
|
|
|
|
homeserver = homeserver,
|
|
|
|
user = user,
|
|
|
|
device_id = device_id,
|
2019-07-25 10:00:01 +10:00
|
|
|
store_path = store,
|
2019-08-20 00:31:53 +10:00
|
|
|
config = nio.AsyncClientConfig(
|
|
|
|
max_timeout_retry_wait_time = 10,
|
2019-11-13 00:13:45 +11:00
|
|
|
# TODO: pass a custom encryption DB pickle key?
|
2019-08-20 00:31:53 +10:00
|
|
|
),
|
2019-07-09 03:08:46 +10:00
|
|
|
)
|
2019-07-03 03:59:52 +10:00
|
|
|
|
2020-02-12 07:22:05 +11:00
|
|
|
self.backend: "Backend" = backend
|
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
|
|
|
self.models: ModelStore = self.backend.models
|
|
|
|
|
2020-03-10 00:51:55 +11:00
|
|
|
self.profile_task: Optional[asyncio.Future] = None
|
|
|
|
self.server_config_task: Optional[asyncio.Future] = None
|
|
|
|
self.sync_task: Optional[asyncio.Future] = None
|
|
|
|
self.load_rooms_task: Optional[asyncio.Future] = None
|
2020-03-08 20:24:07 +11:00
|
|
|
|
2020-04-03 22:13:33 +11:00
|
|
|
self.upload_monitors: Dict[UUID, nio.TransferMonitor] = {}
|
|
|
|
self.upload_tasks: Dict[UUID, asyncio.Task] = {}
|
|
|
|
self.send_message_tasks: Dict[UUID, asyncio.Task] = {}
|
2020-03-08 20:24:07 +11:00
|
|
|
|
|
|
|
self.first_sync_done: asyncio.Event = asyncio.Event()
|
|
|
|
self.first_sync_date: Optional[datetime] = 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
|
|
|
|
2019-09-09 01:40:39 +10:00
|
|
|
self.past_tokens: Dict[str, str] = {} # {room_id: token}
|
|
|
|
self.fully_loaded_rooms: Set[str] = set() # {room_id}
|
|
|
|
self.loaded_once_rooms: Set[str] = set() # {room_id}
|
|
|
|
self.cleared_events_rooms: Set[str] = set() # {room_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
|
|
|
|
|
|
|
self.skipped_events: DefaultDict[str, int] = DefaultDict(lambda: 0)
|
|
|
|
|
2019-11-08 23:30:11 +11:00
|
|
|
self.nio_callbacks = NioCallbacks(self)
|
2019-07-03 03:59:52 +10:00
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self) -> str:
|
|
|
|
return "%s(user_id=%r, homeserver=%r, device_id=%r)" % (
|
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
|
|
|
type(self).__name__, self.user_id, self.homeserver, self.device_id,
|
2019-07-03 03:59:52 +10:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-12-26 23:16:04 +11:00
|
|
|
async def _send(self, *args, **kwargs) -> nio.Response:
|
|
|
|
"""Raise a `MatrixError` subclass for any `nio.ErrorResponse`.
|
|
|
|
|
|
|
|
This function is called by `nio.AsyncClient`'s methods to send
|
|
|
|
requests to the server. Return normal responses, but catch any
|
|
|
|
`ErrorResponse` to turn them into `MatrixError` exceptions we raise.
|
|
|
|
"""
|
|
|
|
|
|
|
|
response = await super()._send(*args, **kwargs)
|
|
|
|
|
|
|
|
if isinstance(response, nio.ErrorResponse):
|
|
|
|
raise MatrixError.from_nio(response)
|
|
|
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
2020-03-22 14:39:57 +11:00
|
|
|
@staticmethod
|
|
|
|
def default_device_name() -> str:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Device name to set at login if the user hasn't set a custom one."""
|
|
|
|
|
2020-03-22 14:39:57 +11:00
|
|
|
os_name = platform.system()
|
|
|
|
|
|
|
|
if not os_name: # unknown OS
|
|
|
|
return __display_name__
|
|
|
|
|
|
|
|
# On Linux, the kernel version is returned, so for a one-time-set
|
|
|
|
# device name it would quickly be outdated.
|
|
|
|
os_ver = platform.release() if os_name == "Windows" else ""
|
|
|
|
return f"{__display_name__} on {os_name} {os_ver}".rstrip()
|
2019-07-03 03:59:52 +10:00
|
|
|
|
|
|
|
|
2019-07-03 05:06:45 +10:00
|
|
|
async def login(self, password: str, device_name: str = "") -> None:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Login to the server using the account's password."""
|
|
|
|
|
2020-03-22 14:39:57 +11:00
|
|
|
await super().login(
|
|
|
|
password, device_name or self.default_device_name(),
|
|
|
|
)
|
2019-12-19 04:16:15 +11:00
|
|
|
asyncio.ensure_future(self._start())
|
2019-07-03 03:59:52 +10:00
|
|
|
|
|
|
|
|
|
|
|
async def resume(self, user_id: str, token: str, device_id: str) -> None:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Login to the server using an existing access token."""
|
|
|
|
|
2019-12-16 22:02:42 +11:00
|
|
|
response = nio.LoginResponse(user_id, device_id, token)
|
|
|
|
await self.receive_response(response)
|
2019-07-03 03:59:52 +10:00
|
|
|
|
2019-12-19 04:16:15 +11:00
|
|
|
asyncio.ensure_future(self._start())
|
2019-07-03 03:59:52 +10:00
|
|
|
|
2019-11-13 09:19:48 +11:00
|
|
|
|
2019-11-22 19:27:20 +11:00
|
|
|
async def logout(self) -> None:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Logout from the server. This will delete the device."""
|
|
|
|
|
2020-03-10 00:51:55 +11:00
|
|
|
tasks = (
|
|
|
|
self.profile_task, self.load_rooms_task, self.sync_task,
|
|
|
|
self.server_config_task,
|
|
|
|
)
|
|
|
|
|
|
|
|
for task in tasks:
|
2019-11-22 19:27:20 +11:00
|
|
|
if task:
|
|
|
|
task.cancel()
|
|
|
|
with suppress(asyncio.CancelledError):
|
|
|
|
await task
|
2019-07-03 03:59:52 +10:00
|
|
|
|
2019-08-22 07:45:05 +10:00
|
|
|
await super().logout()
|
2019-07-03 03:59:52 +10:00
|
|
|
await self.close()
|
|
|
|
|
|
|
|
|
2019-12-16 22:02:42 +11:00
|
|
|
@property
|
|
|
|
def syncing(self) -> bool:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Return whether this client is currently syncing with the server."""
|
|
|
|
|
2019-12-16 22:02:42 +11:00
|
|
|
if not self.sync_task:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return not self.sync_task.done()
|
|
|
|
|
|
|
|
|
2019-12-19 04:16:15 +11:00
|
|
|
async def _start(self) -> None:
|
2020-03-10 04:08:09 +11:00
|
|
|
"""Fetch our user profile, server config and enter the sync loop."""
|
2019-12-19 04:16: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
|
|
|
def on_profile_response(future) -> None:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Update our model `Account` with the received profile details."""
|
|
|
|
|
2020-03-16 07:13:58 +11:00
|
|
|
if future.cancelled(): # Account logged out
|
|
|
|
return
|
|
|
|
|
2019-11-15 07:20:30 +11:00
|
|
|
exception = future.exception()
|
|
|
|
|
|
|
|
if exception:
|
2019-12-16 20:03:57 +11:00
|
|
|
log.warn("On %s client startup: %r", self.user_id, exception)
|
|
|
|
self.profile_task = asyncio.ensure_future(
|
|
|
|
self.backend.get_profile(self.user_id),
|
|
|
|
)
|
|
|
|
self.profile_task.add_done_callback(on_profile_response)
|
2019-11-12 23:47:03 +11:00
|
|
|
return
|
|
|
|
|
|
|
|
resp = future.result()
|
2019-12-03 07:29:29 +11:00
|
|
|
account = self.models["accounts"][self.user_id]
|
2019-11-12 23:47:03 +11:00
|
|
|
account.profile_updated = datetime.now()
|
|
|
|
account.display_name = resp.displayname or ""
|
|
|
|
account.avatar_url = resp.avatar_url or ""
|
2019-07-07 15:37:13 +10:00
|
|
|
|
2020-03-10 00:51:55 +11:00
|
|
|
def on_server_config_response(future) -> None:
|
|
|
|
"""Update our model `Account` with the received config details."""
|
|
|
|
|
2020-03-16 07:13:58 +11:00
|
|
|
if future.cancelled(): # Account logged out
|
|
|
|
return
|
|
|
|
|
2020-03-10 00:51:55 +11:00
|
|
|
exception = future.exception()
|
|
|
|
|
|
|
|
if exception:
|
|
|
|
log.warn("On %s client startup: %r", self.user_id, exception)
|
|
|
|
self.server_config_task = asyncio.ensure_future(
|
|
|
|
self.get_server_config(),
|
|
|
|
)
|
|
|
|
self.server_config_task.add_done_callback(
|
|
|
|
on_server_config_response,
|
|
|
|
)
|
|
|
|
return
|
|
|
|
|
|
|
|
account = self.models["accounts"][self.user_id]
|
|
|
|
account.max_upload_size = future.result()
|
|
|
|
|
2019-11-22 19:27:20 +11:00
|
|
|
self.profile_task = asyncio.ensure_future(
|
|
|
|
self.backend.get_profile(self.user_id),
|
|
|
|
)
|
|
|
|
self.profile_task.add_done_callback(on_profile_response)
|
2019-07-03 03:59:52 +10:00
|
|
|
|
2020-03-10 00:51:55 +11:00
|
|
|
self.server_config_task = asyncio.ensure_future(
|
|
|
|
self.get_server_config(),
|
|
|
|
)
|
|
|
|
self.server_config_task.add_done_callback(on_server_config_response)
|
|
|
|
|
2019-10-31 02:10:40 +11:00
|
|
|
while True:
|
|
|
|
try:
|
2019-11-22 19:27:20 +11:00
|
|
|
self.sync_task = asyncio.ensure_future(
|
|
|
|
self.sync_forever(timeout=10_000),
|
|
|
|
)
|
|
|
|
await self.sync_task
|
|
|
|
break # task cancelled
|
2020-03-10 04:08:09 +11:00
|
|
|
except Exception as err:
|
2019-10-31 02:10:40 +11:00
|
|
|
trace = traceback.format_exc().rstrip()
|
2020-03-10 04:08:09 +11:00
|
|
|
|
|
|
|
if isinstance(err, MatrixError) and err.http_code >= 500:
|
2020-03-16 15:31:31 +11:00
|
|
|
log.warning(
|
|
|
|
"Server failure during sync for %s:\n%s",
|
|
|
|
self.user_id,
|
|
|
|
trace,
|
|
|
|
)
|
2020-03-10 04:08:09 +11:00
|
|
|
else:
|
|
|
|
LoopException(str(err), err, trace)
|
|
|
|
|
2019-10-31 02:10:40 +11:00
|
|
|
await asyncio.sleep(2)
|
2019-07-07 15:37:13 +10:00
|
|
|
|
2019-07-03 03:59:52 +10:00
|
|
|
|
2020-03-10 00:51:55 +11:00
|
|
|
async def get_server_config(self) -> int:
|
|
|
|
"""Return the maximum upload size on this server"""
|
|
|
|
return (await self.content_repository_config()).upload_size
|
|
|
|
|
|
|
|
|
2019-07-05 16:45:30 +10:00
|
|
|
@property
|
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 all_rooms(self) -> Dict[str, nio.MatrixRoom]:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Return dict containing both our joined and invited rooms."""
|
|
|
|
|
2019-07-05 16:45:30 +10:00
|
|
|
return {**self.invited_rooms, **self.rooms}
|
|
|
|
|
|
|
|
|
2019-10-29 04:51:46 +11:00
|
|
|
async def send_text(self, room_id: str, text: str) -> None:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Send a markdown `m.text` or `m.notice` (with `/me`) message ."""
|
|
|
|
|
2020-03-23 11:58:05 +11:00
|
|
|
from_md = partial(HTML.from_markdown, room_id=room_id)
|
2020-03-23 07:21:29 +11:00
|
|
|
|
2019-07-20 10:55:52 +10:00
|
|
|
escape = False
|
|
|
|
if text.startswith("//") or text.startswith(r"\/"):
|
|
|
|
escape = True
|
|
|
|
text = text[1:]
|
|
|
|
|
|
|
|
if text.startswith("/me ") and not escape:
|
2019-10-29 04:49:55 +11:00
|
|
|
event_type = nio.RoomMessageEmote
|
2019-07-20 10:55:52 +10:00
|
|
|
text = text[len("/me "): ]
|
|
|
|
content = {"body": text, "msgtype": "m.emote"}
|
2020-03-23 07:21:29 +11:00
|
|
|
to_html = from_md(text, inline=True, outgoing=True)
|
|
|
|
echo_body = from_md(text, inline=True)
|
2019-07-20 10:55:52 +10:00
|
|
|
else:
|
2019-10-29 04:49:55 +11:00
|
|
|
event_type = nio.RoomMessageText
|
2019-07-20 10:55:52 +10:00
|
|
|
content = {"body": text, "msgtype": "m.text"}
|
2020-03-23 07:21:29 +11:00
|
|
|
to_html = from_md(text, outgoing=True)
|
|
|
|
echo_body = from_md(text)
|
2019-07-20 08:13:04 +10:00
|
|
|
|
2019-07-22 07:41:43 +10:00
|
|
|
if to_html not in (html.escape(text), f"<p>{html.escape(text)}</p>"):
|
2019-07-20 08:13:04 +10:00
|
|
|
content["format"] = "org.matrix.custom.html"
|
|
|
|
content["formatted_body"] = to_html
|
2019-07-04 11:20:49 +10:00
|
|
|
|
2019-12-17 01:36:59 +11:00
|
|
|
# Can't use the standard Matrix transaction IDs; they're only visible
|
|
|
|
# to the sender so our other accounts wouldn't be able to replace
|
|
|
|
# local echoes by real messages.
|
|
|
|
tx_id = uuid4()
|
2019-12-18 21:55:05 +11:00
|
|
|
content[f"{__app_name__}.transaction_id"] = str(tx_id)
|
2019-10-29 04:49:55 +11:00
|
|
|
|
2020-03-24 05:23:32 +11:00
|
|
|
mentions = HTML.mentions_in_html(echo_body)
|
|
|
|
await self._local_echo(
|
|
|
|
room_id, tx_id, event_type, content=echo_body, mentions=mentions,
|
|
|
|
)
|
|
|
|
|
2020-04-03 22:13:33 +11:00
|
|
|
await self._send_message(room_id, content, tx_id)
|
2019-10-29 06:27:36 +11:00
|
|
|
|
|
|
|
|
2020-03-08 20:24:07 +11:00
|
|
|
async def toggle_pause_upload(
|
|
|
|
self, room_id: str, uuid: Union[str, UUID],
|
|
|
|
) -> None:
|
|
|
|
if isinstance(uuid, str):
|
|
|
|
uuid = UUID(uuid)
|
|
|
|
|
|
|
|
pause = not self.upload_monitors[uuid].pause
|
|
|
|
|
|
|
|
self.upload_monitors[uuid].pause = pause
|
|
|
|
self.models[room_id, "uploads"][str(uuid)].paused = pause
|
|
|
|
|
|
|
|
|
|
|
|
async def cancel_upload(self, uuid: Union[str, UUID]) -> None:
|
|
|
|
if isinstance(uuid, str):
|
|
|
|
uuid = UUID(uuid)
|
|
|
|
|
2020-03-13 02:27:56 +11:00
|
|
|
self.upload_tasks[uuid].cancel()
|
2020-03-08 20:24:07 +11:00
|
|
|
|
|
|
|
|
2019-10-29 06:27:36 +11:00
|
|
|
async def send_file(self, room_id: str, path: Union[Path, str]) -> None:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Send a `m.file`, `m.image`, `m.audio` or `m.video` message."""
|
|
|
|
|
2019-12-02 20:06:21 +11:00
|
|
|
item_uuid = uuid4()
|
|
|
|
|
|
|
|
try:
|
|
|
|
await self._send_file(item_uuid, room_id, path)
|
2019-12-06 01:00:23 +11:00
|
|
|
except (nio.TransferCancelledError, asyncio.CancelledError):
|
2019-12-06 23:44:45 +11:00
|
|
|
log.info("Deleting item for cancelled upload %s", item_uuid)
|
2020-03-08 20:24:07 +11:00
|
|
|
del self.upload_monitors[item_uuid]
|
2020-03-13 02:27:56 +11:00
|
|
|
del self.upload_tasks[item_uuid]
|
2019-12-03 07:29:29 +11:00
|
|
|
del self.models[room_id, "uploads"][str(item_uuid)]
|
2019-12-02 20:06:21 +11:00
|
|
|
|
|
|
|
|
|
|
|
async def _send_file(
|
|
|
|
self, item_uuid: UUID, room_id: str, path: Union[Path, str],
|
|
|
|
) -> None:
|
2020-03-13 05:41:00 +11:00
|
|
|
"""Upload and monitor a file + thumbnail and send the built event."""
|
2019-12-19 04:16:15 +11:00
|
|
|
|
2020-02-12 07:22:05 +11:00
|
|
|
# TODO: this function is way too complex, and most of it should be
|
2019-12-19 04:16:15 +11:00
|
|
|
# refactored into nio.
|
2019-11-18 04:31:00 +11:00
|
|
|
|
2019-12-17 01:36:59 +11:00
|
|
|
transaction_id = uuid4()
|
|
|
|
path = Path(path)
|
|
|
|
encrypt = room_id in self.encrypted_rooms
|
2019-10-31 01:34:20 +11:00
|
|
|
|
2019-12-06 00:51:31 +11:00
|
|
|
try:
|
|
|
|
size = path.resolve().stat().st_size
|
|
|
|
except (PermissionError, FileNotFoundError):
|
|
|
|
# This error will be caught again by the try block later below
|
|
|
|
size = 0
|
|
|
|
|
2019-12-06 23:44:45 +11:00
|
|
|
monitor = nio.TransferMonitor(size)
|
2020-03-08 20:24:07 +11:00
|
|
|
upload_item = Upload(item_uuid, path, total_size=size)
|
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
self.models[room_id, "uploads"][str(item_uuid)] = upload_item
|
2019-12-06 01:00:23 +11:00
|
|
|
|
2020-03-13 02:27:56 +11:00
|
|
|
self.upload_monitors[item_uuid] = monitor
|
2020-04-27 03:49:44 +10:00
|
|
|
self.upload_tasks[item_uuid] = current_task() # type: ignore
|
2020-03-13 02:27:56 +11:00
|
|
|
|
2019-12-18 07:18:00 +11:00
|
|
|
def on_transferred(transferred: int) -> None:
|
|
|
|
upload_item.uploaded = transferred
|
2019-12-06 01:00:23 +11:00
|
|
|
|
2019-12-15 02:31:43 +11:00
|
|
|
def on_speed_changed(speed: float) -> None:
|
|
|
|
upload_item.speed = speed
|
2020-03-10 08:36:47 +11:00
|
|
|
upload_item.time_left = monitor.remaining_time or timedelta(0)
|
2019-12-06 01:00:23 +11:00
|
|
|
|
2019-12-18 07:18:00 +11:00
|
|
|
monitor.on_transferred = on_transferred
|
2019-12-15 02:31:43 +11:00
|
|
|
monitor.on_speed_changed = on_speed_changed
|
2019-11-06 09:31:16 +11:00
|
|
|
|
2019-12-02 17:57:47 +11:00
|
|
|
try:
|
|
|
|
url, mime, crypt_dict = await self.upload(
|
2019-12-15 08:40:31 +11:00
|
|
|
lambda *_: path,
|
|
|
|
filename = path.name,
|
2020-03-10 01:23:08 +11:00
|
|
|
filesize = size,
|
2020-03-08 20:24:07 +11:00
|
|
|
encrypt = encrypt,
|
|
|
|
monitor = monitor,
|
2019-12-02 17:57:47 +11:00
|
|
|
)
|
2020-03-08 20:24:07 +11:00
|
|
|
|
|
|
|
# FIXME: nio might not catch the cancel in time
|
|
|
|
if monitor.cancel:
|
|
|
|
raise nio.TransferCancelledError()
|
|
|
|
|
2019-12-06 00:51:31 +11:00
|
|
|
except (MatrixError, OSError) as err:
|
2019-12-02 17:57:47 +11:00
|
|
|
upload_item.status = UploadStatus.Error
|
|
|
|
upload_item.error = type(err)
|
|
|
|
upload_item.error_args = err.args
|
2019-12-02 20:06:21 +11:00
|
|
|
|
2019-12-06 01:00:23 +11:00
|
|
|
# Wait for cancellation from UI, see parent send_file() method
|
2019-12-02 20:06:21 +11:00
|
|
|
while True:
|
|
|
|
await asyncio.sleep(0.1)
|
2019-10-31 01:34:20 +11:00
|
|
|
|
2019-11-18 04:31:00 +11:00
|
|
|
upload_item.status = UploadStatus.Caching
|
|
|
|
await Media.from_existing_file(self.backend.media_cache, url, path)
|
2019-11-07 00:43:05 +11:00
|
|
|
|
2019-10-31 01:34:20 +11:00
|
|
|
kind = (mime or "").split("/")[0]
|
|
|
|
|
2019-11-18 04:31:00 +11:00
|
|
|
thumb_url: str = ""
|
|
|
|
thumb_info: Optional[MatrixImageInfo] = None
|
2019-11-07 00:43:05 +11:00
|
|
|
|
2019-10-29 06:27:36 +11:00
|
|
|
content: dict = {
|
2019-12-18 21:55:05 +11:00
|
|
|
f"{__app_name__}.transaction_id": str(transaction_id),
|
2019-12-17 01:36:59 +11:00
|
|
|
|
2019-10-29 06:27:36 +11:00
|
|
|
"body": path.name,
|
|
|
|
"info": {
|
|
|
|
"mimetype": mime,
|
2019-12-06 00:51:31 +11:00
|
|
|
"size": upload_item.total_size,
|
2019-10-29 06:27:36 +11:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-10-31 01:34:20 +11:00
|
|
|
if encrypt:
|
|
|
|
content["file"] = {"url": url, **crypt_dict}
|
|
|
|
else:
|
|
|
|
content["url"] = url
|
|
|
|
|
2019-10-29 06:27:36 +11:00
|
|
|
if kind == "image":
|
2019-11-06 22:50:31 +11:00
|
|
|
is_svg = mime == "image/svg+xml"
|
|
|
|
|
2019-11-05 05:37:25 +11:00
|
|
|
event_type = \
|
|
|
|
nio.RoomEncryptedImage if encrypt else nio.RoomMessageImage
|
|
|
|
|
2019-10-29 06:27:36 +11:00
|
|
|
content["msgtype"] = "m.image"
|
|
|
|
|
2019-11-06 22:50:31 +11:00
|
|
|
content["info"]["w"], content["info"]["h"] = (
|
2019-11-18 04:31:00 +11:00
|
|
|
await utils.svg_dimensions(path) if is_svg else
|
2019-10-29 06:27:36 +11:00
|
|
|
PILImage.open(path).size
|
2019-11-06 22:50:31 +11:00
|
|
|
)
|
2019-10-29 06:27:36 +11:00
|
|
|
|
2019-10-30 07:42:56 +11:00
|
|
|
try:
|
2019-11-18 04:31:00 +11:00
|
|
|
thumb_data, thumb_info = await self.generate_thumbnail(
|
|
|
|
path, is_svg=is_svg,
|
|
|
|
)
|
|
|
|
except UneededThumbnail:
|
2019-10-30 07:42:56 +11:00
|
|
|
pass
|
2020-03-21 04:51:32 +11:00
|
|
|
except Exception:
|
|
|
|
trace = traceback.format_exc().rstrip()
|
|
|
|
log.warning("Failed thumbnailing %s:\n%s", path, trace)
|
2019-10-30 07:42:56 +11:00
|
|
|
else:
|
2020-03-10 01:10:21 +11:00
|
|
|
thumb_ext = "png" if thumb_info.mime == "image/png" else "jpg"
|
|
|
|
thumb_name = f"{path.stem}_thumbnail.{thumb_ext}"
|
2019-12-07 07:44:25 +11:00
|
|
|
|
|
|
|
upload_item.status = UploadStatus.Uploading
|
|
|
|
upload_item.filepath = Path(thumb_name)
|
|
|
|
upload_item.total_size = len(thumb_data)
|
2019-11-18 04:31:00 +11:00
|
|
|
|
2019-12-02 17:57:47 +11:00
|
|
|
try:
|
2020-03-08 23:05:41 +11:00
|
|
|
upload_item.total_size = thumb_info.size
|
|
|
|
|
|
|
|
monitor = nio.TransferMonitor(thumb_info.size)
|
|
|
|
monitor.on_transferred = on_transferred
|
|
|
|
monitor.on_speed_changed = on_speed_changed
|
|
|
|
|
|
|
|
self.upload_monitors[item_uuid] = monitor
|
2020-03-08 20:24:07 +11:00
|
|
|
|
2019-12-02 17:57:47 +11:00
|
|
|
thumb_url, _, thumb_crypt_dict = await self.upload(
|
2019-12-15 08:40:31 +11:00
|
|
|
lambda *_: thumb_data,
|
2020-03-10 08:33:07 +11:00
|
|
|
filename = f"{path.stem}_sample{path.suffix}",
|
2020-03-10 01:23:08 +11:00
|
|
|
filesize = thumb_info.size,
|
2019-12-02 17:57:47 +11:00
|
|
|
encrypt = encrypt,
|
2020-03-08 20:24:07 +11:00
|
|
|
monitor = monitor,
|
2019-12-02 17:57:47 +11:00
|
|
|
)
|
2020-03-08 20:24:07 +11:00
|
|
|
|
|
|
|
# FIXME: nio might not catch the cancel in time
|
|
|
|
if monitor.cancel:
|
|
|
|
raise nio.TransferCancelledError()
|
2019-12-02 17:57:47 +11:00
|
|
|
except MatrixError as err:
|
|
|
|
log.warning(f"Failed uploading thumbnail {path}: {err}")
|
2019-10-31 01:34:20 +11:00
|
|
|
else:
|
2019-12-07 07:44:25 +11:00
|
|
|
upload_item.status = UploadStatus.Caching
|
2019-12-02 17:57:47 +11:00
|
|
|
|
|
|
|
await Thumbnail.from_bytes(
|
|
|
|
self.backend.media_cache,
|
|
|
|
thumb_url,
|
2020-03-10 08:33:07 +11:00
|
|
|
path.name,
|
2019-12-02 17:57:47 +11:00
|
|
|
thumb_data,
|
|
|
|
wanted_size = (content["info"]["w"],
|
|
|
|
content["info"]["h"]),
|
|
|
|
)
|
|
|
|
|
|
|
|
if encrypt:
|
|
|
|
content["info"]["thumbnail_file"] = {
|
|
|
|
"url": thumb_url,
|
|
|
|
**thumb_crypt_dict,
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
content["info"]["thumbnail_url"] = thumb_url
|
|
|
|
|
2019-12-19 04:16:15 +11:00
|
|
|
content["info"]["thumbnail_info"] = thumb_info.as_dict()
|
2019-10-30 07:42:56 +11:00
|
|
|
|
2019-10-29 06:27:36 +11:00
|
|
|
elif kind == "audio":
|
2019-11-05 05:37:25 +11:00
|
|
|
event_type = \
|
|
|
|
nio.RoomEncryptedAudio if encrypt else nio.RoomMessageAudio
|
|
|
|
|
2019-10-29 06:27:36 +11:00
|
|
|
content["msgtype"] = "m.audio"
|
|
|
|
content["info"]["duration"] = getattr(
|
|
|
|
MediaInfo.parse(path).tracks[0], "duration", 0,
|
|
|
|
) or 0
|
|
|
|
|
|
|
|
elif kind == "video":
|
2019-11-05 05:37:25 +11:00
|
|
|
event_type = \
|
|
|
|
nio.RoomEncryptedVideo if encrypt else nio.RoomMessageVideo
|
|
|
|
|
2019-10-29 06:27:36 +11:00
|
|
|
content["msgtype"] = "m.video"
|
|
|
|
|
|
|
|
tracks = MediaInfo.parse(path).tracks
|
|
|
|
|
|
|
|
content["info"]["duration"] = \
|
|
|
|
getattr(tracks[0], "duration", 0) or 0
|
|
|
|
|
|
|
|
content["info"]["w"] = max(
|
|
|
|
getattr(t, "width", 0) or 0 for t in tracks
|
|
|
|
)
|
|
|
|
content["info"]["h"] = max(
|
|
|
|
getattr(t, "height", 0) or 0 for t in tracks
|
|
|
|
)
|
|
|
|
|
|
|
|
else:
|
2019-11-05 05:37:25 +11:00
|
|
|
event_type = \
|
|
|
|
nio.RoomEncryptedFile if encrypt else nio.RoomMessageFile
|
|
|
|
|
2019-10-29 06:27:36 +11:00
|
|
|
content["msgtype"] = "m.file"
|
|
|
|
content["filename"] = path.name
|
|
|
|
|
2020-03-08 20:24:07 +11:00
|
|
|
del self.upload_monitors[item_uuid]
|
2020-03-13 02:27:56 +11:00
|
|
|
del self.upload_tasks[item_uuid]
|
2019-12-03 07:29:29 +11:00
|
|
|
del self.models[room_id, "uploads"][str(upload_item.id)]
|
2019-11-06 09:31:16 +11:00
|
|
|
|
2019-10-29 06:27:36 +11:00
|
|
|
await self._local_echo(
|
2019-12-17 01:36:59 +11:00
|
|
|
room_id,
|
|
|
|
transaction_id,
|
|
|
|
event_type,
|
2019-11-07 00:43:05 +11:00
|
|
|
inline_content = path.name,
|
|
|
|
media_url = url,
|
|
|
|
media_title = path.name,
|
|
|
|
media_width = content["info"].get("w", 0),
|
|
|
|
media_height = content["info"].get("h", 0),
|
|
|
|
media_duration = content["info"].get("duration", 0),
|
|
|
|
media_size = content["info"]["size"],
|
|
|
|
media_mime = content["info"]["mimetype"],
|
|
|
|
thumbnail_url = thumb_url,
|
2019-11-18 04:31:00 +11:00
|
|
|
thumbnail_width =
|
|
|
|
content["info"].get("thumbnail_info", {}).get("w", 0),
|
|
|
|
thumbnail_height =
|
|
|
|
content["info"].get("thumbnail_info", {}).get("h", 0),
|
2020-03-10 03:06:58 +11:00
|
|
|
thumbnail_mime =
|
|
|
|
content["info"].get("thumbnail_info", {}).get("mimetype", ""),
|
2019-10-29 06:27:36 +11:00
|
|
|
)
|
|
|
|
|
2020-04-03 22:13:33 +11:00
|
|
|
await self._send_message(room_id, content, transaction_id)
|
2019-10-29 04:49:55 +11:00
|
|
|
|
|
|
|
|
|
|
|
async def _local_echo(
|
2019-12-19 04:16:15 +11:00
|
|
|
self,
|
|
|
|
room_id: str,
|
|
|
|
transaction_id: UUID,
|
|
|
|
event_type: Type[nio.Event],
|
|
|
|
**event_fields,
|
2019-10-29 04:49:55 +11:00
|
|
|
) -> None:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Register a local model `Event` while waiting for the server.
|
|
|
|
|
|
|
|
When the user sends a message, we want to show instant feedback in
|
|
|
|
the UI timeline without waiting for the servers to receive our message
|
|
|
|
and retransmit it to us.
|
|
|
|
|
|
|
|
The event will be locally echoed for all our accounts that are members
|
|
|
|
of the `room_id` room.
|
|
|
|
This allows sending messages from other accounts within the same
|
|
|
|
composer without having to go to another page in the UI,
|
|
|
|
and getting direct feedback for these accounts in the timeline.
|
|
|
|
|
|
|
|
When we do get the real event retransmited by the server, it will
|
|
|
|
replace the local one we registered.
|
|
|
|
"""
|
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
|
|
|
our_info = self.models[self.user_id, room_id, "members"][self.user_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
|
|
|
content = event_fields.get("content", "").strip()
|
|
|
|
|
|
|
|
if content and "inline_content" not in event_fields:
|
2020-03-23 11:58:05 +11:00
|
|
|
event_fields["inline_content"] = HTML.filter(
|
|
|
|
content, inline=True, room_id=room_id,
|
|
|
|
)
|
2020-02-12 08:32:22 +11:00
|
|
|
|
2019-10-29 04:49:55 +11:00
|
|
|
event = Event(
|
2020-02-12 08:32:22 +11:00
|
|
|
id = f"echo-{transaction_id}",
|
|
|
|
event_id = "",
|
|
|
|
event_type = event_type,
|
|
|
|
date = datetime.now(),
|
|
|
|
sender_id = self.user_id,
|
|
|
|
sender_name = our_info.display_name,
|
|
|
|
sender_avatar = our_info.avatar_url,
|
|
|
|
is_local_echo = True,
|
|
|
|
links = Event.parse_links(content),
|
2019-10-29 06:27:36 +11:00
|
|
|
**event_fields,
|
2019-07-04 11:20:49 +10:00
|
|
|
)
|
2019-10-29 04:49:55 +11:00
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
for user_id in self.models["accounts"]:
|
|
|
|
if user_id in self.models[self.user_id, room_id, "members"]:
|
2019-12-17 01:36:59 +11:00
|
|
|
key = f"echo-{transaction_id}"
|
2020-03-08 03:35:12 +11:00
|
|
|
self.models[user_id, room_id, "events"][key] = copy(event)
|
2019-07-04 11:20:49 +10:00
|
|
|
|
2019-10-29 04:49:55 +11:00
|
|
|
await self.set_room_last_event(room_id, event)
|
2019-10-29 04:34:59 +11:00
|
|
|
|
|
|
|
|
2020-04-03 22:13:33 +11:00
|
|
|
async def _send_message(
|
|
|
|
self, room_id: str, content: dict, transaction_id: UUID,
|
|
|
|
) -> None:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Send a message event with `content` dict to a room."""
|
2019-08-17 02:23:34 +10:00
|
|
|
|
2020-04-03 22:13:33 +11:00
|
|
|
self.send_message_tasks[transaction_id] = \
|
2020-04-27 03:49:44 +10:00
|
|
|
current_task() # type: ignore
|
2020-04-03 22:13:33 +11:00
|
|
|
|
2019-12-17 01:36:59 +11:00
|
|
|
async with self.backend.send_locks[room_id]:
|
2019-12-26 23:16:04 +11:00
|
|
|
await self.room_send(
|
2019-07-09 03:08:46 +10:00
|
|
|
room_id = room_id,
|
|
|
|
message_type = "m.room.message",
|
|
|
|
content = content,
|
|
|
|
ignore_unverified_devices = True,
|
|
|
|
)
|
2019-07-05 12:25:06 +10:00
|
|
|
|
2019-07-04 11:20:49 +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
|
|
|
async def load_past_events(self, room_id: str) -> bool:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Ask the server for 100 previous events of the room.
|
|
|
|
|
|
|
|
Events from before the client was started will be requested and
|
|
|
|
registered into our models.
|
|
|
|
|
|
|
|
Returns whether there are any messages left to load.
|
|
|
|
"""
|
|
|
|
|
2019-09-09 01:40:39 +10:00
|
|
|
if room_id in self.fully_loaded_rooms or \
|
|
|
|
room_id in self.invited_rooms or \
|
|
|
|
room_id in self.cleared_events_rooms:
|
2019-07-05 16:45:30 +10:00
|
|
|
return False
|
|
|
|
|
2019-08-28 05:00:50 +10:00
|
|
|
await self.first_sync_done.wait()
|
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-15 04:50:21 +11:00
|
|
|
while not self.past_tokens.get(room_id):
|
|
|
|
# If a new room was added, wait for onSyncResponse to set the token
|
|
|
|
await asyncio.sleep(0.1)
|
|
|
|
|
2019-07-05 16:45:30 +10:00
|
|
|
response = await self.room_messages(
|
|
|
|
room_id = room_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
|
|
|
start = self.past_tokens[room_id],
|
|
|
|
limit = 100 if room_id in self.loaded_once_rooms else 25,
|
2019-07-05 16:45:30 +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
|
|
|
self.loaded_once_rooms.add(room_id)
|
2019-07-05 16:45:30 +10:00
|
|
|
more_to_load = True
|
|
|
|
|
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
|
|
|
self.past_tokens[room_id] = response.end
|
2019-07-05 16:45:30 +10:00
|
|
|
|
|
|
|
for event in response.chunk:
|
2019-08-31 00:28:53 +10:00
|
|
|
if isinstance(event, nio.RoomCreateEvent):
|
|
|
|
self.fully_loaded_rooms.add(room_id)
|
|
|
|
more_to_load = False
|
|
|
|
|
2019-07-05 16:45:30 +10:00
|
|
|
for cb in self.event_callbacks:
|
|
|
|
if (cb.filter is None or isinstance(event, cb.filter)):
|
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
|
|
|
await cb.func(self.all_rooms[room_id], event)
|
2019-07-05 16:45:30 +10:00
|
|
|
|
|
|
|
return more_to_load
|
|
|
|
|
|
|
|
|
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
|
|
|
async def load_rooms_without_visible_events(self) -> None:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Call `_load_room_without_visible_events` for all joined rooms."""
|
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
for room_id in self.models[self.user_id, "rooms"]:
|
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
|
|
|
asyncio.ensure_future(
|
|
|
|
self._load_room_without_visible_events(room_id),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def _load_room_without_visible_events(self, room_id: str) -> None:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Request past events for rooms without any suitable event to show.
|
|
|
|
|
|
|
|
Some events are currently not supported, or processed but not
|
|
|
|
shown in the UI timeline/room "last event" subtitle, e.g.
|
|
|
|
the "x changed their name/avatar" events.
|
|
|
|
|
|
|
|
It could happen that all the initial events received in the initial
|
|
|
|
sync for a room are such events,
|
|
|
|
and thus we'd have nothing to show in the room.
|
|
|
|
|
|
|
|
This method tries to load past events until we have at least one
|
|
|
|
to show or there is nothing left to load.
|
|
|
|
"""
|
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
events = self.models[self.user_id, room_id, "events"]
|
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
|
|
|
more = True
|
|
|
|
|
|
|
|
while self.skipped_events[room_id] and not events and more:
|
2019-12-21 00:30:57 +11:00
|
|
|
try:
|
|
|
|
more = await self.load_past_events(room_id)
|
|
|
|
except MatrixError:
|
|
|
|
break
|
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-10 05:20:53 +11:00
|
|
|
async def new_direct_chat(self, invite: str, encrypt: bool = False) -> str:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Create a room and invite a single user in it for a direct chat."""
|
|
|
|
|
2019-11-10 05:20:53 +11:00
|
|
|
if invite == self.user_id:
|
|
|
|
raise InvalidUserInContext(invite)
|
|
|
|
|
2019-12-12 03:42:59 +11:00
|
|
|
if not self.user_id_regex.match(invite):
|
2019-12-05 00:59:14 +11:00
|
|
|
raise InvalidUserId(invite)
|
|
|
|
|
2019-12-26 23:16:04 +11:00
|
|
|
# Raise MatrixNotFound if profile doesn't exist
|
|
|
|
await self.get_profile(invite)
|
2019-11-10 05:20:53 +11:00
|
|
|
|
2019-12-30 05:30:15 +11:00
|
|
|
response = await super().room_create(
|
2019-11-10 05:20:53 +11:00
|
|
|
invite = [invite],
|
|
|
|
is_direct = True,
|
|
|
|
visibility = nio.RoomVisibility.private,
|
|
|
|
initial_state =
|
|
|
|
[nio.EnableEncryptionBuilder().as_dict()] if encrypt else [],
|
2019-12-30 05:30:15 +11:00
|
|
|
)
|
|
|
|
return response.room_id
|
2019-11-10 05:20:53 +11:00
|
|
|
|
|
|
|
|
|
|
|
async def new_group_chat(
|
2019-11-09 06:32:12 +11:00
|
|
|
self,
|
|
|
|
name: Optional[str] = None,
|
|
|
|
topic: Optional[str] = None,
|
|
|
|
public: bool = False,
|
2019-11-10 04:37:51 +11:00
|
|
|
encrypt: bool = False,
|
2019-11-09 06:32:12 +11:00
|
|
|
federate: bool = True,
|
|
|
|
) -> str:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Create a new matrix room with the purpose of being a group chat."""
|
2019-11-09 06:32:12 +11:00
|
|
|
|
2019-12-30 05:30:15 +11:00
|
|
|
response = await super().room_create(
|
2019-11-10 04:41:12 +11:00
|
|
|
name = name or None,
|
|
|
|
topic = topic or None,
|
2019-11-09 06:32:12 +11:00
|
|
|
federate = federate,
|
|
|
|
visibility =
|
|
|
|
nio.RoomVisibility.public if public else
|
|
|
|
nio.RoomVisibility.private,
|
2019-11-10 04:37:51 +11:00
|
|
|
initial_state =
|
|
|
|
[nio.EnableEncryptionBuilder().as_dict()] if encrypt else [],
|
2019-12-30 05:30:15 +11:00
|
|
|
)
|
|
|
|
return response.room_id
|
2019-11-09 06:32:12 +11:00
|
|
|
|
2019-11-10 00:52:16 +11:00
|
|
|
async def room_join(self, alias_or_id_or_url: str) -> str:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Join an existing matrix room."""
|
|
|
|
|
2019-11-10 00:52:16 +11:00
|
|
|
string = alias_or_id_or_url.strip()
|
|
|
|
|
2019-12-12 03:42:59 +11:00
|
|
|
if self.http_s_url.match(string):
|
2019-11-10 00:52:16 +11:00
|
|
|
for part in urlparse(string).fragment.split("/"):
|
2019-12-12 03:42:59 +11:00
|
|
|
if self.room_id_or_alias_regex.match(part):
|
2019-11-10 00:52:16 +11:00
|
|
|
string = part
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
raise ValueError(f"No alias or room id found in url {string}")
|
|
|
|
|
2019-12-12 03:42:59 +11:00
|
|
|
if not self.room_id_or_alias_regex.match(string):
|
2019-11-10 01:20:16 +11:00
|
|
|
raise ValueError("Not an alias or room id")
|
|
|
|
|
2019-12-30 05:30:15 +11:00
|
|
|
response = await super().join(string)
|
|
|
|
return response.room_id
|
2019-11-10 00:52:16 +11:00
|
|
|
|
|
|
|
|
2019-07-08 12:19:17 +10:00
|
|
|
async def room_forget(self, room_id: str) -> None:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Leave a joined room (or decline an invite) and forget its history.
|
|
|
|
|
|
|
|
If all the members of a room leave and forget it, that room
|
|
|
|
will be marked as suitable for destruction by the server.
|
|
|
|
"""
|
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
self.models[self.user_id, "rooms"].pop(room_id, None)
|
|
|
|
self.models.pop((self.user_id, room_id, "events"), None)
|
|
|
|
self.models.pop((self.user_id, room_id, "members"), None)
|
|
|
|
|
|
|
|
try:
|
|
|
|
await super().room_leave(room_id)
|
|
|
|
except MatrixNotFound: # already left
|
|
|
|
pass
|
|
|
|
|
2019-07-08 12:19:17 +10:00
|
|
|
await super().room_forget(room_id)
|
|
|
|
|
|
|
|
|
2019-12-12 03:42:59 +11:00
|
|
|
async def room_mass_invite(
|
|
|
|
self, room_id: str, *user_ids: str,
|
|
|
|
) -> Tuple[List[str], List[Tuple[str, Exception]]]:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Invite users to a room in parallel.
|
|
|
|
|
|
|
|
Returns a tuple with:
|
|
|
|
|
|
|
|
- A list of users we successfully invited
|
|
|
|
- A list of `(user_id, Exception)` tuples for those failed to invite.
|
|
|
|
"""
|
2019-12-12 03:42:59 +11:00
|
|
|
|
|
|
|
user_ids = tuple(
|
|
|
|
uid for uid in user_ids
|
|
|
|
# Server would return a 403 forbidden for users already in the room
|
|
|
|
if uid not in self.all_rooms[room_id].users
|
|
|
|
)
|
|
|
|
|
2020-03-09 22:59:23 +11:00
|
|
|
async def invite(user_id: str):
|
|
|
|
if not self.user_id_regex.match(user_id):
|
|
|
|
return InvalidUserId(user_id)
|
|
|
|
|
|
|
|
if not self.rooms[room_id].federate:
|
|
|
|
_, user_server = user_id.split(":", maxsplit=1)
|
|
|
|
_, room_server = room_id.split(":", maxsplit=1)
|
|
|
|
|
|
|
|
user_server = re.sub(r":443$", "", user_server)
|
|
|
|
room_server = re.sub(r":443$", "", room_server)
|
|
|
|
|
|
|
|
if user_server != room_server:
|
|
|
|
return UserFromOtherServerDisallowed(user_id)
|
2019-12-12 03:42:59 +11:00
|
|
|
|
2019-12-26 23:16:04 +11:00
|
|
|
try:
|
2020-03-09 22:59:23 +11:00
|
|
|
await self.get_profile(user_id)
|
2019-12-26 23:16:04 +11:00
|
|
|
except MatrixNotFound as err:
|
|
|
|
return err
|
2019-12-12 03:42:59 +11:00
|
|
|
|
2020-03-09 22:59:23 +11:00
|
|
|
return await self.room_invite(room_id, user_id)
|
2019-12-12 03:42:59 +11:00
|
|
|
|
|
|
|
coros = [invite(uid) for uid in user_ids]
|
|
|
|
successes = []
|
|
|
|
errors: list = []
|
|
|
|
responses = await asyncio.gather(*coros)
|
|
|
|
|
|
|
|
for user_id, response in zip(user_ids, responses):
|
|
|
|
if isinstance(response, nio.RoomInviteError):
|
|
|
|
errors.append((user_id, MatrixError.from_nio(response)))
|
|
|
|
|
|
|
|
elif isinstance(response, Exception):
|
|
|
|
errors.append((user_id, response))
|
|
|
|
|
|
|
|
else:
|
|
|
|
successes.append(user_id)
|
|
|
|
|
|
|
|
return (successes, errors)
|
|
|
|
|
2020-04-02 04:33:19 +11:00
|
|
|
|
2020-04-03 20:50:02 +11:00
|
|
|
async def get_redacted_event_content(
|
2020-04-03 21:50:24 +11:00
|
|
|
self,
|
|
|
|
nio_type: Type[nio.Event],
|
|
|
|
redacter: str,
|
|
|
|
sender: str,
|
|
|
|
reason: str = "",
|
2020-04-03 20:50:02 +11:00
|
|
|
) -> str:
|
2020-04-03 21:50:24 +11:00
|
|
|
"""Get content to be displayed in place of a redacted event."""
|
2020-04-03 20:50:02 +11:00
|
|
|
|
2020-04-03 21:50:24 +11:00
|
|
|
kind = (
|
|
|
|
"message" if issubclass(nio_type, nio.RoomMessage) else
|
|
|
|
"media" if issubclass(nio_type, nio.RoomMessageMedia) else
|
|
|
|
"event"
|
|
|
|
)
|
2020-04-03 20:50:02 +11:00
|
|
|
|
|
|
|
content = f"%1 removed this {kind}" if redacter == sender else \
|
|
|
|
f"%1's {kind} was removed by %2"
|
|
|
|
|
|
|
|
if reason:
|
|
|
|
content = f"{content}, reason: {reason}"
|
|
|
|
|
|
|
|
return content
|
|
|
|
|
|
|
|
|
2020-03-27 07:31:57 +11:00
|
|
|
async def room_mass_redact(
|
2020-04-03 21:50:24 +11:00
|
|
|
self, room_id: str, reason: str, *event_client_ids: str,
|
2020-04-03 20:50:02 +11:00
|
|
|
) -> List[nio.RoomRedactResponse]:
|
|
|
|
"""Redact events from a room in parallel."""
|
2020-03-27 07:31:57 +11:00
|
|
|
|
2020-04-03 20:50:02 +11:00
|
|
|
tasks = []
|
2020-04-03 11:51:53 +11:00
|
|
|
|
2020-04-03 21:50:24 +11:00
|
|
|
for user_id in self.backend.clients:
|
|
|
|
for client_id in event_client_ids:
|
|
|
|
|
|
|
|
event = self.models[user_id, room_id, "events"].get(client_id)
|
|
|
|
|
|
|
|
if not event:
|
|
|
|
continue
|
|
|
|
|
2020-04-03 22:13:33 +11:00
|
|
|
if event.is_local_echo:
|
|
|
|
if user_id == self.user_id:
|
|
|
|
uuid = UUID(event.id.replace("echo-", ""))
|
|
|
|
self.send_message_tasks[uuid].cancel()
|
|
|
|
|
|
|
|
event.is_local_echo = False
|
|
|
|
else:
|
|
|
|
if user_id == self.user_id:
|
|
|
|
tasks.append(
|
|
|
|
self.room_redact(room_id, event.event_id, reason),
|
|
|
|
)
|
2020-04-03 20:50:02 +11:00
|
|
|
|
2020-04-03 22:13:33 +11:00
|
|
|
event.is_local_echo = True
|
2020-04-03 20:50:02 +11:00
|
|
|
|
|
|
|
event.content = await self.get_redacted_event_content(
|
2020-04-03 21:50:24 +11:00
|
|
|
event.event_type, self.user_id, event.sender_id, reason,
|
2020-04-03 20:50:02 +11:00
|
|
|
)
|
|
|
|
|
|
|
|
event.event_type = nio.RedactedEvent
|
|
|
|
|
|
|
|
return await asyncio.gather(*tasks)
|
2019-12-12 03:42:59 +11:00
|
|
|
|
2020-04-02 04:33:19 +11:00
|
|
|
|
2019-11-18 04:31:00 +11:00
|
|
|
async def generate_thumbnail(
|
|
|
|
self, data: UploadData, is_svg: bool = False,
|
|
|
|
) -> Tuple[bytes, MatrixImageInfo]:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Create a thumbnail from an image, return the bytes and info."""
|
2019-11-05 05:37:25 +11:00
|
|
|
|
|
|
|
png_modes = ("1", "L", "P", "RGBA")
|
|
|
|
|
2019-11-18 04:31:00 +11:00
|
|
|
data = b"".join([c async for c in async_generator_from_data(data)])
|
|
|
|
is_svg = await utils.guess_mime(data) == "image/svg+xml"
|
2019-10-30 07:42:56 +11:00
|
|
|
|
2019-11-18 04:31:00 +11:00
|
|
|
if is_svg:
|
|
|
|
svg_width, svg_height = await utils.svg_dimensions(data)
|
2019-10-30 07:42:56 +11:00
|
|
|
|
2019-11-18 04:31:00 +11:00
|
|
|
data = cairosvg.svg2png(
|
|
|
|
bytestring = data,
|
|
|
|
parent_width = svg_width,
|
|
|
|
parent_height = svg_height,
|
|
|
|
)
|
2019-10-30 07:42:56 +11:00
|
|
|
|
2019-11-18 04:31:00 +11:00
|
|
|
thumb = PILImage.open(io.BytesIO(data))
|
2019-11-06 09:31:16 +11:00
|
|
|
|
2019-11-18 04:31:00 +11:00
|
|
|
small = thumb.width <= 800 and thumb.height <= 600
|
|
|
|
is_jpg_png = thumb.format in ("JPEG", "PNG")
|
|
|
|
jpgable_png = thumb.format == "PNG" and thumb.mode not in png_modes
|
2019-07-16 06:14:08 +10:00
|
|
|
|
2019-11-18 04:31:00 +11:00
|
|
|
if small and is_jpg_png and not jpgable_png and not is_svg:
|
|
|
|
raise UneededThumbnail()
|
2019-10-30 07:42:56 +11:00
|
|
|
|
2019-11-18 04:31:00 +11:00
|
|
|
if not small:
|
2020-03-22 09:56:47 +11:00
|
|
|
thumb.thumbnail((800, 600))
|
2019-10-31 01:34:20 +11:00
|
|
|
|
2019-11-18 04:31:00 +11:00
|
|
|
with io.BytesIO() as out:
|
|
|
|
if thumb.mode in png_modes:
|
|
|
|
thumb.save(out, "PNG", optimize=True)
|
|
|
|
mime = "image/png"
|
|
|
|
else:
|
|
|
|
thumb.convert("RGB").save(out, "JPEG", optimize=True)
|
|
|
|
mime = "image/jpeg"
|
2019-11-06 09:31:16 +11:00
|
|
|
|
2020-03-08 23:10:27 +11:00
|
|
|
thumb_data = out.getvalue()
|
|
|
|
thumb_size = len(thumb_data)
|
2019-10-30 07:42:56 +11:00
|
|
|
|
2020-03-10 01:03:22 +11:00
|
|
|
if thumb_size >= len(data) and is_jpg_png and not is_svg:
|
2020-03-08 23:10:27 +11:00
|
|
|
raise UneededThumbnail()
|
|
|
|
|
|
|
|
info = MatrixImageInfo(thumb.width, thumb.height, mime, thumb_size)
|
|
|
|
return (thumb_data, info)
|
2019-10-30 07:42:56 +11:00
|
|
|
|
|
|
|
|
2019-11-18 04:31:00 +11:00
|
|
|
async def upload(
|
2019-11-06 09:31:16 +11:00
|
|
|
self,
|
2019-12-15 08:40:31 +11:00
|
|
|
data_provider: nio.DataProvider,
|
|
|
|
filename: Optional[str] = None,
|
2020-03-10 01:23:08 +11:00
|
|
|
filesize: Optional[int] = None,
|
|
|
|
mime: Optional[str] = None,
|
2019-12-15 08:40:31 +11:00
|
|
|
encrypt: bool = False,
|
|
|
|
monitor: Optional[nio.TransferMonitor] = None,
|
2019-11-18 04:31:00 +11:00
|
|
|
) -> UploadReturn:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Upload a file to the matrix homeserver."""
|
2019-10-30 07:42:56 +11:00
|
|
|
|
2020-03-10 01:23:08 +11:00
|
|
|
if filesize > self.models["accounts"][self.user_id].max_upload_size:
|
|
|
|
raise MatrixTooLarge()
|
|
|
|
|
2019-12-15 08:40:31 +11:00
|
|
|
mime = mime or await utils.guess_mime(data_provider(0, 0))
|
2019-10-30 07:42:56 +11:00
|
|
|
|
2019-11-18 04:31:00 +11:00
|
|
|
response, decryption_dict = await super().upload(
|
2019-12-15 08:40:31 +11:00
|
|
|
data_provider,
|
2019-11-18 04:31:00 +11:00
|
|
|
"application/octet-stream" if encrypt else mime,
|
|
|
|
filename,
|
|
|
|
encrypt,
|
2019-12-06 01:00:23 +11:00
|
|
|
monitor,
|
2019-11-18 04:31:00 +11:00
|
|
|
)
|
2019-07-16 06:14:08 +10:00
|
|
|
|
2019-11-18 04:31:00 +11:00
|
|
|
return UploadReturn(response.content_uri, mime, decryption_dict)
|
2019-07-16 06:14:08 +10:00
|
|
|
|
|
|
|
|
2019-10-28 23:06:22 +11:00
|
|
|
async def set_avatar_from_file(self, path: Union[Path, str]) -> None:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Upload an image to the homeserver and set it as our avatar."""
|
|
|
|
|
2020-03-10 01:23:08 +11:00
|
|
|
path = Path(path)
|
2019-11-18 04:31:00 +11:00
|
|
|
mime = await utils.guess_mime(path)
|
2019-11-13 00:48:11 +11:00
|
|
|
|
|
|
|
if mime.split("/")[0] != "image":
|
|
|
|
raise BadMimeType(wanted="image/*", got=mime)
|
|
|
|
|
2020-03-10 01:23:08 +11:00
|
|
|
mxc, *_ = await self.upload(
|
|
|
|
data_provider = lambda *_: path,
|
|
|
|
filename = path.name,
|
|
|
|
filesize = path.resolve().stat().st_size,
|
|
|
|
mime = mime,
|
|
|
|
)
|
2019-11-18 04:31:00 +11:00
|
|
|
await self.set_avatar(mxc)
|
2019-07-16 06:14:08 +10:00
|
|
|
|
|
|
|
|
2019-08-29 01:42:52 +10:00
|
|
|
async def import_keys(self, infile: str, passphrase: str) -> None:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Import decryption keys from a file, then retry decrypting events."""
|
|
|
|
|
2019-11-24 02:14:14 +11:00
|
|
|
await super().import_keys(infile, passphrase)
|
2019-08-29 03:23:12 +10:00
|
|
|
await self.retry_decrypting_events()
|
2019-08-28 17:54:53 +10:00
|
|
|
|
|
|
|
|
2019-09-08 09:17:32 +10:00
|
|
|
async def export_keys(self, outfile: str, passphrase: str) -> None:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Export our decryption keys to a file."""
|
|
|
|
|
2019-09-08 09:17:32 +10:00
|
|
|
path = Path(outfile)
|
|
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
2019-09-09 02:17:08 +10:00
|
|
|
# The QML dialog asks the user if he wants to overwrite before this
|
|
|
|
if path.exists():
|
|
|
|
path.unlink()
|
2019-09-08 09:17:32 +10:00
|
|
|
|
|
|
|
await super().export_keys(outfile, passphrase)
|
|
|
|
|
|
|
|
|
2019-08-29 03:23:12 +10:00
|
|
|
async def retry_decrypting_events(self) -> None:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Retry decrypting room `Event`s in our model we failed to decrypt."""
|
|
|
|
|
2019-08-29 03:23:12 +10:00
|
|
|
for sync_id, model in self.models.items():
|
|
|
|
if not (isinstance(sync_id, tuple) and
|
2020-03-16 07:00:29 +11:00
|
|
|
len(sync_id) == 3 and
|
2019-12-03 07:29:29 +11:00
|
|
|
sync_id[0] == self.user_id and
|
|
|
|
sync_id[2] == "events"):
|
2019-08-29 03:23:12 +10:00
|
|
|
continue
|
|
|
|
|
2020-03-16 07:00:29 +11:00
|
|
|
_, room_id, _ = sync_id
|
2019-08-29 03:23:12 +10:00
|
|
|
|
2020-03-16 07:18:32 +11:00
|
|
|
for ev in model.copy().values():
|
2019-08-29 03:23:12 +10:00
|
|
|
room = self.all_rooms[room_id]
|
|
|
|
|
|
|
|
if isinstance(ev.source, nio.MegolmEvent):
|
|
|
|
try:
|
|
|
|
decrypted = self.decrypt_event(ev.source)
|
|
|
|
|
|
|
|
if not decrypted:
|
|
|
|
raise nio.EncryptionError()
|
|
|
|
|
|
|
|
except nio.EncryptionError:
|
|
|
|
continue
|
|
|
|
|
|
|
|
for cb in self.event_callbacks:
|
|
|
|
if not cb.filter or isinstance(decrypted, cb.filter):
|
|
|
|
await asyncio.coroutine(cb.func)(room, decrypted)
|
|
|
|
|
|
|
|
|
2019-09-09 01:40:39 +10:00
|
|
|
async def clear_events(self, room_id: str) -> None:
|
2020-03-13 05:41:00 +11:00
|
|
|
"""Remove every `Event` of a room we registered in our model.
|
2019-12-19 04:16:15 +11:00
|
|
|
|
|
|
|
The events will be gone from the UI, until the client is restarted.
|
|
|
|
"""
|
|
|
|
|
2019-09-09 01:40:39 +10:00
|
|
|
self.cleared_events_rooms.add(room_id)
|
2020-03-17 03:36:39 +11:00
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
model = self.models[self.user_id, room_id, "events"]
|
2019-09-09 01:49:47 +10:00
|
|
|
if model:
|
|
|
|
model.clear()
|
2019-09-09 01:40:39 +10:00
|
|
|
|
2020-03-17 03:36:39 +11:00
|
|
|
self.models[self.user_id, "rooms"][room_id].last_event_date = \
|
|
|
|
ZeroDate
|
2019-09-09 01:40:39 +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
|
|
|
# Functions to register data into models
|
2019-07-03 03:59:52 +10:00
|
|
|
|
2019-08-17 04:27:25 +10:00
|
|
|
async def event_is_past(self, ev: Union[nio.Event, Event]) -> bool:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Return whether an event was created before this client started."""
|
|
|
|
|
2019-08-17 04:27:25 +10:00
|
|
|
if not self.first_sync_date:
|
|
|
|
return True
|
|
|
|
|
|
|
|
if isinstance(ev, Event):
|
|
|
|
return ev.date < self.first_sync_date
|
|
|
|
|
|
|
|
date = datetime.fromtimestamp(ev.server_timestamp / 1000)
|
|
|
|
return date < self.first_sync_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
|
|
|
async def set_room_last_event(self, room_id: str, item: Event) -> None:
|
2019-12-19 04:16:15 +11:00
|
|
|
"""Set the `last_event` for a `Room` using data in our `Event` model.
|
|
|
|
|
|
|
|
The `last_event` is notably displayed in the UI room subtitles.
|
|
|
|
"""
|
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
room = self.models[self.user_id, "rooms"][room_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
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
if item.date > room.last_event_date:
|
|
|
|
room.last_event_date = item.date
|
2019-09-01 06:13: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
|
|
|
|
2019-12-19 04:16:15 +11:00
|
|
|
async def register_nio_room(
|
|
|
|
self, room: nio.MatrixRoom, left: bool = False,
|
|
|
|
) -> None:
|
|
|
|
"""Register a `nio.MatrixRoom` as a `Room` object in our model."""
|
|
|
|
|
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
|
|
|
# Add room
|
2019-12-13 23:32:18 +11:00
|
|
|
inviter = getattr(room, "inviter", "") or ""
|
|
|
|
levels = room.power_levels
|
|
|
|
can_send_state = partial(levels.can_user_send_state, self.user_id)
|
|
|
|
can_send_msg = partial(levels.can_user_send_message, self.user_id)
|
2019-08-16 02:13:41 +10:00
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
try:
|
|
|
|
registered = self.models[self.user_id, "rooms"][room.room_id]
|
|
|
|
last_event_date = registered.last_event_date
|
|
|
|
typing_members = registered.typing_members
|
2020-03-23 14:55:48 +11:00
|
|
|
mentions = registered.mentions
|
2019-12-03 07:29:29 +11:00
|
|
|
except KeyError:
|
|
|
|
last_event_date = datetime.fromtimestamp(0)
|
|
|
|
typing_members = []
|
2020-03-23 14:55:48 +11:00
|
|
|
mentions = 0
|
2019-12-03 07:29:29 +11:00
|
|
|
|
|
|
|
self.models[self.user_id, "rooms"][room.room_id] = Room(
|
|
|
|
id = room.room_id,
|
2019-12-14 08:18:36 +11:00
|
|
|
given_name = room.name or "",
|
2019-11-28 01:03:49 +11:00
|
|
|
display_name = room.display_name or "",
|
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
|
|
|
avatar_url = room.gen_avatar_url or "",
|
2019-12-14 06:09:13 +11:00
|
|
|
plain_topic = room.topic or "",
|
2020-03-23 11:58:05 +11:00
|
|
|
topic = HTML.filter(
|
|
|
|
room.topic or "", inline=True, room_id=room.room_id,
|
|
|
|
),
|
2019-08-16 02:13:41 +10:00
|
|
|
inviter_id = inviter,
|
|
|
|
inviter_name = room.user_name(inviter) if inviter else "",
|
2019-08-18 08:17:14 +10:00
|
|
|
inviter_avatar =
|
|
|
|
(room.avatar_url(inviter) or "") if inviter else "",
|
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 = left,
|
2019-12-12 03:42:59 +11:00
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
typing_members = typing_members,
|
|
|
|
|
2019-12-13 23:32:18 +11:00
|
|
|
encrypted = room.encrypted,
|
|
|
|
invite_required = room.join_rule == "invite",
|
|
|
|
guests_allowed = room.guest_access == "can_join",
|
|
|
|
|
|
|
|
can_invite = levels.can_user_invite(self.user),
|
2020-04-02 06:15:49 +11:00
|
|
|
can_redact_all = levels.can_user_redact(self.user),
|
2019-12-13 23:32:18 +11:00
|
|
|
can_send_messages = can_send_msg(),
|
|
|
|
can_set_name = can_send_state("m.room.name"),
|
|
|
|
can_set_topic = can_send_state("m.room.topic"),
|
|
|
|
can_set_avatar = can_send_state("m.room.avatar"),
|
|
|
|
can_set_encryption = can_send_state("m.room.encryption"),
|
|
|
|
can_set_join_rules = can_send_state("m.room.join_rules"),
|
|
|
|
can_set_guest_access = can_send_state("m.room.guest_access"),
|
2019-12-12 03:42:59 +11:00
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
last_event_date = last_event_date,
|
2020-03-23 14:55:48 +11:00
|
|
|
mentions = mentions,
|
2019-12-03 07:29:29 +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-10 05:36:03 +11:00
|
|
|
# List members that left the room, then remove them from our model
|
|
|
|
left_the_room = [
|
|
|
|
user_id
|
2019-12-03 07:29:29 +11:00
|
|
|
for user_id in self.models[self.user_id, room.room_id, "members"]
|
2019-12-10 05:36:03 +11:00
|
|
|
if user_id not in room.users
|
|
|
|
]
|
|
|
|
|
|
|
|
for user_id in left_the_room:
|
2019-12-03 07:29:29 +11:00
|
|
|
del self.models[self.user_id, room.room_id, "members"][user_id]
|
2020-03-23 11:58:05 +11:00
|
|
|
HTML.rooms_user_id_names[room.room_id].pop(user_id, None)
|
2019-12-10 05:36:03 +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
|
|
|
# Add the room members to the added room
|
|
|
|
new_dict = {
|
|
|
|
user_id: Member(
|
2019-12-03 07:29:29 +11:00
|
|
|
id = user_id,
|
2019-12-13 01:03:39 +11:00
|
|
|
display_name = room.user_name(user_id) # disambiguated
|
|
|
|
if member.display_name else "",
|
|
|
|
avatar_url = member.avatar_url or "",
|
|
|
|
typing = user_id in room.typing_users,
|
|
|
|
power_level = member.power_level,
|
|
|
|
invited = member.invited,
|
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
|
|
|
) for user_id, member in room.users.items()
|
|
|
|
}
|
2019-12-03 07:29:29 +11:00
|
|
|
self.models[self.user_id, room.room_id, "members"].update(new_dict)
|
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-03-23 11:58:05 +11:00
|
|
|
for user_id, member in room.users.items():
|
|
|
|
if member.display_name:
|
|
|
|
HTML.rooms_user_id_names[room.room_id][user_id] = \
|
|
|
|
member.display_name
|
|
|
|
|
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-19 04:16:15 +11:00
|
|
|
async def get_member_name_avatar(
|
|
|
|
self, room_id: str, user_id: str,
|
|
|
|
) -> Tuple[str, str]:
|
|
|
|
"""Return a room member's display name and avatar.
|
|
|
|
|
|
|
|
If the member isn't found in the room (e.g. they left), their
|
|
|
|
profile is retrieved using `MatrixClient.backend.get_profile()`.
|
|
|
|
"""
|
|
|
|
|
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
|
|
|
try:
|
2019-12-03 07:29:29 +11:00
|
|
|
item = self.models[self.user_id, room_id, "members"][user_id]
|
2019-12-19 04:16: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
|
|
|
except KeyError: # e.g. user is not anymore in the room
|
2019-11-12 23:47:03 +11:00
|
|
|
try:
|
|
|
|
info = await self.backend.get_profile(user_id)
|
|
|
|
return (info.displayname or "", info.avatar_url or "")
|
2019-12-19 04:16:15 +11:00
|
|
|
|
2019-11-12 23:47:03 +11:00
|
|
|
except MatrixError:
|
|
|
|
return ("", "")
|
2019-12-19 04:16: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
|
|
|
else:
|
|
|
|
return (item.display_name, item.avatar_url)
|
|
|
|
|
|
|
|
|
2019-08-16 15:51:42 +10:00
|
|
|
async def register_nio_event(
|
2020-04-02 04:33:19 +11:00
|
|
|
self,
|
2020-04-02 06:15:49 +11:00
|
|
|
room: nio.MatrixRoom,
|
|
|
|
ev: nio.Event,
|
2020-04-02 04:33:19 +11:00
|
|
|
event_id: str = "",
|
2020-03-30 09:06:13 +11:00
|
|
|
**fields,
|
2019-08-16 15:51:42 +10:00
|
|
|
) -> None:
|
2019-12-03 07:29:29 +11:00
|
|
|
"""Register a `nio.Event` as a `Event` object in our model."""
|
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
|
|
|
|
|
|
|
await self.register_nio_room(room)
|
|
|
|
|
|
|
|
sender_name, sender_avatar = \
|
|
|
|
await self.get_member_name_avatar(room.room_id, ev.sender)
|
|
|
|
|
|
|
|
target_id = getattr(ev, "state_key", "") or ""
|
|
|
|
|
|
|
|
target_name, target_avatar = \
|
|
|
|
await self.get_member_name_avatar(room.room_id, target_id) \
|
|
|
|
if target_id else ("", "")
|
|
|
|
|
2020-02-12 08:32:22 +11:00
|
|
|
content = fields.get("content", "").strip()
|
|
|
|
|
|
|
|
if content and "inline_content" not in fields:
|
2020-03-23 11:58:05 +11:00
|
|
|
fields["inline_content"] = HTML.filter(
|
|
|
|
content, inline=True, room_id=room.room_id,
|
|
|
|
)
|
2020-02-12 08:32:22 +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
|
|
|
# Create Event ModelItem
|
2020-03-08 03:35:12 +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
|
|
|
item = Event(
|
2020-03-30 09:06:13 +11:00
|
|
|
id = event_id or ev.event_id,
|
2019-09-14 13:02:11 +10:00
|
|
|
event_id = ev.event_id,
|
2020-02-12 08:17:11 +11:00
|
|
|
event_type = type(ev),
|
2019-12-03 07:29:29 +11:00
|
|
|
source = ev,
|
2020-03-30 09:06:13 +11:00
|
|
|
date = datetime.fromtimestamp(ev.server_timestamp / 1000),
|
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
|
|
|
sender_id = ev.sender,
|
|
|
|
sender_name = sender_name,
|
|
|
|
sender_avatar = sender_avatar,
|
|
|
|
target_id = target_id,
|
|
|
|
target_name = target_name,
|
|
|
|
target_avatar = target_avatar,
|
2020-02-12 08:32:22 +11:00
|
|
|
links = Event.parse_links(content),
|
2019-09-14 12:34:20 +10:00
|
|
|
**fields,
|
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
|
|
|
)
|
|
|
|
|
|
|
|
# Add the Event to model
|
2020-03-08 03:35:12 +11:00
|
|
|
|
2020-03-16 08:26:41 +11:00
|
|
|
model = self.models[self.user_id, room.room_id, "events"]
|
|
|
|
|
2019-12-17 01:36:59 +11:00
|
|
|
tx_id = ev.source.get("content", {}).get(
|
2019-12-18 21:55:05 +11:00
|
|
|
f"{__app_name__}.transaction_id",
|
2019-12-17 01:36:59 +11:00
|
|
|
)
|
|
|
|
local_sender = ev.sender in self.backend.clients
|
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-03-16 08:31:10 +11:00
|
|
|
if local_sender and tx_id and f"echo-{tx_id}" in model:
|
2019-12-03 07:29:29 +11:00
|
|
|
item.id = f"echo-{tx_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
|
|
|
|
2019-12-17 01:36:59 +11:00
|
|
|
if not local_sender and not await self.event_is_past(ev):
|
2019-08-17 04:27:25 +10:00
|
|
|
AlertRequested()
|
|
|
|
|
2020-03-16 08:26:41 +11:00
|
|
|
model[item.id] = item
|
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
|
|
|
await self.set_room_last_event(room.room_id, item)
|