Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(qchat): like message #210

Merged
merged 10 commits into from
Oct 25, 2024
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
Loading