Philipp Hörist pushed to branch archive_cache at gajim / gajim
Commits:
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:
| ... | ... | @@ -692,11 +692,14 @@ def _process_occupant_presence_change( |
| 692 | 692 | event = events.MUCUserJoined(
|
| 693 | 693 | timestamp=timestamp,
|
| 694 | 694 | is_self=properties.is_muc_self_presence,
|
| 695 | - nick=self.name,
|
|
| 695 | + nick=occupant.name,
|
|
| 696 | 696 | status_codes=properties.muc_status_codes)
|
| 697 | 697 | |
| 698 | + if occupant.room.is_joined or properties.is_muc_self_presence:
|
|
| 699 | + # Don’t store initial presences on join
|
|
| 700 | + app.storage.events.store(occupant.room, event)
|
|
| 701 | + |
|
| 698 | 702 | occupant.update_presence(presence)
|
| 699 | - app.storage.events.store(self.room, event)
|
|
| 700 | 703 | occupant.notify('user-joined', event)
|
| 701 | 704 | return
|
| 702 | 705 | |
| ... | ... | @@ -705,13 +708,13 @@ def _process_occupant_presence_change( |
| 705 | 708 | event = events.MUCUserLeft(
|
| 706 | 709 | timestamp=timestamp,
|
| 707 | 710 | is_self=properties.is_muc_self_presence,
|
| 708 | - nick=self.name,
|
|
| 711 | + nick=occupant.name,
|
|
| 709 | 712 | status_codes=properties.muc_status_codes,
|
| 710 | 713 | reason=properties.muc_user.reason,
|
| 711 | 714 | actor=properties.muc_user.actor)
|
| 712 | 715 | |
| 716 | + app.storage.events.store(occupant.room, event)
|
|
| 713 | 717 | occupant.update_presence(presence)
|
| 714 | - app.storage.events.store(self.room, event)
|
|
| 715 | 718 | occupant.notify('user-left', event)
|
| 716 | 719 | return
|
| 717 | 720 | |
| ... | ... | @@ -722,11 +725,12 @@ def _process_occupant_presence_change( |
| 722 | 725 | event = events.MUCUserAffiliationChanged(
|
| 723 | 726 | timestamp=timestamp,
|
| 724 | 727 | is_self=properties.is_muc_self_presence,
|
| 725 | - nick=self.name,
|
|
| 726 | - affiliation=self.affiliation,
|
|
| 728 | + nick=occupant.name,
|
|
| 729 | + affiliation=presence.affiliation,
|
|
| 727 | 730 | reason=properties.muc_user.reason,
|
| 728 | 731 | actor=properties.muc_user.actor)
|
| 729 | 732 | |
| 733 | + app.storage.events.store(occupant.room, event)
|
|
| 730 | 734 | signals_and_events.append(('user-affiliation-changed', event))
|
| 731 | 735 | |
| 732 | 736 | if occupant.role != presence.role:
|
| ... | ... | @@ -734,11 +738,12 @@ def _process_occupant_presence_change( |
| 734 | 738 | event = events.MUCUserRoleChanged(
|
| 735 | 739 | timestamp=timestamp,
|
| 736 | 740 | is_self=properties.is_muc_self_presence,
|
| 737 | - nick=self.name,
|
|
| 738 | - role=self.role,
|
|
| 741 | + nick=occupant.name,
|
|
| 742 | + role=presence.role,
|
|
| 739 | 743 | reason=properties.muc_user.reason,
|
| 740 | 744 | actor=properties.muc_user.actor)
|
| 741 | 745 | |
| 746 | + app.storage.events.store(occupant.room, event)
|
|
| 742 | 747 | signals_and_events.append(('user-role-changed', event))
|
| 743 | 748 | |
| 744 | 749 | if (occupant.status != presence.status or
|
| ... | ... | @@ -747,15 +752,16 @@ def _process_occupant_presence_change( |
| 747 | 752 | event = events.MUCUserStatusShowChanged(
|
| 748 | 753 | timestamp=timestamp,
|
| 749 | 754 | is_self=properties.is_muc_self_presence,
|
| 750 | - nick=self.name,
|
|
| 755 | + nick=occupant.name,
|
|
| 751 | 756 | status=properties.status,
|
| 752 | 757 | show_value=properties.show.value)
|
| 753 | 758 | |
| 759 | + app.storage.events.store(occupant, event)
|
|
| 760 | + app.storage.events.store(occupant.room, event)
|
|
| 754 | 761 | signals_and_events.append(('user-status-show-changed', event))
|
| 755 | 762 | |
| 756 | 763 | occupant.update_presence(presence)
|
| 757 | 764 | for signal, event in signals_and_events:
|
| 758 | - app.storage.events.store(self.room, event)
|
|
| 759 | 765 | occupant.notify(signal, event)
|
| 760 | 766 | |
| 761 | 767 | def _process_user_presence(self,
|
| ... | ... | @@ -16,6 +16,7 @@ |
| 16 | 16 | import dataclasses
|
| 17 | 17 | |
| 18 | 18 | from typing import Any
|
| 19 | +from typing import Iterator
|
|
| 19 | 20 | from typing import NamedTuple
|
| 20 | 21 | |
| 21 | 22 | import json
|
| ... | ... | @@ -116,7 +117,7 @@ def load(self, |
| 116 | 117 | contact: ChatContactT,
|
| 117 | 118 | before: bool,
|
| 118 | 119 | timestamp: float
|
| 119 | - ) -> list[EventRow]:
|
|
| 120 | + ) -> Iterator[EventRow]:
|
|
| 120 | 121 | |
| 121 | 122 | time_operator = '<' if before else '>'
|
| 122 | 123 |
| ... | ... | @@ -29,7 +29,6 @@ |
| 29 | 29 | from nbxmpp import JID
|
| 30 | 30 | from nbxmpp.const import StatusCode
|
| 31 | 31 | from nbxmpp.structs import MucSubject
|
| 32 | -from nbxmpp.structs import PresenceProperties
|
|
| 33 | 32 | from nbxmpp.modules.security_labels import Displaymarking
|
| 34 | 33 | |
| 35 | 34 | from gajim.common import app
|
| ... | ... | @@ -167,7 +166,8 @@ def switch_contact(self, contact: Union[BareContact, |
| 167 | 166 | |
| 168 | 167 | if isinstance(contact, GroupchatParticipant):
|
| 169 | 168 | contact.multi_connect({
|
| 170 | - 'user-status-show-changed': self._on_user_status_show_changed,
|
|
| 169 | + 'user-status-show-changed':
|
|
| 170 | + self._on_participant_status_show_changed,
|
|
| 171 | 171 | })
|
| 172 | 172 | |
| 173 | 173 | elif isinstance(contact, GroupchatContact):
|
| ... | ... | @@ -176,8 +176,7 @@ def switch_contact(self, contact: Union[BareContact, |
| 176 | 176 | 'user-left': self._on_user_left,
|
| 177 | 177 | 'user-affiliation-changed': self._on_user_affiliation_changed,
|
| 178 | 178 | 'user-role-changed': self._on_user_role_changed,
|
| 179 | - 'user-status-show-changed':
|
|
| 180 | - self._on_muc_user_status_show_changed,
|
|
| 179 | + 'user-status-show-changed': self._on_user_status_show_changed,
|
|
| 181 | 180 | 'user-nickname-changed': self._on_user_nickname_changed,
|
| 182 | 181 | 'room-kicked': self._on_room_kicked,
|
| 183 | 182 | 'room-destroyed': self._on_room_destroyed,
|
| ... | ... | @@ -602,6 +601,7 @@ def _fetch_n_lines_history(self, |
| 602 | 601 | # if self.conversation_view.reduce_message_count(before):
|
| 603 | 602 | # self._scrolled_view.set_history_complete(before, False)
|
| 604 | 603 | |
| 604 | + assert self._contact is not None
|
|
| 605 | 605 | for event in app.storage.events.load(self._contact, before, timestamp):
|
| 606 | 606 | if isinstance(event, events.MUCUserJoined):
|
| 607 | 607 | self._process_muc_user_joined(event)
|
| ... | ... | @@ -881,26 +881,41 @@ def _process_muc_user_role_changed(self, |
| 881 | 881 | self.add_info_message(message, event.timestamp)
|
| 882 | 882 | |
| 883 | 883 | def _on_user_status_show_changed(self,
|
| 884 | - _user_contact: GroupchatParticipant,
|
|
| 884 | + contact: GroupchatContact,
|
|
| 885 | 885 | _signal_name: str,
|
| 886 | + _user_contact: GroupchatParticipant,
|
|
| 886 | 887 | event: events.MUCUserStatusShowChanged
|
| 887 | 888 | ) -> None:
|
| 888 | 889 | |
| 889 | 890 | self._process_muc_user_status_show_changed(event)
|
| 890 | 891 | |
| 892 | + def _on_participant_status_show_changed(
|
|
| 893 | + self,
|
|
| 894 | + contact: GroupchatParticipant,
|
|
| 895 | + _signal_name: str,
|
|
| 896 | + event: events.MUCUserStatusShowChanged) -> None:
|
|
| 897 | + |
|
| 898 | + self._process_muc_user_status_show_changed(event)
|
|
| 899 | + |
|
| 891 | 900 | def _process_muc_user_status_show_changed(
|
| 892 | 901 | self,
|
| 893 | 902 | event: events.MUCUserStatusShowChanged) -> None:
|
| 894 | 903 | |
| 904 | + if isinstance(self._contact, GroupchatContact):
|
|
| 905 | + contact = self._contact
|
|
| 906 | + elif isinstance(self._contact, GroupchatParticipant):
|
|
| 907 | + contact = self._contact.room
|
|
| 908 | + else:
|
|
| 909 | + raise AssertionError
|
|
| 910 | + |
|
| 911 | + if not contact.settings.get('print_status'):
|
|
| 912 | + return
|
|
| 913 | + |
|
| 895 | 914 | nick = event.nick
|
| 896 | 915 | status = event.status
|
| 897 | 916 | status = '' if not status else f' - {status}'
|
| 898 | 917 | show = helpers.get_uf_show(event.show_value)
|
| 899 | 918 | |
| 900 | - assert isinstance(self.contact, GroupchatParticipant)
|
|
| 901 | - if not self.contact.room.settings.get('print_status'):
|
|
| 902 | - return
|
|
| 903 | - |
|
| 904 | 919 | if event.is_self:
|
| 905 | 920 | message = _('You are now {show}{status}').format(show=show,
|
| 906 | 921 | status=status)
|
| ... | ... | @@ -1026,7 +1041,7 @@ def _process_muc_user_joined(self, event: events.MUCUserJoined) -> None: |
| 1026 | 1041 | |
| 1027 | 1042 | if not event.is_self:
|
| 1028 | 1043 | if self.contact.is_joined:
|
| 1029 | - self.conversation_view.add_muc_user_joined(event.nick)
|
|
| 1044 | + self.conversation_view.add_muc_user_joined(event)
|
|
| 1030 | 1045 | return
|
| 1031 | 1046 | |
| 1032 | 1047 | status_codes = event.status_codes or []
|
| ... | ... | @@ -1066,6 +1081,11 @@ def _process_muc_user_left(self, event: events.MUCUserLeft) -> None: |
| 1066 | 1081 | status_codes = event.status_codes or []
|
| 1067 | 1082 | nick = event.nick
|
| 1068 | 1083 | |
| 1084 | + if StatusCode.REMOVED_ERROR in status_codes:
|
|
| 1085 | + # Handle 333 before 307, some MUCs add both
|
|
| 1086 | + self.conversation_view.add_muc_user_left(event, error=True)
|
|
| 1087 | + return
|
|
| 1088 | + |
|
| 1069 | 1089 | reason = event.reason
|
| 1070 | 1090 | reason = '' if reason is None else f': {reason}'
|
| 1071 | 1091 | |
| ... | ... | @@ -1074,24 +1094,16 @@ def _process_muc_user_left(self, event: events.MUCUserLeft) -> None: |
| 1074 | 1094 | actor = '' if actor is None else _(' by {actor}').format(
|
| 1075 | 1095 | actor=actor)
|
| 1076 | 1096 | |
| 1077 | - # Group Chat: We have been removed from the room
|
|
| 1078 | 1097 | message = _('{nick} has been removed from the group '
|
| 1079 | 1098 | 'chat{by}{reason}')
|
| 1080 | 1099 | |
| 1081 | - if StatusCode.REMOVED_ERROR in status_codes:
|
|
| 1082 | - # Handle 333 before 307, some MUCs add both
|
|
| 1083 | - self.conversation_view.add_muc_user_left(
|
|
| 1084 | - nick, event.reason, error=True)
|
|
| 1085 | - |
|
| 1086 | - elif StatusCode.REMOVED_KICKED in status_codes:
|
|
| 1087 | - # Group Chat: User was kicked by Alice: reason
|
|
| 1100 | + if StatusCode.REMOVED_KICKED in status_codes:
|
|
| 1088 | 1101 | message = _('{nick} has been '
|
| 1089 | 1102 | 'kicked{actor}{reason}').format(nick=nick,
|
| 1090 | 1103 | actor=actor,
|
| 1091 | 1104 | reason=reason)
|
| 1092 | 1105 | |
| 1093 | 1106 | elif StatusCode.REMOVED_BANNED in status_codes:
|
| 1094 | - # Group Chat: User was banned by Alice: reason
|
|
| 1095 | 1107 | message = _('{nick} has been '
|
| 1096 | 1108 | 'banned{actor}{reason}').format(nick=nick,
|
| 1097 | 1109 | actor=actor,
|
| ... | ... | @@ -1106,25 +1118,11 @@ def _process_muc_user_left(self, event: events.MUCUserLeft) -> None: |
| 1106 | 1118 | message = message.format(nick=nick, by=actor, reason=reason)
|
| 1107 | 1119 | |
| 1108 | 1120 | else:
|
| 1109 | - self.conversation_view.add_muc_user_left(nick, event.reason)
|
|
| 1121 | + self.conversation_view.add_muc_user_left(event)
|
|
| 1110 | 1122 | return
|
| 1111 | 1123 | |
| 1112 | 1124 | self.add_info_message(message, event.timestamp)
|
| 1113 | 1125 | |
| 1114 | - def _on_muc_user_status_show_changed(self,
|
|
| 1115 | - contact: GroupchatContact,
|
|
| 1116 | - _signal_name: str,
|
|
| 1117 | - user_contact: GroupchatParticipant,
|
|
| 1118 | - properties: PresenceProperties
|
|
| 1119 | - ) -> None:
|
|
| 1120 | - |
|
| 1121 | - if not contact.settings.get('print_status'):
|
|
| 1122 | - return
|
|
| 1123 | - |
|
| 1124 | - self.conversation_view.add_user_status(user_contact.name,
|
|
| 1125 | - user_contact.show.value,
|
|
| 1126 | - user_contact.status)
|
|
| 1127 | - |
|
| 1128 | 1126 | def add_muc_message(self,
|
| 1129 | 1127 | text: str,
|
| 1130 | 1128 | tim: float,
|
| ... | ... | @@ -27,13 +27,19 @@ |
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | class MUCJoinLeft(BaseRow):
|
| 30 | - def __init__(self, type_: str, account: str, nick: str,
|
|
| 30 | + def __init__(self,
|
|
| 31 | + type_: str,
|
|
| 32 | + account: str,
|
|
| 33 | + nick: str,
|
|
| 31 | 34 | reason: Optional[str] = None,
|
| 32 | - error: bool = False):
|
|
| 35 | + error: bool = False,
|
|
| 36 | + timestamp: Optional[float] = None
|
|
| 37 | + ) -> None:
|
|
| 38 | + |
|
| 33 | 39 | BaseRow.__init__(self, account)
|
| 34 | 40 | |
| 35 | 41 | self.type = type_
|
| 36 | - timestamp = time.time()
|
|
| 42 | + timestamp = timestamp or time.time()
|
|
| 37 | 43 | self.timestamp = datetime.fromtimestamp(timestamp)
|
| 38 | 44 | self.db_timestamp = timestamp
|
| 39 | 45 |
| ... | ... | @@ -37,9 +37,7 @@ |
| 37 | 37 | |
| 38 | 38 | from gajim.common import app
|
| 39 | 39 | from gajim.common import types
|
| 40 | -from gajim.common.events import JingleRequestReceived
|
|
| 41 | -from gajim.common.events import FileRequestReceivedEvent
|
|
| 42 | -from gajim.common.events import FileRequestSent
|
|
| 40 | +from gajim.common import events
|
|
| 43 | 41 | from gajim.common.helpers import AdditionalDataDict
|
| 44 | 42 | from gajim.common.helpers import to_user_string
|
| 45 | 43 | from gajim.common.helpers import get_start_of_day
|
| ... | ... | @@ -175,26 +173,29 @@ def add_muc_subject(self, |
| 175 | 173 | self._insert_message(muc_subject)
|
| 176 | 174 | |
| 177 | 175 | def add_muc_user_left(self,
|
| 178 | - nick: str,
|
|
| 179 | - reason: Optional[str],
|
|
| 180 | - error: bool = False) -> None:
|
|
| 176 | + event: events.MUCUserLeft,
|
|
| 177 | + error: bool = False
|
|
| 178 | + ) -> None:
|
|
| 179 | + |
|
| 181 | 180 | assert isinstance(self._contact, GroupchatContact)
|
| 182 | 181 | if not self._contact.settings.get('print_join_left'):
|
| 183 | 182 | return
|
| 184 | 183 | join_left = MUCJoinLeft('muc-user-left',
|
| 185 | 184 | self._contact.account,
|
| 186 | - nick,
|
|
| 187 | - reason=reason,
|
|
| 188 | - error=error)
|
|
| 185 | + event.nick,
|
|
| 186 | + reason=event.reason,
|
|
| 187 | + error=error,
|
|
| 188 | + timestamp=event.timestamp)
|
|
| 189 | 189 | self._insert_message(join_left)
|
| 190 | 190 | |
| 191 | - def add_muc_user_joined(self, nick: str) -> None:
|
|
| 191 | + def add_muc_user_joined(self, event: events.MUCUserJoined) -> None:
|
|
| 192 | 192 | assert isinstance(self._contact, GroupchatContact)
|
| 193 | 193 | if not self._contact.settings.get('print_join_left'):
|
| 194 | 194 | return
|
| 195 | 195 | join_left = MUCJoinLeft('muc-user-joined',
|
| 196 | 196 | self._contact.account,
|
| 197 | - nick)
|
|
| 197 | + event.nick,
|
|
| 198 | + timestamp=event.timestamp)
|
|
| 198 | 199 | self._insert_message(join_left)
|
| 199 | 200 | |
| 200 | 201 | def add_user_status(self, name: str, show: str, status: str) -> None:
|
| ... | ... | @@ -215,8 +216,8 @@ def add_file_transfer(self, transfer: HTTPFileTransfer) -> None: |
| 215 | 216 | |
| 216 | 217 | def add_jingle_file_transfer(self,
|
| 217 | 218 | event: Union[
|
| 218 | - FileRequestReceivedEvent,
|
|
| 219 | - FileRequestSent,
|
|
| 219 | + events.FileRequestReceivedEvent,
|
|
| 220 | + events.FileRequestSent,
|
|
| 220 | 221 | None] = None,
|
| 221 | 222 | db_message: Optional[ConversationRow] = None
|
| 222 | 223 | ) -> None:
|
| ... | ... | @@ -230,7 +231,7 @@ def add_jingle_file_transfer(self, |
| 230 | 231 | self._insert_message(jingle_transfer_row)
|
| 231 | 232 | |
| 232 | 233 | def add_call_message(self,
|
| 233 | - event: Optional[JingleRequestReceived] = None,
|
|
| 234 | + event: Optional[events.JingleRequestReceived] = None,
|
|
| 234 | 235 | db_message: Optional[ConversationRow] = None
|
| 235 | 236 | ) -> None:
|
| 236 | 237 | assert isinstance(self._contact, BareContact)
|
| ... | ... | @@ -38,7 +38,7 @@ |
| 38 | 38 | "gajim/common/regex.py",
|
| 39 | 39 | "gajim/common/setting_values.py",
|
| 40 | 40 | "gajim/common/sound.py",
|
| 41 | - "gajim/common/storage/",
|
|
| 41 | + "gajim/common/storage/*",
|
|
| 42 | 42 | "gajim/common/task_manager.py",
|
| 43 | 43 | "gajim/gajim.py",
|
| 44 | 44 | "gajim/gajim_remote.py",
|