send custom emoji

This commit is contained in:
2026-07-31 09:53:42 +07:00
parent a93f827a55
commit 48ea6ca81c
3 changed files with 20 additions and 1 deletions

View File

@@ -25,4 +25,5 @@ serde.workspace = true
linkify = "0.10.0"
pulldown-cmark = "0.13.1"
regex = "1"

View File

@@ -1,5 +1,5 @@
use std::collections::{BTreeMap, HashMap, HashSet};
use std::sync::{Arc, RwLock};
use std::sync::{Arc, LazyLock, RwLock};
pub use actions::*;
use anyhow::{Context as AnyhowContext, Error};
@@ -17,6 +17,7 @@ use gpui::{
use itertools::Itertools;
use nostr_sdk::prelude::*;
use person::{Person, PersonRegistry};
use regex::Regex;
use settings::{AppSettings, SignerKind};
use smallvec::{SmallVec, smallvec};
use state::{NostrRegistry, upload};
@@ -38,6 +39,11 @@ use crate::text::RenderedText;
const REACTION_EMOJIS: &[&str] = &["👍", "👎", "😄", "🎉", "😕", "❤️", "🚀", "👀"];
const COMPACT_REACTION_EMOJIS: &[&str] = &["👍", "❤️", "👀"];
/// Regex matching strings that consist entirely of emoji characters,
/// zero-width joiners, variation selectors, and keycap combiners.
static EMOJI_RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^[\p{Emoji}\u{200D}\u{FE0F}\u{20E3}]+$").unwrap());
mod actions;
mod text;
@@ -361,6 +367,17 @@ impl ChatPanel {
return;
}
// If replying to exactly one message with only a valid emoji,
// send as a reaction instead of a text message
if replies.len() == 1 && EMOJI_RE.is_match(&content) && self.attachments.read(cx).is_empty()
{
for reply in &replies {
self.send_reaction(&content, reply, window, cx);
}
self.clear(window, cx);
return;
}
self.send_message(&content, replies, false, window, cx);
}