Philipp Hörist pushed to branch master at gajim / gajim
Commits: dc61b224 by lovetox at 2022-01-21T22:48:24+01:00 ConversationView: Improve displaying of user status in single chats
- Don’t load user status history - Use UserStatus row for displaying
- - - - -
8 changed files:
- gajim/common/storage/archive.py - gajim/gtk/controls/base.py - gajim/gtk/controls/chat.py - gajim/gtk/controls/groupchat.py - gajim/gtk/conversation/rows/muc_user_status.py → gajim/gtk/conversation/rows/user_status.py - gajim/gtk/conversation/view.py - gajim/gtk/types.py - pyrightconfig.json
Changes:
===================================== gajim/common/storage/archive.py ===================================== @@ -386,7 +386,8 @@ def get_conversation_before_after(self, """ jids = [jid] account_id = self.get_account_id(account) - kinds = map(str, [KindConstant.ERROR]) + kinds = map(str, [KindConstant.ERROR, + KindConstant.STATUS])
if before: time_order = 'AND time < ? ORDER BY time DESC, log_line_id DESC'
===================================== gajim/gtk/controls/base.py ===================================== @@ -1486,11 +1486,6 @@ def add_messages(self, messages: list[ConversationRow]): if not msg.message: continue
- if msg.kind in (KindConstant.STATUS, - KindConstant.GCSTATUS): - self.conversation_view.add_info_message(msg.message) - continue - message_text = msg.message
contact_name = msg.contact_name
===================================== gajim/gtk/controls/chat.py ===================================== @@ -740,15 +740,12 @@ def _on_client_state_changed(self, self.update_actions()
def _on_presence_received(self, event: events.PresenceReceived) -> None: - uf_show = helpers.get_uf_show(event.show) - name = self.contact.name - self.update_ui()
if not app.settings.get('print_status_in_chats'): return
- status = f'- {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_info_message(status_line) + contact = self._client.get_module('Contacts').get_contact(event.fjid) + self.conversation_view.add_user_status(self.contact.name, + contact.show.value, + contact.status)
===================================== gajim/gtk/controls/groupchat.py ===================================== @@ -1064,9 +1064,9 @@ def _on_user_status_show_changed(self, properties: MessageProperties ) -> None:
- self.conversation_view.add_muc_user_status( - user_contact, - properties.is_muc_self_presence) + self.conversation_view.add_user_status(user_contact.name, + user_contact.show.value, + user_contact.status)
def _on_user_affiliation_changed(self, _contact: GroupchatContact,
===================================== gajim/gtk/conversation/rows/muc_user_status.py → gajim/gtk/conversation/rows/user_status.py ===================================== @@ -12,27 +12,32 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see http://www.gnu.org/licenses/.
+from __future__ import annotations + +from typing import Optional + import time from datetime import datetime
from gi.repository import Gtk
-from gajim.common.modules.contacts import GroupchatParticipant from gajim.common.i18n import _ from gajim.common.const import AvatarSize from gajim.common.helpers import get_uf_show
from .widgets import SimpleLabel from .base import BaseRow - from ..message_widget import MessageWidget - from ...avatar import get_show_circle
-class MUCUserStatus(BaseRow): - def __init__(self, account: str, user_contact: GroupchatParticipant, - is_self: bool) -> None: +class UserStatus(BaseRow): + def __init__(self, + account: str, + name: str, + show: str, + status: Optional[str]) -> None: + BaseRow.__init__(self, account)
self.type = 'muc-user-status' @@ -46,22 +51,23 @@ def __init__(self, account: str, user_contact: GroupchatParticipant,
show_icon = Gtk.Image() show_icon.set_opacity(0.6) - surface = get_show_circle( - user_contact.show.value, - 16, - self.get_scale_factor()) + surface = get_show_circle(show, 16, self.get_scale_factor()) show_icon.set_from_surface(surface) self.grid.attach(show_icon, 1, 0, 1, 1)
+ show = get_uf_show(show) + + message = _('{nick} is now {show}').format(nick=name, show=show) + self._label = SimpleLabel() - self._label.set_text(self._make_show_text(user_contact, is_self)) + self._label.set_text(message) self._label.get_style_context().add_class('gajim-status-message') self.grid.attach(self._label, 2, 0, 1, 1)
- if user_contact.status is not None: + if status is not None: message_widget = MessageWidget(account) message_widget.get_style_context().add_class('gajim-status-message') - message_widget.add_with_styling(user_contact.status) + message_widget.add_with_styling(status) self.grid.attach(message_widget, 2, 1, 1, 1)
timestamp_widget = self.create_timestamp_widget(self.timestamp) @@ -71,17 +77,3 @@ def __init__(self, account: str, user_contact: GroupchatParticipant, self.grid.attach(timestamp_widget, 3, 0, 1, 1)
self.show_all() - - @staticmethod - def _make_show_text(user_contact: GroupchatParticipant, - is_self: bool) -> str: - nick = user_contact.name - show = get_uf_show(user_contact.show.value) - - if is_self: - message = _('You are now {show}').format(show=show) - - else: - message = _('{nick} is now {show}').format(nick=nick, - show=show) - return message
===================================== gajim/gtk/conversation/view.py ===================================== @@ -46,7 +46,6 @@ from gajim.common.storage.archive import ConversationRow from gajim.common.modules.contacts import BareContact from gajim.common.modules.contacts import GroupchatContact -from gajim.common.modules.contacts import GroupchatParticipant from gajim.common.types import ChatContactT
from .rows.base import BaseRow @@ -61,7 +60,7 @@ from .rows.file_transfer_jingle import FileTransferJingleRow from .rows.muc_subject import MUCSubject from .rows.muc_join_left import MUCJoinLeft -from .rows.muc_user_status import MUCUserStatus +from .rows.user_status import UserStatus
log = logging.getLogger('gajim.gui.conversation_view')
@@ -222,9 +221,8 @@ def add_muc_user_joined(self, nick: str) -> None: nick) self._insert_message(join_left)
- def add_muc_user_status(self, user_contact: GroupchatParticipant, - is_self: bool) -> None: - user_status = MUCUserStatus(self._account, user_contact, is_self) + def add_user_status(self, name: str, show: str, status: str) -> None: + user_status = UserStatus(self._account, name, show, status) self._insert_message(user_status)
def add_info_message(self, text: str) -> None:
===================================== gajim/gtk/types.py ===================================== @@ -33,7 +33,7 @@ from .conversation.rows.message import MessageRow from .conversation.rows.muc_join_left import MUCJoinLeft from .conversation.rows.muc_subject import MUCSubject - from .conversation.rows.muc_user_status import MUCUserStatus + from .conversation.rows.user_status import UserStatus from .conversation.rows.read_marker import ReadMarkerRow from .conversation.rows.scroll_hint import ScrollHintRow
===================================== pyrightconfig.json ===================================== @@ -45,7 +45,7 @@ "gajim/gtk/conversation/rows/message.py", "gajim/gtk/conversation/rows/muc_join_left.py", "gajim/gtk/conversation/rows/muc_subject.py", - "gajim/gtk/conversation/rows/muc_user_status.py", + "gajim/gtk/conversation/rows/user_status.py", "gajim/gtk/conversation/rows/read_marker.py", "gajim/gtk/conversation/rows/scroll_hint.py", "gajim/gtk/conversation/rows/widgets.py",
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/dc61b224448cdfc003a5332eff32db41b...