diff --git a/qtribu/gui/dck_qchat.py b/qtribu/gui/dck_qchat.py index 15541f69..1b735e98 100644 --- a/qtribu/gui/dck_qchat.py +++ b/qtribu/gui/dck_qchat.py @@ -49,6 +49,7 @@ QChatNbUsersMessage, QChatNewcomerMessage, QChatTextMessage, + QChatUncompliantMessage, ) from qtribu.logic.qchat_websocket import QChatWebsocket from qtribu.tasks.dizzy import DizzyTask @@ -143,6 +144,9 @@ def __init__( # initialize websocket client self.qchat_ws = QChatWebsocket() self.qchat_ws.error.connect(self.on_ws_error) + self.qchat_ws.uncompliant_message_received.connect( + self.on_uncompliant_message_received + ) self.qchat_ws.text_message_received.connect(self.on_text_message_received) self.qchat_ws.image_message_received.connect(self.on_image_message_received) self.qchat_ws.nb_users_message_received.connect( @@ -423,6 +427,17 @@ def on_ws_error(self, error_code: int) -> None: # region websocket message received + def on_uncompliant_message_received(self, message: QChatUncompliantMessage) -> None: + self.log( + message=self.tr("Uncompliant message: {reason}").format( + reason=message.reason + ), + application=self.tr("QChat"), + log_level=Qgis.Critical, + push=PlgOptionsManager().get_plg_settings().notify_push_info, + duration=PlgOptionsManager().get_plg_settings().notify_push_duration, + ) + def on_text_message_received(self, message: QChatTextMessage) -> None: """ Launched when a text message is received from the websocket diff --git a/qtribu/logic/qchat_messages.py b/qtribu/logic/qchat_messages.py index db2c5f7e..14642be2 100644 --- a/qtribu/logic/qchat_messages.py +++ b/qtribu/logic/qchat_messages.py @@ -7,6 +7,11 @@ class QChatMessage: type: str +@dataclass(init=True, frozen=True) +class QChatUncompliantMessage(QChatMessage): + reason: str + + @dataclass(init=True, frozen=True) class QChatTextMessage(QChatMessage): author: str diff --git a/qtribu/logic/qchat_websocket.py b/qtribu/logic/qchat_websocket.py index 620a4a06..ba3928e1 100644 --- a/qtribu/logic/qchat_websocket.py +++ b/qtribu/logic/qchat_websocket.py @@ -14,6 +14,7 @@ QChatNbUsersMessage, QChatNewcomerMessage, QChatTextMessage, + QChatUncompliantMessage, ) from qtribu.toolbelt import PlgLogger @@ -49,6 +50,7 @@ def __init__(self): error = pyqtSignal(int) # QChat message signals + uncompliant_message_received = pyqtSignal(QChatUncompliantMessage) text_message_received = pyqtSignal(QChatTextMessage) image_message_received = pyqtSignal(QChatImageMessage) nb_users_message_received = pyqtSignal(QChatNbUsersMessage) @@ -96,7 +98,9 @@ def on_message_received(self, text: str) -> None: """ message = json.loads(text) msg_type = message["type"] - if msg_type == "text": + if msg_type == "uncompliant": + self.uncompliant_message_received.emit(QChatUncompliantMessage(**message)) + elif msg_type == "text": self.text_message_received.emit(QChatTextMessage(**message)) elif msg_type == "image": self.image_message_received.emit(QChatImageMessage(**message))