Commit 1f927251 authored by Philipp Hörist's avatar Philipp Hörist

Add config settings for chat markers

parent 1e37e384
Pipeline #4361 passed with stages
in 2 minutes and 59 seconds
......@@ -112,7 +112,7 @@ class ChatControl(ChatControlBase):
# Menu for the HeaderBar
self.control_menu = gui_menu_builder.get_singlechat_menu(
self.control_id, self.account, self.contact.jid)
self.control_id, self.account, self.contact.jid, self.TYPE_ID)
# Settings menu
self.xml.settings_menu.set_menu_model(self.control_menu)
......@@ -274,6 +274,16 @@ class ChatControl(ChatControlBase):
act.connect('change-state', self._on_send_chatstate)
self.parent_win.window.add_action(act)
value = app.config.get_per(
'contacts', self.contact.jid, 'send_marker', False)
act = Gio.SimpleAction.new_stateful(
'send-marker-' + self.control_id,
None,
GLib.Variant.new_boolean(value))
act.connect('change-state', self._on_send_marker)
self.parent_win.window.add_action(act)
def update_actions(self):
win = self.parent_win.window
online = app.account_is_connected(self.account)
......@@ -388,6 +398,11 @@ class ChatControl(ChatControlBase):
app.config.set_per('contacts', self.contact.jid,
'send_chatstate', param.get_string())
def _on_send_marker(self, action, param):
action.set_state(param)
app.config.set_per('contacts', self.contact.jid,
'send_marker', param.get_boolean())
def subscribe_events(self):
"""
Register listeners to the events class
......
......@@ -1229,8 +1229,9 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self.redraw_after_event_removed(jid)
# XEP-0333 Send <displayed> tag.
con.get_module('ChatMarkers').send_displayed_marker(
self.get_full_jid(), self.last_msg_id,
self.type_id == message_control.TYPE_GC)
self.contact,
self.last_msg_id,
self.type_id)
self.last_msg_id = None
# send chatstate inactive to the one we're leaving
# and active to the one we visit
......@@ -1279,8 +1280,9 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self.redraw_after_event_removed(jid)
# XEP-0333 Send <displayed> tag.
con.get_module('ChatMarkers').send_displayed_marker(
self.get_full_jid(), self.last_msg_id,
self.type_id == message_control.TYPE_GC)
self.contact,
self.last_msg_id,
self.type_id)
self.last_msg_id = None
def _on_scrollbar_button_release(self, scrollbar, event):
......
......@@ -414,6 +414,7 @@ class Config:
'contacts': ({
'speller_language': [opt_str, '', _('Language used for spell checking.')],
'send_chatstate': [opt_str, 'composing_only', _('Chat state notifications that are sent to contacts. Possible values: \'all\', \'composing_only\', \'disabled\'')],
'send_marker': [opt_bool, False, _('If enabled, contacts are informed when you read a message.')],
}, {}),
'encryption': ({
'encryption': [opt_str, '', _('The currently active encryption for that contact.')],
......@@ -426,6 +427,7 @@ class Config:
'minimize_on_autojoin': [opt_bool, True, _('If enabled, the group chat is minimized into the contact list when joining automatically.')],
'minimize_on_close': [opt_bool, True, _('If enabled, the group chat is minimized into the contact list when closing it.')],
'send_chatstate': [opt_str, 'composing_only', _('Chat state notifications that are sent to the group chat. Possible values: \'all\', \'composing_only\' or \'disabled\'.')],
'send_marker': [opt_bool, False, _('If enabled, contacts are informed when you read a message.')],
}, {}),
'plugins': ({
'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):
# TODO: Implement showing displayed state in ConversationsTextview
raise nbxmpp.NodeProcessed
def send_marker(self, jid, marker, id_, is_gc):
if is_gc:
message = nbxmpp.Message(to=jid, typ='groupchat')
else:
message = nbxmpp.Message(to=jid, typ='chat')
message.setTag(marker, namespace=nbxmpp.NS_CHATMARKERS,
attrs={'id': id_})
def _send_marker(self, contact, marker, id_, type_):
jid = contact.jid
if contact.is_pm_contact:
jid = app.get_jid_without_resource(contact.jid)
config = 'rooms' if type_ in ('gc', 'pm') else 'contacts'
if not app.config.get_per(config, jid, 'send_marker', False):
return
typ = 'groupchat' if type_ == 'gc' else 'chat'
message = nbxmpp.Message(to=contact.jid, typ=typ)
message.setMarker(marker, id_)
self._log.info('Send %s: %s', marker, contact.jid)
self._nbxmpp().send(message)
def send_displayed_marker(self, jid, id_, is_gc):
self.send_marker(jid, 'displayed', id_, is_gc)
def send_displayed_marker(self, contact, id_, type_):
self._send_marker(contact, 'displayed', id_, type_)
def get_instance(*args, **kwargs):
......
......@@ -354,6 +354,16 @@ class GroupchatControl(ChatControlBase):
act.connect('change-state', self._on_sync_threshold)
self.parent_win.window.add_action(act)
value = app.config.get_per(
'rooms', self.contact.jid, 'send_marker', False)
act = Gio.SimpleAction.new_stateful(
'send-marker-' + self.control_id,
None,
GLib.Variant.new_boolean(value))
act.connect('change-state', self._on_send_marker)
self.parent_win.window.add_action(act)
def update_actions(self):
if self.parent_win is None:
return
......@@ -587,6 +597,11 @@ class GroupchatControl(ChatControlBase):
app.config.set_per('rooms', self.contact.jid,
'send_chatstate', param.get_string())
def _on_send_marker(self, action, param):
action.set_state(param)
app.config.set_per('rooms', self.contact.jid,
'send_marker', param.get_boolean())
def _on_notify_on_all_messages(self, action, param):
action.set_state(param)
app.config.set_per('rooms', self.contact.jid,
......
......@@ -511,12 +511,13 @@ def get_transport_menu(contact, account):
return menu
def get_singlechat_menu(control_id, account, jid):
def get_singlechat_menu(control_id, account, jid, type_):
singlechat_menu = [
(_('Send File…'), [
('win.send-file-httpupload-', _('Upload File…')),
('win.send-file-jingle-', _('Send File Directly…')),
]),
('win.send-marker-', _('Send read marker')),
(_('Send Chatstate'), ['chatstate']),
('win.invite-contacts-', _('Invite Contacts')),
('win.add-to-roster-', _('Add to Contact List')),
......@@ -545,6 +546,9 @@ def get_singlechat_menu(control_id, account, jid):
for item in preset:
if isinstance(item[1], str):
action_name, label = item
if action_name == 'win.send-marker-' and type_ == 'pm':
continue
if action_name == 'app.browse-history':
menuitem = Gio.MenuItem.new(label, action_name)
dict_ = {'account': GLib.Variant('s', account),
......@@ -577,6 +581,7 @@ def get_groupchat_menu(control_id, account, jid):
('win.destroy-', _('Destroy Group Chat')),
]),
(_('Chat Settings'), [
('win.send-marker-', _('Send read marker')),
('win.print-join-left-', _('Show join/leave')),
('win.print-status-', _('Show status changes')),
('win.notify-on-message-', _('Notify on all messages')),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment