Philipp Hörist pushed to branch master at gajim / gajim

Commits:

4 changed files:

Changes:

  • gajim/gtk/const.py
    ... ... @@ -55,6 +55,8 @@ class Setting(NamedTuple):
    55 55
     # Drag and drop target type URI list (for dropped files)
    
    56 56
     TARGET_TYPE_URI_LIST = 80
    
    57 57
     
    
    58
    +MAX_MESSAGE_LENGTH = 5000
    
    59
    +
    
    58 60
     
    
    59 61
     @unique
    
    60 62
     class Theme(IntEnum):
    

  • gajim/gtk/conversation/message_widget.py
    ... ... @@ -18,14 +18,17 @@
    18 18
     from typing import Optional
    
    19 19
     from typing import Union
    
    20 20
     
    
    21
    +from gi.repository import Gdk
    
    21 22
     from gi.repository import Gtk
    
    22 23
     
    
    24
    +from gajim.common.i18n import _
    
    23 25
     from gajim.common.styling import ParsingResult
    
    24 26
     from gajim.common.styling import PlainBlock
    
    25 27
     from gajim.common.styling import PreBlock
    
    26 28
     from gajim.common.styling import process
    
    27 29
     from gajim.common.styling import QuoteBlock
    
    28 30
     
    
    31
    +from gajim.gtk.const import MAX_MESSAGE_LENGTH
    
    29 32
     from gajim.gtk.conversation.code_widget import CodeWidget
    
    30 33
     from gajim.gtk.conversation.plain_widget import PlainWidget
    
    31 34
     from gajim.gtk.conversation.quote_widget import QuoteWidget
    
    ... ... @@ -59,12 +62,20 @@ def add_with_styling(self,
    59 62
                              text: str,
    
    60 63
                              nickname: Optional[str] = None) -> None:
    
    61 64
     
    
    65
    +        original_text = text
    
    66
    +        if len(text) > MAX_MESSAGE_LENGTH:
    
    67
    +            text = text[:MAX_MESSAGE_LENGTH]
    
    68
    +
    
    62 69
             if text.startswith('/me') and nickname is not None:
    
    63 70
                 self._add_action_phrase(text, nickname)
    
    71
    +            if len(original_text) > MAX_MESSAGE_LENGTH:
    
    72
    +                self._add_read_more_button(original_text)
    
    64 73
                 return
    
    65 74
     
    
    66 75
             result = process(text)
    
    67 76
             self.add_content(result)
    
    77
    +        if len(original_text) > MAX_MESSAGE_LENGTH:
    
    78
    +            self._add_read_more_button(original_text)
    
    68 79
     
    
    69 80
         def _add_action_phrase(self, text: str, nickname: str):
    
    70 81
             self.clear()
    
    ... ... @@ -101,5 +112,49 @@ def add_content(self, content: ContentT) -> None:
    101 112
     
    
    102 113
             self.show_all()
    
    103 114
     
    
    115
    +    def _add_read_more_button(self, text: str) -> None:
    
    116
    +        link_button = Gtk.LinkButton(label=_('[read more]'))
    
    117
    +        link_button.set_halign(Gtk.Align.START)
    
    118
    +        link_button.connect('activate-link', self._on_read_more, text)
    
    119
    +        self.add(link_button)
    
    120
    +
    
    121
    +    def _on_read_more(self, _button: Gtk.LinkButton, text: str) -> bool:
    
    122
    +        FullMessageWindow(text)
    
    123
    +        return True
    
    124
    +
    
    104 125
         def clear(self) -> None:
    
    105 126
             self.foreach(self.remove)
    
    127
    +
    
    128
    +
    
    129
    +class FullMessageWindow(Gtk.ApplicationWindow):
    
    130
    +    def __init__(self, text: str) -> None:
    
    131
    +        Gtk.ApplicationWindow.__init__(self)
    
    132
    +        self.set_size_request(800, 800)
    
    133
    +        self.set_title(_('Full Message View'))
    
    134
    +        self.get_style_context().add_class('dialog-margin')
    
    135
    +
    
    136
    +        textview = Gtk.TextView()
    
    137
    +        textview.set_editable(False)
    
    138
    +        textview.set_left_margin(3)
    
    139
    +        textview.set_top_margin(3)
    
    140
    +        textview.get_buffer().set_text(text)
    
    141
    +
    
    142
    +        scrolled = Gtk.ScrolledWindow()
    
    143
    +        scrolled.set_hexpand(True)
    
    144
    +        scrolled.set_shadow_type(Gtk.ShadowType.IN)
    
    145
    +        scrolled.add(textview)
    
    146
    +
    
    147
    +        box = Gtk.Box()
    
    148
    +        box.add(scrolled)
    
    149
    +
    
    150
    +        self.add(box)
    
    151
    +        self.show_all()
    
    152
    +
    
    153
    +        self.connect('key-press-event', self._on_key_press_event)
    
    154
    +
    
    155
    +    def _on_key_press_event(self,
    
    156
    +                            _widget: Gtk.Widget,
    
    157
    +                            event: Gdk.EventKey
    
    158
    +                            ) -> None:
    
    159
    +        if event.keyval == Gdk.KEY_Escape:
    
    160
    +            self.destroy()

  • gajim/gtk/conversation/plain_widget.py
    ... ... @@ -28,6 +28,7 @@
    28 28
     from gajim.common.styling import PlainBlock
    
    29 29
     from gajim.common.styling import process_uris
    
    30 30
     
    
    31
    +from gajim.gtk.const import MAX_MESSAGE_LENGTH
    
    31 32
     from gajim.gtk.menus import get_conv_action_context_menu
    
    32 33
     from gajim.gtk.menus import populate_uri_context_menu
    
    33 34
     from gajim.gtk.util import make_pango_attributes
    
    ... ... @@ -107,7 +108,7 @@ def print_text_with_styling(self, block: PlainBlock) -> None:
    107 108
             text = self._build_link_markup(block.text, block.uris)
    
    108 109
             self.set_markup(text)
    
    109 110
     
    
    110
    -        if len(self.get_text()) > 10000:
    
    111
    +        if len(self.get_text()) > MAX_MESSAGE_LENGTH:
    
    111 112
                 # Limit message styling processing
    
    112 113
                 return
    
    113 114
     
    

  • gajim/gtk/message_input.py
    ... ... @@ -41,6 +41,7 @@
    41 41
     from gajim.common.types import ChatContactT
    
    42 42
     
    
    43 43
     from gajim.gtk.chat_action_processor import ChatActionProcessor
    
    44
    +from gajim.gtk.const import MAX_MESSAGE_LENGTH
    
    44 45
     from gajim.gtk.util import scroll_to_end
    
    45 46
     
    
    46 47
     if app.is_installed('GSPELL'):
    
    ... ... @@ -311,7 +312,7 @@ def _on_text_changed(self, buf: Gtk.TextBuffer) -> None:
    311 312
     
    
    312 313
             self._clear_tags()
    
    313 314
     
    
    314
    -        if len(text) > 10000:
    
    315
    +        if len(text) > MAX_MESSAGE_LENGTH:
    
    315 316
                 # Limit message styling processing
    
    316 317
                 return
    
    317 318