[acronyms] Dont expand if acronym euqals nick

Fixes #68
This commit is contained in:
Philipp Hörist
2018-12-09 12:22:27 +01:00
parent 7119f70bba
commit d4a16bd27e

View File

@@ -22,6 +22,7 @@ from functools import partial
from gi.repository import GLib from gi.repository import GLib
from gajim.common import app
from gajim.common import configpaths from gajim.common import configpaths
from gajim.plugins import GajimPlugin from gajim.plugins import GajimPlugin
@@ -82,7 +83,7 @@ class AcronymsExpanderPlugin(GajimPlugin):
self.acronyms = acronyms self.acronyms = acronyms
self._save_acronyms(acronyms) self._save_acronyms(acronyms)
def _on_buffer_changed(self, _textview, buffer_): def _on_buffer_changed(self, _textview, buffer_, contact, account):
if self._replace_in_progress: if self._replace_in_progress:
return return
@@ -108,6 +109,17 @@ class AcronymsExpanderPlugin(GajimPlugin):
# Get last word and cut invoker # Get last word and cut invoker
last_word = word_start_iter.get_slice(insert_iter).strip() last_word = word_start_iter.get_slice(insert_iter).strip()
if contact.is_groupchat():
nick_list = app.contacts.get_nick_list(account, contact.jid)
if last_word in nick_list:
log.info('Groupchat participant has same nick as acronym')
return
if contact.is_pm_contact:
if last_word == contact.get_shown_name():
log.info('Contact name equals acronym')
return
substitute = self.acronyms.get(last_word) substitute = self.acronyms.get(last_word)
if substitute is None: if substitute is None:
log.debug('%s not an acronym', last_word) log.debug('%s not an acronym', last_word)
@@ -130,7 +142,10 @@ class AcronymsExpanderPlugin(GajimPlugin):
def _connect(self, chat_control): def _connect(self, chat_control):
textview = chat_control.msg_textview textview = chat_control.msg_textview
handler_id = textview.connect('text-changed', self._on_buffer_changed) handler_id = textview.connect('text-changed',
self._on_buffer_changed,
chat_control.contact,
chat_control.account)
self._handler_ids[id(textview)] = handler_id self._handler_ids[id(textview)] = handler_id
def _disconnect(self, chat_control): def _disconnect(self, chat_control):