feat: add support for custom emojis (NIP-30) (#63)

Reviewed-on: reya/coop#63
This commit is contained in:
2026-10-11 13:22:53 +00:00
parent b4ce9368e2
commit 291471075b
16 changed files with 493 additions and 63 deletions
+2
View File
@@ -10,6 +10,8 @@ anyhow.workspace = true
futures.workspace = true
serde_json.workspace = true
state = { path = "../state" }
common = { path = "../common" }
person = { path = "../person" }
chat = { path = "../chat" }
gpui.workspace = true
+19 -3
View File
@@ -3,8 +3,10 @@ use std::time::Duration;
use anyhow::{Result, anyhow, bail};
use chat::Message;
use gpui::{App, AppContext, Context, EventEmitter, SharedString, Task};
use common::emojis_from_tags;
use gpui::{App, AppContext, Context, EventEmitter, SharedString, SharedUri, Task};
use nostr_sdk::prelude::*;
use person::PersonRegistry;
use smallvec::{SmallVec, smallvec};
use state::NostrRegistry;
@@ -31,6 +33,7 @@ enum Absorbed {
pub struct Reaction {
pub id: EventId,
pub emoji: String,
pub image: Option<SharedUri>,
pub author: PublicKey,
}
@@ -233,7 +236,11 @@ impl Group {
replies: Vec<EventId>,
cx: &mut Context<Self>,
) -> Task<Result<()>> {
self.dispatch(move |id, prev| id.message(content, &replies, prev), cx)
let emojis = PersonRegistry::emoji_tags(content, cx);
self.dispatch(
move |id, prev| id.message(content, &replies, &emojis, prev),
cx,
)
}
pub fn send_reaction(
@@ -242,7 +249,11 @@ impl Group {
emoji: String,
cx: &mut Context<Self>,
) -> Task<Result<()>> {
self.dispatch(move |id, prev| id.reaction(target, &emoji, prev), cx)
let emojis = PersonRegistry::emoji_tags(&emoji, cx);
self.dispatch(
move |id, prev| id.reaction(target, &emoji, &emojis, prev),
cx,
)
}
pub fn remove_user(
@@ -756,9 +767,14 @@ impl Group {
return false;
}
let emojis = emojis_from_tags(&event.tags);
let image = Message::reaction_image(&event.content, &emojis)
.map(|url| SharedUri::from(url.to_string()));
self.reactions.entry(target).or_default().push(Reaction {
id: event.id,
emoji: event.content.clone(),
image,
author: event.pubkey,
});
+10 -1
View File
@@ -110,18 +110,27 @@ impl GroupId {
&self,
content: &str,
replies: &[EventId],
emojis: &[Tag],
previous: Option<Tag>,
) -> EventBuilder {
EventBuilder::new(Kind::ChatMessage, content)
.tag(self.h_tag())
.tags(replies.iter().copied().map(Tag::event))
.tags(emojis.iter().cloned())
.tag_maybe(previous)
}
pub fn reaction(&self, target: EventId, emoji: &str, previous: Option<Tag>) -> EventBuilder {
pub fn reaction(
&self,
target: EventId,
emoji: &str,
emojis: &[Tag],
previous: Option<Tag>,
) -> EventBuilder {
EventBuilder::new(Kind::Reaction, emoji)
.tag(self.h_tag())
.tag(Tag::event(target))
.tags(emojis.iter().cloned())
.tag_maybe(previous)
}