diff options
author | fiaxh <git@lightrise.org> | 2018-12-27 12:35:48 +0100 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2018-12-27 13:01:35 +0100 |
commit | 965f4da75ae5a5b308191bd61890b4277504f5b1 (patch) | |
tree | 038763267d512b8f64681af80fdeec4e09de6f17 /main/src/ui/util | |
parent | d0d68f5878267320eb99ad544e9117553af11532 (diff) | |
download | dino-965f4da75ae5a5b308191bd61890b4277504f5b1.tar.gz dino-965f4da75ae5a5b308191bd61890b4277504f5b1.zip |
Detect emoji-only messages and display them larger
Diffstat (limited to 'main/src/ui/util')
-rw-r--r-- | main/src/ui/util/helper.vala | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala index 049b2d07..2f2bb84d 100644 --- a/main/src/ui/util/helper.vala +++ b/main/src/ui/util/helper.vala @@ -203,4 +203,46 @@ public static string parse_add_markup(string s_, string? highlight_word, bool pa return s; } +public int get_only_emoji_count(string markup_text) { + int emoji_no = 0; + int index_ref = 0; + unichar curchar = 0, altchar = 0; + bool last_was_emoji = false, last_was_modifier_base = false, last_was_keycap = false; + while (markup_text.get_next_char(ref index_ref, out curchar)) { + if (last_was_emoji && last_was_keycap && curchar == 0x20E3) { + // keycap sequence + continue; + } + + last_was_keycap = false; + + if (last_was_emoji && curchar == 0x200D && markup_text.get_next_char(ref index_ref, out curchar)) { + // zero width joiner + last_was_emoji = false; + emoji_no--; + } + + if (last_was_emoji && last_was_modifier_base && Unicode.has_binary_property(curchar, Unicode.EMOJI_MODIFIER)) { + // still an emoji, but no longer a modifier base + last_was_modifier_base = false; + } else if (Unicode.has_binary_property(curchar, Unicode.EMOJI_PRESENTATION)) { + if (Unicode.has_binary_property(curchar, Unicode.EMOJI_MODIFIER_BASE)) { + last_was_modifier_base = true; + } + emoji_no++; + last_was_emoji = true; + } else if (curchar == ' ') { + last_was_emoji = false; + } else if (markup_text.get_next_char(ref index_ref, out altchar) && altchar == 0xFE0F) { + // U+FE0F = VARIATION SELECTOR-16 + emoji_no++; + last_was_emoji = true; + last_was_keycap = (curchar >= 0x30 && curchar <= 0x39) || curchar == 0x23 || curchar == 0x2A; + } else { + return -1; + } + } + return emoji_no; +} + } |