Philipp Hörist pushed to branch mainwindow at gajim / gajim
Commits: 16488c20 by lovetox at 2021-04-27T13:11:48+02:00 More Control work
- - - - -
8 changed files:
- gajim/chat_control.py - gajim/chat_control_base.py - gajim/groupchat_control.py - gajim/gtk/conversation/rows/base.py - gajim/gtk/conversation/rows/info.py - + gajim/gtk/conversation/rows/muc_subject.py - gajim/gtk/conversation/view.py - gajim/privatechat_control.py
Changes:
===================================== gajim/chat_control.py ===================================== @@ -478,7 +478,7 @@ def _on_mam_message_received(self, event): if not event.properties.jid.bare_match(self.contact.jid): return
- kind = '' # incoming + kind = 'incoming' if event.kind == KindConstant.CHAT_MSG_SENT: kind = 'outgoing'
@@ -493,12 +493,12 @@ def _on_message_received(self, event): if not event.msgtxt: return
- typ = '' + kind = 'incoming' if event.properties.is_sent_carbon: - typ = 'out' + kind = 'outgoing'
self.add_message(event.msgtxt, - typ, + kind, tim=event.properties.timestamp, subject=event.properties.subject, displaymarking=event.displaymarking, @@ -529,7 +529,7 @@ def _on_message_sent(self, event): self.msg_textview, 'gajim-msg-correcting')
self.add_message(event.message, - self.contact.jid, + 'outgoing', tim=event.timestamp, displaymarking=displaymarking, message_id=message_id, @@ -928,7 +928,7 @@ def get_our_nick(self):
def add_message(self, text, - frm='', + kind, tim=None, subject=None, displaymarking=None, @@ -936,36 +936,14 @@ def add_message(self, correct_id=None, message_id=None, additional_data=None): - """ - Print a line in the conversation - - If frm is set to status: it's a status message. - if frm is set to error: it's an error message. The difference between - status and error is mainly that with error, msg count as a new - message (in systray and in control). - If frm is set to info: it's a information message. - If frm is set to print_queue: it is incoming from queue. - If frm is set to another value: it's an outgoing message. - If frm is not set: it's an incoming message. - """ - contact = self.contact
if additional_data is None: additional_data = AdditionalDataDict()
- if frm == 'error': - kind = 'error' - name = '' + if kind == 'incoming': + name = self.contact.name else: - if not frm: - kind = 'incoming' - name = contact.name - elif frm == 'print_queue': - kind = 'incoming_queue' - name = contact.name - else: - kind = 'outgoing' - name = self.get_our_nick() + name = self.get_our_nick()
ChatControlBase.add_message(self, text, @@ -978,11 +956,6 @@ def add_message(self, correct_id=correct_id, additional_data=additional_data)
- if text.startswith('/me ') or text.startswith('/me\n'): - self.old_msg_kind = None - else: - self.old_msg_kind = kind - def prepare_context_menu(self, hide_buttonbar_items=False): """ Set compact view menuitem active state sets active and sensitivity state @@ -1117,7 +1090,7 @@ def _on_presence_received(self, event): status = '- %s' % event.status if event.status else '' status_line = _('%(name)s is now %(show)s %(status)s') % { 'name': name, 'show': uf_show, 'status': status} - self.add_status_message(status_line) + self.add_info_message(status_line)
def _info_bar_show_message(self): if self.info_bar.get_visible():
===================================== gajim/chat_control_base.py ===================================== @@ -1073,13 +1073,8 @@ def save_message(self, message, msg_type): else: self.received_history_pos = pos
- def add_info_message(self, text, message_id=None): - self.conversation_view.add_message( - text, 'info', '', None, message_id=message_id) - - def add_status_message(self, text): - self.conversation_view.add_message( - text, 'status', '', None) + def add_info_message(self, text): + self.conversation_view.add_info_message(text)
def add_message(self, text, @@ -1108,16 +1103,13 @@ def add_message(self, log_line_id=msg_log_id, additional_data=additional_data)
- if restored: - return - if message_id: if self._type.is_groupchat: self.last_msg_id = stanza_id or message_id else: self.last_msg_id = message_id
- if kind in ('incoming', 'incoming_queue'): + if kind == 'incoming': # Record the history of received messages self.save_message(text, 'received')
@@ -1334,7 +1326,7 @@ def add_messages(self, messages): for msg in messages: if not msg: continue - kind = 'status' + contact_name = msg.contact_name if msg.kind in ( KindConstant.SINGLE_MSG_RECV, KindConstant.CHAT_MSG_RECV): @@ -1346,6 +1338,9 @@ def add_messages(self, messages): KindConstant.SINGLE_MSG_SENT, KindConstant.CHAT_MSG_SENT): kind = 'outgoing' contact_name = self.get_our_nick() + else: + raise ValueError('no kind attribute') + if not msg.message: continue self.conversation_view.add_message(
===================================== gajim/groupchat_control.py ===================================== @@ -691,26 +691,23 @@ def _on_gc_message_received(self, event): additional_data=event.additional_data) event.needs_highlight = self.needs_visual_notification(event.msgtxt)
- def add_message(self, text, contact='', tim=None, - displaymarking=None, correct_id=None, message_id=None, - stanza_id=None, additional_data=None): - """ - Add message to the ConversationsTextview - - If contact is set: it's a message from someone - If contact is not set: it's a message from the server or help. - """ - - if not contact: - # Message from the server - kind = 'status' - elif contact == self.contact.nickname: # it's us + def add_message(self, + text, + contact='', + tim=None, + displaymarking=None, + correct_id=None, + message_id=None, + stanza_id=None, + additional_data=None): + + if contact == self.contact.nickname: kind = 'outgoing' else: kind = 'incoming' # muc-specific chatstate
- if kind == 'incoming': # it's a message NOT from us + if kind == 'incoming': # highlighting and sounds highlight, _sound = self.highlighting_for_message(text, tim) # other_tags_for_name.append('muc_nickname_color_%s' % contact) @@ -820,7 +817,7 @@ def _on_room_subject(self, _contact, _signal_name, properties):
if (app.settings.get('show_subject_on_join') or not self.contact.is_joining): - self.add_info_message(text) + self.conversation_view.add_muc_subject(text)
def _on_room_config_changed(self, _contact, _signal_name, properties): # http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify @@ -996,7 +993,7 @@ def _on_user_status_show_changed(self, message = _('{nick} is now {show}{status}').format(nick=nick, show=show, status=status) - self.add_status_message(message) + self.add_info_message(message)
def _on_user_affiliation_changed(self, _contact,
===================================== gajim/gtk/conversation/rows/base.py ===================================== @@ -23,7 +23,6 @@ from gajim.common.i18n import _ from gajim.common.helpers import from_one_line
-from ...conversation_textview import ConversationTextview from ...util import convert_rgba_to_hex from ...util import text_to_color from ...util import wrap_with_event_box
===================================== gajim/gtk/conversation/rows/info.py ===================================== @@ -12,40 +12,30 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see http://www.gnu.org/licenses/.
+import time from datetime import datetime
from gi.repository import GLib from gi.repository import Gtk
from gajim.common.const import AvatarSize -from gajim.common.i18n import _ from gajim.common.styling import process
from .base import BaseRow from ..message_widget import MessageWidget
-class InfoMessageRow(BaseRow): - def __init__(self, - account, - timestamp, - text, - kind, - subject, - history_mode=False): - BaseRow.__init__(self, account, history_mode=history_mode) +class InfoMessage(BaseRow): + def __init__(self, account, text): + BaseRow.__init__(self, account) + self.type = 'info' + timestamp = time.time() self.timestamp = datetime.fromtimestamp(timestamp) self.db_timestamp = timestamp - self.kind = kind - - if subject: - subject_title = _('Subject:') - text = (f'{subject_title}\n' - f'{GLib.markup_escape_text(subject)}\n' - f'{GLib.markup_escape_text(text)}') - else: - text = GLib.markup_escape_text(text) + self.kind = 'info' + + text = GLib.markup_escape_text(text)
avatar_placeholder = Gtk.Box() avatar_placeholder.set_size_request(AvatarSize.ROSTER, -1)
===================================== gajim/gtk/conversation/rows/muc_subject.py ===================================== @@ -0,0 +1,52 @@ +# This file is part of Gajim. +# +# Gajim is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published +# by the Free Software Foundation; version 3 only. +# +# Gajim is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Gajim. If not, see http://www.gnu.org/licenses/. + +import time +from datetime import datetime + +from gi.repository import GLib +from gi.repository import Gtk + +from gajim.common.styling import process + +from .base import BaseRow +from ..message_widget import MessageWidget + + +class MUCSubject(BaseRow): + + type = 'muc-subject' + + def __init__(self, account, text): + BaseRow.__init__(self, account) + + timestamp = time.time() + self.timestamp = datetime.fromtimestamp(timestamp) + self.db_timestamp = timestamp + + text = GLib.markup_escape_text(text) + + # avatar_placeholder = Gtk.Box() + # avatar_placeholder.set_size_request(AvatarSize.ROSTER, -1) + # self.grid.attach(avatar_placeholder, 0, 0, 1, 2) + timestamp_widget = self.create_timestamp_widget(self.timestamp) + timestamp_widget.set_valign(Gtk.Align.START) + self.grid.attach(timestamp_widget, 2, 0, 1, 1) + + result = process(text) + message_widget = MessageWidget(account) + message_widget.add_content(result) + + self.grid.attach(message_widget, 1, 0, 1, 1) + self.show_all()
===================================== gajim/gtk/conversation/view.py ===================================== @@ -30,8 +30,9 @@ from .conversation.rows.read_marker import ReadMarkerRow from .conversation.rows.scroll_hint import ScrollHintRow from .conversation.rows.message import MessageRow -from .conversation.rows.info import InfoMessageRow +from .conversation.rows.info import InfoMessage from .conversation.rows.date import DateRow +from .conversation.rows.muc_subject import MUCSubject
log = logging.getLogger('gajim.gui.conversation_view') @@ -105,6 +106,14 @@ def _sort_func(self, row1, row2): return 0 return -1 if row1.timestamp < row2.timestamp else 1
+ def add_muc_subject(self, text): + subject = MUCSubject(self._account, text) + self._insert_message(subject) + + def add_info_message(self, text): + message = InfoMessage(self._account, text) + self._insert_message(message) + def add_message(self, text, kind, @@ -122,43 +131,32 @@ def add_message(self, if not timestamp: timestamp = time.time()
- muc_subject = bool(subject and self._contact is not None and - self._contact.is_groupchat) - if kind in ('status', 'info') or muc_subject: - message = InfoMessageRow( - self._account, - timestamp, - text, - kind, - subject, - history_mode=self._history_mode) - else: - if correct_id: - self.correct_message(correct_id, message_id, text) - return + if correct_id: + self.correct_message(correct_id, message_id, text) + return
- avatar = self._get_avatar(kind, name) - - is_groupchat = False - if self._contact is not None: - is_groupchat = self._contact.is_groupchat - - message = MessageRow( - self._account, - message_id, - timestamp, - kind, - name, - text, - avatar, - is_groupchat, - additional_data=additional_data, - display_marking=display_marking, - marker=marker, - error=error, - encryption_enabled=self.encryption_enabled, - history_mode=self._history_mode, - log_line_id=log_line_id) + avatar = self._get_avatar(kind, name) + + is_groupchat = False + if self._contact is not None: + is_groupchat = self._contact.is_groupchat + + message = MessageRow( + self._account, + message_id, + timestamp, + kind, + name, + text, + avatar, + is_groupchat, + additional_data=additional_data, + display_marking=display_marking, + marker=marker, + error=error, + encryption_enabled=self.encryption_enabled, + history_mode=self._history_mode, + log_line_id=log_line_id)
if message.type == 'chat': self._message_id_row_map[message.message_id] = message
===================================== gajim/privatechat_control.py ===================================== @@ -116,7 +116,7 @@ def _on_user_status_show_changed(self, message = _('{nick} is now {show}{status}').format(nick=nick, show=show, status=status) - self.add_status_message(message) + self.add_info_message(message) self.update_ui()
# def _on_disconnected(self, event):
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/16488c203cddb121df156602a49098846...