Philipp Hörist pushed to branch master at gajim / gajim
Commits: 3fcdc8a5 by André Apitzsch at 2021-02-12T21:54:30+01:00 Remove conversion of ASCII emojis
Display emojis as intended by the sender, i.e. don't replace it.
Closes #10416.
- - - - -
6 changed files:
- gajim/common/config.py - gajim/common/setting_values.py - gajim/gtk/emoji_data.py - gajim/gtk/emoji_data.pyi - gajim/gtk/preferences.py - gajim/gui_interface.py
Changes:
===================================== gajim/common/config.py ===================================== @@ -93,7 +93,6 @@ class Config: 'speller_language': [opt_str, '', _('Language used for spell checking.')], 'print_time': [opt_str, 'always', _(''always' - print time for every message.\n'sometimes' - print time every print_ichat_every_foo_minutes minute.\n'never' - never print time.')], 'emoticons_theme': [opt_str, 'noto-emoticons', '', True], - 'ascii_emoticons': [opt_bool, True, _('When enabled, ASCII emojis will be converted to graphical emojis.'), True], 'ascii_formatting': [opt_bool, True, _('Treat * / _ pairs as possible formatting characters.'), True], 'show_ascii_formatting_chars': [opt_bool, True, _('If enabled, do not '
===================================== gajim/common/setting_values.py ===================================== @@ -41,7 +41,6 @@ class _ACCOUNT_DEFAULT: 'speller_language': '', 'print_time': 'always', 'emoticons_theme': 'noto-emoticons', - 'ascii_emoticons': True, 'ascii_formatting': True, 'show_ascii_formatting_chars': True, 'sounds_on': True,
===================================== gajim/gtk/emoji_data.py ===================================== @@ -144,45 +144,11 @@ def _replace_emojis(self): start(), end(), pixbuf.copy(), codepoint)
-class EmojiAsciiData(dict): - def get_regex(self): - # When an emoticon is bordered by an alphanumeric character it - # is NOT expanded. e.g., foo:) NO, foo :) YES, (brb) NO, - # (:)) YES, etc. We still allow multiple emoticons - # side-by-side like :P:P:P - - # TODO: Refactor this - keys = sorted(self.keys(), key=len, reverse=True) - pre_pattern = '' - post_pattern = '' - emoticon_length = 0 - emoticons_pattern = '' - for emoticon in keys: - # escape regexp metachars - emoticon_escaped = re.escape(emoticon) - emoticons_pattern += emoticon_escaped + '|' - if emoticon_length != len(emoticon): - # Build up expressions to match emoticons next to others - pre_pattern = pre_pattern[:-1] + ')|(?<=' - post_pattern = post_pattern[:-1] + ')|(?=' - emoticon_length = len(emoticon) - pre_pattern += emoticon_escaped + '|' - post_pattern += emoticon_escaped + '|' - # We match from our list of emoticons, but they must either have - # whitespace, or another emoticon next to it to match successfully - # [\w.] alphanumeric and dot (for not matching 8) in (2.8)) - emoticons_pattern = r'(?:(?<![\w.]' + \ - pre_pattern[:-1] + '))' + '(?:' + \ - emoticons_pattern[:-1] + ')' + r'(?:(?![\w]' + \ - post_pattern[:-1] + '))' - return emoticons_pattern - - emoji_pixbufs = EmojiPixbufs()
# pylint: disable=line-too-long
-emoji_ascii_data = EmojiAsciiData([ +emoji_ascii_data = dict([ ("':-D", '\U0001F605'), (':)', '\U0001F642'), (':-O', '\U0001F62e'),
===================================== gajim/gtk/emoji_data.pyi ===================================== @@ -29,11 +29,8 @@ class EmojiData(OrderedDict): class EmojiPixbufs(dict): ...
-class EmojiAsciiData(dict): - ... - emoji_pixbufs = EmojiPixbufs()
-emoji_ascii_data = EmojiAsciiData() +emoji_ascii_data: dict[str, str]
emoji_data = EmojiData()
===================================== gajim/gtk/preferences.py ===================================== @@ -103,6 +103,8 @@ def __init__(self): self._ui.connect_signals(self)
self.show_all() + if sys.platform not in ('win32', 'darwin'): + self._ui.emoji.hide()
def get_ui(self): return self._ui @@ -727,30 +729,24 @@ def _on_dark_theme(value, *args):
class Emoji(PreferenceBox): def __init__(self, *args): + if sys.platform not in ('win32', 'darwin'): + PreferenceBox.__init__(self, []) + return
emoji_themes_items = [] for theme in helpers.get_available_emoticon_themes(): emoji_themes_items.append(theme)
settings = [ - Setting(SettingKind.SWITCH, - _('Convert ASCII Emojis'), + Setting(SettingKind.POPOVER, + _('Emoji Theme'), SettingType.CONFIG, - 'ascii_emoticons', - desc=_('Typing short codes like :-) will display emojis'), - callback=self._on_ascii_emoticons), + 'emoticons_theme', + desc=_('Choose from various emoji styles'), + props={'entries': emoji_themes_items}, + callback=self._on_emoticons_theme) ]
- if sys.platform in ('win32', 'darwin'): - settings.append( - Setting(SettingKind.POPOVER, - _('Emoji Theme'), - SettingType.CONFIG, - 'emoticons_theme', - desc=_('Choose from various emoji styles'), - props={'entries': emoji_themes_items}, - callback=self._on_emoticons_theme)) - PreferenceBox.__init__(self, settings)
def _on_emoticons_theme(self, *args): @@ -763,10 +759,6 @@ def _toggle_emoticons(): for ctrl in controls: ctrl.toggle_emoticons()
- @staticmethod - def _on_ascii_emoticons(*args): - app.interface.make_regexps() -
class StatusIcon(PreferenceBox): def __init__(self, *args):
===================================== gajim/gui_interface.py ===================================== @@ -102,7 +102,6 @@ from gajim.gui.dialogs import PassphraseDialog from gajim.gui.filechoosers import FileChooserDialog from gajim.gui.emoji_data import emoji_data -from gajim.gui.emoji_data import emoji_ascii_data from gajim.gui.filetransfer import FileTransfersWindow from gajim.gui.filetransfer_progress import FileTransferProgress from gajim.gui.roster_item_exchange import RosterItemExchangeWindow @@ -1392,8 +1391,6 @@ def make_regexps(self): # because emoticons match later (in the string) they need to be after # basic matches that may occur earlier emoticons = emoji_data.get_regex() - if app.settings.get('ascii_emoticons'): - emoticons += '|%s' % emoji_ascii_data.get_regex()
self.emot_and_basic = '%s|%s' % (basic_pattern, emoticons)
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/3fcdc8a5d0c4019f8b95ecc38dac94aa6...