add event map
This commit is contained in:
@@ -87,6 +87,9 @@ pub struct ChatRegistry {
|
|||||||
/// Tracking events seen on which relays in the current session
|
/// Tracking events seen on which relays in the current session
|
||||||
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
|
||||||
|
event_map: Arc<RwLock<HashMap<EventId, EventId>>>,
|
||||||
|
|
||||||
/// Tracking the status of unwrapping gift wrap events.
|
/// Tracking the status of unwrapping gift wrap events.
|
||||||
tracking_flag: Arc<AtomicBool>,
|
tracking_flag: Arc<AtomicBool>,
|
||||||
|
|
||||||
@@ -150,6 +153,7 @@ impl ChatRegistry {
|
|||||||
rooms: vec![],
|
rooms: vec![],
|
||||||
trashes: cx.new(|_| BTreeSet::default()),
|
trashes: cx.new(|_| BTreeSet::default()),
|
||||||
seens: Arc::new(RwLock::new(HashMap::default())),
|
seens: Arc::new(RwLock::new(HashMap::default())),
|
||||||
|
event_map: Arc::new(RwLock::new(HashMap::default())),
|
||||||
tracking_flag: Arc::new(AtomicBool::new(false)),
|
tracking_flag: Arc::new(AtomicBool::new(false)),
|
||||||
signal_rx: rx,
|
signal_rx: rx,
|
||||||
signal_tx: tx,
|
signal_tx: tx,
|
||||||
@@ -165,6 +169,7 @@ impl ChatRegistry {
|
|||||||
let signer = nostr.read(cx).signer();
|
let signer = nostr.read(cx).signer();
|
||||||
let status = self.tracking_flag.clone();
|
let status = self.tracking_flag.clone();
|
||||||
let seens = self.seens.clone();
|
let seens = self.seens.clone();
|
||||||
|
let event_map = self.event_map.clone();
|
||||||
let trashes = self.trashes.downgrade();
|
let trashes = self.trashes.downgrade();
|
||||||
|
|
||||||
let initialized_at = Timestamp::now();
|
let initialized_at = Timestamp::now();
|
||||||
@@ -206,6 +211,13 @@ impl ChatRegistry {
|
|||||||
// Extract the rumor from the gift wrap event
|
// Extract the rumor from the gift wrap event
|
||||||
match extract_rumor(&client, &signer, event.as_ref()).await {
|
match extract_rumor(&client, &signer, event.as_ref()).await {
|
||||||
Ok(rumor) => {
|
Ok(rumor) => {
|
||||||
|
// Map the rumor id to the gift wrap event id for later lookup
|
||||||
|
{
|
||||||
|
let mut event_map = event_map.write().await;
|
||||||
|
event_map.insert(rumor.id.unwrap(), event.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the rumor has a recipient
|
||||||
if rumor.tags.is_empty() {
|
if rumor.tags.is_empty() {
|
||||||
let signal =
|
let signal =
|
||||||
Signal::error(event.as_ref(), "Recipient is missing");
|
Signal::error(event.as_ref(), "Recipient is missing");
|
||||||
@@ -214,6 +226,7 @@ impl ChatRegistry {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the rumor was created after the chat was initialized (for detecting new messages)
|
||||||
if rumor.created_at >= initialized_at {
|
if rumor.created_at >= initialized_at {
|
||||||
let signal = Signal::message(event.id, rumor);
|
let signal = Signal::message(event.id, rumor);
|
||||||
tx.send_async(signal).await?;
|
tx.send_async(signal).await?;
|
||||||
|
|||||||
@@ -13,4 +13,5 @@ pub enum Command {
|
|||||||
Copy(PublicKey),
|
Copy(PublicKey),
|
||||||
Relays(PublicKey),
|
Relays(PublicKey),
|
||||||
Njump(PublicKey),
|
Njump(PublicKey),
|
||||||
|
Trace(EventId),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -658,9 +658,19 @@ impl ChatPanel {
|
|||||||
Command::Njump(public_key) => {
|
Command::Njump(public_key) => {
|
||||||
self.open_njump(public_key, cx);
|
self.open_njump(public_key, cx);
|
||||||
}
|
}
|
||||||
|
Command::Trace(id) => {
|
||||||
|
self.open_trace(id, window, cx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn open_trace(&mut self, id: &EventId, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
window.open_modal(cx, move |this, _window, cx| {
|
||||||
|
// TODO
|
||||||
|
this.child(v_flex().child(""))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn open_relays(&mut self, public_key: &PublicKey, window: &mut Window, cx: &mut Context<Self>) {
|
fn open_relays(&mut self, public_key: &PublicKey, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let profile = self.profile(public_key, cx);
|
let profile = self.profile(public_key, cx);
|
||||||
|
|
||||||
@@ -1131,15 +1141,10 @@ impl ChatPanel {
|
|||||||
.ghost()
|
.ghost()
|
||||||
.dropdown_menu({
|
.dropdown_menu({
|
||||||
let public_key = *public_key;
|
let public_key = *public_key;
|
||||||
let _id = *id;
|
let id = *id;
|
||||||
move |this, _window, _cx| {
|
move |this, _window, _cx| {
|
||||||
this.menu("Copy author", Box::new(Command::Copy(public_key)))
|
this.menu("Copy author", Box::new(Command::Copy(public_key)))
|
||||||
/*
|
.menu("Seen on", Box::new(Command::Trace(id)))
|
||||||
.menu(
|
|
||||||
"Trace",
|
|
||||||
Box::new(Command::Trace(id)),
|
|
||||||
)
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user