Skip to content

Commit

Permalink
feature(qchat): like message (#210)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gounux authored and Guts committed Nov 6, 2024
1 parent 172e38e commit b24f3d8
Showing 1 changed file with 57 additions and 14 deletions.
71 changes: 57 additions & 14 deletions qtribu/gui/dck_qchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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
Expand All @@ -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"),
Expand All @@ -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:
Expand Down

0 comments on commit b24f3d8

Please sign in to comment.