diff --git a/harmonyqml/backend/client.py b/harmonyqml/backend/client.py index a5363f57..c9f5ed5f 100644 --- a/harmonyqml/backend/client.py +++ b/harmonyqml/backend/client.py @@ -4,13 +4,13 @@ import time from concurrent.futures import ThreadPoolExecutor from threading import Event -from typing import DefaultDict, Tuple +from typing import Any, DefaultDict, Dict, Optional, Tuple from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal, pyqtSlot import nio -import nio.responses as nr import nio.events as ne +import nio.responses as nr from .network_manager import NetworkManager from .pyqt_future import futurize @@ -78,6 +78,16 @@ class Client(QObject): return self.nio.user_id + @pyqtSlot(str, result="QVariant") + @pyqtSlot(str, list, result="QVariant") + @pyqtSlot(str, list, "QVariantMap", result="QVariant") + def call(self, + method: str, + args: Optional[list] = None, + kwargs: Optional[Dict[str, Any]] = None) -> Any: + return getattr(self, method)(*args or [], **kwargs or {}) + + @pyqtSlot(str) @pyqtSlot(str, str) @futurize() @@ -232,3 +242,21 @@ class Client(QObject): ) return send(self) + + + @pyqtSlot(str) + @futurize() + def joinRoom(self, room_id: str) -> None: + return self.net.talk(self.nio.join, room_id=room_id) + + + @pyqtSlot(str) + @futurize() + def leaveRoom(self, room_id: str) -> None: + return self.net.talk(self.nio.room_leave, room_id=room_id) + + + @pyqtSlot(str) + @futurize() + def forgetRoom(self, room_id: str) -> None: + raise NotImplementedError() diff --git a/harmonyqml/components/chat/Banner.qml b/harmonyqml/components/chat/Banner.qml index 597a1d4a..0fdb2d63 100644 --- a/harmonyqml/components/chat/Banner.qml +++ b/harmonyqml/components/chat/Banner.qml @@ -80,6 +80,10 @@ Rectangle { icon.width: 32 display: bannerButtons.displayMode + onClicked: + Backend.clientManager.clients[chatPage.userId]. + call(modelData.clientFunction, modelData.clientArgs) + Layout.maximumWidth: bannerButtons.compact ? height : -1 Layout.fillHeight: true } diff --git a/harmonyqml/components/chat/InviteBanner.qml b/harmonyqml/components/chat/InviteBanner.qml index ff17d659..47143414 100644 --- a/harmonyqml/components/chat/InviteBanner.qml +++ b/harmonyqml/components/chat/InviteBanner.qml @@ -19,11 +19,15 @@ Banner { text: "Accept", iconName: "accept", iconColor: Qt.hsla(0.45, 0.9, 0.3, 1), + clientFunction: "joinRoom", + clientArgs: [chatPage.roomId], }, { text: "Decline", iconName: "decline", iconColor: Qt.hsla(0.95, 0.9, 0.35, 1), + clientFunction: "leaveRoom", + clientArgs: [chatPage.roomId], } ] } diff --git a/harmonyqml/components/chat/LeftBanner.qml b/harmonyqml/components/chat/LeftBanner.qml index be785f33..ec06be40 100644 --- a/harmonyqml/components/chat/LeftBanner.qml +++ b/harmonyqml/components/chat/LeftBanner.qml @@ -15,6 +15,8 @@ Banner { text: "Forget", iconName: "trash_can", iconColor: Qt.hsla(0.95, 0.9, 0.35, 1), + clientFunction: "forgetRoom", + clientArgs: [chatPage.roomId], } ] }