Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
843b6f1d
by lovetox at 2022-08-13T17:19:01+02:00
-
c90c3353
by lovetox at 2022-08-13T17:48:22+02:00
-
de8cb97b
by lovetox at 2022-08-13T17:48:22+02:00
-
ba7e88c2
by lovetox at 2022-08-13T18:06:43+02:00
6 changed files:
- gajim/common/ged.py
- gajim/common/modules/muc.py
- gajim/gtk/chat_banner.py
- gajim/gtk/control.py
- gajim/gtk/groupchat_nick_completion.py
- gajim/gtk/groupchat_roster.py
Changes:
| ... | ... | @@ -57,6 +57,10 @@ def register_event_handler(self, |
| 57 | 57 | |
| 58 | 58 | if event_name in self.handlers:
|
| 59 | 59 | handlers_list = self.handlers[event_name]
|
| 60 | + if (priority, handler) in handlers_list:
|
|
| 61 | + # Don’t register same handler/prio multiple times
|
|
| 62 | + return
|
|
| 63 | + |
|
| 60 | 64 | i = 0
|
| 61 | 65 | for i, handler_tuple in enumerate(handlers_list):
|
| 62 | 66 | if priority < handler_tuple[0]:
|
| ... | ... | @@ -122,11 +126,16 @@ def register_event(self, |
| 122 | 126 | priority: int,
|
| 123 | 127 | handler: HandlerFuncT) -> None:
|
| 124 | 128 | |
| 129 | + if (event_name, priority, handler) in self.__event_handlers:
|
|
| 130 | + return
|
|
| 131 | + |
|
| 125 | 132 | self.__event_handlers.append((event_name, priority, handler))
|
| 126 | 133 | app.ged.register_event_handler(event_name, priority, handler)
|
| 127 | 134 | |
| 128 | 135 | def register_events(self, events: list[EventHandlerT]) -> None:
|
| 129 | 136 | for handler in events:
|
| 137 | + if handler in self.__event_handlers:
|
|
| 138 | + continue
|
|
| 130 | 139 | self.__event_handlers.append(handler)
|
| 131 | 140 | app.ged.register_event_handler(*handler)
|
| 132 | 141 |
| ... | ... | @@ -575,21 +575,21 @@ def _on_muc_user_presence(self, |
| 575 | 575 | properties.jid,
|
| 576 | 576 | properties.muc_user.nick)
|
| 577 | 577 | |
| 578 | - # Create a copy of the contact object
|
|
| 579 | - new_occupant = room.add_resource(properties.muc_user.nick)
|
|
| 578 | + # We receive only the unavailable presence here, so we take
|
|
| 579 | + # the current presence and create a new contact with it, before we
|
|
| 580 | + # update the precence.
|
|
| 581 | + nickname = properties.muc_user.nick
|
|
| 582 | + new_occupant = room.add_resource(nickname)
|
|
| 580 | 583 | new_occupant.set_presence(occupant.presence)
|
| 584 | + self._joined_users[room.jid][nickname] = occupant.presence
|
|
| 581 | 585 | |
| 582 | 586 | presence = self._process_user_presence(properties)
|
| 583 | 587 | occupant.update_presence(presence, properties)
|
| 584 | 588 | |
| 585 | - # new_nick = properties.muc_user.nick
|
|
| 586 | - # nick = properties.muc_nickname
|
|
| 587 | - # presence_dict = self._joined_users[properties.jid.bare]
|
|
| 588 | - # presence_dict[new_nick] = presence_dict.pop(nick)
|
|
| 589 | - # self._manager.change_nickname
|
|
| 590 | - # TODO remove presence from manager
|
|
| 591 | - |
|
| 592 | - room.notify('user-nickname-changed', occupant, properties)
|
|
| 589 | + room.notify('user-nickname-changed',
|
|
| 590 | + occupant,
|
|
| 591 | + new_occupant,
|
|
| 592 | + properties)
|
|
| 593 | 593 | return
|
| 594 | 594 | |
| 595 | 595 | is_joined = self._is_user_joined(properties.jid)
|
| ... | ... | @@ -117,16 +117,18 @@ def switch_contact(self, contact: types.ChatContactT) -> None: |
| 117 | 117 | 'user-joined': self._on_user_state_changed,
|
| 118 | 118 | 'user-left': self._on_user_state_changed,
|
| 119 | 119 | 'user-avatar-update': self._on_user_avatar_update,
|
| 120 | - 'user-nickname-changed': self._on_user_nickname_changed
|
|
| 121 | 120 | })
|
| 122 | 121 | |
| 123 | - self.register_events([
|
|
| 124 | - ('message-received', ged.GUI1, self._on_message_received),
|
|
| 125 | - ('bookmarks-received', ged.GUI1, self._on_bookmarks_received),
|
|
| 126 | - ('muc-disco-update', ged.GUI1, self._on_muc_disco_update),
|
|
| 127 | - ('account-enabled', ged.GUI2, self._on_account_changed),
|
|
| 128 | - ('account-disabled', ged.GUI2, self._on_account_changed)
|
|
| 129 | - ])
|
|
| 122 | + if not self.has_events_registered():
|
|
| 123 | + self.register_events([
|
|
| 124 | + ('message-received', ged.GUI2, self._on_message_received),
|
|
| 125 | + ('muc-disco-update', ged.GUI2, self._on_muc_disco_update),
|
|
| 126 | + ('bookmarks-received', ged.GUI2, self._on_bookmarks_received),
|
|
| 127 | + ('account-enabled', ged.GUI2, self._on_account_changed),
|
|
| 128 | + ('account-disabled', ged.GUI2, self._on_account_changed)
|
|
| 129 | + ])
|
|
| 130 | + |
|
| 131 | + self._ui.phone_image.set_visible(False)
|
|
| 130 | 132 | |
| 131 | 133 | if hide_banner:
|
| 132 | 134 | self.set_no_show_all(True)
|
| ... | ... | @@ -188,15 +190,6 @@ def _on_user_role_changed(self, |
| 188 | 190 | user_contact: GroupchatParticipant,
|
| 189 | 191 | properties: PresenceProperties
|
| 190 | 192 | ) -> None:
|
| 191 | - self._update_content()
|
|
| 192 | - |
|
| 193 | - def _on_user_nickname_changed(self,
|
|
| 194 | - user_contact: GroupchatParticipant,
|
|
| 195 | - _signal_name: str,
|
|
| 196 | - properties: PresenceProperties,
|
|
| 197 | - ) -> None:
|
|
| 198 | - if user_contact.name != properties.muc_nickname:
|
|
| 199 | - return
|
|
| 200 | 193 | |
| 201 | 194 | self._update_content()
|
| 202 | 195 | |
| ... | ... | @@ -207,45 +200,32 @@ def _on_user_avatar_update(self, *args: Any) -> None: |
| 207 | 200 | self._update_avatar()
|
| 208 | 201 | |
| 209 | 202 | def _on_bookmarks_received(self, _event: BookmarksReceived) -> None:
|
| 203 | + if not isinstance(self._contact, GroupchatContact):
|
|
| 204 | + return
|
|
| 205 | + |
|
| 210 | 206 | self._update_content()
|
| 211 | 207 | |
| 212 | 208 | def _on_muc_disco_update(self, event: MucDiscoUpdate) -> None:
|
| 213 | - if self._contact is None or event.jid != self._contact.jid:
|
|
| 209 | + assert self._contact is not None
|
|
| 210 | + if event.jid != self._contact.jid:
|
|
| 214 | 211 | return
|
| 215 | 212 | |
| 216 | 213 | self._update_content()
|
| 217 | 214 | |
| 218 | 215 | def _on_account_changed(self, event: AccountEnabled) -> None:
|
| 219 | - if self._contact is None:
|
|
| 220 | - return
|
|
| 221 | - |
|
| 216 | + assert self._contact is not None
|
|
| 222 | 217 | self._update_account_badge(self._contact.account)
|
| 223 | 218 | |
| 224 | 219 | def _on_message_received(self, event: MessageReceived) -> None:
|
| 225 | - if not event.msgtxt:
|
|
| 226 | - return
|
|
| 227 | - |
|
| 228 | - if event.properties.is_sent_carbon:
|
|
| 229 | - return
|
|
| 230 | - |
|
| 231 | - assert self._contact is not None
|
|
| 232 | - |
|
| 233 | - if event.jid != self._contact.jid:
|
|
| 234 | - return
|
|
| 235 | - |
|
| 236 | - self._ui.phone_image.set_visible(False)
|
|
| 237 | - |
|
| 238 | - if isinstance(self._contact, (
|
|
| 239 | - GroupchatContact, GroupchatParticipant)):
|
|
| 240 | - return
|
|
| 241 | - |
|
| 242 | - kind = 'outgoing' if event.properties.is_sent_carbon else 'incoming'
|
|
| 243 | - if kind == 'outgoing':
|
|
| 220 | + if (not isinstance(self._contact, BareContact) or
|
|
| 221 | + event.jid != self._contact.jid or
|
|
| 222 | + not event.msgtxt or
|
|
| 223 | + event.properties.is_sent_carbon or
|
|
| 224 | + event.resource is None):
|
|
| 244 | 225 | return
|
| 245 | 226 | |
| 246 | - if event.resource is not None and not self._contact.is_groupchat:
|
|
| 247 | - resource_contact = self._contact.get_resource(event.resource)
|
|
| 248 | - self._ui.phone_image.set_visible(resource_contact.is_phone)
|
|
| 227 | + resource_contact = self._contact.get_resource(event.resource)
|
|
| 228 | + self._ui.phone_image.set_visible(resource_contact.is_phone)
|
|
| 249 | 229 | |
| 250 | 230 | def _update_avatar(self) -> None:
|
| 251 | 231 | scale = app.window.get_scale_factor()
|
| ... | ... | @@ -174,9 +174,6 @@ def switch_contact(self, contact: Union[BareContact, |
| 174 | 174 | if isinstance(contact, GroupchatParticipant):
|
| 175 | 175 | contact.multi_connect({
|
| 176 | 176 | 'user-status-show-changed': self._on_user_status_show_changed,
|
| 177 | - # 'user-nickname-changed': self._on_user_nickname_changed,
|
|
| 178 | - # 'room-kicked': self._on_room_kicked,
|
|
| 179 | - # 'room-destroyed': self._on_room_destroyed,
|
|
| 180 | 177 | })
|
| 181 | 178 | |
| 182 | 179 | elif isinstance(contact, GroupchatContact):
|
| ... | ... | @@ -187,7 +184,7 @@ def switch_contact(self, contact: Union[BareContact, |
| 187 | 184 | 'user-role-changed': self._on_user_role_changed,
|
| 188 | 185 | 'user-status-show-changed':
|
| 189 | 186 | self._on_muc_user_status_show_changed,
|
| 190 | - # 'user-nickname-changed': self._on_user_nickname_changed,
|
|
| 187 | + 'user-nickname-changed': self._on_user_nickname_changed,
|
|
| 191 | 188 | 'room-kicked': self._on_room_kicked,
|
| 192 | 189 | 'room-destroyed': self._on_room_destroyed,
|
| 193 | 190 | 'room-config-finished': self._on_room_config_finished,
|
| ... | ... | @@ -693,27 +690,21 @@ def add_message(self, |
| 693 | 690 | additional_data=additional_data)
|
| 694 | 691 | |
| 695 | 692 | def _on_user_nickname_changed(self,
|
| 696 | - _user_contact: GroupchatParticipant,
|
|
| 693 | + contact: types.GroupchatContact,
|
|
| 697 | 694 | _signal_name: str,
|
| 698 | - properties: PresenceProperties,
|
|
| 695 | + old_contact: types.GroupchatParticipant,
|
|
| 696 | + new_contact: types.GroupchatParticipant,
|
|
| 697 | + properties: PresenceProperties
|
|
| 699 | 698 | ) -> None:
|
| 700 | 699 | |
| 701 | - # TODO: check if the nick logic makes sense
|
|
| 702 | - return
|
|
| 703 | - # if isinstance(self.contact, GroupchatContact):
|
|
| 704 | - # nick = user_contact.name
|
|
| 705 | - # else:
|
|
| 706 | - # nick = properties.muc_nickname
|
|
| 707 | - |
|
| 708 | - # assert properties.muc_user is not None
|
|
| 709 | - # new_nick = properties.muc_user.nick
|
|
| 710 | - # if properties.is_muc_self_presence:
|
|
| 711 | - # message = _('You are now known as %s') % new_nick
|
|
| 712 | - # else:
|
|
| 713 | - # message = _('{nick} is now known '
|
|
| 714 | - # 'as {new_nick}').format(nick=nick, new_nick=new_nick)
|
|
| 715 | - |
|
| 716 | - # self.add_info_message(message)
|
|
| 700 | + if properties.is_muc_self_presence:
|
|
| 701 | + message = _('You are now known as %s') % new_contact.name
|
|
| 702 | + else:
|
|
| 703 | + message = _('{nick} is now known '
|
|
| 704 | + 'as {new_nick}').format(nick=old_contact.name,
|
|
| 705 | + new_nick=new_contact.name)
|
|
| 706 | + |
|
| 707 | + self.add_info_message(message)
|
|
| 717 | 708 | |
| 718 | 709 | def _on_muc_user_status_show_changed(self,
|
| 719 | 710 | contact: GroupchatContact,
|
| ... | ... | @@ -78,16 +78,17 @@ def switch_contact(self, contact: types.GroupchatContactT) -> None: |
| 78 | 78 | def _on_user_nickname_changed(self,
|
| 79 | 79 | _contact: types.GroupchatContact,
|
| 80 | 80 | _signal_name: str,
|
| 81 | - user_contact: types.GroupchatParticipant,
|
|
| 81 | + old_contact: types.GroupchatParticipant,
|
|
| 82 | + new_contact: types.GroupchatParticipant,
|
|
| 82 | 83 | properties: PresenceProperties
|
| 83 | 84 | ) -> None:
|
| 85 | + |
|
| 84 | 86 | if properties.is_muc_self_presence:
|
| 85 | 87 | return
|
| 86 | 88 | |
| 87 | - old_name = user_contact.name
|
|
| 88 | - assert properties.muc_user
|
|
| 89 | - new_name = properties.muc_user.nick
|
|
| 90 | - assert new_name is not None
|
|
| 89 | + old_name = old_contact.name
|
|
| 90 | + new_name = new_contact.name
|
|
| 91 | + |
|
| 91 | 92 | log.debug('Contact %s renamed to %s', old_name, new_name)
|
| 92 | 93 | for lst in (self._highlight_list, self._sender_list):
|
| 93 | 94 | for idx, contact in enumerate(lst):
|
| ... | ... | @@ -283,16 +283,13 @@ def _update_contact(self, |
| 283 | 283 | def _on_user_nickname_changed(self,
|
| 284 | 284 | contact: types.GroupchatContact,
|
| 285 | 285 | _signal_name: str,
|
| 286 | - user_contact: types.GroupchatParticipant,
|
|
| 286 | + old_contact: types.GroupchatParticipant,
|
|
| 287 | + new_contact: types.GroupchatParticipant,
|
|
| 287 | 288 | properties: PresenceProperties
|
| 288 | 289 | ) -> None:
|
| 289 | 290 | |
| 290 | - self._remove_contact(user_contact)
|
|
| 291 | - |
|
| 292 | - assert properties.muc_user is not None
|
|
| 293 | - assert properties.muc_user.nick is not None
|
|
| 294 | - user_contact = contact.get_resource(properties.muc_user.nick)
|
|
| 295 | - self._add_contact(user_contact)
|
|
| 291 | + self._remove_contact(old_contact)
|
|
| 292 | + self._add_contact(new_contact)
|
|
| 296 | 293 | |
| 297 | 294 | def _on_user_status_show_changed(self,
|
| 298 | 295 | _contact: types.GroupchatContact,
|