feat: add support for reaction #37

Merged
reya merged 4 commits from feat/reaction into master 2026-07-31 02:58:43 +00:00
3 changed files with 20 additions and 1 deletions
Showing only changes of commit 48ea6ca81c - Show all commits

1
Cargo.lock generated
View File

@@ -1087,6 +1087,7 @@ dependencies = [
"nostr-sdk", "nostr-sdk",
"person", "person",
"pulldown-cmark", "pulldown-cmark",
"regex",
"serde", "serde",
"settings", "settings",
"smallvec", "smallvec",

View File

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

View File

@@ -1,5 +1,5 @@
use std::collections::{BTreeMap, HashMap, HashSet}; use std::collections::{BTreeMap, HashMap, HashSet};
use std::sync::{Arc, RwLock}; use std::sync::{Arc, LazyLock, RwLock};
pub use actions::*; pub use actions::*;
use anyhow::{Context as AnyhowContext, Error}; use anyhow::{Context as AnyhowContext, Error};
@@ -17,6 +17,7 @@ use gpui::{
use itertools::Itertools; use itertools::Itertools;
use nostr_sdk::prelude::*; use nostr_sdk::prelude::*;
use person::{Person, PersonRegistry}; use person::{Person, PersonRegistry};
use regex::Regex;
use settings::{AppSettings, SignerKind}; use settings::{AppSettings, SignerKind};
use smallvec::{SmallVec, smallvec}; use smallvec::{SmallVec, smallvec};
use state::{NostrRegistry, upload}; use state::{NostrRegistry, upload};
@@ -38,6 +39,11 @@ use crate::text::RenderedText;
const REACTION_EMOJIS: &[&str] = &["👍", "👎", "😄", "🎉", "😕", "❤️", "🚀", "👀"]; const REACTION_EMOJIS: &[&str] = &["👍", "👎", "😄", "🎉", "😕", "❤️", "🚀", "👀"];
const COMPACT_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 actions;
mod text; mod text;
@@ -361,6 +367,17 @@ impl ChatPanel {
return; 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); self.send_message(&content, replies, false, window, cx);
} }