Philipp Hörist pushed to branch chat_markers at gajim / gajim
Commits:
-
1f927251
by Philipp Hörist at 2019-10-07T18:44:28Z
6 changed files:
- gajim/chat_control.py
- gajim/chat_control_base.py
- gajim/common/config.py
- gajim/common/modules/chat_markers.py
- gajim/groupchat_control.py
- gajim/gui_menu_builder.py
Changes:
| ... | ... | @@ -112,7 +112,7 @@ class ChatControl(ChatControlBase): |
| 112 | 112 |
|
| 113 | 113 |
# Menu for the HeaderBar
|
| 114 | 114 |
self.control_menu = gui_menu_builder.get_singlechat_menu(
|
| 115 |
- self.control_id, self.account, self.contact.jid)
|
|
| 115 |
+ self.control_id, self.account, self.contact.jid, self.TYPE_ID)
|
|
| 116 | 116 |
|
| 117 | 117 |
# Settings menu
|
| 118 | 118 |
self.xml.settings_menu.set_menu_model(self.control_menu)
|
| ... | ... | @@ -274,6 +274,16 @@ class ChatControl(ChatControlBase): |
| 274 | 274 |
act.connect('change-state', self._on_send_chatstate)
|
| 275 | 275 |
self.parent_win.window.add_action(act)
|
| 276 | 276 |
|
| 277 |
+ value = app.config.get_per(
|
|
| 278 |
+ 'contacts', self.contact.jid, 'send_marker', False)
|
|
| 279 |
+ |
|
| 280 |
+ act = Gio.SimpleAction.new_stateful(
|
|
| 281 |
+ 'send-marker-' + self.control_id,
|
|
| 282 |
+ None,
|
|
| 283 |
+ GLib.Variant.new_boolean(value))
|
|
| 284 |
+ act.connect('change-state', self._on_send_marker)
|
|
| 285 |
+ self.parent_win.window.add_action(act)
|
|
| 286 |
+ |
|
| 277 | 287 |
def update_actions(self):
|
| 278 | 288 |
win = self.parent_win.window
|
| 279 | 289 |
online = app.account_is_connected(self.account)
|
| ... | ... | @@ -388,6 +398,11 @@ class ChatControl(ChatControlBase): |
| 388 | 398 |
app.config.set_per('contacts', self.contact.jid,
|
| 389 | 399 |
'send_chatstate', param.get_string())
|
| 390 | 400 |
|
| 401 |
+ def _on_send_marker(self, action, param):
|
|
| 402 |
+ action.set_state(param)
|
|
| 403 |
+ app.config.set_per('contacts', self.contact.jid,
|
|
| 404 |
+ 'send_marker', param.get_boolean())
|
|
| 405 |
+ |
|
| 391 | 406 |
def subscribe_events(self):
|
| 392 | 407 |
"""
|
| 393 | 408 |
Register listeners to the events class
|
| ... | ... | @@ -1229,8 +1229,9 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): |
| 1229 | 1229 |
self.redraw_after_event_removed(jid)
|
| 1230 | 1230 |
# XEP-0333 Send <displayed> tag.
|
| 1231 | 1231 |
con.get_module('ChatMarkers').send_displayed_marker(
|
| 1232 |
- self.get_full_jid(), self.last_msg_id,
|
|
| 1233 |
- self.type_id == message_control.TYPE_GC)
|
|
| 1232 |
+ self.contact,
|
|
| 1233 |
+ self.last_msg_id,
|
|
| 1234 |
+ self.type_id)
|
|
| 1234 | 1235 |
self.last_msg_id = None
|
| 1235 | 1236 |
# send chatstate inactive to the one we're leaving
|
| 1236 | 1237 |
# and active to the one we visit
|
| ... | ... | @@ -1279,8 +1280,9 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): |
| 1279 | 1280 |
self.redraw_after_event_removed(jid)
|
| 1280 | 1281 |
# XEP-0333 Send <displayed> tag.
|
| 1281 | 1282 |
con.get_module('ChatMarkers').send_displayed_marker(
|
| 1282 |
- self.get_full_jid(), self.last_msg_id,
|
|
| 1283 |
- self.type_id == message_control.TYPE_GC)
|
|
| 1283 |
+ self.contact,
|
|
| 1284 |
+ self.last_msg_id,
|
|
| 1285 |
+ self.type_id)
|
|
| 1284 | 1286 |
self.last_msg_id = None
|
| 1285 | 1287 |
|
| 1286 | 1288 |
def _on_scrollbar_button_release(self, scrollbar, event):
|
| ... | ... | @@ -414,6 +414,7 @@ class Config: |
| 414 | 414 |
'contacts': ({
|
| 415 | 415 |
'speller_language': [opt_str, '', _('Language used for spell checking.')],
|
| 416 | 416 |
'send_chatstate': [opt_str, 'composing_only', _('Chat state notifications that are sent to contacts. Possible values: \'all\', \'composing_only\', \'disabled\'')],
|
| 417 |
+ 'send_marker': [opt_bool, False, _('If enabled, contacts are informed when you read a message.')],
|
|
| 417 | 418 |
}, {}),
|
| 418 | 419 |
'encryption': ({
|
| 419 | 420 |
'encryption': [opt_str, '', _('The currently active encryption for that contact.')],
|
| ... | ... | @@ -426,6 +427,7 @@ class Config: |
| 426 | 427 |
'minimize_on_autojoin': [opt_bool, True, _('If enabled, the group chat is minimized into the contact list when joining automatically.')],
|
| 427 | 428 |
'minimize_on_close': [opt_bool, True, _('If enabled, the group chat is minimized into the contact list when closing it.')],
|
| 428 | 429 |
'send_chatstate': [opt_str, 'composing_only', _('Chat state notifications that are sent to the group chat. Possible values: \'all\', \'composing_only\' or \'disabled\'.')],
|
| 430 |
+ 'send_marker': [opt_bool, False, _('If enabled, contacts are informed when you read a message.')],
|
|
| 429 | 431 |
}, {}),
|
| 430 | 432 |
'plugins': ({
|
| 431 | 433 |
'active': [opt_bool, False, _('If enabled, plugins will be activated on startup (this is saved when exiting Gajim). This option SHOULD NOT be used to (de)activate plugins. Use the plugin window instead.')],
|
| ... | ... | @@ -86,17 +86,23 @@ class ChatMarkers(BaseModule): |
| 86 | 86 |
# TODO: Implement showing displayed state in ConversationsTextview
|
| 87 | 87 |
raise nbxmpp.NodeProcessed
|
| 88 | 88 |
|
| 89 |
- def send_marker(self, jid, marker, id_, is_gc):
|
|
| 90 |
- if is_gc:
|
|
| 91 |
- message = nbxmpp.Message(to=jid, typ='groupchat')
|
|
| 92 |
- else:
|
|
| 93 |
- message = nbxmpp.Message(to=jid, typ='chat')
|
|
| 94 |
- message.setTag(marker, namespace=nbxmpp.NS_CHATMARKERS,
|
|
| 95 |
- attrs={'id': id_})
|
|
| 89 |
+ def _send_marker(self, contact, marker, id_, type_):
|
|
| 90 |
+ jid = contact.jid
|
|
| 91 |
+ if contact.is_pm_contact:
|
|
| 92 |
+ jid = app.get_jid_without_resource(contact.jid)
|
|
| 93 |
+ |
|
| 94 |
+ config = 'rooms' if type_ in ('gc', 'pm') else 'contacts'
|
|
| 95 |
+ if not app.config.get_per(config, jid, 'send_marker', False):
|
|
| 96 |
+ return
|
|
| 97 |
+ |
|
| 98 |
+ typ = 'groupchat' if type_ == 'gc' else 'chat'
|
|
| 99 |
+ message = nbxmpp.Message(to=contact.jid, typ=typ)
|
|
| 100 |
+ message.setMarker(marker, id_)
|
|
| 101 |
+ self._log.info('Send %s: %s', marker, contact.jid)
|
|
| 96 | 102 |
self._nbxmpp().send(message)
|
| 97 | 103 |
|
| 98 |
- def send_displayed_marker(self, jid, id_, is_gc):
|
|
| 99 |
- self.send_marker(jid, 'displayed', id_, is_gc)
|
|
| 104 |
+ def send_displayed_marker(self, contact, id_, type_):
|
|
| 105 |
+ self._send_marker(contact, 'displayed', id_, type_)
|
|
| 100 | 106 |
|
| 101 | 107 |
|
| 102 | 108 |
def get_instance(*args, **kwargs):
|
| ... | ... | @@ -354,6 +354,16 @@ class GroupchatControl(ChatControlBase): |
| 354 | 354 |
act.connect('change-state', self._on_sync_threshold)
|
| 355 | 355 |
self.parent_win.window.add_action(act)
|
| 356 | 356 |
|
| 357 |
+ value = app.config.get_per(
|
|
| 358 |
+ 'rooms', self.contact.jid, 'send_marker', False)
|
|
| 359 |
+ |
|
| 360 |
+ act = Gio.SimpleAction.new_stateful(
|
|
| 361 |
+ 'send-marker-' + self.control_id,
|
|
| 362 |
+ None,
|
|
| 363 |
+ GLib.Variant.new_boolean(value))
|
|
| 364 |
+ act.connect('change-state', self._on_send_marker)
|
|
| 365 |
+ self.parent_win.window.add_action(act)
|
|
| 366 |
+ |
|
| 357 | 367 |
def update_actions(self):
|
| 358 | 368 |
if self.parent_win is None:
|
| 359 | 369 |
return
|
| ... | ... | @@ -587,6 +597,11 @@ class GroupchatControl(ChatControlBase): |
| 587 | 597 |
app.config.set_per('rooms', self.contact.jid,
|
| 588 | 598 |
'send_chatstate', param.get_string())
|
| 589 | 599 |
|
| 600 |
+ def _on_send_marker(self, action, param):
|
|
| 601 |
+ action.set_state(param)
|
|
| 602 |
+ app.config.set_per('rooms', self.contact.jid,
|
|
| 603 |
+ 'send_marker', param.get_boolean())
|
|
| 604 |
+ |
|
| 590 | 605 |
def _on_notify_on_all_messages(self, action, param):
|
| 591 | 606 |
action.set_state(param)
|
| 592 | 607 |
app.config.set_per('rooms', self.contact.jid,
|
| ... | ... | @@ -511,12 +511,13 @@ def get_transport_menu(contact, account): |
| 511 | 511 |
return menu
|
| 512 | 512 |
|
| 513 | 513 |
|
| 514 |
-def get_singlechat_menu(control_id, account, jid):
|
|
| 514 |
+def get_singlechat_menu(control_id, account, jid, type_):
|
|
| 515 | 515 |
singlechat_menu = [
|
| 516 | 516 |
(_('Send File…'), [
|
| 517 | 517 |
('win.send-file-httpupload-', _('Upload File…')),
|
| 518 | 518 |
('win.send-file-jingle-', _('Send File Directly…')),
|
| 519 | 519 |
]),
|
| 520 |
+ ('win.send-marker-', _('Send read marker')),
|
|
| 520 | 521 |
(_('Send Chatstate'), ['chatstate']),
|
| 521 | 522 |
('win.invite-contacts-', _('Invite Contacts')),
|
| 522 | 523 |
('win.add-to-roster-', _('Add to Contact List')),
|
| ... | ... | @@ -545,6 +546,9 @@ def get_singlechat_menu(control_id, account, jid): |
| 545 | 546 |
for item in preset:
|
| 546 | 547 |
if isinstance(item[1], str):
|
| 547 | 548 |
action_name, label = item
|
| 549 |
+ if action_name == 'win.send-marker-' and type_ == 'pm':
|
|
| 550 |
+ continue
|
|
| 551 |
+ |
|
| 548 | 552 |
if action_name == 'app.browse-history':
|
| 549 | 553 |
menuitem = Gio.MenuItem.new(label, action_name)
|
| 550 | 554 |
dict_ = {'account': GLib.Variant('s', account),
|
| ... | ... | @@ -577,6 +581,7 @@ def get_groupchat_menu(control_id, account, jid): |
| 577 | 581 |
('win.destroy-', _('Destroy Group Chat')),
|
| 578 | 582 |
]),
|
| 579 | 583 |
(_('Chat Settings'), [
|
| 584 |
+ ('win.send-marker-', _('Send read marker')),
|
|
| 580 | 585 |
('win.print-join-left-', _('Show join/leave')),
|
| 581 | 586 |
('win.print-status-', _('Show status changes')),
|
| 582 | 587 |
('win.notify-on-message-', _('Notify on all messages')),
|