Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
fbcce35b
by Philipp Hörist at 2019-11-13T20:42:33Z
-
4726272d
by Philipp Hörist at 2019-11-13T20:46:33Z
-
40106f2b
by Philipp Hörist at 2019-11-13T21:14:46Z
-
4b312c2d
by Philipp Hörist at 2019-11-13T21:19:47Z
-
4fb0c787
by Philipp Hörist at 2019-11-13T21:44:18Z
7 changed files:
- gajim/chat_control.py
- gajim/common/connection.py
- gajim/common/helpers.py
- gajim/common/modules/caps.py
- gajim/groupchat_control.py
- gajim/gtk/util.py
- gajim/privatechat_control.py
Changes:
| ... | ... | @@ -67,7 +67,6 @@ from gajim.gtk.dialogs import NewConfirmationDialog |
| 67 | 67 |
from gajim.gtk.add_contact import AddNewContactWindow
|
| 68 | 68 |
from gajim.gtk.util import get_icon_name
|
| 69 | 69 |
from gajim.gtk.util import get_cursor
|
| 70 |
-from gajim.gtk.util import ensure_proper_control
|
|
| 71 | 70 |
from gajim.gtk.util import format_mood
|
| 72 | 71 |
from gajim.gtk.util import format_activity
|
| 73 | 72 |
from gajim.gtk.util import format_tune
|
| ... | ... | @@ -217,11 +216,11 @@ class ChatControl(ChatControlBase): |
| 217 | 216 |
('tune-received', ged.GUI1, self._on_tune_received),
|
| 218 | 217 |
('location-received', ged.GUI1, self._on_location_received),
|
| 219 | 218 |
('update-client-info', ged.GUI1, self._on_update_client_info),
|
| 220 |
- ('chatstate-received', ged.GUI1, self._nec_chatstate_received),
|
|
| 221 |
- ('caps-update', ged.GUI1, self._nec_caps_received),
|
|
| 222 |
- ('message-sent', ged.OUT_POSTCORE, self._message_sent),
|
|
| 223 |
- ('mam-decrypted-message-received', ged.GUI1, self._nec_mam_decrypted_message_received),
|
|
| 224 |
- ('decrypted-message-received', ged.GUI1, self._nec_decrypted_message_received),
|
|
| 219 |
+ ('chatstate-received', ged.GUI1, self._on_chatstate_received),
|
|
| 220 |
+ ('caps-update', ged.GUI1, self._on_caps_update),
|
|
| 221 |
+ ('message-sent', ged.OUT_POSTCORE, self._on_message_sent),
|
|
| 222 |
+ ('mam-decrypted-message-received', ged.GUI1, self._on_mam_decrypted_message_received),
|
|
| 223 |
+ ('decrypted-message-received', ged.GUI1, self._on_decrypted_message_received),
|
|
| 225 | 224 |
('receipt-received', ged.GUI1, self._receipt_received),
|
| 226 | 225 |
('message-error', ged.GUI1, self._on_message_error),
|
| 227 | 226 |
('zeroconf-error', ged.GUI1, self._on_zeroconf_error),
|
| ... | ... | @@ -229,7 +228,7 @@ class ChatControl(ChatControlBase): |
| 229 | 228 |
|
| 230 | 229 |
if self._type.is_chat:
|
| 231 | 230 |
# Dont connect this when PrivateChatControl is used
|
| 232 |
- self.register_event('update-roster-avatar', ged.GUI1, self._nec_update_avatar)
|
|
| 231 |
+ self.register_event('update-roster-avatar', ged.GUI1, self._on_update_roster_avatar)
|
|
| 233 | 232 |
# pylint: enable=line-too-long
|
| 234 | 233 |
|
| 235 | 234 |
# PluginSystem: adding GUI extension point for this ChatControl
|
| ... | ... | @@ -468,29 +467,29 @@ class ChatControl(ChatControlBase): |
| 468 | 467 |
return self.xml.location_image
|
| 469 | 468 |
return None
|
| 470 | 469 |
|
| 471 |
- @ensure_proper_control
|
|
| 470 |
+ @event_filter(['account', 'jid'])
|
|
| 472 | 471 |
def _on_mood_received(self, _event):
|
| 473 | 472 |
self._update_pep(PEPEventType.MOOD)
|
| 474 | 473 |
|
| 475 |
- @ensure_proper_control
|
|
| 474 |
+ @event_filter(['account', 'jid'])
|
|
| 476 | 475 |
def _on_activity_received(self, _event):
|
| 477 | 476 |
self._update_pep(PEPEventType.ACTIVITY)
|
| 478 | 477 |
|
| 479 |
- @ensure_proper_control
|
|
| 478 |
+ @event_filter(['account', 'jid'])
|
|
| 480 | 479 |
def _on_tune_received(self, _event):
|
| 481 | 480 |
self._update_pep(PEPEventType.TUNE)
|
| 482 | 481 |
|
| 483 |
- @ensure_proper_control
|
|
| 482 |
+ @event_filter(['account', 'jid'])
|
|
| 484 | 483 |
def _on_location_received(self, _event):
|
| 485 | 484 |
self._update_pep(PEPEventType.LOCATION)
|
| 486 | 485 |
|
| 487 |
- @ensure_proper_control
|
|
| 486 |
+ @event_filter(['account', 'jid'])
|
|
| 488 | 487 |
def _on_nickname_received(self, _event):
|
| 489 | 488 |
self.update_ui()
|
| 490 | 489 |
self.parent_win.redraw_tab(self)
|
| 491 | 490 |
self.parent_win.show_title()
|
| 492 | 491 |
|
| 493 |
- @ensure_proper_control
|
|
| 492 |
+ @event_filter(['account', 'jid'])
|
|
| 494 | 493 |
def _on_update_client_info(self, event):
|
| 495 | 494 |
contact = app.contacts.get_contact(
|
| 496 | 495 |
self.account, event.jid, event.resource)
|
| ... | ... | @@ -498,6 +497,136 @@ class ChatControl(ChatControlBase): |
| 498 | 497 |
return
|
| 499 | 498 |
self.xml.phone_image.set_visible(contact.uses_phone)
|
| 500 | 499 |
|
| 500 |
+ @event_filter(['account'])
|
|
| 501 |
+ def _on_chatstate_received(self, event):
|
|
| 502 |
+ if self._type.is_privatechat:
|
|
| 503 |
+ if event.contact != self.gc_contact:
|
|
| 504 |
+ return
|
|
| 505 |
+ else:
|
|
| 506 |
+ if event.contact.jid != self.contact.jid:
|
|
| 507 |
+ return
|
|
| 508 |
+ |
|
| 509 |
+ self.draw_banner_text()
|
|
| 510 |
+ |
|
| 511 |
+ # update chatstate in tab for this chat
|
|
| 512 |
+ if event.contact.is_gc_contact:
|
|
| 513 |
+ chatstate = event.contact.chatstate
|
|
| 514 |
+ else:
|
|
| 515 |
+ chatstate = app.contacts.get_combined_chatstate(
|
|
| 516 |
+ self.account, self.contact.jid)
|
|
| 517 |
+ self.parent_win.redraw_tab(self, chatstate)
|
|
| 518 |
+ |
|
| 519 |
+ @event_filter(['account'])
|
|
| 520 |
+ def _on_caps_update(self, event):
|
|
| 521 |
+ if self._type.is_chat and event.jid != self.contact.jid:
|
|
| 522 |
+ return
|
|
| 523 |
+ if self._type.is_privatechat and event.fjid != self.contact.jid:
|
|
| 524 |
+ return
|
|
| 525 |
+ self.update_ui()
|
|
| 526 |
+ |
|
| 527 |
+ @event_filter(['account'])
|
|
| 528 |
+ def _on_mam_decrypted_message_received(self, event):
|
|
| 529 |
+ if event.properties.type.is_groupchat:
|
|
| 530 |
+ return
|
|
| 531 |
+ |
|
| 532 |
+ if event.properties.is_muc_pm:
|
|
| 533 |
+ if not event.properties.jid == self.contact.get_full_jid():
|
|
| 534 |
+ return
|
|
| 535 |
+ else:
|
|
| 536 |
+ if not event.properties.jid.bareMatch(self.contact.jid):
|
|
| 537 |
+ return
|
|
| 538 |
+ |
|
| 539 |
+ kind = '' # incoming
|
|
| 540 |
+ if event.kind == KindConstant.CHAT_MSG_SENT:
|
|
| 541 |
+ kind = 'outgoing'
|
|
| 542 |
+ |
|
| 543 |
+ self.add_message(event.msgtxt,
|
|
| 544 |
+ kind,
|
|
| 545 |
+ tim=event.properties.mam.timestamp,
|
|
| 546 |
+ correct_id=event.correct_id,
|
|
| 547 |
+ message_id=event.properties.id,
|
|
| 548 |
+ additional_data=event.additional_data)
|
|
| 549 |
+ |
|
| 550 |
+ @event_filter(['account'])
|
|
| 551 |
+ def _on_decrypted_message_received(self, event):
|
|
| 552 |
+ if not event.msgtxt:
|
|
| 553 |
+ return True
|
|
| 554 |
+ |
|
| 555 |
+ if event.session.control != self:
|
|
| 556 |
+ return
|
|
| 557 |
+ |
|
| 558 |
+ typ = ''
|
|
| 559 |
+ if event.properties.is_sent_carbon:
|
|
| 560 |
+ typ = 'out'
|
|
| 561 |
+ |
|
| 562 |
+ self.add_message(event.msgtxt,
|
|
| 563 |
+ typ,
|
|
| 564 |
+ tim=event.properties.timestamp,
|
|
| 565 |
+ subject=event.properties.subject,
|
|
| 566 |
+ displaymarking=event.displaymarking,
|
|
| 567 |
+ msg_log_id=event.msg_log_id,
|
|
| 568 |
+ message_id=event.properties.id,
|
|
| 569 |
+ correct_id=event.correct_id,
|
|
| 570 |
+ additional_data=event.additional_data)
|
|
| 571 |
+ if event.msg_log_id:
|
|
| 572 |
+ pw = self.parent_win
|
|
| 573 |
+ end = self.conv_textview.autoscroll
|
|
| 574 |
+ if not pw or (pw.get_active_control() and self \
|
|
| 575 |
+ == pw.get_active_control() and pw.is_active() and end):
|
|
| 576 |
+ app.logger.set_read_messages([event.msg_log_id])
|
|
| 577 |
+ |
|
| 578 |
+ @event_filter(['account', 'jid'])
|
|
| 579 |
+ def _on_message_error(self, event):
|
|
| 580 |
+ self.conv_textview.show_error(event.message_id, event.error)
|
|
| 581 |
+ |
|
| 582 |
+ @event_filter(['account', 'jid'])
|
|
| 583 |
+ def _on_message_sent(self, event):
|
|
| 584 |
+ if not event.message:
|
|
| 585 |
+ return
|
|
| 586 |
+ |
|
| 587 |
+ self.last_sent_msg = event.stanza_id
|
|
| 588 |
+ message_id = event.msg_iq.getID()
|
|
| 589 |
+ |
|
| 590 |
+ if event.label:
|
|
| 591 |
+ displaymarking = event.label.getTag('displaymarking')
|
|
| 592 |
+ else:
|
|
| 593 |
+ displaymarking = None
|
|
| 594 |
+ if self.correcting:
|
|
| 595 |
+ self.correcting = False
|
|
| 596 |
+ gtkgui_helpers.remove_css_class(
|
|
| 597 |
+ self.msg_textview, 'gajim-msg-correcting')
|
|
| 598 |
+ |
|
| 599 |
+ self.add_message(event.message,
|
|
| 600 |
+ self.contact.jid,
|
|
| 601 |
+ tim=event.timestamp,
|
|
| 602 |
+ displaymarking=displaymarking,
|
|
| 603 |
+ message_id=message_id,
|
|
| 604 |
+ correct_id=event.correct_id,
|
|
| 605 |
+ additional_data=event.additional_data)
|
|
| 606 |
+ |
|
| 607 |
+ @event_filter(['account', 'jid'])
|
|
| 608 |
+ def _receipt_received(self, event):
|
|
| 609 |
+ self.conv_textview.show_receipt(event.receipt_id)
|
|
| 610 |
+ |
|
| 611 |
+ @event_filter(['account', 'jid'])
|
|
| 612 |
+ def _on_zeroconf_error(self, event):
|
|
| 613 |
+ self.add_status_message(event.message)
|
|
| 614 |
+ |
|
| 615 |
+ @event_filter(['account', 'jid'])
|
|
| 616 |
+ def _on_update_roster_avatar(self, obj):
|
|
| 617 |
+ self.show_avatar()
|
|
| 618 |
+ |
|
| 619 |
+ def _nec_ping(self, event):
|
|
| 620 |
+ if self.contact != event.contact:
|
|
| 621 |
+ return
|
|
| 622 |
+ if event.name == 'ping-sent':
|
|
| 623 |
+ self.add_info_message(_('Ping?'))
|
|
| 624 |
+ elif event.name == 'ping-reply':
|
|
| 625 |
+ self.add_info_message(
|
|
| 626 |
+ _('Pong! (%s seconds)') % event.seconds)
|
|
| 627 |
+ elif event.name == 'ping-error':
|
|
| 628 |
+ self.add_info_message(_('Error.'))
|
|
| 629 |
+ |
|
| 501 | 630 |
def _update_jingle(self, jingle_type):
|
| 502 | 631 |
if jingle_type not in ('audio', 'video'):
|
| 503 | 632 |
return
|
| ... | ... | @@ -787,90 +916,6 @@ class ChatControl(ChatControlBase): |
| 787 | 916 |
fixed.set_no_show_all(True)
|
| 788 | 917 |
self.close_jingle_content(jingle_type)
|
| 789 | 918 |
|
| 790 |
- @event_filter(['account'])
|
|
| 791 |
- def _nec_mam_decrypted_message_received(self, obj):
|
|
| 792 |
- if obj.properties.type.is_groupchat:
|
|
| 793 |
- return
|
|
| 794 |
- |
|
| 795 |
- if obj.properties.is_muc_pm:
|
|
| 796 |
- if not obj.properties.jid == self.contact.get_full_jid():
|
|
| 797 |
- return
|
|
| 798 |
- else:
|
|
| 799 |
- if not obj.properties.jid.bareMatch(self.contact.jid):
|
|
| 800 |
- return
|
|
| 801 |
- |
|
| 802 |
- kind = '' # incoming
|
|
| 803 |
- if obj.kind == KindConstant.CHAT_MSG_SENT:
|
|
| 804 |
- kind = 'outgoing'
|
|
| 805 |
- |
|
| 806 |
- self.add_message(obj.msgtxt,
|
|
| 807 |
- kind,
|
|
| 808 |
- tim=obj.properties.mam.timestamp,
|
|
| 809 |
- correct_id=obj.correct_id,
|
|
| 810 |
- message_id=obj.properties.id,
|
|
| 811 |
- additional_data=obj.additional_data)
|
|
| 812 |
- |
|
| 813 |
- def _nec_decrypted_message_received(self, obj):
|
|
| 814 |
- if not obj.msgtxt:
|
|
| 815 |
- return True
|
|
| 816 |
- if obj.conn.name != self.account:
|
|
| 817 |
- return
|
|
| 818 |
- |
|
| 819 |
- if obj.session.control != self:
|
|
| 820 |
- return
|
|
| 821 |
- |
|
| 822 |
- typ = ''
|
|
| 823 |
- if obj.properties.is_sent_carbon:
|
|
| 824 |
- typ = 'out'
|
|
| 825 |
- |
|
| 826 |
- self.add_message(obj.msgtxt,
|
|
| 827 |
- typ,
|
|
| 828 |
- tim=obj.properties.timestamp,
|
|
| 829 |
- subject=obj.properties.subject,
|
|
| 830 |
- displaymarking=obj.displaymarking,
|
|
| 831 |
- msg_log_id=obj.msg_log_id,
|
|
| 832 |
- message_id=obj.properties.id,
|
|
| 833 |
- correct_id=obj.correct_id,
|
|
| 834 |
- additional_data=obj.additional_data)
|
|
| 835 |
- if obj.msg_log_id:
|
|
| 836 |
- pw = self.parent_win
|
|
| 837 |
- end = self.conv_textview.autoscroll
|
|
| 838 |
- if not pw or (pw.get_active_control() and self \
|
|
| 839 |
- == pw.get_active_control() and pw.is_active() and end):
|
|
| 840 |
- app.logger.set_read_messages([obj.msg_log_id])
|
|
| 841 |
- |
|
| 842 |
- @event_filter(['account', 'jid'])
|
|
| 843 |
- def _on_message_error(self, event):
|
|
| 844 |
- self.conv_textview.show_error(event.message_id, event.error)
|
|
| 845 |
- |
|
| 846 |
- def _message_sent(self, obj):
|
|
| 847 |
- if obj.conn.name != self.account:
|
|
| 848 |
- return
|
|
| 849 |
- if obj.jid != self.contact.jid:
|
|
| 850 |
- return
|
|
| 851 |
- if not obj.message:
|
|
| 852 |
- return
|
|
| 853 |
- |
|
| 854 |
- self.last_sent_msg = obj.stanza_id
|
|
| 855 |
- message_id = obj.msg_iq.getID()
|
|
| 856 |
- |
|
| 857 |
- if obj.label:
|
|
| 858 |
- displaymarking = obj.label.getTag('displaymarking')
|
|
| 859 |
- else:
|
|
| 860 |
- displaymarking = None
|
|
| 861 |
- if self.correcting:
|
|
| 862 |
- self.correcting = False
|
|
| 863 |
- gtkgui_helpers.remove_css_class(
|
|
| 864 |
- self.msg_textview, 'gajim-msg-correcting')
|
|
| 865 |
- |
|
| 866 |
- self.add_message(obj.message,
|
|
| 867 |
- self.contact.jid,
|
|
| 868 |
- tim=obj.timestamp,
|
|
| 869 |
- displaymarking=displaymarking,
|
|
| 870 |
- message_id=message_id,
|
|
| 871 |
- correct_id=obj.correct_id,
|
|
| 872 |
- additional_data=obj.additional_data)
|
|
| 873 |
- |
|
| 874 | 919 |
def send_message(self, message, xhtml=None,
|
| 875 | 920 |
process_commands=True, attention=False):
|
| 876 | 921 |
"""
|
| ... | ... | @@ -958,10 +1003,6 @@ class ChatControl(ChatControlBase): |
| 958 | 1003 |
else:
|
| 959 | 1004 |
self.old_msg_kind = kind
|
| 960 | 1005 |
|
| 961 |
- @event_filter(['account', 'jid'])
|
|
| 962 |
- def _receipt_received(self, event):
|
|
| 963 |
- self.conv_textview.show_receipt(event.receipt_id)
|
|
| 964 |
- |
|
| 965 | 1006 |
def get_tab_label(self):
|
| 966 | 1007 |
unread = ''
|
| 967 | 1008 |
if self.resource:
|
| ... | ... | @@ -1112,47 +1153,6 @@ class ChatControl(ChatControlBase): |
| 1112 | 1153 |
return
|
| 1113 | 1154 |
on_yes(self)
|
| 1114 | 1155 |
|
| 1115 |
- def _nec_chatstate_received(self, event):
|
|
| 1116 |
- if event.account != self.account:
|
|
| 1117 |
- return
|
|
| 1118 |
- |
|
| 1119 |
- if self._type.is_privatechat:
|
|
| 1120 |
- if event.contact != self.gc_contact:
|
|
| 1121 |
- return
|
|
| 1122 |
- else:
|
|
| 1123 |
- if event.contact.jid != self.contact.jid:
|
|
| 1124 |
- return
|
|
| 1125 |
- |
|
| 1126 |
- self.draw_banner_text()
|
|
| 1127 |
- |
|
| 1128 |
- # update chatstate in tab for this chat
|
|
| 1129 |
- if event.contact.is_gc_contact:
|
|
| 1130 |
- chatstate = event.contact.chatstate
|
|
| 1131 |
- else:
|
|
| 1132 |
- chatstate = app.contacts.get_combined_chatstate(
|
|
| 1133 |
- self.account, self.contact.jid)
|
|
| 1134 |
- self.parent_win.redraw_tab(self, chatstate)
|
|
| 1135 |
- |
|
| 1136 |
- def _nec_caps_received(self, obj):
|
|
| 1137 |
- if obj.conn.name != self.account:
|
|
| 1138 |
- return
|
|
| 1139 |
- if self._type.is_chat and obj.jid != self.contact.jid:
|
|
| 1140 |
- return
|
|
| 1141 |
- if self._type.is_privatechat and obj.fjid != self.contact.jid:
|
|
| 1142 |
- return
|
|
| 1143 |
- self.update_ui()
|
|
| 1144 |
- |
|
| 1145 |
- def _nec_ping(self, obj):
|
|
| 1146 |
- if self.contact != obj.contact:
|
|
| 1147 |
- return
|
|
| 1148 |
- if obj.name == 'ping-sent':
|
|
| 1149 |
- self.add_info_message(_('Ping?'))
|
|
| 1150 |
- elif obj.name == 'ping-reply':
|
|
| 1151 |
- self.add_info_message(
|
|
| 1152 |
- _('Pong! (%s seconds)') % obj.seconds)
|
|
| 1153 |
- elif obj.name == 'ping-error':
|
|
| 1154 |
- self.add_info_message(_('Error.'))
|
|
| 1155 |
- |
|
| 1156 | 1156 |
def show_avatar(self):
|
| 1157 | 1157 |
if not app.config.get('show_avatar_in_chat'):
|
| 1158 | 1158 |
return
|
| ... | ... | @@ -1166,13 +1166,6 @@ class ChatControl(ChatControlBase): |
| 1166 | 1166 |
|
| 1167 | 1167 |
self.xml.avatar_image.set_from_surface(surface)
|
| 1168 | 1168 |
|
| 1169 |
- def _nec_update_avatar(self, obj):
|
|
| 1170 |
- if obj.account != self.account:
|
|
| 1171 |
- return
|
|
| 1172 |
- if obj.jid != self.contact.jid:
|
|
| 1173 |
- return
|
|
| 1174 |
- self.show_avatar()
|
|
| 1175 |
- |
|
| 1176 | 1169 |
def _on_drag_data_received(self, widget, context, x, y, selection,
|
| 1177 | 1170 |
target_type, timestamp):
|
| 1178 | 1171 |
if not selection.get_data():
|
| ... | ... | @@ -1364,10 +1357,6 @@ class ChatControl(ChatControlBase): |
| 1364 | 1357 |
'name': name, 'show': uf_show, 'status': status or ''}
|
| 1365 | 1358 |
self.add_status_message(status_line)
|
| 1366 | 1359 |
|
| 1367 |
- @event_filter(['account', 'jid'])
|
|
| 1368 |
- def _on_zeroconf_error(self, event):
|
|
| 1369 |
- self.add_status_message(event.message)
|
|
| 1370 |
- |
|
| 1371 | 1360 |
def _info_bar_show_message(self):
|
| 1372 | 1361 |
if self.info_bar.get_visible():
|
| 1373 | 1362 |
# A message is already shown
|
| ... | ... | @@ -1666,9 +1666,14 @@ class Connection(CommonConnection, ConnectionHandlers): |
| 1666 | 1666 |
def send_gc_message(self, obj):
|
| 1667 | 1667 |
obj.stanza_id = self.connection.send(obj.msg_iq)
|
| 1668 | 1668 |
app.nec.push_incoming_event(MessageSentEvent(
|
| 1669 |
- None, conn=self, jid=obj.jid, message=obj.message,
|
|
| 1669 |
+ None,
|
|
| 1670 |
+ conn=self,
|
|
| 1671 |
+ account=self.name,
|
|
| 1672 |
+ jid=obj.jid,
|
|
| 1673 |
+ message=obj.message,
|
|
| 1670 | 1674 |
automatic_message=obj.automatic_message,
|
| 1671 |
- stanza_id=obj.stanza_id, additional_data=obj.additional_data))
|
|
| 1675 |
+ stanza_id=obj.stanza_id,
|
|
| 1676 |
+ additional_data=obj.additional_data))
|
|
| 1672 | 1677 |
|
| 1673 | 1678 |
def unregister_account(self, on_remove_success):
|
| 1674 | 1679 |
self._unregister_account = True
|
| ... | ... | @@ -1453,12 +1453,17 @@ def event_filter(filter_): |
| 1453 | 1453 |
@wraps(func)
|
| 1454 | 1454 |
def func_wrapper(self, event, *args, **kwargs):
|
| 1455 | 1455 |
for attr in filter_:
|
| 1456 |
+ if '=' in attr:
|
|
| 1457 |
+ attr1, attr2 = attr.split('=')
|
|
| 1458 |
+ else:
|
|
| 1459 |
+ attr1, attr2 = attr, attr
|
|
| 1456 | 1460 |
try:
|
| 1457 |
- if getattr(event, attr) != getattr(self, attr):
|
|
| 1458 |
- return
|
|
| 1461 |
+ if getattr(event, attr1) != getattr(self, attr2):
|
|
| 1462 |
+ return None
|
|
| 1459 | 1463 |
except AttributeError:
|
| 1460 |
- if getattr(event, attr) != getattr(self, '_%s' % attr):
|
|
| 1461 |
- return
|
|
| 1464 |
+ if getattr(event, attr1) != getattr(self, '_%s' % attr2):
|
|
| 1465 |
+ return None
|
|
| 1466 |
+ |
|
| 1462 | 1467 |
return func(self, event, *args, **kwargs)
|
| 1463 | 1468 |
return func_wrapper
|
| 1464 | 1469 |
return event_filter_decorator
|
| ... | ... | @@ -75,7 +75,7 @@ class Caps(BaseModule): |
| 75 | 75 |
|
| 76 | 76 |
app.nec.push_incoming_event(
|
| 77 | 77 |
NetworkEvent('caps-update',
|
| 78 |
- conn=self._con,
|
|
| 78 |
+ account=self._account,
|
|
| 79 | 79 |
fjid=jid,
|
| 80 | 80 |
jid=properties.jid.getBare()))
|
| 81 | 81 |
|
| ... | ... | @@ -134,7 +134,7 @@ class Caps(BaseModule): |
| 134 | 134 |
|
| 135 | 135 |
app.nec.push_incoming_event(
|
| 136 | 136 |
NetworkEvent('caps-update',
|
| 137 |
- conn=self._con,
|
|
| 137 |
+ account=self._account,
|
|
| 138 | 138 |
fjid=str(info.jid),
|
| 139 | 139 |
jid=bare_jid))
|
| 140 | 140 |
|
| ... | ... | @@ -204,12 +204,12 @@ class GroupchatControl(ChatControlBase): |
| 204 | 204 |
('muc-disco-update', ged.GUI1, self._on_disco_update),
|
| 205 | 205 |
('muc-configuration-finished', ged.GUI1, self._on_configuration_finished),
|
| 206 | 206 |
('muc-configuration-failed', ged.GUI1, self._on_configuration_failed),
|
| 207 |
- ('gc-message-received', ged.GUI1, self._nec_gc_message_received),
|
|
| 208 |
- ('mam-decrypted-message-received', ged.GUI1, self._nec_mam_decrypted_message_received),
|
|
| 209 |
- ('update-room-avatar', ged.GUI1, self._nec_update_room_avatar),
|
|
| 210 |
- ('signed-in', ged.GUI1, self._nec_signed_in),
|
|
| 211 |
- ('decrypted-message-received', ged.GUI2, self._nec_decrypted_message_received),
|
|
| 212 |
- ('gc-stanza-message-outgoing', ged.OUT_POSTCORE, self._message_sent),
|
|
| 207 |
+ ('gc-message-received', ged.GUI1, self._on_gc_message_received),
|
|
| 208 |
+ ('mam-decrypted-message-received', ged.GUI1, self._on_mam_decrypted_message_received),
|
|
| 209 |
+ ('update-room-avatar', ged.GUI1, self._on_update_room_avatar),
|
|
| 210 |
+ ('signed-in', ged.GUI1, self._on_signed_in),
|
|
| 211 |
+ ('decrypted-message-received', ged.GUI2, self._on_decrypted_message_received),
|
|
| 212 |
+ ('gc-stanza-message-outgoing', ged.OUT_POSTCORE, self._on_message_sent),
|
|
| 213 | 213 |
('bookmarks-received', ged.GUI2, self._on_bookmarks_received),
|
| 214 | 214 |
])
|
| 215 | 215 |
# pylint: enable=line-too-long
|
| ... | ... | @@ -785,9 +785,8 @@ class GroupchatControl(ChatControlBase): |
| 785 | 785 |
"""
|
| 786 | 786 |
self.xml.banner_name_label.set_text(self.room_name)
|
| 787 | 787 |
|
| 788 |
- def _nec_update_room_avatar(self, obj):
|
|
| 789 |
- if obj.jid != self.room_jid:
|
|
| 790 |
- return
|
|
| 788 |
+ @event_filter(['jid=room_jid'])
|
|
| 789 |
+ def _on_update_room_avatar(self, event):
|
|
| 791 | 790 |
self._update_banner_state_image()
|
| 792 | 791 |
|
| 793 | 792 |
@event_filter(['account'])
|
| ... | ... | @@ -815,37 +814,37 @@ class GroupchatControl(ChatControlBase): |
| 815 | 814 |
modal=False).show()
|
| 816 | 815 |
|
| 817 | 816 |
@event_filter(['account'])
|
| 818 |
- def _nec_mam_decrypted_message_received(self, obj):
|
|
| 819 |
- if not obj.properties.type.is_groupchat:
|
|
| 817 |
+ def _on_mam_decrypted_message_received(self, event):
|
|
| 818 |
+ if not event.properties.type.is_groupchat:
|
|
| 820 | 819 |
return
|
| 821 |
- if obj.archive_jid != self.room_jid:
|
|
| 820 |
+ if event.archive_jid != self.room_jid:
|
|
| 822 | 821 |
return
|
| 823 |
- self.add_message(obj.msgtxt,
|
|
| 824 |
- contact=obj.properties.muc_nickname,
|
|
| 825 |
- tim=obj.properties.mam.timestamp,
|
|
| 826 |
- correct_id=obj.correct_id,
|
|
| 827 |
- message_id=obj.properties.id,
|
|
| 828 |
- additional_data=obj.additional_data)
|
|
| 822 |
+ self.add_message(event.msgtxt,
|
|
| 823 |
+ contact=event.properties.muc_nickname,
|
|
| 824 |
+ tim=event.properties.mam.timestamp,
|
|
| 825 |
+ correct_id=event.correct_id,
|
|
| 826 |
+ message_id=event.properties.id,
|
|
| 827 |
+ additional_data=event.additional_data)
|
|
| 829 | 828 |
|
| 830 | 829 |
@event_filter(['account', 'room_jid'])
|
| 831 |
- def _nec_gc_message_received(self, obj):
|
|
| 832 |
- if obj.properties.muc_nickname is None:
|
|
| 830 |
+ def _on_gc_message_received(self, event):
|
|
| 831 |
+ if event.properties.muc_nickname is None:
|
|
| 833 | 832 |
# message from server
|
| 834 |
- self.add_message(obj.msgtxt,
|
|
| 835 |
- tim=obj.properties.timestamp,
|
|
| 836 |
- displaymarking=obj.displaymarking,
|
|
| 837 |
- additional_data=obj.additional_data)
|
|
| 833 |
+ self.add_message(event.msgtxt,
|
|
| 834 |
+ tim=event.properties.timestamp,
|
|
| 835 |
+ displaymarking=event.displaymarking,
|
|
| 836 |
+ additional_data=event.additional_data)
|
|
| 838 | 837 |
else:
|
| 839 |
- if obj.properties.muc_nickname == self.nick:
|
|
| 840 |
- self.last_sent_txt = obj.msgtxt
|
|
| 841 |
- self.add_message(obj.msgtxt,
|
|
| 842 |
- contact=obj.properties.muc_nickname,
|
|
| 843 |
- tim=obj.properties.timestamp,
|
|
| 844 |
- displaymarking=obj.displaymarking,
|
|
| 845 |
- correct_id=obj.correct_id,
|
|
| 846 |
- message_id=obj.properties.id,
|
|
| 847 |
- additional_data=obj.additional_data)
|
|
| 848 |
- obj.needs_highlight = self.needs_visual_notification(obj.msgtxt)
|
|
| 838 |
+ if event.properties.muc_nickname == self.nick:
|
|
| 839 |
+ self.last_sent_txt = event.msgtxt
|
|
| 840 |
+ self.add_message(event.msgtxt,
|
|
| 841 |
+ contact=event.properties.muc_nickname,
|
|
| 842 |
+ tim=event.properties.timestamp,
|
|
| 843 |
+ displaymarking=event.displaymarking,
|
|
| 844 |
+ correct_id=event.correct_id,
|
|
| 845 |
+ message_id=event.properties.id,
|
|
| 846 |
+ additional_data=event.additional_data)
|
|
| 847 |
+ event.needs_highlight = self.needs_visual_notification(event.msgtxt)
|
|
| 849 | 848 |
|
| 850 | 849 |
def on_private_message(self, nick, sent, msg, tim, session, additional_data,
|
| 851 | 850 |
msg_log_id=None, displaymarking=None):
|
| ... | ... | @@ -1083,43 +1082,41 @@ class GroupchatControl(ChatControlBase): |
| 1083 | 1082 |
for change in changes:
|
| 1084 | 1083 |
self.add_info_message(change)
|
| 1085 | 1084 |
|
| 1086 |
- def _nec_signed_in(self, obj):
|
|
| 1087 |
- if obj.conn.name != self.account:
|
|
| 1088 |
- return
|
|
| 1089 |
- obj.conn.get_module('MUC').join(self._muc_data)
|
|
| 1090 |
- |
|
| 1091 |
- def _nec_decrypted_message_received(self, obj):
|
|
| 1092 |
- if obj.conn.name != self.account:
|
|
| 1085 |
+ def _on_signed_in(self, event):
|
|
| 1086 |
+ if event.conn.name != self.account:
|
|
| 1093 | 1087 |
return
|
| 1088 |
+ event.conn.get_module('MUC').join(self._muc_data)
|
|
| 1094 | 1089 |
|
| 1095 |
- if not obj.properties.jid.bareMatch(self.room_jid):
|
|
| 1090 |
+ @event_filter(['account'])
|
|
| 1091 |
+ def _on_decrypted_message_received(self, event):
|
|
| 1092 |
+ if not event.properties.jid.bareMatch(self.room_jid):
|
|
| 1096 | 1093 |
return
|
| 1097 | 1094 |
|
| 1098 |
- if obj.properties.is_muc_pm and not obj.session.control:
|
|
| 1095 |
+ if event.properties.is_muc_pm and not event.session.control:
|
|
| 1099 | 1096 |
# We got a pm from this room
|
| 1100 |
- nick = obj.resource
|
|
| 1097 |
+ nick = event.resource
|
|
| 1101 | 1098 |
# otherwise pass it off to the control to be queued
|
| 1102 | 1099 |
self.on_private_message(nick,
|
| 1103 |
- obj.properties.is_sent_carbon,
|
|
| 1104 |
- obj.msgtxt,
|
|
| 1105 |
- obj.properties.timestamp,
|
|
| 1100 |
+ event.properties.is_sent_carbon,
|
|
| 1101 |
+ event.msgtxt,
|
|
| 1102 |
+ event.properties.timestamp,
|
|
| 1106 | 1103 |
self.session,
|
| 1107 |
- obj.additional_data,
|
|
| 1108 |
- msg_log_id=obj.msg_log_id,
|
|
| 1109 |
- displaymarking=obj.displaymarking)
|
|
| 1104 |
+ event.additional_data,
|
|
| 1105 |
+ msg_log_id=event.msg_log_id,
|
|
| 1106 |
+ displaymarking=event.displaymarking)
|
|
| 1110 | 1107 |
|
| 1111 |
- def _nec_ping(self, obj):
|
|
| 1112 |
- if self.contact.jid != obj.contact.room_jid:
|
|
| 1108 |
+ def _nec_ping(self, event):
|
|
| 1109 |
+ if self.contact.jid != event.contact.room_jid:
|
|
| 1113 | 1110 |
return
|
| 1114 | 1111 |
|
| 1115 |
- nick = obj.contact.get_shown_name()
|
|
| 1116 |
- if obj.name == 'ping-sent':
|
|
| 1112 |
+ nick = event.contact.get_shown_name()
|
|
| 1113 |
+ if event.name == 'ping-sent':
|
|
| 1117 | 1114 |
self.add_info_message(_('Ping? (%s)') % nick)
|
| 1118 |
- elif obj.name == 'ping-reply':
|
|
| 1115 |
+ elif event.name == 'ping-reply':
|
|
| 1119 | 1116 |
self.add_info_message(
|
| 1120 | 1117 |
_('Pong! (%(nick)s %(delay)s s.)') % {'nick': nick,
|
| 1121 |
- 'delay': obj.seconds})
|
|
| 1122 |
- elif obj.name == 'ping-error':
|
|
| 1118 |
+ 'delay': event.seconds})
|
|
| 1119 |
+ elif event.name == 'ping-error':
|
|
| 1123 | 1120 |
self.add_info_message(_('Error.'))
|
| 1124 | 1121 |
|
| 1125 | 1122 |
@property
|
| ... | ... | @@ -1519,15 +1516,13 @@ class GroupchatControl(ChatControlBase): |
| 1519 | 1516 |
if self._wait_for_destruction:
|
| 1520 | 1517 |
self._close_control()
|
| 1521 | 1518 |
|
| 1522 |
- @event_filter(['account'])
|
|
| 1523 |
- def _message_sent(self, obj):
|
|
| 1524 |
- if not obj.message:
|
|
| 1525 |
- return
|
|
| 1526 |
- if obj.jid != self.room_jid:
|
|
| 1519 |
+ @event_filter(['account', 'jid=room_jid'])
|
|
| 1520 |
+ def _on_message_sent(self, event):
|
|
| 1521 |
+ if not event.message:
|
|
| 1527 | 1522 |
return
|
| 1528 | 1523 |
# we'll save sent message text when we'll receive it in
|
| 1529 | 1524 |
# _nec_gc_message_received
|
| 1530 |
- self.last_sent_msg = obj.stanza_id
|
|
| 1525 |
+ self.last_sent_msg = event.stanza_id
|
|
| 1531 | 1526 |
if self.correcting:
|
| 1532 | 1527 |
self.correcting = False
|
| 1533 | 1528 |
gtkgui_helpers.remove_css_class(
|
| ... | ... | @@ -519,17 +519,6 @@ def ensure_not_destroyed(func): |
| 519 | 519 |
return func_wrapper
|
| 520 | 520 |
|
| 521 | 521 |
|
| 522 |
-def ensure_proper_control(func):
|
|
| 523 |
- @wraps(func)
|
|
| 524 |
- def func_wrapper(self, event):
|
|
| 525 |
- if event.account != self.account:
|
|
| 526 |
- return
|
|
| 527 |
- if event.jid != self.contact.jid:
|
|
| 528 |
- return
|
|
| 529 |
- return func(self, event)
|
|
| 530 |
- return func_wrapper
|
|
| 531 |
- |
|
| 532 |
- |
|
| 533 | 522 |
def format_mood(mood, text):
|
| 534 | 523 |
if mood is None:
|
| 535 | 524 |
return ''
|
| ... | ... | @@ -29,6 +29,7 @@ from gajim.common import helpers |
| 29 | 29 |
from gajim.common import ged
|
| 30 | 30 |
from gajim.common.i18n import _
|
| 31 | 31 |
from gajim.common.const import AvatarSize
|
| 32 |
+from gajim.common.helpers import event_filter
|
|
| 32 | 33 |
|
| 33 | 34 |
from gajim.chat_control import ChatControl
|
| 34 | 35 |
from gajim.command_system.implementation.hosts import PrivateChatCommands
|
| ... | ... | @@ -58,15 +59,15 @@ class PrivateChatControl(ChatControl): |
| 58 | 59 |
|
| 59 | 60 |
# pylint: disable=line-too-long
|
| 60 | 61 |
self.register_events([
|
| 61 |
- ('update-gc-avatar', ged.GUI1, self._nec_update_avatar),
|
|
| 62 |
- ('caps-update', ged.GUI1, self._nec_caps_received_pm),
|
|
| 62 |
+ ('update-gc-avatar', ged.GUI1, self._on_update_gc_avatar),
|
|
| 63 |
+ ('caps-update', ged.GUI1, self._on_caps_update),
|
|
| 63 | 64 |
('muc-user-joined', ged.GUI1, self._on_user_joined),
|
| 64 | 65 |
('muc-user-left', ged.GUI1, self._on_user_left),
|
| 65 | 66 |
('muc-nickname-changed', ged.GUI1, self._on_nickname_changed),
|
| 66 | 67 |
('muc-self-presence', ged.GUI1, self._on_self_presence),
|
| 67 |
- ('muc-self-kicked', ged.GUI1, self._on_diconnected),
|
|
| 68 |
+ ('muc-self-kicked', ged.GUI1, self._on_disconnected),
|
|
| 68 | 69 |
('muc-user-status-show-changed', ged.GUI1, self._on_status_show_changed),
|
| 69 |
- ('muc-destroyed', ged.GUI1, self._on_diconnected),
|
|
| 70 |
+ ('muc-destroyed', ged.GUI1, self._on_disconnected),
|
|
| 70 | 71 |
])
|
| 71 | 72 |
# pylint: enable=line-too-long
|
| 72 | 73 |
|
| ... | ... | @@ -88,15 +89,14 @@ class PrivateChatControl(ChatControl): |
| 88 | 89 |
def get_our_nick(self):
|
| 89 | 90 |
return self.room_ctrl.nick
|
| 90 | 91 |
|
| 91 |
- def _nec_caps_received_pm(self, obj):
|
|
| 92 |
- if obj.conn.name != self.account or \
|
|
| 93 |
- obj.fjid != self.gc_contact.get_full_jid():
|
|
| 92 |
+ @event_filter(['account'])
|
|
| 93 |
+ def _on_caps_update(self, event):
|
|
| 94 |
+ if event.fjid != self.gc_contact.get_full_jid():
|
|
| 94 | 95 |
return
|
| 95 | 96 |
self.update_contact()
|
| 96 | 97 |
|
| 98 |
+ @event_filter(['account'])
|
|
| 97 | 99 |
def _on_nickname_changed(self, event):
|
| 98 |
- if event.account != self.account:
|
|
| 99 |
- return
|
|
| 100 | 100 |
if event.properties.new_jid != self.gc_contact.get_full_jid():
|
| 101 | 101 |
return
|
| 102 | 102 |
|
| ... | ... | @@ -118,9 +118,8 @@ class PrivateChatControl(ChatControl): |
| 118 | 118 |
self.parent_win.redraw_tab(self)
|
| 119 | 119 |
self.update_ui()
|
| 120 | 120 |
|
| 121 |
+ @event_filter(['account'])
|
|
| 121 | 122 |
def _on_status_show_changed(self, event):
|
| 122 |
- if event.account != self.account:
|
|
| 123 |
- return
|
|
| 124 | 123 |
if event.properties.jid != self.gc_contact.get_full_jid():
|
| 125 | 124 |
return
|
| 126 | 125 |
|
| ... | ... | @@ -146,25 +145,22 @@ class PrivateChatControl(ChatControl): |
| 146 | 145 |
self.parent_win.redraw_tab(self)
|
| 147 | 146 |
self.update_ui()
|
| 148 | 147 |
|
| 149 |
- def _on_diconnected(self, event):
|
|
| 150 |
- if event.account != self.account:
|
|
| 151 |
- return
|
|
| 148 |
+ @event_filter(['account'])
|
|
| 149 |
+ def _on_disconnected(self, event):
|
|
| 152 | 150 |
if event.properties.jid != self.gc_contact.get_full_jid():
|
| 153 | 151 |
return
|
| 154 | 152 |
|
| 155 | 153 |
self.got_disconnected()
|
| 156 | 154 |
|
| 155 |
+ @event_filter(['account'])
|
|
| 157 | 156 |
def _on_user_left(self, event):
|
| 158 |
- if event.account != self.account:
|
|
| 159 |
- return
|
|
| 160 | 157 |
if event.properties.jid != self.gc_contact.get_full_jid():
|
| 161 | 158 |
return
|
| 162 | 159 |
|
| 163 | 160 |
self.got_disconnected()
|
| 164 | 161 |
|
| 162 |
+ @event_filter(['account'])
|
|
| 165 | 163 |
def _on_user_joined(self, event):
|
| 166 |
- if event.account != self.account:
|
|
| 167 |
- return
|
|
| 168 | 164 |
if event.properties.jid != self.gc_contact.get_full_jid():
|
| 169 | 165 |
return
|
| 170 | 166 |
|
| ... | ... | @@ -173,15 +169,19 @@ class PrivateChatControl(ChatControl): |
| 173 | 169 |
self.parent_win.redraw_tab(self)
|
| 174 | 170 |
self.got_connected()
|
| 175 | 171 |
|
| 172 |
+ @event_filter(['account'])
|
|
| 176 | 173 |
def _on_self_presence(self, event):
|
| 177 |
- if event.account != self.account:
|
|
| 178 |
- return
|
|
| 179 | 174 |
if event.properties.jid != self.gc_contact.get_full_jid():
|
| 180 | 175 |
return
|
| 181 | 176 |
|
| 182 | 177 |
self.parent_win.redraw_tab(self)
|
| 183 | 178 |
self.got_connected()
|
| 184 | 179 |
|
| 180 |
+ def _on_update_gc_avatar(self, event):
|
|
| 181 |
+ if event.contact != self.gc_contact:
|
|
| 182 |
+ return
|
|
| 183 |
+ self.show_avatar()
|
|
| 184 |
+ |
|
| 185 | 185 |
def send_message(self, message, xhtml=None, process_commands=True,
|
| 186 | 186 |
attention=False):
|
| 187 | 187 |
"""
|
| ... | ... | @@ -214,11 +214,6 @@ class PrivateChatControl(ChatControl): |
| 214 | 214 |
else:
|
| 215 | 215 |
self.got_connected()
|
| 216 | 216 |
|
| 217 |
- def _nec_update_avatar(self, obj):
|
|
| 218 |
- if obj.contact != self.gc_contact:
|
|
| 219 |
- return
|
|
| 220 |
- self.show_avatar()
|
|
| 221 |
- |
|
| 222 | 217 |
def show_avatar(self):
|
| 223 | 218 |
if not app.config.get('show_avatar_in_chat'):
|
| 224 | 219 |
return
|