Show max file size on upload button tooltip
This commit is contained in:
parent
ca8dd65f34
commit
61cc87cf18
2
TODO.md
2
TODO.md
|
@ -4,7 +4,7 @@
|
|||
|
||||
- "exception during sync" aren't caught
|
||||
- nio ClientTimeout
|
||||
- Handle upload file size limit
|
||||
- Name
|
||||
- Update docstrings
|
||||
- Update TODO.md
|
||||
- Update README.md
|
||||
|
|
|
@ -111,6 +111,7 @@ class MatrixClient(nio.AsyncClient):
|
|||
self.models: ModelStore = self.backend.models
|
||||
|
||||
self.profile_task: Optional[asyncio.Future] = None
|
||||
self.server_config_task: Optional[asyncio.Future] = None
|
||||
self.sync_task: Optional[asyncio.Future] = None
|
||||
self.load_rooms_task: Optional[asyncio.Future] = None
|
||||
|
||||
|
@ -179,7 +180,12 @@ class MatrixClient(nio.AsyncClient):
|
|||
async def logout(self) -> None:
|
||||
"""Logout from the server. This will delete the device."""
|
||||
|
||||
for task in (self.profile_task, self.load_rooms_task, self.sync_task):
|
||||
tasks = (
|
||||
self.profile_task, self.load_rooms_task, self.sync_task,
|
||||
self.server_config_task,
|
||||
)
|
||||
|
||||
for task in tasks:
|
||||
if task:
|
||||
task.cancel()
|
||||
with suppress(asyncio.CancelledError):
|
||||
|
@ -221,11 +227,34 @@ class MatrixClient(nio.AsyncClient):
|
|||
account.display_name = resp.displayname or ""
|
||||
account.avatar_url = resp.avatar_url or ""
|
||||
|
||||
def on_server_config_response(future) -> None:
|
||||
"""Update our model `Account` with the received config details."""
|
||||
|
||||
exception = future.exception()
|
||||
|
||||
if exception:
|
||||
log.warn("On %s client startup: %r", self.user_id, exception)
|
||||
self.server_config_task = asyncio.ensure_future(
|
||||
self.get_server_config(),
|
||||
)
|
||||
self.server_config_task.add_done_callback(
|
||||
on_server_config_response,
|
||||
)
|
||||
return
|
||||
|
||||
account = self.models["accounts"][self.user_id]
|
||||
account.max_upload_size = future.result()
|
||||
|
||||
self.profile_task = asyncio.ensure_future(
|
||||
self.backend.get_profile(self.user_id),
|
||||
)
|
||||
self.profile_task.add_done_callback(on_profile_response)
|
||||
|
||||
self.server_config_task = asyncio.ensure_future(
|
||||
self.get_server_config(),
|
||||
)
|
||||
self.server_config_task.add_done_callback(on_server_config_response)
|
||||
|
||||
while True:
|
||||
try:
|
||||
self.sync_task = asyncio.ensure_future(
|
||||
|
@ -239,6 +268,11 @@ class MatrixClient(nio.AsyncClient):
|
|||
await asyncio.sleep(2)
|
||||
|
||||
|
||||
async def get_server_config(self) -> int:
|
||||
"""Return the maximum upload size on this server"""
|
||||
return (await self.content_repository_config()).upload_size
|
||||
|
||||
|
||||
@property
|
||||
def all_rooms(self) -> Dict[str, nio.MatrixRoom]:
|
||||
"""Return dict containing both our joined and invited rooms."""
|
||||
|
|
|
@ -35,8 +35,9 @@ class Account(ModelItem):
|
|||
id: str = field()
|
||||
display_name: str = ""
|
||||
avatar_url: str = ""
|
||||
first_sync_done: bool = False
|
||||
max_upload_size: int = 0
|
||||
profile_updated: datetime = ZeroDate
|
||||
first_sync_done: bool = False
|
||||
|
||||
def __lt__(self, other: "Account") -> bool:
|
||||
"""Sort by display name or user ID."""
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
import QtQuick 2.12
|
||||
import QtQuick.Layouts 1.12
|
||||
import Clipboard 0.1
|
||||
import CppUtils 0.1
|
||||
import "../.."
|
||||
import "../../Base"
|
||||
import "../../Dialogs"
|
||||
|
@ -218,7 +219,13 @@ Rectangle {
|
|||
enabled: chat.roomInfo.can_send_messages
|
||||
icon.name: "upload-file"
|
||||
backgroundColor: theme.chat.composer.uploadButton.background
|
||||
toolTip.text: qsTr("Send files")
|
||||
toolTip.text:
|
||||
chat.userInfo.max_upload_size ?
|
||||
qsTr("Send files (%1 max)").arg(
|
||||
CppUtils.formattedBytes(chat.userInfo.max_upload_size, 0),
|
||||
) :
|
||||
qsTr("Send files")
|
||||
|
||||
onClicked: sendFilePicker.dialog.open()
|
||||
|
||||
Layout.fillHeight: true
|
||||
|
|
Loading…
Reference in New Issue
Block a user