feat: add tracking for which signer encrypted the message #27

Merged
reya merged 2 commits from track-signer into master 2026-04-01 02:53:50 +00:00
Showing only changes of commit cdba276a35 - Show all commits

View File

@@ -75,6 +75,9 @@ impl Signal {
} }
} }
type Dekey = bool;
type GiftWrapId = EventId;
/// Chat Registry /// Chat Registry
#[derive(Debug)] #[derive(Debug)]
pub struct ChatRegistry { pub struct ChatRegistry {
@@ -88,7 +91,7 @@ pub struct ChatRegistry {
seens: Arc<RwLock<HashMap<EventId, HashSet<RelayUrl>>>>, seens: Arc<RwLock<HashMap<EventId, HashSet<RelayUrl>>>>,
/// Mapping of unwrapped event ids to their gift wrap event ids /// Mapping of unwrapped event ids to their gift wrap event ids
event_map: Arc<RwLock<HashMap<EventId, EventId>>>, event_map: Arc<RwLock<HashMap<EventId, (GiftWrapId, Dekey)>>>,
/// Tracking the status of unwrapping gift wrap events. /// Tracking the status of unwrapping gift wrap events.
tracking_flag: Arc<AtomicBool>, tracking_flag: Arc<AtomicBool>,
@@ -191,7 +194,10 @@ impl ChatRegistry {
}; };
match *message { match *message {
RelayMessage::Event { event, .. } => { RelayMessage::Event {
event,
subscription_id,
} => {
// Keep track of which relays have seen this event // Keep track of which relays have seen this event
{ {
let mut seens = seens.write().await; let mut seens = seens.write().await;
@@ -214,7 +220,8 @@ impl ChatRegistry {
// Map the rumor id to the gift wrap event id for later lookup // Map the rumor id to the gift wrap event id for later lookup
{ {
let mut event_map = event_map.write().await; let mut event_map = event_map.write().await;
event_map.insert(rumor.id.unwrap(), event.id); let dekey = subscription_id.as_ref() == &sub_id1;
event_map.insert(rumor.id.unwrap(), (event.id, dekey));
} }
// Check if the rumor has a recipient // Check if the rumor has a recipient
@@ -222,8 +229,6 @@ impl ChatRegistry {
let signal = let signal =
Signal::error(event.as_ref(), "Recipient is missing"); Signal::error(event.as_ref(), "Recipient is missing");
tx.send_async(signal).await?; tx.send_async(signal).await?;
continue;
} }
// Check if the rumor was created after the chat was initialized (for detecting new messages) // Check if the rumor was created after the chat was initialized (for detecting new messages)
@@ -231,6 +236,7 @@ impl ChatRegistry {
let signal = Signal::message(event.id, rumor); let signal = Signal::message(event.id, rumor);
tx.send_async(signal).await?; tx.send_async(signal).await?;
} else { } else {
// Mark the chat still processing new messages
status.store(true, Ordering::Release); status.store(true, Ordering::Release);
} }
} }
@@ -473,7 +479,7 @@ impl ChatRegistry {
self.event_map self.event_map
.read_blocking() .read_blocking()
.get(id) .get(id)
.map(|id| self.seen_on(id)) .map(|(id, _dekey)| self.seen_on(id))
} }
/// Get the relays that have seen a given gift wrap id. /// Get the relays that have seen a given gift wrap id.
@@ -485,6 +491,15 @@ impl ChatRegistry {
.unwrap_or_default() .unwrap_or_default()
} }
/// Check if a given rumor was encrypted by the dekey.
pub fn encrypted_by_dekey(&self, id: &EventId) -> bool {
self.event_map
.read_blocking()
.get(id)
.map(|(_, dekey)| *dekey)
.unwrap_or(false)
}
/// Add a new room to the start of list. /// Add a new room to the start of list.
pub fn add_room<I>(&mut self, room: I, cx: &mut Context<Self>) pub fn add_room<I>(&mut self, room: I, cx: &mut Context<Self>)
where where