From b24f3d8286885a5f73111ec54221e26c7ab5f1d5 Mon Sep 17 00:00:00 2001 From: Guilhem Allaman <40383801+gounux@users.noreply.github.com> Date: Fri, 25 Oct 2024 10:40:47 +0200 Subject: [PATCH] feature(qchat): like message (#210) * feature(qchat): handle users registration * feature(qchat): set user registration optional * feature(qchat): notify when a user has left * refactor(qchat): rename registration to incognito mode * ui(qchat): set settings tooltips * ui(qchat): set qchat groupbox enabled * feature(qchat): like message --- qtribu/gui/dck_qchat.py | 71 +++++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/qtribu/gui/dck_qchat.py b/qtribu/gui/dck_qchat.py index 034e2753..2392220e 100644 --- a/qtribu/gui/dck_qchat.py +++ b/qtribu/gui/dck_qchat.py @@ -474,6 +474,25 @@ def handle_internal_message(self, message: dict[str, Any]) -> None: self.add_admin_message( self.tr("{newcomer} has left the room").format(newcomer=exiter) ) + if ( + "liker_author" in message + and "liked_author" in message + and message["liked_author"] == self.settings.author_nickname + ): + self.log( + message=self.tr('{liker_author} liked your message "{message}"').format( + liker_author=message["liker_author"], message=message["message"] + ), + application=self.tr("QChat"), + log_level=Qgis.Success, + push=PlgOptionsManager().get_plg_settings().notify_push_info, + duration=PlgOptionsManager().get_plg_settings().notify_push_duration, + ) + # play a notification sound if enabled + if self.settings.qchat_play_sounds: + play_resource_sound( + self.settings.qchat_ring_tone, self.settings.qchat_sound_volume + ) def on_message_double_clicked(self, item: QTreeWidgetItem, column: int) -> None: """ @@ -484,6 +503,19 @@ def on_message_double_clicked(self, item: QTreeWidgetItem, column: int) -> None: self.lne_message.setText(f"{text}@{author} ") self.lne_message.setFocus() + def on_like_message(self, liked_author: str, message: str) -> None: + """ + Action called when the "Like message" action is triggered + This may happen on right-click on a message + """ + internal_message = { + "author": INTERNAL_MESSAGE_AUTHOR, + "message": message, + "liker_author": self.settings.author_nickname, + "liked_author": liked_author, + } + self.ws_client.sendTextMessage(json.dumps(internal_message)) + def on_custom_context_menu_requested(self, point: QPoint) -> None: """ Action called when right clicking on a chat message @@ -494,6 +526,31 @@ def on_custom_context_menu_requested(self, point: QPoint) -> None: menu = QMenu(self.tr("QChat Menu"), self) + if ( + author != self.settings.author_nickname + and author != ADMIN_MESSAGES_NICKNAME + ): + # like message action + like_action = QAction( + QgsApplication.getThemeIcon("mActionInOverview.svg"), + self.tr("Like message"), + ) + like_action.triggered.connect( + partial(self.on_like_message, author, message) + ) + menu.addAction(like_action) + + # mention user action + mention_action = QAction( + QgsApplication.getThemeIcon("mMessageLogRead.svg"), + self.tr("Mention user"), + ) + mention_action.triggered.connect( + partial(self.on_message_double_clicked, item, 2) + ) + menu.addAction(mention_action) + menu.addSeparator() + # copy message to clipboard action copy_action = QAction( QgsApplication.getThemeIcon("mActionEditCopy.svg"), @@ -512,20 +569,6 @@ def on_custom_context_menu_requested(self, point: QPoint) -> None: hide_action.triggered.connect(partial(self.on_hide_message, item)) menu.addAction(hide_action) - # mention user action - if ( - author != self.settings.author_nickname - and author != ADMIN_MESSAGES_NICKNAME - ): - mention_action = QAction( - QgsApplication.getThemeIcon("mMessageLogRead.svg"), - self.tr("Mention user"), - ) - mention_action.triggered.connect( - partial(self.on_message_double_clicked, item, 2) - ) - menu.addAction(mention_action) - menu.exec(QCursor.pos()) def on_copy_message_to_clipboard(self, message: str) -> None: