diff --git a/gajim/chat_control.py b/gajim/chat_control.py index 93f833295ccdb1114076a3158810f7288ca40d10..9847cba1ec185741fcf830f4dad3877686f7e6f5 100644 --- a/gajim/chat_control.py +++ b/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(): diff --git a/gajim/chat_control_base.py b/gajim/chat_control_base.py index 65b608a644ab131fe28607038334966a56e42e23..724e34ac4106f129752703e74c170a15d867e812 100644 --- a/gajim/chat_control_base.py +++ b/gajim/chat_control_base.py @@ -1072,13 +1072,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, @@ -1107,16 +1102,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') @@ -1333,7 +1325,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): @@ -1345,6 +1337,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( diff --git a/gajim/groupchat_control.py b/gajim/groupchat_control.py index 4455cc145ffd94dd41d6046854cc80c63c64f98a..b09476d53ed44d71196d819a206fc55ad2d66d7c 100644 --- a/gajim/groupchat_control.py +++ b/gajim/groupchat_control.py @@ -754,26 +754,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) @@ -883,7 +880,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 @@ -1059,7 +1056,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, diff --git a/gajim/gtk/conversation/rows/base.py b/gajim/gtk/conversation/rows/base.py index 6710b4d8ea55e82d48795855ce6f0e90a0630da4..1228af233005cf77cb9c41ebd57e0eeebc3ff5a1 100644 --- a/gajim/gtk/conversation/rows/base.py +++ b/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 diff --git a/gajim/gtk/conversation/rows/info.py b/gajim/gtk/conversation/rows/info.py index a6e0e4a0b830c29f0f7195e4677954af94871a39..243111644e00269decc0b03fa39684af9cc4a05e 100644 --- a/gajim/gtk/conversation/rows/info.py +++ b/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) diff --git a/gajim/gtk/conversation/rows/muc_subject.py b/gajim/gtk/conversation/rows/muc_subject.py new file mode 100644 index 0000000000000000000000000000000000000000..750bbd1d5c3d84008b6888d82f86d13a1cbbffb3 --- /dev/null +++ b/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() diff --git a/gajim/gtk/conversation/view.py b/gajim/gtk/conversation/view.py index 573d37b5248c28c4ae1eb033db0b0c8a90b73746..ff9b33734c2422edb13f882d55b2d6b6281ccd98 100644 --- a/gajim/gtk/conversation/view.py +++ b/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 diff --git a/gajim/privatechat_control.py b/gajim/privatechat_control.py index 1ea5bcc89cbbb8539783e845f692e94b1348f3f8..6193c8b308da006ade9fdcf94e1a2b59240eedfa 100644 --- a/gajim/privatechat_control.py +++ b/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):