From fd7d760609f058d948ba990928b033de020fdddb Mon Sep 17 00:00:00 2001 From: wurstsalat Date: Sat, 4 Nov 2023 23:58:44 +0100 Subject: fix: Message row menu: Show quote and copy actions only if there is text Fixes #11652 --- gajim/gtk/menus.py | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/gajim/gtk/menus.py b/gajim/gtk/menus.py index 7c767ea23..9fb0693d1 100644 --- a/gajim/gtk/menus.py +++ b/gajim/gtk/menus.py @@ -688,37 +688,40 @@ def get_chat_row_menu(contact: types.ChatContactT, menu_items: MenuItemListT = [] - format_string = app.settings.get('date_time_format') - timestamp_formatted = timestamp.strftime(format_string) + if text: + # Text can be an empty string, + # e.g. if a preview has not been loaded yet + timestamp_formatted = timestamp.strftime( + app.settings.get('date_time_format')) + + copy_text = f'{timestamp_formatted} - {name}: ' + if text.startswith(('```', '> ')): + # Prepend a line break in order to keep code block/quotes rendering + copy_text += '\n' + copy_text += text - copy_text = f'{timestamp_formatted} - {name}: ' - if text.startswith(('```', '> ')): - # Prepend a line break in order to keep code block/quotes rendering - copy_text += '\n' - copy_text += text - - menu_items.append( - (p_('Message row action', 'Copy'), - 'win.copy-message', - copy_text)) + menu_items.append( + (p_('Message row action', 'Copy'), + 'win.copy-message', + copy_text)) + + show_quote = True + if isinstance(contact, GroupchatContact): + if contact.is_joined: + self_contact = contact.get_self() + assert self_contact is not None + show_quote = not self_contact.role.is_visitor + else: + show_quote = False + if show_quote: + menu_items.append(( + p_('Message row action', 'Quote…'), 'win.quote', text)) menu_items.append( (p_('Message row action', 'Select Messages…'), 'win.activate-message-selection', GLib.Variant('u', log_line_id or 0))) - show_quote = True - if isinstance(contact, GroupchatContact): - if contact.is_joined: - self_contact = contact.get_self() - assert self_contact is not None - show_quote = not self_contact.role.is_visitor - else: - show_quote = False - if show_quote: - menu_items.append(( - p_('Message row action', 'Quote…'), 'win.quote', text)) - show_correction = False if message_id is not None: show_correction = app.window.is_message_correctable( -- cgit v1.2.3