2019-07-03 03:59:52 +10:00
|
|
|
import asyncio
|
2019-11-05 06:18:01 +11:00
|
|
|
import functools
|
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-10-31 02:10:40 +11:00
|
|
|
import traceback
|
2019-07-03 03:59:52 +10:00
|
|
|
from contextlib import suppress
|
2019-10-28 23:06:22 +11:00
|
|
|
from dataclasses import dataclass
|
2019-07-04 11:20:49 +10:00
|
|
|
from datetime import datetime
|
2019-08-28 17:54:53 +10: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 (
|
2019-11-06 00:19:48 +11:00
|
|
|
Any, BinaryIO, DefaultDict, Dict, Optional, Set, Tuple, Type, Union,
|
2019-11-05 06:18:01 +11:00
|
|
|
)
|
2019-07-05 09:49:55 +10:00
|
|
|
from uuid import uuid4
|
2019-07-03 03:59:52 +10:00
|
|
|
|
2019-11-06 22:50:31 +11:00
|
|
|
import cairosvg
|
2019-10-29 06:27:36 +11:00
|
|
|
from PIL import Image as PILImage
|
|
|
|
from pymediainfo import MediaInfo
|
2019-07-03 03:59:52 +10:00
|
|
|
|
2019-11-05 06:18:01 +11:00
|
|
|
import nio
|
|
|
|
|
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 . import __about__, utils
|
2019-07-03 03:59:52 +10:00
|
|
|
from .html_filter import HTML_FILTER
|
2019-11-06 09:31:16 +11:00
|
|
|
from .models.items import (
|
|
|
|
Account, Event, Member, Room, TypeSpecifier, Upload, UploadStatus,
|
|
|
|
)
|
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
|
2019-08-17 04:27:25 +10:00
|
|
|
from .pyotherside_events import AlertRequested
|
2019-07-03 03:59:52 +10:00
|
|
|
|
2019-11-05 06:18:01 +11:00
|
|
|
CryptDict = Dict[str, Any]
|
|
|
|
|
2019-07-03 03:59:52 +10:00
|
|
|
|
2019-11-09 06:32:12 +11:00
|
|
|
@dataclass
|
|
|
|
class RequestFailed(Exception):
|
|
|
|
m_code: Optional[str] = None
|
|
|
|
|
2019-10-28 23:06:22 +11:00
|
|
|
@dataclass
|
|
|
|
class UploadError(Exception):
|
|
|
|
http_code: Optional[int] = None
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class UploadForbidden(UploadError):
|
|
|
|
http_code: Optional[int] = 403
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class UploadTooLarge(UploadError):
|
|
|
|
http_code: Optional[int] = 413
|
2019-07-16 06:14:08 +10:00
|
|
|
|
2019-10-30 07:42:56 +11:00
|
|
|
@dataclass
|
|
|
|
class UneededThumbnail(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class UnthumbnailableError(Exception):
|
|
|
|
exception: Optional[Exception] = None
|
|
|
|
|
2019-07-16 06:14:08 +10:00
|
|
|
|
2019-07-03 03:59:52 +10:00
|
|
|
class MatrixClient(nio.AsyncClient):
|
|
|
|
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
|
|
|
|
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
|
|
|
store = Path(backend.app.appdirs.user_data_dir) / "encryption"
|
2019-07-25 10:00:01 +10:00
|
|
|
store.mkdir(parents=True, exist_ok=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
|
|
|
# TODO: ensure homeserver starts by a scheme://
|
2019-07-09 03:08:46 +10:00
|
|
|
# TODO: pass a ClientConfig with a pickle key
|
|
|
|
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-07-09 03:08:46 +10:00
|
|
|
)
|
2019-07-03 03:59:52 +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
|
|
|
from .backend import Backend
|
|
|
|
self.backend: Backend = backend
|
|
|
|
self.models: ModelStore = self.backend.models
|
|
|
|
|
2019-08-28 05:00:50 +10:00
|
|
|
self.sync_task: Optional[asyncio.Future] = None
|
|
|
|
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
|
|
|
|
|
|
|
self.send_locks: DefaultDict[str, asyncio.Lock] = \
|
|
|
|
DefaultDict(asyncio.Lock) # {room_id: lock}
|
|
|
|
|
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.local_echoes_uuid: Set[str] = set()
|
|
|
|
self.resolved_echoes: Dict[str, str] = {} # {event_id: echo_uuid}
|
|
|
|
|
|
|
|
self.skipped_events: DefaultDict[str, int] = DefaultDict(lambda: 0)
|
|
|
|
|
2019-11-04 04:48:12 +11:00
|
|
|
from .media_cache import MediaCache
|
|
|
|
cache_dir = Path(self.backend.app.appdirs.user_cache_dir)
|
|
|
|
self.media_cache = MediaCache(self, cache_dir)
|
|
|
|
|
2019-11-08 23:30:11 +11:00
|
|
|
from .nio_callbacks import NioCallbacks
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
def default_device_name(self) -> str:
|
|
|
|
os_ = f" on {platform.system()}".rstrip()
|
|
|
|
os_ = f"{os_} {platform.release()}".rstrip() if os_ != " on" else ""
|
|
|
|
return f"{__about__.__pretty_name__}{os_}"
|
|
|
|
|
|
|
|
|
2019-07-03 05:06:45 +10:00
|
|
|
async def login(self, password: str, device_name: str = "") -> None:
|
|
|
|
response = await super().login(
|
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
|
|
|
password, device_name or self.default_device_name,
|
2019-07-03 05:06:45 +10:00
|
|
|
)
|
2019-07-03 03:59:52 +10:00
|
|
|
|
|
|
|
if isinstance(response, nio.LoginError):
|
2019-08-17 06:30:18 +10:00
|
|
|
raise RuntimeError(response)
|
2019-11-08 23:30:11 +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:
|
|
|
|
response = nio.LoginResponse(user_id, device_id, token)
|
|
|
|
await self.receive_response(response)
|
2019-10-31 02:10:40 +11:00
|
|
|
asyncio.ensure_future(self.start())
|
2019-07-03 03:59:52 +10:00
|
|
|
|
|
|
|
|
|
|
|
async def logout(self) -> None:
|
|
|
|
if self.sync_task:
|
|
|
|
self.sync_task.cancel()
|
|
|
|
with suppress(asyncio.CancelledError):
|
|
|
|
await self.sync_task
|
|
|
|
|
2019-08-22 07:45:05 +10:00
|
|
|
await super().logout()
|
2019-07-03 03:59:52 +10:00
|
|
|
await self.close()
|
|
|
|
|
|
|
|
|
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 start(self) -> None:
|
|
|
|
def on_profile_response(future) -> None:
|
|
|
|
resp = future.result()
|
|
|
|
if isinstance(resp, nio.ProfileGetResponse):
|
|
|
|
account = self.models[Account][self.user_id]
|
|
|
|
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
|
|
|
|
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
|
|
|
ft = asyncio.ensure_future(self.backend.get_profile(self.user_id))
|
|
|
|
ft.add_done_callback(on_profile_response)
|
2019-07-03 03:59:52 +10:00
|
|
|
|
2019-10-31 02:10:40 +11:00
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
await self.sync_forever(timeout=10_000)
|
|
|
|
except Exception:
|
|
|
|
trace = traceback.format_exc().rstrip()
|
|
|
|
log.error("Exception during sync, will restart:\n%s", trace)
|
|
|
|
await asyncio.sleep(2)
|
2019-07-07 15:37:13 +10:00
|
|
|
|
2019-07-03 03:59:52 +10:00
|
|
|
|
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-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-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"}
|
2019-07-22 07:41:43 +10:00
|
|
|
to_html = HTML_FILTER.from_markdown_inline(text, outgoing=True)
|
2019-08-31 01:53:55 +10:00
|
|
|
echo_body = HTML_FILTER.from_markdown_inline(text)
|
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"}
|
2019-07-22 07:41:43 +10:00
|
|
|
to_html = HTML_FILTER.from_markdown(text, outgoing=True)
|
2019-08-31 01:53:55 +10:00
|
|
|
echo_body = HTML_FILTER.from_markdown(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
|
|
|
|
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
|
|
|
uuid = str(uuid4())
|
2019-10-29 04:49:55 +11:00
|
|
|
|
2019-10-29 06:27:36 +11:00
|
|
|
await self._local_echo(room_id, uuid, event_type, content=echo_body)
|
|
|
|
await self._send_message(room_id, uuid, content)
|
|
|
|
|
|
|
|
|
|
|
|
async def send_file(self, room_id: str, path: Union[Path, str]) -> None:
|
2019-10-31 01:34:20 +11:00
|
|
|
path = Path(path)
|
2019-11-06 09:31:16 +11:00
|
|
|
size = path.resolve().stat().st_size
|
2019-10-31 01:34:20 +11:00
|
|
|
encrypt = room_id in self.encrypted_rooms
|
|
|
|
|
2019-11-06 09:31:16 +11:00
|
|
|
upload_item = Upload(str(path), total_size=size)
|
|
|
|
self.models[Upload, room_id][upload_item.uuid] = upload_item
|
|
|
|
|
|
|
|
url, mime, crypt_dict = await self.upload_file(
|
|
|
|
path, upload_item, encrypt=encrypt,
|
|
|
|
)
|
2019-10-31 01:34:20 +11:00
|
|
|
|
2019-11-07 00:43:05 +11:00
|
|
|
await self.media_cache.create_media(url, path.read_bytes())
|
|
|
|
|
2019-10-31 01:34:20 +11:00
|
|
|
kind = (mime or "").split("/")[0]
|
|
|
|
|
2019-11-07 00:43:05 +11:00
|
|
|
thumb_url: str = ""
|
|
|
|
thumb_info: Dict[str, Any] = {}
|
|
|
|
|
2019-10-29 06:27:36 +11:00
|
|
|
content: dict = {
|
|
|
|
"body": path.name,
|
|
|
|
"info": {
|
|
|
|
"mimetype": mime,
|
2019-11-06 09:31:16 +11:00
|
|
|
"size": 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"] = (
|
|
|
|
utils.svg_dimensions(str(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-07 00:43:05 +11:00
|
|
|
thumb_data, thumb_url, thumb_info, thumb_crypt_dict = \
|
2019-11-06 09:31:16 +11:00
|
|
|
await self.upload_thumbnail(
|
2019-11-06 22:50:31 +11:00
|
|
|
path, upload_item, is_svg=is_svg, encrypt=encrypt,
|
2019-11-06 09:31:16 +11:00
|
|
|
)
|
2019-10-30 07:42:56 +11:00
|
|
|
except (UneededThumbnail, UnthumbnailableError):
|
|
|
|
pass
|
|
|
|
else:
|
2019-11-07 00:43:05 +11:00
|
|
|
await self.media_cache.create_thumbnail(
|
|
|
|
thumb_url,
|
|
|
|
thumb_data,
|
|
|
|
content["info"]["w"],
|
|
|
|
content["info"]["h"],
|
|
|
|
)
|
|
|
|
|
2019-10-31 01:34:20 +11:00
|
|
|
if encrypt:
|
|
|
|
content["info"]["thumbnail_file"] = {
|
|
|
|
"url": thumb_url,
|
|
|
|
**thumb_crypt_dict,
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
content["info"]["thumbnail_url"] = thumb_url
|
|
|
|
|
2019-10-30 07:42:56 +11:00
|
|
|
content["info"]["thumbnail_info"] = thumb_info
|
|
|
|
|
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
|
|
|
|
|
2019-11-06 22:50:31 +11:00
|
|
|
del self.models[Upload, room_id][upload_item.uuid]
|
2019-11-06 09:31:16 +11:00
|
|
|
|
2019-10-29 06:27:36 +11:00
|
|
|
uuid = str(uuid4())
|
|
|
|
|
|
|
|
await self._local_echo(
|
|
|
|
room_id, uuid, 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,
|
|
|
|
thumbnail_width = thumb_info.get("w", 0),
|
|
|
|
thumbnail_height = thumb_info.get("h", 0),
|
2019-10-29 06:27:36 +11:00
|
|
|
)
|
|
|
|
|
2019-10-29 04:49:55 +11:00
|
|
|
await self._send_message(room_id, uuid, content)
|
|
|
|
|
|
|
|
|
|
|
|
async def _local_echo(
|
2019-10-29 06:27:36 +11:00
|
|
|
self, room_id: str, uuid: str,
|
2019-10-29 04:49:55 +11:00
|
|
|
event_type: Type[nio.Event], **event_fields,
|
|
|
|
) -> 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-08-31 01:53:55 +10:00
|
|
|
our_info = self.models[Member, room_id][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
|
|
|
|
2019-10-29 04:49:55 +11:00
|
|
|
event = Event(
|
2019-08-29 03:29:49 +10:00
|
|
|
source = None,
|
|
|
|
client_id = f"echo-{uuid}",
|
|
|
|
event_id = "",
|
|
|
|
date = datetime.now(),
|
2019-09-14 13:02:11 +10:00
|
|
|
sender_id = self.user_id,
|
|
|
|
sender_name = our_info.display_name,
|
|
|
|
sender_avatar = our_info.avatar_url,
|
2019-08-29 03:29:49 +10:00
|
|
|
is_local_echo = True,
|
2019-11-07 00:43:05 +11:00
|
|
|
local_event_type = event_type,
|
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
|
|
|
|
|
|
|
self.local_echoes_uuid.add(uuid)
|
|
|
|
|
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 in self.models[Account]:
|
|
|
|
if user_id in self.models[Member, room_id]:
|
2019-10-29 04:49:55 +11:00
|
|
|
self.models[Event, user_id, room_id][f"echo-{uuid}"] = event
|
2019-09-01 06:13:50 +10:00
|
|
|
self.models[Event, user_id, room_id].sync_now()
|
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
|
|
|
|
|
|
|
|
|
|
|
async def _send_message(self, room_id: str, uuid: str, content: dict,
|
|
|
|
) -> None:
|
2019-08-17 02:23:34 +10:00
|
|
|
|
2019-07-05 09:49:55 +10:00
|
|
|
async with self.send_locks[room_id]:
|
2019-07-09 03:08:46 +10:00
|
|
|
response = await self.room_send(
|
|
|
|
room_id = room_id,
|
|
|
|
message_type = "m.room.message",
|
|
|
|
content = content,
|
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
|
|
|
tx_id = uuid,
|
2019-07-09 03:08:46 +10:00
|
|
|
ignore_unverified_devices = True,
|
|
|
|
)
|
2019-07-05 12:25:06 +10:00
|
|
|
|
|
|
|
if isinstance(response, nio.RoomSendError):
|
2019-09-09 22:26:09 +10:00
|
|
|
log.error("Sending message failed: %s", response)
|
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-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-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
|
|
|
)
|
|
|
|
|
2019-09-09 22:26:09 +10:00
|
|
|
if isinstance(response, nio.RoomMessagesError):
|
|
|
|
log.error("Loading past messages for room %s failed: %s",
|
|
|
|
room_id, response)
|
|
|
|
return 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.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:
|
|
|
|
for room_id in self.models[Room, self.user_id]:
|
|
|
|
asyncio.ensure_future(
|
|
|
|
self._load_room_without_visible_events(room_id),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def _load_room_without_visible_events(self, room_id: str) -> None:
|
|
|
|
events = self.models[Event, self.user_id, room_id]
|
|
|
|
more = True
|
|
|
|
|
|
|
|
while self.skipped_events[room_id] and not events and more:
|
|
|
|
more = await self.load_past_events(room_id)
|
|
|
|
|
|
|
|
|
2019-11-09 06:32:12 +11:00
|
|
|
async def room_create(
|
|
|
|
self,
|
|
|
|
name: Optional[str] = None,
|
|
|
|
topic: Optional[str] = None,
|
|
|
|
public: bool = False,
|
|
|
|
encrypt: bool = False, # TODO
|
|
|
|
federate: bool = True,
|
|
|
|
) -> str:
|
|
|
|
|
|
|
|
response = await super().room_create(
|
|
|
|
name = name,
|
|
|
|
topic = topic,
|
|
|
|
federate = federate,
|
|
|
|
visibility =
|
|
|
|
nio.RoomVisibility.public if public else
|
|
|
|
nio.RoomVisibility.private,
|
|
|
|
)
|
|
|
|
|
|
|
|
if isinstance(response, nio.RoomCreateError):
|
|
|
|
raise RequestFailed(response.status_code)
|
|
|
|
|
|
|
|
return response.room_id
|
|
|
|
|
|
|
|
|
2019-07-08 12:19:17 +10:00
|
|
|
async def room_forget(self, room_id: str) -> None:
|
2019-09-10 10:58:19 +10:00
|
|
|
await super().room_leave(room_id)
|
2019-07-08 12:19:17 +10:00
|
|
|
await super().room_forget(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.models[Room, self.user_id].pop(room_id, None)
|
2019-08-16 03:00:15 +10:00
|
|
|
self.models.pop((Event, self.user_id, room_id), None)
|
|
|
|
self.models.pop((Member, room_id), None)
|
2019-07-08 12:19:17 +10:00
|
|
|
|
|
|
|
|
2019-11-05 06:18:01 +11:00
|
|
|
async def encrypt_attachment(self, data: bytes) -> Tuple[bytes, CryptDict]:
|
|
|
|
func = functools.partial(
|
|
|
|
nio.crypto.attachments.encrypt_attachment,
|
|
|
|
data,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Run in a separate thread
|
|
|
|
return await asyncio.get_event_loop().run_in_executor(None, func)
|
|
|
|
|
|
|
|
|
2019-10-31 01:34:20 +11:00
|
|
|
async def upload_thumbnail(
|
2019-11-06 09:31:16 +11:00
|
|
|
self,
|
|
|
|
path: Union[Path, str],
|
|
|
|
item: Optional[Upload] = None,
|
2019-11-06 22:50:31 +11:00
|
|
|
is_svg: bool = False,
|
2019-11-06 09:31:16 +11:00
|
|
|
encrypt: bool = False,
|
2019-11-07 00:43:05 +11:00
|
|
|
) -> Tuple[bytes, str, Dict[str, Any], CryptDict]:
|
2019-11-05 05:37:25 +11:00
|
|
|
|
|
|
|
png_modes = ("1", "L", "P", "RGBA")
|
|
|
|
|
2019-10-30 07:42:56 +11:00
|
|
|
try:
|
2019-11-06 22:50:31 +11:00
|
|
|
if is_svg:
|
|
|
|
svg_width, svg_height = utils.svg_dimensions(str(path))
|
|
|
|
|
|
|
|
thumb = PILImage.open(io.BytesIO(
|
|
|
|
cairosvg.svg2png(
|
|
|
|
url = str(path),
|
|
|
|
parent_width = svg_width,
|
|
|
|
parent_height = svg_height,
|
|
|
|
),
|
|
|
|
))
|
|
|
|
else:
|
|
|
|
thumb = PILImage.open(path)
|
2019-10-30 07:42:56 +11:00
|
|
|
|
2019-11-05 05:37:25 +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-10-30 07:42:56 +11:00
|
|
|
|
2019-11-06 22:50:31 +11:00
|
|
|
if small and is_jpg_png and not jpgable_png and not is_svg:
|
2019-10-30 07:42:56 +11:00
|
|
|
raise UneededThumbnail()
|
|
|
|
|
2019-11-06 09:31:16 +11:00
|
|
|
if item:
|
|
|
|
item.status = UploadStatus.CreatingThumbnail
|
|
|
|
|
2019-10-30 20:34:32 +11:00
|
|
|
if not small:
|
2019-11-04 05:08:29 +11:00
|
|
|
thumb.thumbnail((800, 600), PILImage.LANCZOS)
|
2019-07-16 06:14:08 +10:00
|
|
|
|
2019-10-30 07:42:56 +11:00
|
|
|
with io.BytesIO() as out:
|
2019-11-05 05:37:25 +11:00
|
|
|
if thumb.mode in png_modes:
|
2019-10-30 20:47:22 +11:00
|
|
|
thumb.save(out, "PNG", optimize=True)
|
2019-10-30 07:42:56 +11:00
|
|
|
mime = "image/png"
|
|
|
|
else:
|
2019-10-30 20:47:22 +11:00
|
|
|
thumb.convert("RGB").save(out, "JPEG", optimize=True)
|
2019-10-30 07:42:56 +11:00
|
|
|
mime = "image/jpeg"
|
|
|
|
|
2019-10-31 01:34:20 +11:00
|
|
|
data = out.getvalue()
|
|
|
|
|
|
|
|
if encrypt:
|
2019-11-06 09:31:16 +11:00
|
|
|
if item:
|
|
|
|
item.status = UploadStatus.EncryptingThumbnail
|
|
|
|
|
2019-11-05 06:18:01 +11:00
|
|
|
data, crypt_dict = await self.encrypt_attachment(data)
|
2019-10-31 01:34:20 +11:00
|
|
|
upload_mime = "application/octet-stream"
|
|
|
|
else:
|
|
|
|
crypt_dict, upload_mime = {}, mime
|
|
|
|
|
2019-11-06 09:31:16 +11:00
|
|
|
if item:
|
|
|
|
item.status = UploadStatus.UploadingThumbnail
|
|
|
|
|
2019-10-30 07:42:56 +11:00
|
|
|
return (
|
2019-11-07 00:43:05 +11:00
|
|
|
data,
|
2019-10-31 01:34:20 +11:00
|
|
|
await self.upload(data, upload_mime, Path(path).name),
|
2019-10-30 07:42:56 +11:00
|
|
|
{
|
|
|
|
"w": thumb.width,
|
|
|
|
"h": thumb.height,
|
|
|
|
"mimetype": mime,
|
2019-10-31 01:34:20 +11:00
|
|
|
"size": len(data),
|
2019-10-30 07:42:56 +11:00
|
|
|
},
|
2019-10-31 01:34:20 +11:00
|
|
|
crypt_dict,
|
2019-10-30 07:42:56 +11:00
|
|
|
)
|
|
|
|
|
|
|
|
except OSError as err:
|
2019-10-30 20:36:54 +11:00
|
|
|
log.warning("Error when creating thumbnail: %s", err)
|
2019-10-30 07:42:56 +11:00
|
|
|
raise UnthumbnailableError(err)
|
|
|
|
|
|
|
|
|
2019-11-06 09:31:16 +11:00
|
|
|
async def upload_file(
|
|
|
|
self,
|
|
|
|
path: Union[Path, str],
|
|
|
|
item: Optional[Upload] = None,
|
|
|
|
encrypt: bool = False,
|
|
|
|
) -> Tuple[str, str, CryptDict]:
|
|
|
|
|
2019-07-16 06:14:08 +10:00
|
|
|
with open(path, "rb") as file:
|
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
|
|
|
mime = utils.guess_mime(file)
|
2019-07-16 06:14:08 +10:00
|
|
|
file.seek(0, 0)
|
|
|
|
|
2019-11-05 06:18:01 +11:00
|
|
|
data: Union[BinaryIO, bytes]
|
|
|
|
|
2019-10-31 01:34:20 +11:00
|
|
|
if encrypt:
|
2019-11-06 09:31:16 +11:00
|
|
|
if item:
|
|
|
|
item.status = UploadStatus.Encrypting
|
|
|
|
|
2019-11-05 06:18:01 +11:00
|
|
|
data, crypt_dict = await self.encrypt_attachment(file.read())
|
2019-10-31 01:34:20 +11:00
|
|
|
upload_mime = "application/octet-stream"
|
|
|
|
else:
|
|
|
|
data, crypt_dict, upload_mime = file, {}, mime
|
|
|
|
|
2019-11-06 09:31:16 +11:00
|
|
|
if item:
|
|
|
|
item.status = UploadStatus.Uploading
|
|
|
|
|
2019-10-31 01:34:20 +11:00
|
|
|
return (
|
|
|
|
await self.upload(data, upload_mime, Path(path).name),
|
|
|
|
mime,
|
|
|
|
crypt_dict,
|
|
|
|
)
|
2019-10-30 07:42:56 +11:00
|
|
|
|
|
|
|
|
|
|
|
async def upload(self, data, mime: str, filename: Optional[str] = None,
|
|
|
|
) -> str:
|
|
|
|
response = await super().upload(data, mime, filename)
|
2019-07-16 06:14:08 +10:00
|
|
|
|
2019-10-30 07:42:56 +11:00
|
|
|
if not isinstance(response, nio.ErrorResponse):
|
|
|
|
return response.content_uri
|
2019-07-16 06:14:08 +10:00
|
|
|
|
2019-10-30 07:42:56 +11:00
|
|
|
if response.status_code == 403:
|
2019-10-28 23:06:22 +11:00
|
|
|
raise UploadForbidden()
|
2019-07-16 06:14:08 +10:00
|
|
|
|
2019-10-30 07:42:56 +11:00
|
|
|
if response.status_code == 413:
|
2019-10-28 23:06:22 +11:00
|
|
|
raise UploadTooLarge()
|
2019-07-16 06:14:08 +10:00
|
|
|
|
2019-10-30 07:42:56 +11:00
|
|
|
raise UploadError(response.status_code)
|
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-10-29 06:27:36 +11:00
|
|
|
# TODO: check if mime is image
|
|
|
|
await self.set_avatar((await self.upload_file(path))[0])
|
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-08-28 17:54:53 +10:00
|
|
|
# Reimplemented until better solutions are worked on in nio
|
2019-08-29 01:42:52 +10:00
|
|
|
await self.clear_import_error()
|
|
|
|
|
2019-08-28 17:54:53 +10:00
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
|
2019-08-29 01:42:52 +10:00
|
|
|
account = self.models[Account][self.user_id]
|
2019-08-28 17:54:53 +10:00
|
|
|
import_keys = partial(self.olm.import_keys_static, infile, passphrase)
|
2019-08-29 01:42:52 +10:00
|
|
|
|
2019-09-10 04:42:58 +10:00
|
|
|
account.importing_key = 0
|
|
|
|
account.total_keys_to_import = -1 # preparing
|
|
|
|
|
2019-08-28 17:54:53 +10:00
|
|
|
try:
|
|
|
|
sessions = await loop.run_in_executor(None, import_keys)
|
2019-10-28 23:06:22 +11:00
|
|
|
except nio.EncryptionError as err: # XXX raise
|
2019-08-29 01:42:52 +10:00
|
|
|
account.import_error = (infile, passphrase, str(err))
|
|
|
|
return
|
2019-08-28 17:54:53 +10:00
|
|
|
|
|
|
|
account.total_keys_to_import = len(sessions)
|
|
|
|
|
|
|
|
for session in sessions:
|
|
|
|
if self.olm.inbound_group_store.add(session):
|
|
|
|
await loop.run_in_executor(
|
|
|
|
None, self.store.save_inbound_group_session, session,
|
|
|
|
)
|
|
|
|
account.importing_key += 1
|
|
|
|
|
|
|
|
account.importing_key = 0
|
|
|
|
account.total_keys_to_import = 0
|
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:
|
|
|
|
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 01:42:52 +10:00
|
|
|
async def clear_import_error(self) -> None:
|
|
|
|
self.models[Account][self.user_id].import_error = ("", "", "")
|
|
|
|
|
|
|
|
|
2019-08-29 03:23:12 +10:00
|
|
|
async def retry_decrypting_events(self) -> None:
|
|
|
|
for sync_id, model in self.models.items():
|
|
|
|
if not (isinstance(sync_id, tuple) and
|
|
|
|
sync_id[0:2] == (Event, self.user_id)):
|
|
|
|
continue
|
|
|
|
|
|
|
|
_, _, room_id = sync_id
|
|
|
|
|
|
|
|
for ev in model.values():
|
|
|
|
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:
|
|
|
|
self.cleared_events_rooms.add(room_id)
|
|
|
|
model = self.models[Event, self.user_id, room_id]
|
2019-09-09 01:49:47 +10:00
|
|
|
if model:
|
|
|
|
model.clear()
|
|
|
|
model.sync_now()
|
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:
|
|
|
|
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-09-01 06:13:50 +10:00
|
|
|
model = self.models[Room, self.user_id]
|
|
|
|
room = model[room_id]
|
2019-07-03 03:59:52 +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
|
|
|
if room.last_event is None:
|
2019-08-20 01:51:09 +10:00
|
|
|
room.last_event = item.serialized
|
2019-09-01 06:13:50 +10:00
|
|
|
|
|
|
|
if item.is_local_echo:
|
|
|
|
model.sync_now()
|
|
|
|
|
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
|
|
|
return
|
2019-07-09 02:28:49 +10:00
|
|
|
|
2019-08-16 15:51:42 +10:00
|
|
|
is_profile_ev = item.type_specifier == TypeSpecifier.profile_change
|
2019-07-09 02:28: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
|
|
|
# If there were no better events available to show previously
|
2019-08-31 00:09:09 +10:00
|
|
|
prev_is_profile_ev = \
|
|
|
|
room.last_event["type_specifier"] == TypeSpecifier.profile_change
|
2019-07-03 03:59:52 +10:00
|
|
|
|
2019-08-31 00:09:09 +10:00
|
|
|
# If this is a profile event, only replace the currently shown one if
|
|
|
|
# it was also a profile event (we had nothing better to show).
|
|
|
|
if is_profile_ev and not prev_is_profile_ev:
|
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
|
|
|
return
|
|
|
|
|
2019-08-31 00:09:09 +10:00
|
|
|
# If this event is older than the currently shown one, only replace
|
|
|
|
# it if the previous was a profile event.
|
|
|
|
if item.date < room.last_event["date"] and not prev_is_profile_ev:
|
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
|
|
|
return
|
|
|
|
|
2019-08-20 01:51:09 +10:00
|
|
|
room.last_event = item.serialized
|
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-01 06:13:50 +10:00
|
|
|
if item.is_local_echo:
|
|
|
|
model.sync_now()
|
|
|
|
|
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 register_nio_room(self, room: nio.MatrixRoom, left: bool = False,
|
|
|
|
) -> None:
|
|
|
|
# Add room
|
|
|
|
try:
|
|
|
|
last_ev = self.models[Room, self.user_id][room.room_id].last_event
|
|
|
|
except KeyError:
|
|
|
|
last_ev = None
|
|
|
|
|
2019-08-16 02:13:41 +10:00
|
|
|
inviter = getattr(room, "inviter", "") 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
|
|
|
self.models[Room, self.user_id][room.room_id] = Room(
|
|
|
|
room_id = room.room_id,
|
2019-08-30 06:47:07 +10:00
|
|
|
display_name = room.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
|
|
|
avatar_url = room.gen_avatar_url or "",
|
2019-09-12 06:01:37 +10:00
|
|
|
topic = HTML_FILTER.filter_inline(room.topic or ""),
|
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,
|
|
|
|
last_event = last_ev,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Add the room members to the added room
|
|
|
|
new_dict = {
|
|
|
|
user_id: Member(
|
|
|
|
user_id = user_id,
|
|
|
|
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,
|
|
|
|
) for user_id, member in room.users.items()
|
|
|
|
}
|
|
|
|
self.models[Member, room.room_id].update(new_dict)
|
|
|
|
|
|
|
|
|
|
|
|
async def get_member_name_avatar(self, room_id: str, user_id: str,
|
|
|
|
) -> Tuple[str, str]:
|
|
|
|
try:
|
|
|
|
item = self.models[Member, room_id][user_id]
|
|
|
|
except KeyError: # e.g. user is not anymore in the room
|
|
|
|
info = await self.backend.get_profile(user_id)
|
|
|
|
|
|
|
|
return (info.displayname or "", info.avatar_url or "") \
|
|
|
|
if isinstance(info, nio.ProfileGetResponse) else \
|
|
|
|
("", "")
|
|
|
|
else:
|
|
|
|
return (item.display_name, item.avatar_url)
|
|
|
|
|
|
|
|
|
2019-08-16 15:51:42 +10:00
|
|
|
async def register_nio_event(
|
2019-09-14 13:02:11 +10:00
|
|
|
self, room: nio.MatrixRoom, ev: nio.Event, **fields,
|
2019-08-16 15:51:42 +10:00
|
|
|
) -> 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
|
|
|
|
|
|
|
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 ("", "")
|
|
|
|
|
|
|
|
# Create Event ModelItem
|
|
|
|
item = Event(
|
2019-09-14 13:02:11 +10:00
|
|
|
source = ev,
|
|
|
|
client_id = ev.event_id,
|
|
|
|
event_id = ev.event_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
|
|
|
date = datetime.fromtimestamp(ev.server_timestamp / 1000),
|
|
|
|
sender_id = ev.sender,
|
|
|
|
sender_name = sender_name,
|
|
|
|
sender_avatar = sender_avatar,
|
|
|
|
target_id = target_id,
|
|
|
|
target_name = target_name,
|
|
|
|
target_avatar = target_avatar,
|
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
|
|
|
|
if ev.transaction_id in self.local_echoes_uuid:
|
|
|
|
self.resolved_echoes[ev.event_id] = ev.transaction_id
|
|
|
|
self.local_echoes_uuid.discard(ev.transaction_id)
|
|
|
|
item.client_id = f"echo-{ev.transaction_id}"
|
|
|
|
|
|
|
|
elif ev.sender in self.backend.clients:
|
|
|
|
client = self.backend.clients[ev.sender]
|
|
|
|
|
|
|
|
# Wait until our other account has no more pending local echoes,
|
|
|
|
# so that we can know if this event should replace an echo
|
|
|
|
# from that client by finding its ID in the resolved_echoes dict.
|
|
|
|
# Server only gives back the transaction ID to the original sender.
|
|
|
|
while client.local_echoes_uuid: # while there are pending echoes
|
|
|
|
await asyncio.sleep(0.1)
|
|
|
|
|
|
|
|
with suppress(KeyError):
|
|
|
|
item.client_id = f"echo-{client.resolved_echoes[ev.event_id]}"
|
|
|
|
|
2019-08-17 04:27:25 +10:00
|
|
|
elif not await self.event_is_past(ev):
|
|
|
|
AlertRequested()
|
|
|
|
|
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[Event, self.user_id, room.room_id][item.client_id] = item
|
2019-07-09 02:28: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
|
|
|
await self.set_room_last_event(room.room_id, item)
|
2019-07-09 02:28:49 +10:00
|
|
|
|
2019-09-01 06:18:27 +10:00
|
|
|
if item.sender_id == self.user_id:
|
|
|
|
self.models[Event, self.user_id, room.room_id].sync_now()
|