mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
Merge pull request #140 from fiatjaf/tag-unique
eliminate all forms of "p" tag duplication
This commit is contained in:
commit
8ccfb2a945
@ -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() {
|
if let Some((root, _maybeurl)) = event.replies_to_root() {
|
||||||
// Add an 'e' tag for the root
|
// Add an 'e' tag for the root
|
||||||
tags.push(Tag::Event {
|
tags.push(Tag::Event {
|
||||||
id: root,
|
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()),
|
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 {
|
if GLOBALS.settings.read().await.set_client_tag {
|
||||||
tags.push(Tag::Other {
|
tags.push(Tag::Other {
|
||||||
tag: "client".to_owned(),
|
tag: "client".to_owned(),
|
||||||
|
@ -542,24 +542,18 @@ fn render_post_actual(
|
|||||||
if ui.add(ReplyButton {}).clicked() {
|
if ui.add(ReplyButton {}).clicked() {
|
||||||
app.replying_to = Some(event.id);
|
app.replying_to = Some(event.id);
|
||||||
|
|
||||||
// Add a 'p' tag for the author we are replying to
|
// Cleanup tags
|
||||||
app.draft_tags.push(Tag::Pubkey {
|
app.draft_tags = vec![];
|
||||||
pubkey: event.pubkey.into(),
|
// Add a 'p' tag for the author we are replying to (except if it is our own key)
|
||||||
recommended_relay_url: None, // FIXME
|
if let Some(pubkey) = GLOBALS.signer.blocking_read().public_key() {
|
||||||
petname: None,
|
if pubkey != event.pubkey {
|
||||||
});
|
app.draft_tags.push(Tag::Pubkey {
|
||||||
|
pubkey: event.pubkey.into(),
|
||||||
// Add all the 'p' tags from the note we are replying to
|
recommended_relay_url: None, // FIXME
|
||||||
let parent_p_tags: Vec<Tag> = event
|
petname: None,
|
||||||
.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);
|
ui.add_space(24.0);
|
||||||
|
Loading…
Reference in New Issue
Block a user