Philipp Hörist pushed to branch mainwindow at gajim / gajim
Commits:
-
0a1e65bb
by lovetox at 2021-02-07T23:31:21+01:00
7 changed files:
- gajim/chat_control.py
- gajim/common/modules/message.py
- gajim/groupchat_control.py
- gajim/gtk/chat_list.py
- gajim/gtk/chat_stack.py
- gajim/gtk/main.py
- gajim/privatechat_control.py
Changes:
| ... | ... | @@ -188,19 +188,19 @@ def __init__(self, parent_win, contact, acct, session, resource=None): |
| 188 | 188 |
|
| 189 | 189 |
self.subscribe_events()
|
| 190 | 190 |
|
| 191 |
- if not session:
|
|
| 192 |
- # Don't use previous session if we want to a specific resource
|
|
| 193 |
- # and it's not the same
|
|
| 194 |
- if not resource:
|
|
| 195 |
- resource = contact.resource
|
|
| 196 |
- session = app.connections[self.account].find_controlless_session(
|
|
| 197 |
- self.contact.jid, resource)
|
|
| 191 |
+ # if not session:
|
|
| 192 |
+ # # Don't use previous session if we want to a specific resource
|
|
| 193 |
+ # # and it's not the same
|
|
| 194 |
+ # if not resource:
|
|
| 195 |
+ # resource = contact.resource
|
|
| 196 |
+ # session = app.connections[self.account].find_controlless_session(
|
|
| 197 |
+ # self.contact.jid, resource)
|
|
| 198 |
+ |
|
| 199 |
+ # if session:
|
|
| 200 |
+ # session.control = self
|
|
| 201 |
+ # self.session = session
|
|
| 198 | 202 |
|
| 199 | 203 |
self.setup_seclabel()
|
| 200 |
- if session:
|
|
| 201 |
- session.control = self
|
|
| 202 |
- self.session = session
|
|
| 203 |
- |
|
| 204 | 204 |
self.add_actions()
|
| 205 | 205 |
self.update_ui()
|
| 206 | 206 |
self.set_lock_image()
|
| ... | ... | @@ -176,7 +176,7 @@ def _message_received(self, _con, stanza, properties): |
| 176 | 176 |
'account': self._account,
|
| 177 | 177 |
'additional_data': additional_data,
|
| 178 | 178 |
'fjid': fjid,
|
| 179 |
- 'jid': jid,
|
|
| 179 |
+ 'jid': fjid if properties.is_muc_pm else jid,
|
|
| 180 | 180 |
'resource': resource,
|
| 181 | 181 |
'stanza_id': stanza_id,
|
| 182 | 182 |
'unique_id': stanza_id or message_id,
|
| ... | ... | @@ -679,7 +679,13 @@ def on_groupchat_maximize(self): |
| 679 | 679 |
self.last_msg_id = None
|
| 680 | 680 |
|
| 681 | 681 |
def _on_roster_row_activated(self, _roster, nick):
|
| 682 |
- self._start_private_message(nick)
|
|
| 682 |
+ gc_c = app.contacts.get_gc_contact(self.account, self.room_jid, nick)
|
|
| 683 |
+ muc_prefer_direct_msg = app.settings.get('muc_prefer_direct_msg')
|
|
| 684 |
+ if not self.is_anonymous and muc_prefer_direct_msg:
|
|
| 685 |
+ jid = app.get_jid_without_resource(gc_c.jid)
|
|
| 686 |
+ app.window.add_chat(self.account, jid, 'contact', select=True)
|
|
| 687 |
+ else:
|
|
| 688 |
+ app.window.add_private_chat(self.account, gc_c.get_full_jid())
|
|
| 683 | 689 |
|
| 684 | 690 |
def on_msg_textview_populate_popup(self, textview, menu):
|
| 685 | 691 |
"""
|
| ... | ... | @@ -823,38 +829,6 @@ def _on_gc_message_received(self, event): |
| 823 | 829 |
additional_data=event.additional_data)
|
| 824 | 830 |
event.needs_highlight = self.needs_visual_notification(event.msgtxt)
|
| 825 | 831 |
|
| 826 |
- def on_private_message(self, nick, sent, msg, tim, session, additional_data,
|
|
| 827 |
- message_id, msg_log_id=None, displaymarking=None):
|
|
| 828 |
- # Do we have a queue?
|
|
| 829 |
- fjid = self.room_jid + '/' + nick
|
|
| 830 |
- |
|
| 831 |
- event = events.PmEvent(msg,
|
|
| 832 |
- '',
|
|
| 833 |
- 'incoming',
|
|
| 834 |
- tim,
|
|
| 835 |
- '',
|
|
| 836 |
- msg_log_id,
|
|
| 837 |
- session=session,
|
|
| 838 |
- displaymarking=displaymarking,
|
|
| 839 |
- sent_forwarded=sent,
|
|
| 840 |
- additional_data=additional_data,
|
|
| 841 |
- message_id=message_id)
|
|
| 842 |
- |
|
| 843 |
- app.events.add_event(self.account, fjid, event)
|
|
| 844 |
- |
|
| 845 |
- if allow_popup_window(self.account):
|
|
| 846 |
- self._start_private_message(nick)
|
|
| 847 |
- else:
|
|
| 848 |
- self.roster.draw_contact(nick)
|
|
| 849 |
- if self.parent_win:
|
|
| 850 |
- self.parent_win.show_title()
|
|
| 851 |
- self.parent_win.redraw_tab(self)
|
|
| 852 |
- |
|
| 853 |
- contact = app.contacts.get_contact_with_highest_priority(
|
|
| 854 |
- self.account, self.room_jid)
|
|
| 855 |
- if contact:
|
|
| 856 |
- app.interface.roster.draw_contact(self.room_jid, self.account)
|
|
| 857 |
- |
|
| 858 | 832 |
def add_message(self, text, contact='', tim=None,
|
| 859 | 833 |
displaymarking=None, correct_id=None, message_id=None,
|
| 860 | 834 |
stanza_id=None, additional_data=None):
|
| ... | ... | @@ -1052,24 +1026,6 @@ def _on_muc_config_changed(self, event): |
| 1052 | 1026 |
for change in changes:
|
| 1053 | 1027 |
self.add_info_message(change)
|
| 1054 | 1028 |
|
| 1055 |
- def _on_message_received(self, event):
|
|
| 1056 |
- if not event.properties.jid.bare_match(self.room_jid):
|
|
| 1057 |
- return
|
|
| 1058 |
- |
|
| 1059 |
- if event.properties.is_muc_pm and not event.session.control:
|
|
| 1060 |
- # We got a pm from this room
|
|
| 1061 |
- nick = event.resource
|
|
| 1062 |
- # otherwise pass it off to the control to be queued
|
|
| 1063 |
- self.on_private_message(nick,
|
|
| 1064 |
- event.properties.is_sent_carbon,
|
|
| 1065 |
- event.msgtxt,
|
|
| 1066 |
- event.properties.timestamp,
|
|
| 1067 |
- self.session,
|
|
| 1068 |
- event.additional_data,
|
|
| 1069 |
- event.properties.id,
|
|
| 1070 |
- msg_log_id=event.msg_log_id,
|
|
| 1071 |
- displaymarking=event.displaymarking)
|
|
| 1072 |
- |
|
| 1073 | 1029 |
def _on_our_show(self, event):
|
| 1074 | 1030 |
client = app.get_client(event.account)
|
| 1075 | 1031 |
if (event.show == 'offline' and
|
| ... | ... | @@ -1111,10 +1067,10 @@ def leave(self, reason=None): |
| 1111 | 1067 |
def rejoin(self):
|
| 1112 | 1068 |
app.connections[self.account].get_module('MUC').join(self._muc_data)
|
| 1113 | 1069 |
|
| 1114 |
- def send_pm(self, nick, message=None):
|
|
| 1115 |
- ctrl = self._start_private_message(nick)
|
|
| 1116 |
- if message is not None:
|
|
| 1117 |
- ctrl.send_message(message)
|
|
| 1070 |
+ # def send_pm(self, nick, message=None):
|
|
| 1071 |
+ # ctrl = self._start_private_message(nick)
|
|
| 1072 |
+ # if message is not None:
|
|
| 1073 |
+ # ctrl.send_message(message)
|
|
| 1118 | 1074 |
|
| 1119 | 1075 |
def _on_muc_self_presence(self, event):
|
| 1120 | 1076 |
nick = event.properties.muc_nickname
|
| ... | ... | @@ -1758,22 +1714,6 @@ def focus(self): |
| 1758 | 1714 |
elif page_name == 'destroy':
|
| 1759 | 1715 |
self.xml.destroy_reason_entry.grab_focus_without_selecting()
|
| 1760 | 1716 |
|
| 1761 |
- def _start_private_message(self, nick):
|
|
| 1762 |
- gc_c = app.contacts.get_gc_contact(self.account, self.room_jid, nick)
|
|
| 1763 |
- nick_jid = gc_c.get_full_jid()
|
|
| 1764 |
- |
|
| 1765 |
- muc_prefer_direct_msg = app.settings.get('muc_prefer_direct_msg')
|
|
| 1766 |
- pm_queue = len(app.events.get_events(
|
|
| 1767 |
- self.account, jid=nick_jid, types=['pm']))
|
|
| 1768 |
- if not self.is_anonymous and muc_prefer_direct_msg and not pm_queue:
|
|
| 1769 |
- jid = app.get_jid_without_resource(gc_c.jid)
|
|
| 1770 |
- ctrl = app.interface.new_chat_from_jid(self.account, jid)
|
|
| 1771 |
- else:
|
|
| 1772 |
- ctrl = app.interface.new_private_chat(gc_c, self.account)
|
|
| 1773 |
- ctrl.parent_win.set_active_tab(ctrl)
|
|
| 1774 |
- |
|
| 1775 |
- return ctrl
|
|
| 1776 |
- |
|
| 1777 | 1717 |
def append_nick_in_msg_textview(self, _widget, nick):
|
| 1778 | 1718 |
self.msg_textview.remove_placeholder()
|
| 1779 | 1719 |
message_buffer = self.msg_textview.get_buffer()
|
| ... | ... | @@ -63,7 +63,7 @@ def _update_timer(self): |
| 63 | 63 |
|
| 64 | 64 |
def _query_tooltip(self, widget, _x_pos, y_pos, _keyboard_mode, tooltip):
|
| 65 | 65 |
row = self.get_row_at_y(y_pos)
|
| 66 |
- if row is None:
|
|
| 66 |
+ if row is None or row.type == 'pm':
|
|
| 67 | 67 |
self._tab_tooltip.clear_tooltip()
|
| 68 | 68 |
return False
|
| 69 | 69 |
|
| ... | ... | @@ -6,6 +6,7 @@ |
| 6 | 6 |
from gajim.common import app
|
| 7 | 7 |
from gajim.chat_control import ChatControl
|
| 8 | 8 |
from gajim.groupchat_control import GroupchatControl
|
| 9 |
+from gajim.privatechat_control import PrivateChatControl
|
|
| 9 | 10 |
|
| 10 | 11 |
from gajim.common.i18n import _
|
| 11 | 12 |
|
| ... | ... | @@ -77,6 +78,17 @@ def add_group_chat(self, account, jid): |
| 77 | 78 |
self.add_named(control.widget, f'{account}:{jid}')
|
| 78 | 79 |
control.widget.show_all()
|
| 79 | 80 |
|
| 81 |
+ def add_private_chat(self, account, jid):
|
|
| 82 |
+ mw = self.get_toplevel()
|
|
| 83 |
+ bare_jid = app.get_jid_without_resource(jid)
|
|
| 84 |
+ nick = app.get_resource_from_jid(jid)
|
|
| 85 |
+ gc_c = app.contacts.get_gc_contact(account, bare_jid, nick)
|
|
| 86 |
+ contact = gc_c.as_contact()
|
|
| 87 |
+ control = PrivateChatControl(mw, gc_c, contact, account, None)
|
|
| 88 |
+ self._controls[(account, str(jid))] = control
|
|
| 89 |
+ self.add_named(control.widget, f'{account}:{jid}')
|
|
| 90 |
+ control.widget.show_all()
|
|
| 91 |
+ |
|
| 80 | 92 |
def remove_chat(self, account, jid):
|
| 81 | 93 |
control = self._controls.pop((account, jid))
|
| 82 | 94 |
self.remove(control.widget)
|
| ... | ... | @@ -363,6 +363,14 @@ def add_chat(self, account, jid, type_, select=False): |
| 363 | 363 |
type_,
|
| 364 | 364 |
select=select)
|
| 365 | 365 |
|
| 366 |
+ def add_private_chat(self, account, jid, select=False):
|
|
| 367 |
+ workspace_id = self._workspace_side_bar.get_active_workspace()
|
|
| 368 |
+ self.add_chat_for_workspace(workspace_id,
|
|
| 369 |
+ account,
|
|
| 370 |
+ jid,
|
|
| 371 |
+ 'pm',
|
|
| 372 |
+ select=select)
|
|
| 373 |
+ |
|
| 366 | 374 |
def add_chat_for_workspace(self,
|
| 367 | 375 |
workspace_id,
|
| 368 | 376 |
account,
|
| ... | ... | @@ -377,6 +385,12 @@ def add_chat_for_workspace(self, |
| 377 | 385 |
|
| 378 | 386 |
if type_ == 'groupchat':
|
| 379 | 387 |
self._chat_stack.add_group_chat(account, jid)
|
| 388 |
+ elif type_ == 'pm':
|
|
| 389 |
+ if not self._startup_finished:
|
|
| 390 |
+ # TODO: Currently we cant load private chats at start
|
|
| 391 |
+ # because the Contacts dont exist yet
|
|
| 392 |
+ return
|
|
| 393 |
+ self._chat_stack.add_private_chat(account, jid)
|
|
| 380 | 394 |
else:
|
| 381 | 395 |
self._chat_stack.add_chat(account, jid)
|
| 382 | 396 |
self._chat_list_stack.add_chat(workspace_id, account, jid, type_)
|
| ... | ... | @@ -449,7 +463,10 @@ def _on_event(self, event): |
| 449 | 463 |
|
| 450 | 464 |
if not self.chat_exists(event.account, event.jid):
|
| 451 | 465 |
if event.name == 'message-received':
|
| 452 |
- self.add_chat(event.account, event.jid, 'contact')
|
|
| 466 |
+ if event.properties.is_muc_pm:
|
|
| 467 |
+ self.add_private_chat(event.account, event.jid, 'pm')
|
|
| 468 |
+ else:
|
|
| 469 |
+ self.add_chat(event.account, event.jid, 'contact')
|
|
| 453 | 470 |
else:
|
| 454 | 471 |
# No chat is open, dont handle any gui events
|
| 455 | 472 |
return
|
| ... | ... | @@ -48,26 +48,22 @@ class PrivateChatControl(ChatControl): |
| 48 | 48 |
|
| 49 | 49 |
def __init__(self, parent_win, gc_contact, contact, account, session):
|
| 50 | 50 |
room_jid = gc_contact.room_jid
|
| 51 |
- self.room_ctrl = app.interface.msg_win_mgr.get_gc_control(
|
|
| 52 |
- room_jid, account)
|
|
| 53 |
- if room_jid in app.interface.minimized_controls[account]:
|
|
| 54 |
- self.room_ctrl = app.interface.minimized_controls[account][room_jid]
|
|
| 55 |
- |
|
| 51 |
+ self.room_ctrl = app.window.get_control(account, room_jid)
|
|
| 56 | 52 |
self.gc_contact = gc_contact
|
| 57 | 53 |
ChatControl.__init__(self, parent_win, contact, account, session)
|
| 58 | 54 |
|
| 59 | 55 |
# pylint: disable=line-too-long
|
| 60 |
- self.register_events([
|
|
| 61 |
- ('update-gc-avatar', ged.GUI1, self._on_update_gc_avatar),
|
|
| 62 |
- ('caps-update', ged.GUI1, self._on_caps_update),
|
|
| 63 |
- ('muc-user-joined', ged.GUI1, self._on_user_joined),
|
|
| 64 |
- ('muc-user-left', ged.GUI1, self._on_user_left),
|
|
| 65 |
- ('muc-nickname-changed', ged.GUI1, self._on_nickname_changed),
|
|
| 66 |
- ('muc-self-presence', ged.GUI1, self._on_self_presence),
|
|
| 67 |
- ('muc-self-kicked', ged.GUI1, self._on_disconnected),
|
|
| 68 |
- ('muc-user-status-show-changed', ged.GUI1, self._on_status_show_changed),
|
|
| 69 |
- ('muc-destroyed', ged.GUI1, self._on_disconnected),
|
|
| 70 |
- ])
|
|
| 56 |
+ # self.register_events([
|
|
| 57 |
+ # ('update-gc-avatar', ged.GUI1, self._on_update_gc_avatar),
|
|
| 58 |
+ # ('caps-update', ged.GUI1, self._on_caps_update),
|
|
| 59 |
+ # ('muc-user-joined', ged.GUI1, self._on_user_joined),
|
|
| 60 |
+ # ('muc-user-left', ged.GUI1, self._on_user_left),
|
|
| 61 |
+ # ('muc-nickname-changed', ged.GUI1, self._on_nickname_changed),
|
|
| 62 |
+ # ('muc-self-presence', ged.GUI1, self._on_self_presence),
|
|
| 63 |
+ # ('muc-self-kicked', ged.GUI1, self._on_disconnected),
|
|
| 64 |
+ # ('muc-user-status-show-changed', ged.GUI1, self._on_status_show_changed),
|
|
| 65 |
+ # ('muc-destroyed', ged.GUI1, self._on_disconnected),
|
|
| 66 |
+ # ])
|
|
| 71 | 67 |
# pylint: enable=line-too-long
|
| 72 | 68 |
|
| 73 | 69 |
@property
|