Philipp Hörist pushed to branch master at gajim / gajim
Commits: 0b1d7c02 by Daniel Brötzmann at 2023-01-13T22:54:14+00:00 imprv: Limit message length and add FullMessageWindow
- - - - -
4 changed files:
- gajim/gtk/const.py - gajim/gtk/conversation/message_widget.py - gajim/gtk/conversation/plain_widget.py - gajim/gtk/message_input.py
Changes:
===================================== gajim/gtk/const.py ===================================== @@ -55,6 +55,8 @@ class Setting(NamedTuple): # Drag and drop target type URI list (for dropped files) TARGET_TYPE_URI_LIST = 80
+MAX_MESSAGE_LENGTH = 5000 +
@unique class Theme(IntEnum):
===================================== gajim/gtk/conversation/message_widget.py ===================================== @@ -18,14 +18,17 @@ from typing import Optional from typing import Union
+from gi.repository import Gdk from gi.repository import Gtk
+from gajim.common.i18n import _ from gajim.common.styling import ParsingResult from gajim.common.styling import PlainBlock from gajim.common.styling import PreBlock from gajim.common.styling import process from gajim.common.styling import QuoteBlock
+from gajim.gtk.const import MAX_MESSAGE_LENGTH from gajim.gtk.conversation.code_widget import CodeWidget from gajim.gtk.conversation.plain_widget import PlainWidget from gajim.gtk.conversation.quote_widget import QuoteWidget @@ -59,12 +62,20 @@ def add_with_styling(self, text: str, nickname: Optional[str] = None) -> None:
+ original_text = text + if len(text) > MAX_MESSAGE_LENGTH: + text = text[:MAX_MESSAGE_LENGTH] + if text.startswith('/me') and nickname is not None: self._add_action_phrase(text, nickname) + if len(original_text) > MAX_MESSAGE_LENGTH: + self._add_read_more_button(original_text) return
result = process(text) self.add_content(result) + if len(original_text) > MAX_MESSAGE_LENGTH: + self._add_read_more_button(original_text)
def _add_action_phrase(self, text: str, nickname: str): self.clear() @@ -101,5 +112,49 @@ def add_content(self, content: ContentT) -> None:
self.show_all()
+ def _add_read_more_button(self, text: str) -> None: + link_button = Gtk.LinkButton(label=_('[read more]')) + link_button.set_halign(Gtk.Align.START) + link_button.connect('activate-link', self._on_read_more, text) + self.add(link_button) + + def _on_read_more(self, _button: Gtk.LinkButton, text: str) -> bool: + FullMessageWindow(text) + return True + def clear(self) -> None: self.foreach(self.remove) + + +class FullMessageWindow(Gtk.ApplicationWindow): + def __init__(self, text: str) -> None: + Gtk.ApplicationWindow.__init__(self) + self.set_size_request(800, 800) + self.set_title(_('Full Message View')) + self.get_style_context().add_class('dialog-margin') + + textview = Gtk.TextView() + textview.set_editable(False) + textview.set_left_margin(3) + textview.set_top_margin(3) + textview.get_buffer().set_text(text) + + scrolled = Gtk.ScrolledWindow() + scrolled.set_hexpand(True) + scrolled.set_shadow_type(Gtk.ShadowType.IN) + scrolled.add(textview) + + box = Gtk.Box() + box.add(scrolled) + + self.add(box) + self.show_all() + + self.connect('key-press-event', self._on_key_press_event) + + def _on_key_press_event(self, + _widget: Gtk.Widget, + event: Gdk.EventKey + ) -> None: + if event.keyval == Gdk.KEY_Escape: + self.destroy()
===================================== gajim/gtk/conversation/plain_widget.py ===================================== @@ -28,6 +28,7 @@ from gajim.common.styling import PlainBlock from gajim.common.styling import process_uris
+from gajim.gtk.const import MAX_MESSAGE_LENGTH from gajim.gtk.menus import get_conv_action_context_menu from gajim.gtk.menus import populate_uri_context_menu from gajim.gtk.util import make_pango_attributes @@ -107,7 +108,7 @@ def print_text_with_styling(self, block: PlainBlock) -> None: text = self._build_link_markup(block.text, block.uris) self.set_markup(text)
- if len(self.get_text()) > 10000: + if len(self.get_text()) > MAX_MESSAGE_LENGTH: # Limit message styling processing return
===================================== gajim/gtk/message_input.py ===================================== @@ -41,6 +41,7 @@ from gajim.common.types import ChatContactT
from gajim.gtk.chat_action_processor import ChatActionProcessor +from gajim.gtk.const import MAX_MESSAGE_LENGTH from gajim.gtk.util import scroll_to_end
if app.is_installed('GSPELL'): @@ -311,7 +312,7 @@ def _on_text_changed(self, buf: Gtk.TextBuffer) -> None:
self._clear_tags()
- if len(text) > 10000: + if len(text) > MAX_MESSAGE_LENGTH: # Limit message styling processing return
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/0b1d7c028ba21c626393c28b3ff2dde4b...