Just import nio
Instead of nio.events, nio.responses, etc. All the classes are already available at nio.
This commit is contained in:
parent
d3749af4bc
commit
f65ea9dd0d
10
TODO.md
10
TODO.md
@ -1,22 +1,19 @@
|
||||
- Current focus
|
||||
- Remember account dialog
|
||||
- Just import nio?
|
||||
- Refactoring
|
||||
- Use new H\* components everywhere
|
||||
- TextInput.accepted() for SendBox
|
||||
|
||||
- Refactoring
|
||||
- Migrate more JS functions to their own files / Implement in Python instead
|
||||
- Don't bake in size properties for components
|
||||
- Better names and organization for the Message components
|
||||
|
||||
- Bug fixes
|
||||
- Fix tooltip hide()
|
||||
- ![A picture](https://picsum.photos/256/256) not clickable?
|
||||
- Sending `![A picture](https://picsum.photos/256/256)` → not clickable?
|
||||
- Icons aren't reloaded
|
||||
- Bug when resizing window being tiled (i3), can't figure it out
|
||||
- HStyle singleton isn't reloaded
|
||||
|
||||
- UI
|
||||
- Register/Forgot? for SignIn dialog
|
||||
- Test HGlassRectangle elements when no effects are available
|
||||
- Leave room
|
||||
- Forget room warning popup
|
||||
@ -72,4 +69,3 @@
|
||||
- Distribution
|
||||
- Review setup.py, add dependencies
|
||||
- REAMDE.md
|
||||
- Remove initial test room switch
|
||||
|
@ -9,8 +9,6 @@ from typing import Any, DefaultDict, Dict, Optional, Tuple
|
||||
from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal, pyqtSlot
|
||||
|
||||
import nio
|
||||
import nio.events as ne
|
||||
import nio.responses as nr
|
||||
|
||||
from .network_manager import NetworkManager
|
||||
from .pyqt_future import futurize
|
||||
@ -103,7 +101,7 @@ class Client(QObject):
|
||||
@futurize()
|
||||
def resumeSession(self, user_id: str, token: str, device_id: str
|
||||
) -> "Client":
|
||||
response = nr.LoginResponse(user_id, device_id, token)
|
||||
response = nio.LoginResponse(user_id, device_id, token)
|
||||
self.nio.receive_response(response)
|
||||
self.nio_sync.receive_response(response)
|
||||
return self
|
||||
@ -130,12 +128,12 @@ class Client(QObject):
|
||||
break
|
||||
|
||||
|
||||
def _on_sync(self, response: nr.SyncResponse) -> None:
|
||||
def _on_sync(self, response: nio.SyncResponse) -> None:
|
||||
self.nio.receive_response(response)
|
||||
|
||||
for room_id, room_info in response.rooms.invite.items():
|
||||
for ev in room_info.invite_state:
|
||||
member_ev = isinstance(ev, ne.InviteMemberEvent)
|
||||
member_ev = isinstance(ev, nio.InviteMemberEvent)
|
||||
|
||||
if member_ev and ev.content["membership"] == "join":
|
||||
self.roomInvited.emit(room_id, ev.content)
|
||||
@ -156,14 +154,14 @@ class Client(QObject):
|
||||
)
|
||||
|
||||
for ev in room_info.ephemeral:
|
||||
if isinstance(ev, nr.TypingNoticeEvent):
|
||||
if isinstance(ev, nio.TypingNoticeEvent):
|
||||
self.roomTypingUsersUpdated.emit(room_id, ev.users)
|
||||
else:
|
||||
print("ephemeral event: ", ev)
|
||||
|
||||
for room_id, room_info in response.rooms.leave.items():
|
||||
for ev in room_info.timeline.events:
|
||||
member_ev = isinstance(ev, ne.RoomMemberEvent)
|
||||
member_ev = isinstance(ev, nio.RoomMemberEvent)
|
||||
|
||||
if member_ev and ev.content["membership"] in ("leave", "ban"):
|
||||
self.roomLeft.emit(room_id, ev.__dict__)
|
||||
@ -190,7 +188,7 @@ class Client(QObject):
|
||||
self._loading = False
|
||||
|
||||
|
||||
def _on_past_events(self, room_id: str, response: nr.RoomMessagesResponse
|
||||
def _on_past_events(self, room_id: str, response: nio.RoomMessagesResponse
|
||||
) -> None:
|
||||
self.roomPastPrevBatchTokenReceived.emit(room_id, response.end)
|
||||
|
||||
|
@ -10,15 +10,13 @@ from typing import Callable, Optional, Tuple
|
||||
from uuid import UUID
|
||||
|
||||
import nio
|
||||
import nio.responses as nr
|
||||
from nio.exceptions import ProtocolError, RemoteTransportError
|
||||
|
||||
OptSock = Optional[ssl.SSLSocket]
|
||||
NioRequestFunc = Callable[..., Tuple[UUID, bytes]]
|
||||
|
||||
|
||||
class NioErrorResponse(Exception):
|
||||
def __init__(self, response: nr.ErrorResponse) -> None:
|
||||
def __init__(self, response: nio.ErrorResponse) -> None:
|
||||
self.response = response
|
||||
super().__init__(str(response))
|
||||
|
||||
@ -77,11 +75,11 @@ class NetworkManager:
|
||||
def http_disconnect(self) -> None:
|
||||
try:
|
||||
self.write(self.nio.disconnect())
|
||||
except (OSError, ProtocolError):
|
||||
except (OSError, nio.ProtocolError):
|
||||
pass
|
||||
|
||||
|
||||
def read(self, with_sock: OptSock = None) -> nr.Response:
|
||||
def read(self, with_sock: OptSock = None) -> nio.Response:
|
||||
sock = with_sock or self._get_socket()
|
||||
|
||||
response = None
|
||||
@ -93,7 +91,7 @@ class NetworkManager:
|
||||
self.nio.receive(sock.recv(4096))
|
||||
response = self.nio.next_response()
|
||||
|
||||
if isinstance(response, nr.ErrorResponse):
|
||||
if isinstance(response, nio.ErrorResponse):
|
||||
raise NioErrorResponse(response)
|
||||
|
||||
if not with_sock:
|
||||
@ -113,7 +111,7 @@ class NetworkManager:
|
||||
def talk(self,
|
||||
nio_func: NioRequestFunc,
|
||||
*args,
|
||||
**kwargs) -> nr.Response:
|
||||
**kwargs) -> nio.Response:
|
||||
|
||||
with self._lock:
|
||||
retry = RetrySleeper()
|
||||
@ -132,7 +130,7 @@ class NetworkManager:
|
||||
self.write(to_send, sock)
|
||||
response = self.read(sock)
|
||||
|
||||
except (OSError, RemoteTransportError) as err:
|
||||
except (OSError, nio.RemoteTransportError) as err:
|
||||
self._close_socket(sock)
|
||||
self.http_disconnect()
|
||||
retry.sleep(max_time=2)
|
||||
|
@ -67,7 +67,6 @@ Item {
|
||||
loginWith === "phone" ? "Phone" :
|
||||
"Username"
|
||||
)
|
||||
text: "test_mary"
|
||||
onAccepted: signInBox.clickEnterButtonTarget()
|
||||
|
||||
Layout.fillWidth: true
|
||||
@ -75,7 +74,6 @@ Item {
|
||||
}
|
||||
|
||||
Base.HTextField {
|
||||
text: "1234"
|
||||
id: passwordField
|
||||
placeholderText: qsTr("Password")
|
||||
echoMode: TextField.Password
|
||||
|
Loading…
Reference in New Issue
Block a user