mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-29 08:21:47 +00:00
Threads: if main event is replaceable, subscribe replies appropriately
This commit is contained in:
parent
def1bfbd37
commit
c7d85ae2b3
@ -267,7 +267,7 @@ pub(crate) enum ToMinionPayloadDetail {
|
||||
SubscribeInbox(Unixtime),
|
||||
SubscribePersonFeed(PublicKey, Unixtime),
|
||||
SubscribeReplies(IdHex),
|
||||
SubscribeRootReplies(IdHex),
|
||||
SubscribeRootReplies(EventReference),
|
||||
SubscribeDmChannel(DmChannel),
|
||||
SubscribeNip46,
|
||||
TempSubscribeGeneralFeedChunk(Unixtime),
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::dm_channel::DmChannel;
|
||||
use crate::globals::GLOBALS;
|
||||
use nostr_types::{EventKind, Filter, IdHex, PublicKey, PublicKeyHex, Unixtime};
|
||||
use nostr_types::{EventAddr, EventKind, Filter, IdHex, PublicKey, PublicKeyHex, Tag, Unixtime};
|
||||
|
||||
pub enum FeedRange {
|
||||
// Long-term subscription for anything after the given time
|
||||
@ -219,8 +219,6 @@ pub fn discover(pubkeys: &[PublicKey]) -> Vec<Filter> {
|
||||
}]
|
||||
}
|
||||
|
||||
// ancestors can be done with FetchEvent, FetchEventAddr
|
||||
|
||||
pub fn replies(main: IdHex, spamsafe: bool) -> Vec<Filter> {
|
||||
let mut filters: Vec<Filter> = Vec::new();
|
||||
|
||||
@ -253,6 +251,38 @@ pub fn replies(main: IdHex, spamsafe: bool) -> Vec<Filter> {
|
||||
filters
|
||||
}
|
||||
|
||||
pub fn replies_to_eaddr(ea: &EventAddr, spamsafe: bool) -> Vec<Filter> {
|
||||
let mut filters: Vec<Filter> = Vec::new();
|
||||
|
||||
// Allow all feed related event kinds (excluding DMs)
|
||||
// (related because we want deletion events, and may as well get likes and zaps too)
|
||||
let event_kinds = crate::feed::feed_related_event_kinds(false);
|
||||
|
||||
let filter = {
|
||||
let mut filter = Filter {
|
||||
kinds: event_kinds,
|
||||
..Default::default()
|
||||
};
|
||||
let a_tag = Tag::new_address(ea, None);
|
||||
filter.set_tag_values('a', vec![a_tag.value().to_owned()]);
|
||||
|
||||
// Spam prevention:
|
||||
if !spamsafe && GLOBALS.storage.read_setting_avoid_spam_on_unsafe_relays() {
|
||||
filter.authors = GLOBALS
|
||||
.people
|
||||
.get_subscribed_pubkeys()
|
||||
.drain(..)
|
||||
.map(|pk| pk.into())
|
||||
.collect();
|
||||
}
|
||||
|
||||
filter
|
||||
};
|
||||
filters.push(filter);
|
||||
|
||||
filters
|
||||
}
|
||||
|
||||
pub fn dm_channel(dmchannel: DmChannel) -> Vec<Filter> {
|
||||
let pubkey = match GLOBALS.identity.public_key() {
|
||||
Some(pk) => pk,
|
||||
|
@ -19,8 +19,8 @@ use http::uri::{Parts, Scheme};
|
||||
use http::Uri;
|
||||
use mime::Mime;
|
||||
use nostr_types::{
|
||||
ClientMessage, EventAddr, EventKind, Filter, Id, IdHex, PreEvent, PublicKey, PublicKeyHex,
|
||||
RelayInformationDocument, RelayUrl, Tag, Unixtime,
|
||||
ClientMessage, EventAddr, EventKind, EventReference, Filter, Id, IdHex, PreEvent, PublicKey,
|
||||
PublicKeyHex, RelayInformationDocument, RelayUrl, Tag, Unixtime,
|
||||
};
|
||||
use reqwest::Response;
|
||||
use std::borrow::Cow;
|
||||
@ -958,12 +958,19 @@ impl Minion {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn subscribe_root_replies(&mut self, job_id: u64, main: IdHex) -> Result<(), Error> {
|
||||
async fn subscribe_root_replies(
|
||||
&mut self,
|
||||
job_id: u64,
|
||||
main: EventReference,
|
||||
) -> Result<(), Error> {
|
||||
// NOTE we do not unsubscribe to the general feed
|
||||
|
||||
// Replies
|
||||
let spamsafe = self.dbrelay.has_usage_bits(Relay::SPAMSAFE);
|
||||
let filters = filter_fns::replies(main, spamsafe);
|
||||
let filters = match main {
|
||||
EventReference::Id { id, .. } => filter_fns::replies(id.into(), spamsafe),
|
||||
EventReference::Addr(ref eaddr) => filter_fns::replies_to_eaddr(eaddr, spamsafe),
|
||||
};
|
||||
self.subscribe(filters, "root_replies", job_id).await?;
|
||||
|
||||
Ok(())
|
||||
|
@ -2517,20 +2517,22 @@ impl Overlord {
|
||||
});
|
||||
|
||||
// Subscribe to replies to root
|
||||
if let Some(EventReference::Id { id, relays, .. }) = ancestors.root {
|
||||
if let Some(ref root_eref) = ancestors.root {
|
||||
let relays = root_eref.copy_relays();
|
||||
for url in relays.iter() {
|
||||
// Subscribe root replies
|
||||
let jobs: Vec<RelayJob> = vec![RelayJob {
|
||||
reason: RelayConnectionReason::ReadThread,
|
||||
payload: ToMinionPayload {
|
||||
job_id: rand::random::<u64>(),
|
||||
detail: ToMinionPayloadDetail::SubscribeRootReplies(id.into()),
|
||||
detail: ToMinionPayloadDetail::SubscribeRootReplies(root_eref.clone()),
|
||||
},
|
||||
}];
|
||||
|
||||
self.engage_minion(url.to_owned(), jobs).await?;
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME what if root is an EventAddr? minion doesn't have a way to subscribe
|
||||
// to their replies.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user