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

Commits:

5 changed files:

Changes:

  • gajim/gtk/conversation/message_widget.py
    ... ... @@ -12,28 +12,45 @@
    12 12
     # You should have received a copy of the GNU General Public License
    
    13 13
     # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
    
    14 14
     
    
    15
    +from __future__ import annotations
    
    16
    +
    
    17
    +from typing import Any
    
    18
    +from typing import Union
    
    19
    +from typing import cast
    
    20
    +
    
    15 21
     from gi.repository import Gtk
    
    16 22
     
    
    23
    +from gajim.common.styling import process
    
    24
    +from gajim.common.styling import ParsingResult
    
    25
    +from gajim.common.styling import QuoteBlock
    
    26
    +
    
    17 27
     from .code_widget import CodeWidget
    
    18 28
     from .quote_widget import QuoteWidget
    
    19 29
     from .plain_widget import PlainWidget
    
    20 30
     
    
    21 31
     
    
    32
    +ContentT = Union[ParsingResult, QuoteBlock]
    
    33
    +
    
    34
    +
    
    22 35
     class MessageWidget(Gtk.Box):
    
    23 36
         def __init__(self, account: str, selectable: bool = True) -> None:
    
    24 37
             Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
    
    25 38
             self._account = account
    
    26 39
             self._selectable = selectable
    
    27 40
     
    
    28
    -        self._content = None
    
    41
    +        self._content = cast(ContentT, None)
    
    29 42
     
    
    30
    -    def get_content(self):
    
    43
    +    def get_content(self) -> ContentT:
    
    31 44
             return self._content
    
    32 45
     
    
    33
    -    def get_text(self):
    
    46
    +    def get_text(self) -> str:
    
    34 47
             return self._content.text
    
    35 48
     
    
    36
    -    def add_content(self, content):
    
    49
    +    def add_with_styling(self, text: str) -> None:
    
    50
    +        result = process(text)
    
    51
    +        self.add_content(result)
    
    52
    +
    
    53
    +    def add_content(self, content: ContentT) -> None:
    
    37 54
             self.clear()
    
    38 55
             self._content = content
    
    39 56
             for block in content.blocks:
    
    ... ... @@ -62,7 +79,7 @@ def add_content(self, content):
    62 79
         def clear(self) -> None:
    
    63 80
             self.foreach(self.remove)
    
    64 81
     
    
    65
    -    def update_text_tags(self, *args):
    
    82
    +    def update_text_tags(self, *args: Any) -> None:
    
    66 83
             for widget in self.get_children():
    
    67 84
                 if not isinstance(widget, CodeWidget):
    
    68 85
                     widget.update_text_tags()

  • gajim/gtk/conversation/rows/message.py
    ... ... @@ -39,7 +39,6 @@
    39 39
     from gajim.common.helpers import message_needs_highlight
    
    40 40
     from gajim.common.helpers import reduce_chars_newlines
    
    41 41
     from gajim.common.helpers import to_user_string
    
    42
    -from gajim.common.styling import process
    
    43 42
     from gajim.common.styling import ParsingResult
    
    44 43
     from gajim.common.i18n import _
    
    45 44
     from gajim.common.i18n import Q_
    
    ... ... @@ -110,14 +109,13 @@ def __init__(self,
    110 109
                 app.interface.preview_manager.create_preview(
    
    111 110
                     text, self._message_widget, context)
    
    112 111
             else:
    
    113
    -            result = process(text)
    
    114 112
                 self._message_widget = MessageWidget(account)
    
    115
    -            self._message_widget.add_content(result)
    
    113
    +            self._message_widget.add_with_styling(text)
    
    116 114
                 if self._is_groupchat:
    
    117 115
                     our_nick = get_group_chat_nick(
    
    118 116
                         self._account, self._contact.jid)
    
    119 117
                     if name != our_nick:
    
    120
    -                    self._check_for_highlight(result)
    
    118
    +                    self._check_for_highlight(self._message_widget.content)
    
    121 119
     
    
    122 120
             if self._is_groupchat:
    
    123 121
                 our_nick = get_group_chat_nick(self._account, self._contact.jid)
    
    ... ... @@ -353,12 +351,11 @@ def set_displayed(self):
    353 351
             self._has_displayed = True
    
    354 352
     
    
    355 353
         def set_retracted(self, text: str) -> None:
    
    356
    -        self._message_widget.add_content(process(text))
    
    354
    +        self._message_widget.add_with_styling(text)
    
    357 355
             self.get_style_context().add_class('retracted-message')
    
    358 356
     
    
    359 357
         def set_correction(self, text: str) -> None:
    
    360
    -        result = process(text)
    
    361
    -        self._message_widget.add_content(result)
    
    358
    +        self._message_widget.add_with_styling(text)
    
    362 359
     
    
    363 360
             self._has_receipt = False
    
    364 361
             self._message_icons.set_receipt_icon_visible(False)
    

  • gajim/gtk/conversation/rows/muc_subject.py
    ... ... @@ -19,7 +19,6 @@
    19 19
     
    
    20 20
     from gajim.common.const import AvatarSize
    
    21 21
     from gajim.common.i18n import _
    
    22
    -from gajim.common.styling import process
    
    23 22
     
    
    24 23
     from .base import BaseRow
    
    25 24
     from ..message_widget import MessageWidget
    
    ... ... @@ -57,9 +56,8 @@ def __init__(self, account: str, text: str, nick: str, date: str) -> None:
    57 56
             meta.get_style_context().add_class('small-label')
    
    58 57
             subject_box.add(meta)
    
    59 58
     
    
    60
    -        result = process(text)
    
    61 59
             message_widget = MessageWidget(account)
    
    62
    -        message_widget.add_content(result)
    
    60
    +        message_widget.add_with_styling(text)
    
    63 61
             subject_box.add(message_widget)
    
    64 62
             self.grid.attach(subject_box, 1, 0, 1, 1)
    
    65 63
     
    

  • gajim/gtk/conversation/rows/muc_user_status.py
    ... ... @@ -21,7 +21,6 @@
    21 21
     from gajim.common.i18n import _
    
    22 22
     from gajim.common.const import AvatarSize
    
    23 23
     from gajim.common.helpers import get_uf_show
    
    24
    -from gajim.common.styling import process
    
    25 24
     
    
    26 25
     from .widgets import SimpleLabel
    
    27 26
     from .base import BaseRow
    
    ... ... @@ -60,10 +59,9 @@ def __init__(self, account: str, user_contact: GroupchatParticipant,
    60 59
             self.grid.attach(self._label, 2, 0, 1, 1)
    
    61 60
     
    
    62 61
             if user_contact.status is not None:
    
    63
    -            result = process(user_contact.status)
    
    64 62
                 message_widget = MessageWidget(account)
    
    65 63
                 message_widget.get_style_context().add_class('gajim-status-message')
    
    66
    -            message_widget.add_content(result)
    
    64
    +            message_widget.add_with_styling(user_contact.status)
    
    67 65
                 self.grid.attach(message_widget, 2, 1, 1, 1)
    
    68 66
     
    
    69 67
             timestamp_widget = self.create_timestamp_widget(self.timestamp)
    

  • gajim/gtk/search_view.py
    ... ... @@ -35,7 +35,6 @@
    35 35
     from gajim.common.const import KindConstant
    
    36 36
     from gajim.common.const import FILE_CATEGORIES
    
    37 37
     from gajim.common.i18n import _
    
    38
    -from gajim.common.styling import process
    
    39 38
     
    
    40 39
     from .conversation.message_widget import MessageWidget
    
    41 40
     from .util import get_builder
    
    ... ... @@ -361,9 +360,8 @@ def __init__(self, msg: namedtuple, account: str, jid: JID) -> None:
    361 360
             self._ui.row_time_label.set_label(date)
    
    362 361
     
    
    363 362
             message_widget = MessageWidget(account, selectable=False)
    
    363
    +        message_widget.add_with_styling(msg.message_widget)
    
    364 364
             self._ui.result_row_grid.attach(message_widget, 1, 1, 2, 1)
    
    365
    -        result = process(msg.message)
    
    366
    -        message_widget.add_content(result)
    
    367 365
     
    
    368 366
             self.show_all()
    
    369 367