Philipp Hörist pushed to branch master at gajim / gajim
Commits: cb7c00f1 by wurstsalat at 2022-10-01T18:54:47+00:00 imprv: MUC: Add participant menu to avatar
- - - - -
3 changed files:
- gajim/gtk/conversation/rows/message.py - gajim/gtk/groupchat_roster.py - gajim/gtk/menus.py
Changes:
===================================== gajim/gtk/conversation/rows/message.py ===================================== @@ -53,6 +53,7 @@ from ..message_widget import MessageWidget from ...dialogs import InputDialog from ...dialogs import DialogButton +from ...menus import get_groupchat_participant_menu from ...preview import PreviewWidget from ...util import format_fingerprint from ...util import get_cursor @@ -265,10 +266,43 @@ def _on_avatar_clicked(self, event: Gdk.EventButton, name: str ) -> int: - if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 1: - app.window.activate_action('mention', GLib.Variant('s', name)) + if event.type == Gdk.EventType.BUTTON_PRESS: + if event.button == 1: + app.window.activate_action('mention', GLib.Variant('s', name)) + elif event.button == 3: + rect = Gdk.Rectangle() + rect.x, rect.y = int(event.x), int(event.y) + rect.height, rect.width = 1, 1 + self._show_participant_menu(name, rect) + return Gdk.EVENT_STOP
+ def _show_participant_menu(self, nick: str, rect: Gdk.Rectangle) -> None: + assert isinstance(self._contact, GroupchatContact) + if not self._contact.is_joined: + return + + self_contact = self._contact.get_self() + assert self_contact is not None + + if nick == self_contact.name: + # Don’t show menu for us + return + + contact = self._contact.get_resource(nick) + menu = get_groupchat_participant_menu(self._contact.account, + self_contact, + contact) + + def destroy(popover: Gtk.Popover) -> None: + app.check_finalize(popover) + GLib.idle_add(popover.set_relative_to, None) + + popover = Gtk.Popover.new_from_model(self, menu) + popover.set_pointing_to(rect) + popover.connect('closed', destroy) + popover.popup() + @staticmethod def _on_realize(event_box: Gtk.EventBox) -> None: window = event_box.get_window()
===================================== gajim/gtk/groupchat_roster.py ===================================== @@ -38,7 +38,7 @@ from gajim.common.events import MUCNicknameChanged from gajim.common.modules.contacts import GroupchatContact
-from .menus import get_groupchat_roster_menu +from .menus import get_groupchat_participant_menu from .tooltips import GCTooltip from .builder import get_builder from .util import EventHelper @@ -427,9 +427,9 @@ def _show_contact_menu(self, nick: str, rect: Gdk.Rectangle) -> None: self_contact = self._contact.get_self() assert self_contact is not None contact = self._contact.get_resource(nick) - menu = get_groupchat_roster_menu(self._contact.account, - self_contact, - contact) + menu = get_groupchat_participant_menu(self._contact.account, + self_contact, + contact)
def destroy(popover: Gtk.Popover) -> None: app.check_finalize(popover)
===================================== gajim/gtk/menus.py ===================================== @@ -465,6 +465,10 @@ def get_groupchat_admin_menu(self_contact: types.GroupchatParticipant,
menu = GajimMenu()
+ if contact.real_jid is None: + menu.add_item(_('Not Available'), 'dummy', None) + return menu + action = 'win.muc-change-affiliation'
if is_affiliation_change_allowed(self_contact, contact, 'owner'): @@ -499,6 +503,10 @@ def get_groupchat_mod_menu(self_contact: types.GroupchatParticipant,
menu = GajimMenu()
+ if not contact.is_available: + menu.add_item(_('Not Available'), 'dummy', None) + return menu + if is_role_change_allowed(self_contact, contact): value = f'"{contact.name}"' menu.add_item(_('Kick…'), 'win.muc-kick', value) @@ -519,10 +527,10 @@ def get_groupchat_mod_menu(self_contact: types.GroupchatParticipant, return menu
-def get_groupchat_roster_menu(account: str, - self_contact: types.GroupchatParticipant, - contact: types.GroupchatParticipant - ) -> GajimMenu: +def get_groupchat_participant_menu(account: str, + self_contact: types.GroupchatParticipant, + contact: types.GroupchatParticipant + ) -> GajimMenu:
value = f'"{contact.name}"'
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/cb7c00f1e3fb37fe22de03e031140f7ef...