diff --git a/gajim/gtk/controls/groupchat.py b/gajim/gtk/controls/groupchat.py index c4a8d4343293aba34fbd4bae96ed4fd5cc90b09a..fbfe63dda10e3e0e8087489f9c6103be25cfe44a 100644 --- a/gajim/gtk/controls/groupchat.py +++ b/gajim/gtk/controls/groupchat.py @@ -51,7 +51,6 @@ from gajim.common.const import AvatarSize from gajim.common.i18n import _ -from gajim.common.const import MUCJoinedState from gajim.common.structs import OutgoingMessage from gajim.gui.controls.base import BaseControl @@ -89,9 +88,9 @@ class GroupchatControl(BaseControl): def __init__(self, account, jid): BaseControl.__init__(self, - 'groupchat_control', - account, - jid) + 'groupchat_control', + account, + jid) self._client.connect_signal('state-changed', self._on_client_state_changed) @@ -1035,23 +1034,9 @@ def _on_user_status_show_changed(self, user_contact, properties): - if not self.contact.settings.get('print_status'): - return - - nick = user_contact.name - status = user_contact.status - status = '' if status is None else ' - %s' % status - show = helpers.get_uf_show(user_contact.show.value) - - if properties.is_muc_self_presence: - message = _('You are now {show}{status}').format(show=show, - status=status) - - else: - message = _('{nick} is now {show}{status}').format(nick=nick, - show=show, - status=status) - self.add_info_message(message) + self.conversation_view.add_muc_user_status( + user_contact, + properties.is_muc_self_presence) def _on_user_affiliation_changed(self, _contact, diff --git a/gajim/gtk/conversation/rows/muc_user_status.py b/gajim/gtk/conversation/rows/muc_user_status.py new file mode 100644 index 0000000000000000000000000000000000000000..1ecdbb1edafc03920c8ad99b0653f45fc2ec67b2 --- /dev/null +++ b/gajim/gtk/conversation/rows/muc_user_status.py @@ -0,0 +1,73 @@ +# 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 Gtk + +from gajim.common.i18n import _ +from gajim.common.const import AvatarSize +from gajim.common import helpers + +from .widgets import SimpleLabel +from .base import BaseRow + + +class MUCUserStatus(BaseRow): + def __init__(self, account, user_contact, is_self): + BaseRow.__init__(self, account) + + self.type = 'muc-user-status' + timestamp = time.time() + self.timestamp = datetime.fromtimestamp(timestamp) + self.db_timestamp = timestamp + + avatar_placeholder = Gtk.Box() + avatar_placeholder.set_size_request(AvatarSize.ROSTER, -1) + self.grid.attach(avatar_placeholder, 0, 0, 1, 1) + + icon_name = 'feather-info-symbolic' + icon = Gtk.Image.new_from_icon_name(icon_name, Gtk.IconSize.MENU) + self.grid.attach(icon, 1, 0, 1, 1) + + self._label = SimpleLabel() + self._label.set_text(self._make_text(user_contact, is_self)) + self._label.get_style_context().add_class('gajim-status-message') + self.grid.attach(self._label, 2, 0, 1, 1) + + timestamp_widget = self.create_timestamp_widget(self.timestamp) + timestamp_widget.set_hexpand(True) + timestamp_widget.set_halign(Gtk.Align.END) + timestamp_widget.set_valign(Gtk.Align.START) + self.grid.attach(timestamp_widget, 3, 0, 1, 1) + + self.show_all() + + @staticmethod + def _make_text(user_contact, is_self): + nick = user_contact.name + status = user_contact.status + status = '' if status is None else ' - %s' % status + show = helpers.get_uf_show(user_contact.show.value) + + if is_self: + message = _('You are now {show}{status}').format(show=show, + status=status) + + else: + message = _('{nick} is now {show}{status}').format(nick=nick, + show=show, + status=status) + return message diff --git a/gajim/gtk/conversation/view.py b/gajim/gtk/conversation/view.py index 87f8a8921ccb5c9f2a1a526322d6f5cfaf5c6a92..74f46351f076de413b8fcd58b4dfd8d38b53fced 100644 --- a/gajim/gtk/conversation/view.py +++ b/gajim/gtk/conversation/view.py @@ -34,6 +34,7 @@ from .conversation.rows.date import DateRow from .conversation.rows.muc_subject import MUCSubject from .conversation.rows.muc_join_left import MUCJoinLeft +from .conversation.rows.muc_user_status import MUCUserStatus log = logging.getLogger('gajim.gui.conversation_view') @@ -80,6 +81,11 @@ def __init__(self, account, contact, history_mode=False): account=self._account, jid=self._contact.jid) + app.settings.connect_signal('print_status', + self._on_contact_setting_changed, + account=self._account, + jid=self._contact.jid) + if self._contact is not None: self._read_marker_row = ReadMarkerRow(self._account, self._contact) self.add(self._read_marker_row) @@ -116,6 +122,9 @@ def _sort_func(self, row1, row2): def _filter_func(self, row): if row.type in ('muc-user-joined', 'muc-user-left'): return self._contact.settings.get('print_join_left') + if row.type == 'muc-user-status': + return self._contact.settings.get('print_status') + return True def add_muc_subject(self, text, nick, date): @@ -136,6 +145,10 @@ def add_muc_user_joined(self, nick): nick) self._insert_message(join_left) + def add_muc_user_status(self, user_contact, is_self): + user_status = MUCUserStatus(self._account, user_contact, is_self) + self._insert_message(user_status) + def add_info_message(self, text): message = InfoMessage(self._account, text) self._insert_message(message)