Make the banner buttons work

For invitation accept/decline.
Forget remains to be implemented in nio.
This commit is contained in:
miruka 2019-04-21 16:12:53 -04:00
parent ac70634256
commit 99d5fb551c
4 changed files with 40 additions and 2 deletions

View File

@ -4,13 +4,13 @@
import time import time
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from threading import Event 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 from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal, pyqtSlot
import nio import nio
import nio.responses as nr
import nio.events as ne import nio.events as ne
import nio.responses as nr
from .network_manager import NetworkManager from .network_manager import NetworkManager
from .pyqt_future import futurize from .pyqt_future import futurize
@ -78,6 +78,16 @@ class Client(QObject):
return self.nio.user_id 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)
@pyqtSlot(str, str) @pyqtSlot(str, str)
@futurize() @futurize()
@ -232,3 +242,21 @@ class Client(QObject):
) )
return send(self) 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()

View File

@ -80,6 +80,10 @@ Rectangle {
icon.width: 32 icon.width: 32
display: bannerButtons.displayMode display: bannerButtons.displayMode
onClicked:
Backend.clientManager.clients[chatPage.userId].
call(modelData.clientFunction, modelData.clientArgs)
Layout.maximumWidth: bannerButtons.compact ? height : -1 Layout.maximumWidth: bannerButtons.compact ? height : -1
Layout.fillHeight: true Layout.fillHeight: true
} }

View File

@ -19,11 +19,15 @@ Banner {
text: "Accept", text: "Accept",
iconName: "accept", iconName: "accept",
iconColor: Qt.hsla(0.45, 0.9, 0.3, 1), iconColor: Qt.hsla(0.45, 0.9, 0.3, 1),
clientFunction: "joinRoom",
clientArgs: [chatPage.roomId],
}, },
{ {
text: "Decline", text: "Decline",
iconName: "decline", iconName: "decline",
iconColor: Qt.hsla(0.95, 0.9, 0.35, 1), iconColor: Qt.hsla(0.95, 0.9, 0.35, 1),
clientFunction: "leaveRoom",
clientArgs: [chatPage.roomId],
} }
] ]
} }

View File

@ -15,6 +15,8 @@ Banner {
text: "Forget", text: "Forget",
iconName: "trash_can", iconName: "trash_can",
iconColor: Qt.hsla(0.95, 0.9, 0.35, 1), iconColor: Qt.hsla(0.95, 0.9, 0.35, 1),
clientFunction: "forgetRoom",
clientArgs: [chatPage.roomId],
} }
] ]
} }