From 15c2803c70445d2620275888af116efd79b0e56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Sat, 25 Dec 2021 10:42:05 +0100 Subject: [PATCH] message-text: Make emoji-only messages bigger --- Cargo.lock | 1 + Cargo.toml | 1 + data/resources/style.css | 4 ++++ .../content/room_history/message_row/text.rs | 21 +++++++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index c4a959c9..80c329d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1001,6 +1001,7 @@ dependencies = [ "once_cell", "qrcode", "rand 0.8.4", + "regex", "secret-service", "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index e4271a56..83f44389 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,7 @@ gst = {version = "0.17", package = "gstreamer"} gst_base = {version = "0.17", package = "gstreamer-base"} gst_video = {version = "0.17", package = "gstreamer-video"} image = {version = "0.23", default-features = false, features=["png"]} +regex = "1.5.4" [dependencies.sourceview] package = "sourceview5" diff --git a/data/resources/style.css b/data/resources/style.css index c2b64b43..5b172e45 100644 --- a/data/resources/style.css +++ b/data/resources/style.css @@ -209,6 +209,10 @@ headerbar.flat { margin-left: 46px; } +.room-history .event-content .emoji { + font-size: 3em; +} + .room-history .event-content .thumbnail { border-radius: 6px; background-color: @light_3; diff --git a/src/session/content/room_history/message_row/text.rs b/src/session/content/room_history/message_row/text.rs index d08ea060..31a26b2c 100644 --- a/src/session/content/room_history/message_row/text.rs +++ b/src/session/content/room_history/message_row/text.rs @@ -5,6 +5,8 @@ use html2pango::{ html_escape, markup_links, }; use matrix_sdk::ruma::events::room::message::{FormattedBody, MessageFormat}; +use once_cell::sync::Lazy; +use regex::Regex; use sourceview::prelude::*; use crate::session::{ @@ -13,6 +15,21 @@ use crate::session::{ UserExt, }; +static EMOJI_REGEX: Lazy = Lazy::new(|| { + Regex::new( + r"(?x) + ^ + [\p{White_Space}\p{Emoji_Component}]* + [\p{Emoji}--\p{Decimal_Number}]+ + [\p{White_Space}\p{Emoji}\p{Emoji_Component}--\p{Decimal_Number}]* + $ + # That string is made of at least one emoji, except digits, possibly more, + # possibly with modifiers, possibly with spaces, but nothing else + ", + ) + .unwrap() +}); + mod imp { use super::*; use once_cell::sync::Lazy; @@ -199,6 +216,10 @@ impl MessageText { child }; + if EMOJI_REGEX.is_match(text) { + child.add_css_class("emoji"); + } + if use_markup { child.set_markup(text); } else {