Unverified Commit 3fcdc8a5 authored by André's avatar André

Remove conversion of ASCII emojis

Display emojis as intended by the sender, i.e. don't replace it.

Closes #10416.
parent 739ead2b
Pipeline #7291 passed with stages
in 8 minutes and 19 seconds
......@@ -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 '
......
......@@ -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,
......
......@@ -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'),
......
......@@ -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()
......@@ -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):
......
......@@ -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)
......
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