Merge pull request #140 from fiatjaf/tag-unique

eliminate all forms of "p" tag duplication
This commit is contained in:
Michael Dilger 2023-01-15 14:36:28 +13:00 committed by GitHub
commit 8ccfb2a945
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 43 deletions

View File

@ -680,11 +680,43 @@ impl Overlord {
}
};
// Add all the 'p' tags from the note we are replying to
for parent_p_tag in event.tags.iter() {
match parent_p_tag {
Tag::Pubkey {
pubkey: parent_p_tag_pubkey,
..
} => {
if parent_p_tag_pubkey.0 == public_key.as_hex_string() {
// do not tag ourselves
continue;
}
if tags
.iter()
.find(|existing_tag| {
matches!(
existing_tag,
Tag::Pubkey { pubkey: existing_pubkey, .. } if existing_pubkey.0 == parent_p_tag_pubkey.0
)
})
.is_some() {
// we already have this `p` tag, do not add again
continue;
}
// add (FIXME: include relay hint it not exists)
tags.push(parent_p_tag.to_owned())
}
_ => {}
}
}
if let Some((root, _maybeurl)) = event.replies_to_root() {
// Add an 'e' tag for the root
tags.push(Tag::Event {
id: root,
recommended_relay_url: DbRelay::recommended_relay_for_reply(reply_to).await?,
recommended_relay_url: DbRelay::recommended_relay_for_reply(root).await?,
marker: Some("root".to_string()),
});
@ -705,30 +737,6 @@ impl Overlord {
});
}
/* These are now done in the UI so the poster can refer to them
// Add a 'p' tag for the author we are replying to
tags.push(Tag::Pubkey {
pubkey: event.pubkey,
recommended_relay_url: None, // FIXME
petname: None,
});
// Add all the 'p' tags from the note we are replying to
let parent_p_tags: Vec<Tag> = event
.tags
.iter()
.filter(|t| match t {
Tag::Pubkey { pubkey, .. } => *pubkey != event.pubkey,
_ => false,
})
.map(|t| t.to_owned())
.collect();
tags.extend(parent_p_tags);
// FIXME deduplicate 'p' tags
*/
if GLOBALS.settings.read().await.set_client_tag {
tags.push(Tag::Other {
tag: "client".to_owned(),

View File

@ -542,24 +542,18 @@ fn render_post_actual(
if ui.add(ReplyButton {}).clicked() {
app.replying_to = Some(event.id);
// Add a 'p' tag for the author we are replying to
// Cleanup tags
app.draft_tags = vec![];
// Add a 'p' tag for the author we are replying to (except if it is our own key)
if let Some(pubkey) = GLOBALS.signer.blocking_read().public_key() {
if pubkey != event.pubkey {
app.draft_tags.push(Tag::Pubkey {
pubkey: event.pubkey.into(),
recommended_relay_url: None, // FIXME
petname: None,
});
// Add all the 'p' tags from the note we are replying to
let parent_p_tags: Vec<Tag> = event
.tags
.iter()
.filter(|t| match t {
Tag::Pubkey { pubkey, .. } => *pubkey != event.pubkey.into(),
_ => false,
})
.map(|t| t.to_owned())
.collect();
app.draft_tags.extend(parent_p_tags);
}
}
}
ui.add_space(24.0);