Philipp Hörist pushed to branch archive_cache at gajim / gajim
Commits: e3ad70b9 by lovetox at 2022-09-04T13:37:46+02:00 cfix: fix more stuff
- - - - - 88b53048 by lovetox at 2022-09-04T18:02:25+02:00 cfix: more stuff
- - - - -
6 changed files:
- gajim/common/modules/muc.py - gajim/common/storage/events.py - gajim/gtk/control.py - gajim/gtk/conversation/rows/muc_join_left.py - gajim/gtk/conversation/view.py - pyrightconfig.json
Changes:
===================================== gajim/common/modules/muc.py ===================================== @@ -692,11 +692,14 @@ def _process_occupant_presence_change( event = events.MUCUserJoined( timestamp=timestamp, is_self=properties.is_muc_self_presence, - nick=self.name, + nick=occupant.name, status_codes=properties.muc_status_codes)
+ if occupant.room.is_joined or properties.is_muc_self_presence: + # Don’t store initial presences on join + app.storage.events.store(occupant.room, event) + occupant.update_presence(presence) - app.storage.events.store(self.room, event) occupant.notify('user-joined', event) return
@@ -705,13 +708,13 @@ def _process_occupant_presence_change( event = events.MUCUserLeft( timestamp=timestamp, is_self=properties.is_muc_self_presence, - nick=self.name, + nick=occupant.name, status_codes=properties.muc_status_codes, reason=properties.muc_user.reason, actor=properties.muc_user.actor)
+ app.storage.events.store(occupant.room, event) occupant.update_presence(presence) - app.storage.events.store(self.room, event) occupant.notify('user-left', event) return
@@ -722,11 +725,12 @@ def _process_occupant_presence_change( event = events.MUCUserAffiliationChanged( timestamp=timestamp, is_self=properties.is_muc_self_presence, - nick=self.name, - affiliation=self.affiliation, + nick=occupant.name, + affiliation=presence.affiliation, reason=properties.muc_user.reason, actor=properties.muc_user.actor)
+ app.storage.events.store(occupant.room, event) signals_and_events.append(('user-affiliation-changed', event))
if occupant.role != presence.role: @@ -734,11 +738,12 @@ def _process_occupant_presence_change( event = events.MUCUserRoleChanged( timestamp=timestamp, is_self=properties.is_muc_self_presence, - nick=self.name, - role=self.role, + nick=occupant.name, + role=presence.role, reason=properties.muc_user.reason, actor=properties.muc_user.actor)
+ app.storage.events.store(occupant.room, event) signals_and_events.append(('user-role-changed', event))
if (occupant.status != presence.status or @@ -747,15 +752,16 @@ def _process_occupant_presence_change( event = events.MUCUserStatusShowChanged( timestamp=timestamp, is_self=properties.is_muc_self_presence, - nick=self.name, + nick=occupant.name, status=properties.status, show_value=properties.show.value)
+ app.storage.events.store(occupant, event) + app.storage.events.store(occupant.room, event) signals_and_events.append(('user-status-show-changed', event))
occupant.update_presence(presence) for signal, event in signals_and_events: - app.storage.events.store(self.room, event) occupant.notify(signal, event)
def _process_user_presence(self,
===================================== gajim/common/storage/events.py ===================================== @@ -16,6 +16,7 @@ import dataclasses
from typing import Any +from typing import Iterator from typing import NamedTuple
import json @@ -116,7 +117,7 @@ def load(self, contact: ChatContactT, before: bool, timestamp: float - ) -> list[EventRow]: + ) -> Iterator[EventRow]:
time_operator = '<' if before else '>'
===================================== gajim/gtk/control.py ===================================== @@ -29,7 +29,6 @@ from nbxmpp import JID from nbxmpp.const import StatusCode from nbxmpp.structs import MucSubject -from nbxmpp.structs import PresenceProperties from nbxmpp.modules.security_labels import Displaymarking
from gajim.common import app @@ -167,7 +166,8 @@ def switch_contact(self, contact: Union[BareContact,
if isinstance(contact, GroupchatParticipant): contact.multi_connect({ - 'user-status-show-changed': self._on_user_status_show_changed, + 'user-status-show-changed': + self._on_participant_status_show_changed, })
elif isinstance(contact, GroupchatContact): @@ -176,8 +176,7 @@ def switch_contact(self, contact: Union[BareContact, 'user-left': self._on_user_left, 'user-affiliation-changed': self._on_user_affiliation_changed, 'user-role-changed': self._on_user_role_changed, - 'user-status-show-changed': - self._on_muc_user_status_show_changed, + 'user-status-show-changed': self._on_user_status_show_changed, 'user-nickname-changed': self._on_user_nickname_changed, 'room-kicked': self._on_room_kicked, 'room-destroyed': self._on_room_destroyed, @@ -602,6 +601,7 @@ def _fetch_n_lines_history(self, # if self.conversation_view.reduce_message_count(before): # self._scrolled_view.set_history_complete(before, False)
+ assert self._contact is not None for event in app.storage.events.load(self._contact, before, timestamp): if isinstance(event, events.MUCUserJoined): self._process_muc_user_joined(event) @@ -881,26 +881,41 @@ def _process_muc_user_role_changed(self, self.add_info_message(message, event.timestamp)
def _on_user_status_show_changed(self, - _user_contact: GroupchatParticipant, + contact: GroupchatContact, _signal_name: str, + _user_contact: GroupchatParticipant, event: events.MUCUserStatusShowChanged ) -> None:
self._process_muc_user_status_show_changed(event)
+ def _on_participant_status_show_changed( + self, + contact: GroupchatParticipant, + _signal_name: str, + event: events.MUCUserStatusShowChanged) -> None: + + self._process_muc_user_status_show_changed(event) + def _process_muc_user_status_show_changed( self, event: events.MUCUserStatusShowChanged) -> None:
+ if isinstance(self._contact, GroupchatContact): + contact = self._contact + elif isinstance(self._contact, GroupchatParticipant): + contact = self._contact.room + else: + raise AssertionError + + if not contact.settings.get('print_status'): + return + nick = event.nick status = event.status status = '' if not status else f' - {status}' show = helpers.get_uf_show(event.show_value)
- assert isinstance(self.contact, GroupchatParticipant) - if not self.contact.room.settings.get('print_status'): - return - if event.is_self: message = _('You are now {show}{status}').format(show=show, status=status) @@ -1026,7 +1041,7 @@ def _process_muc_user_joined(self, event: events.MUCUserJoined) -> None:
if not event.is_self: if self.contact.is_joined: - self.conversation_view.add_muc_user_joined(event.nick) + self.conversation_view.add_muc_user_joined(event) return
status_codes = event.status_codes or [] @@ -1066,6 +1081,11 @@ def _process_muc_user_left(self, event: events.MUCUserLeft) -> None: status_codes = event.status_codes or [] nick = event.nick
+ if StatusCode.REMOVED_ERROR in status_codes: + # Handle 333 before 307, some MUCs add both + self.conversation_view.add_muc_user_left(event, error=True) + return + reason = event.reason reason = '' if reason is None else f': {reason}'
@@ -1074,24 +1094,16 @@ def _process_muc_user_left(self, event: events.MUCUserLeft) -> None: actor = '' if actor is None else _(' by {actor}').format( actor=actor)
- # Group Chat: We have been removed from the room message = _('{nick} has been removed from the group ' 'chat{by}{reason}')
- if StatusCode.REMOVED_ERROR in status_codes: - # Handle 333 before 307, some MUCs add both - self.conversation_view.add_muc_user_left( - nick, event.reason, error=True) - - elif StatusCode.REMOVED_KICKED in status_codes: - # Group Chat: User was kicked by Alice: reason + if StatusCode.REMOVED_KICKED in status_codes: message = _('{nick} has been ' 'kicked{actor}{reason}').format(nick=nick, actor=actor, reason=reason)
elif StatusCode.REMOVED_BANNED in status_codes: - # Group Chat: User was banned by Alice: reason message = _('{nick} has been ' 'banned{actor}{reason}').format(nick=nick, actor=actor, @@ -1106,25 +1118,11 @@ def _process_muc_user_left(self, event: events.MUCUserLeft) -> None: message = message.format(nick=nick, by=actor, reason=reason)
else: - self.conversation_view.add_muc_user_left(nick, event.reason) + self.conversation_view.add_muc_user_left(event) return
self.add_info_message(message, event.timestamp)
- def _on_muc_user_status_show_changed(self, - contact: GroupchatContact, - _signal_name: str, - user_contact: GroupchatParticipant, - properties: PresenceProperties - ) -> None: - - if not contact.settings.get('print_status'): - return - - self.conversation_view.add_user_status(user_contact.name, - user_contact.show.value, - user_contact.status) - def add_muc_message(self, text: str, tim: float,
===================================== gajim/gtk/conversation/rows/muc_join_left.py ===================================== @@ -27,13 +27,19 @@
class MUCJoinLeft(BaseRow): - def __init__(self, type_: str, account: str, nick: str, + def __init__(self, + type_: str, + account: str, + nick: str, reason: Optional[str] = None, - error: bool = False): + error: bool = False, + timestamp: Optional[float] = None + ) -> None: + BaseRow.__init__(self, account)
self.type = type_ - timestamp = time.time() + timestamp = timestamp or time.time() self.timestamp = datetime.fromtimestamp(timestamp) self.db_timestamp = timestamp
===================================== gajim/gtk/conversation/view.py ===================================== @@ -37,9 +37,7 @@
from gajim.common import app from gajim.common import types -from gajim.common.events import JingleRequestReceived -from gajim.common.events import FileRequestReceivedEvent -from gajim.common.events import FileRequestSent +from gajim.common import events from gajim.common.helpers import AdditionalDataDict from gajim.common.helpers import to_user_string from gajim.common.helpers import get_start_of_day @@ -175,26 +173,29 @@ def add_muc_subject(self, self._insert_message(muc_subject)
def add_muc_user_left(self, - nick: str, - reason: Optional[str], - error: bool = False) -> None: + event: events.MUCUserLeft, + error: bool = False + ) -> None: + assert isinstance(self._contact, GroupchatContact) if not self._contact.settings.get('print_join_left'): return join_left = MUCJoinLeft('muc-user-left', self._contact.account, - nick, - reason=reason, - error=error) + event.nick, + reason=event.reason, + error=error, + timestamp=event.timestamp) self._insert_message(join_left)
- def add_muc_user_joined(self, nick: str) -> None: + def add_muc_user_joined(self, event: events.MUCUserJoined) -> None: assert isinstance(self._contact, GroupchatContact) if not self._contact.settings.get('print_join_left'): return join_left = MUCJoinLeft('muc-user-joined', self._contact.account, - nick) + event.nick, + timestamp=event.timestamp) self._insert_message(join_left)
def add_user_status(self, name: str, show: str, status: str) -> None: @@ -215,8 +216,8 @@ def add_file_transfer(self, transfer: HTTPFileTransfer) -> None:
def add_jingle_file_transfer(self, event: Union[ - FileRequestReceivedEvent, - FileRequestSent, + events.FileRequestReceivedEvent, + events.FileRequestSent, None] = None, db_message: Optional[ConversationRow] = None ) -> None: @@ -230,7 +231,7 @@ def add_jingle_file_transfer(self, self._insert_message(jingle_transfer_row)
def add_call_message(self, - event: Optional[JingleRequestReceived] = None, + event: Optional[events.JingleRequestReceived] = None, db_message: Optional[ConversationRow] = None ) -> None: assert isinstance(self._contact, BareContact)
===================================== pyrightconfig.json ===================================== @@ -38,7 +38,7 @@ "gajim/common/regex.py", "gajim/common/setting_values.py", "gajim/common/sound.py", - "gajim/common/storage/", + "gajim/common/storage/*", "gajim/common/task_manager.py", "gajim/gajim.py", "gajim/gajim_remote.py",
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/0a0b70cff2a45286e6737cc44839b227...