mirror of
https://github.com/youwen5/iamb.git
synced 2025-06-19 21:29:52 -07:00
Support displaying shortcodes instead of Emojis in messages (#222)
This commit is contained in:
parent
0c52375e06
commit
23a729e565
8 changed files with 164 additions and 49 deletions
|
@ -61,7 +61,7 @@ use crate::{
|
|||
base::RoomInfo,
|
||||
config::ApplicationSettings,
|
||||
message::html::{parse_matrix_html, StyleTree},
|
||||
util::{space, space_span, take_width, wrapped_text},
|
||||
util::{replace_emojis_in_str, space, space_span, take_width, wrapped_text},
|
||||
};
|
||||
|
||||
mod html;
|
||||
|
@ -834,7 +834,8 @@ impl Message {
|
|||
|
||||
if let Some(r) = &reply {
|
||||
let w = width.saturating_sub(2);
|
||||
let mut replied = r.show_msg(w, style, true);
|
||||
let mut replied =
|
||||
r.show_msg(w, style, true, settings.tunables.message_shortcode_display);
|
||||
let mut sender = r.sender_span(info, settings);
|
||||
let sender_width = UnicodeWidthStr::width(sender.content.as_ref());
|
||||
let trailing = w.saturating_sub(sender_width + 1);
|
||||
|
@ -862,7 +863,12 @@ impl Message {
|
|||
}
|
||||
|
||||
// Now show the message contents, and the inlined reply if we couldn't find it above.
|
||||
let msg = self.show_msg(width, style, reply.is_some());
|
||||
let msg = self.show_msg(
|
||||
width,
|
||||
style,
|
||||
reply.is_some(),
|
||||
settings.tunables.message_shortcode_display,
|
||||
);
|
||||
fmt.push_text(msg, style, &mut text);
|
||||
|
||||
if text.lines.is_empty() {
|
||||
|
@ -871,7 +877,9 @@ impl Message {
|
|||
}
|
||||
|
||||
if settings.tunables.reaction_display {
|
||||
let mut emojis = printer::TextPrinter::new(width, style, false);
|
||||
// Pass false for emoji_shortcodes parameter because we handle shortcodes ourselves
|
||||
// before pushing to the printer.
|
||||
let mut emojis = printer::TextPrinter::new(width, style, false, false);
|
||||
let mut reactions = 0;
|
||||
|
||||
for (key, count) in info.get_reactions(self.event.event_id()).into_iter() {
|
||||
|
@ -917,7 +925,9 @@ impl Message {
|
|||
|
||||
if len > 0 {
|
||||
let style = Style::default();
|
||||
let mut threaded = printer::TextPrinter::new(width, style, false).literal(true);
|
||||
let emoji_shortcodes = settings.tunables.message_shortcode_display;
|
||||
let mut threaded =
|
||||
printer::TextPrinter::new(width, style, false, emoji_shortcodes).literal(true);
|
||||
let len = Span::styled(len.to_string(), style.add_modifier(StyleModifier::BOLD));
|
||||
threaded.push_str(" \u{2937} ", style);
|
||||
threaded.push_span_nobreak(len);
|
||||
|
@ -929,11 +939,20 @@ impl Message {
|
|||
text
|
||||
}
|
||||
|
||||
pub fn show_msg(&self, width: usize, style: Style, hide_reply: bool) -> Text {
|
||||
pub fn show_msg(
|
||||
&self,
|
||||
width: usize,
|
||||
style: Style,
|
||||
hide_reply: bool,
|
||||
emoji_shortcodes: bool,
|
||||
) -> Text {
|
||||
if let Some(html) = &self.html {
|
||||
html.to_text(width, style, hide_reply)
|
||||
html.to_text(width, style, hide_reply, emoji_shortcodes)
|
||||
} else {
|
||||
let mut msg = self.event.body();
|
||||
if emoji_shortcodes {
|
||||
msg = Cow::Owned(replace_emojis_in_str(msg.as_ref()));
|
||||
}
|
||||
|
||||
if self.downloaded {
|
||||
msg.to_mut().push_str(" \u{2705}");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue