diff --git a/qtribu/gui/dck_qchat.py b/qtribu/gui/dck_qchat.py index 9093f1a2..034e2753 100644 --- a/qtribu/gui/dck_qchat.py +++ b/qtribu/gui/dck_qchat.py @@ -102,6 +102,12 @@ def __init__( self.on_custom_context_menu_requested ) + # list users signal listener + self.btn_list_users.pressed.connect(self.on_list_users_button_clicked) + self.btn_list_users.setIcon( + QIcon(QgsApplication.iconPath("processingResult.svg")) + ) + # clear chat signal listener self.btn_clear_chat.pressed.connect(self.on_clear_chat_button_clicked) self.btn_clear_chat.setIcon( @@ -305,6 +311,7 @@ def on_ws_connected(self, room: str) -> None: self.btn_connect.setText(self.tr("Disconnect")) self.lbl_status.setText("Connected") self.grb_room.setTitle(self.tr("Room: {room}").format(room=room)) + self.btn_list_users.setEnabled(True) self.grb_user.setEnabled(True) self.current_room = room @@ -321,6 +328,14 @@ def on_ws_connected(self, room: str) -> None: self.tr("Connected to room '{room}'").format(room=room) ) + # send newcomer message to websocket + if not self.settings.qchat_incognito_mode: + message = { + "author": INTERNAL_MESSAGE_AUTHOR, + "newcomer": self.settings.author_nickname, + } + self.ws_client.sendTextMessage(json.dumps(message)) + def disconnect_from_room(self, log: bool = True, close_ws: bool = True) -> None: """ Disconnect widget from the current room @@ -335,6 +350,7 @@ def disconnect_from_room(self, log: bool = True, close_ws: bool = True) -> None: self.lbl_status.setText("Disconnected") self.grb_room.setTitle(self.tr("Room")) self.grb_qchat.setTitle(self.tr("QChat")) + self.btn_list_users.setEnabled(False) self.grb_user.setEnabled(False) self.connected = False if close_ws: @@ -440,6 +456,24 @@ def handle_internal_message(self, message: dict[str, Any]) -> None: ) ) self.log(message=f"Internal message received: {nb_users} users in room") + if ( + "newcomer" in message + and self.settings.qchat_display_admin_messages + and message["newcomer"] != self.settings.author_nickname + ): + newcomer = message["newcomer"] + self.add_admin_message( + self.tr("{newcomer} has joined the room").format(newcomer=newcomer) + ) + if ( + "exiter" in message + and self.settings.qchat_display_admin_messages + and message["exiter"] != self.settings.author_nickname + ): + exiter = message["exiter"] + self.add_admin_message( + self.tr("{newcomer} has left the room").format(newcomer=exiter) + ) def on_message_double_clicked(self, item: QTreeWidgetItem, column: int) -> None: """ @@ -507,6 +541,25 @@ def on_hide_message(self, item: QTreeWidgetItem) -> None: root = self.twg_chat.invisibleRootItem() (item.parent() or root).removeChild(item) + def on_list_users_button_clicked(self) -> None: + """ + Action called when the list users button is clicked + """ + try: + users = self.qchat_client.get_registered_users(self.current_room) + QMessageBox.information( + self, + self.tr("Registered users"), + self.tr( + """Registered users in room ({room}): + +{users}""" + ).format(room=self.current_room, users=",".join(users)), + ) + except Exception as exc: + self.iface.messageBar().pushCritical(self.tr("QChat error"), str(exc)) + self.log(message=str(exc), log_level=Qgis.Critical) + def on_clear_chat_button_clicked(self) -> None: """ Action called when the clear chat button is clicked diff --git a/qtribu/gui/dck_qchat.ui b/qtribu/gui/dck_qchat.ui index f85814d2..bbc29f9e 100644 --- a/qtribu/gui/dck_qchat.ui +++ b/qtribu/gui/dck_qchat.ui @@ -152,6 +152,9 @@ + + true + 0 @@ -215,14 +218,31 @@ - - - PointingHandCursor - - - Clear - - + + + + + false + + + PointingHandCursor + + + List users + + + + + + + PointingHandCursor + + + Clear + + + + diff --git a/qtribu/gui/dlg_settings.py b/qtribu/gui/dlg_settings.py index 8fecbe92..0732f58d 100644 --- a/qtribu/gui/dlg_settings.py +++ b/qtribu/gui/dlg_settings.py @@ -118,6 +118,7 @@ def apply(self): self.ckb_display_admin_messages.isChecked() ) settings.qchat_show_avatars = self.ckb_show_avatars.isChecked() + settings.qchat_incognito_mode = self.ckb_incognito_mode.isChecked() settings.qchat_play_sounds = self.ckb_play_sounds.isChecked() settings.qchat_sound_volume = self.hsl_sound_volume.value() settings.qchat_ring_tone = self.cbb_ring_tone.currentText() @@ -166,6 +167,7 @@ def load_settings(self) -> None: settings.qchat_display_admin_messages ) self.ckb_show_avatars.setChecked(settings.qchat_show_avatars) + self.ckb_incognito_mode.setChecked(settings.qchat_incognito_mode) self.ckb_play_sounds.setChecked(settings.qchat_play_sounds) self.hsl_sound_volume.setValue(settings.qchat_sound_volume) beep_index = self.cbb_ring_tone.findText( diff --git a/qtribu/gui/dlg_settings.ui b/qtribu/gui/dlg_settings.ui index f03dac15..ecb66812 100644 --- a/qtribu/gui/dlg_settings.ui +++ b/qtribu/gui/dlg_settings.ui @@ -42,8 +42,8 @@ 0 0 - 875 - 577 + 877 + 579 @@ -389,13 +389,32 @@ + + + Show avatars + + + + + + + Incognito mode + + + false + + + + + + Display admin messages @@ -403,6 +422,9 @@ + + + Activate cheatcodes diff --git a/qtribu/logic/qchat_client.py b/qtribu/logic/qchat_client.py index d73b14a9..bb7c654f 100644 --- a/qtribu/logic/qchat_client.py +++ b/qtribu/logic/qchat_client.py @@ -82,3 +82,17 @@ def get_rooms(self) -> list[str]: ) data = json.loads(str(response, "UTF8")) return data + + def get_registered_users(self, room: str) -> list[str]: + """ + Get registered users in a room with an API HTTP CALL + """ + url = f"{self.instance_uri}/room/{room}/users" + response: QByteArray = self.qntwk.get_from_source( + headers=HEADERS, + url=url, + response_expected_content_type=CONTENT_TYPE_JSON, + use_cache=False, + ) + data = json.loads(str(response, "UTF8")) + return data diff --git a/qtribu/toolbelt/preferences.py b/qtribu/toolbelt/preferences.py index f4ae4f05..49caa1cc 100644 --- a/qtribu/toolbelt/preferences.py +++ b/qtribu/toolbelt/preferences.py @@ -43,6 +43,7 @@ class PlgSettingsStructure: qchat_activate_cheatcode: bool = True qchat_display_admin_messages: bool = False qchat_show_avatars: bool = True + qchat_incognito_mode: bool = False qchat_play_sounds: bool = True qchat_sound_volume: int = 33 qchat_ring_tone: str = "beep_1"