Add 'E' tags when generating events

This commit is contained in:
Mike Dilger 2023-10-13 11:25:16 +13:00
parent 2596eff98a
commit 94651b8ca0
2 changed files with 31 additions and 4 deletions

View File

@ -11,8 +11,8 @@ use crate::people::Person;
use crate::person_relay::PersonRelay; use crate::person_relay::PersonRelay;
use crate::relay::Relay; use crate::relay::Relay;
use crate::tags::{ use crate::tags::{
add_addr_to_tags, add_event_to_tags, add_pubkey_hex_to_tags, add_pubkey_to_tags, add_addr_to_tags, add_event_parent_to_tags, add_event_to_tags, add_pubkey_hex_to_tags,
add_subject_to_tags_if_missing, add_pubkey_to_tags, add_subject_to_tags_if_missing,
}; };
use gossip_relay_picker::{Direction, RelayAssignment}; use gossip_relay_picker::{Direction, RelayAssignment};
use http::StatusCode; use http::StatusCode;
@ -1407,17 +1407,19 @@ impl Overlord {
// Add an 'e' tag for the root // Add an 'e' tag for the root
add_event_to_tags(&mut tags, root, "root").await; add_event_to_tags(&mut tags, root, "root").await;
// Add an 'e' tag for the note we are replying to // Add an 'e' and 'E' tag for the note we are replying to
add_event_to_tags(&mut tags, parent_id, "reply").await; add_event_to_tags(&mut tags, parent_id, "reply").await;
add_event_parent_to_tags(&mut tags, parent_id).await;
} else { } else {
let ancestors = parent.referred_events(); let ancestors = parent.referred_events();
if ancestors.is_empty() { if ancestors.is_empty() {
// parent is the root // parent is the root
add_event_to_tags(&mut tags, parent_id, "root").await; add_event_to_tags(&mut tags, parent_id, "root").await;
} else { } else {
// Add an 'e' tag for the note we are replying to // Add an 'e' and 'E' tag for the note we are replying to
// (and we don't know about the root, the parent is malformed). // (and we don't know about the root, the parent is malformed).
add_event_to_tags(&mut tags, parent_id, "reply").await; add_event_to_tags(&mut tags, parent_id, "reply").await;
add_event_parent_to_tags(&mut tags, parent_id).await;
} }
} }

View File

@ -28,6 +28,31 @@ pub async fn add_pubkey_to_tags(existing_tags: &mut Vec<Tag>, added: &PublicKey)
add_pubkey_hex_to_tags(existing_tags, &added.as_hex_string().into()).await add_pubkey_hex_to_tags(existing_tags, &added.as_hex_string().into()).await
} }
pub async fn add_event_parent_to_tags(existing_tags: &mut Vec<Tag>, added: Id) -> usize {
let newtag = Tag::EventParent {
id: added,
recommended_relay_url: Relay::recommended_relay_for_reply(added)
.await
.ok()
.flatten()
.map(|rr| rr.to_unchecked_url()),
trailing: Vec::new(),
};
match existing_tags.iter().position(|existing_tag| {
matches!(
existing_tag,
Tag::EventParent { id: existing_e, .. } if existing_e.0 == added.0
)
}) {
None => {
existing_tags.push(newtag);
existing_tags.len() - 1
}
Some(idx) => idx,
}
}
pub async fn add_event_to_tags(existing_tags: &mut Vec<Tag>, added: Id, marker: &str) -> usize { pub async fn add_event_to_tags(existing_tags: &mut Vec<Tag>, added: Id, marker: &str) -> usize {
let newtag = Tag::Event { let newtag = Tag::Event {
id: added, id: added,