replace ToMinionPayloadDetail::SubscribeDmChannel

This commit is contained in:
Mike Dilger 2024-08-18 10:37:05 +12:00
parent 5877dd6dfc
commit 8d598796dc
4 changed files with 3 additions and 50 deletions

View File

@ -269,7 +269,6 @@ pub(crate) enum ToMinionPayloadDetail {
SubscribePersonFeed(PublicKey, Unixtime),
SubscribeReplies(IdHex),
SubscribeRootReplies(EventReference),
SubscribeDmChannel(DmChannel),
TempSubscribePersonFeedChunk { pubkey: PublicKey, anchor: Unixtime },
TempSubscribeInboxFeedChunk(Unixtime),
UnsubscribePersonFeed,

View File

@ -1,4 +1,3 @@
use crate::dm_channel::DmChannel;
use crate::filter_set::FeedRange;
use crate::globals::GLOBALS;
use nostr_types::{EventKind, Filter, IdHex, NAddr, PublicKey, PublicKeyHex, Tag};
@ -128,27 +127,3 @@ pub fn replies_to_eaddr(ea: &NAddr, spamsafe: bool) -> Vec<Filter> {
filters
}
pub fn dm_channel(dmchannel: DmChannel) -> Vec<Filter> {
let pubkey = match GLOBALS.identity.public_key() {
Some(pk) => pk,
None => return vec![],
};
let pkh: PublicKeyHex = pubkey.into();
// note: giftwraps can't be subscribed by channel. they are subscribed more
// globally, and have to be limited to recent ones.
let mut authors: Vec<PublicKeyHex> = dmchannel.keys().iter().map(|k| k.into()).collect();
authors.push(pkh.clone());
let mut filter = Filter {
authors: authors.clone(),
kinds: vec![EventKind::EncryptedDirectMessage],
..Default::default()
};
// tagging the user
filter.set_tag_values('p', authors.iter().map(|x| x.as_str().to_owned()).collect());
vec![filter]
}

View File

@ -5,7 +5,6 @@ mod subscription;
mod subscription_map;
use crate::comms::{ToMinionMessage, ToMinionPayload, ToMinionPayloadDetail, ToOverlordMessage};
use crate::dm_channel::DmChannel;
use crate::error::{Error, ErrorKind};
use crate::filter_set::{FeedRange, FilterSet};
use crate::globals::GLOBALS;
@ -650,9 +649,6 @@ impl Minion {
ToMinionPayloadDetail::SubscribeRootReplies(main) => {
self.subscribe_root_replies(message.job_id, main).await?;
}
ToMinionPayloadDetail::SubscribeDmChannel(dmchannel) => {
self.subscribe_dm_channel(message.job_id, dmchannel).await?;
}
ToMinionPayloadDetail::TempSubscribePersonFeedChunk { pubkey, anchor } => {
self.temp_subscribe_person_feed_chunk(message.job_id, pubkey, anchor)
.await?;
@ -846,25 +842,6 @@ impl Minion {
Ok(())
}
async fn subscribe_dm_channel(
&mut self,
job_id: u64,
dmchannel: DmChannel,
) -> Result<(), Error> {
// We will need the private key to auth to the relay for this
if !GLOBALS.identity.is_unlocked() {
return Err(ErrorKind::NoPrivateKey.into());
}
let filters = filter_fns::dm_channel(dmchannel);
if !filters.is_empty() {
self.subscribe(filters, "dm_channel", job_id).await?;
}
Ok(())
}
async fn get_events(&mut self) -> Result<(), Error> {
// Collect all the sought events we have not yet asked for, and
// presumptively mark them as having been asked for.

View File

@ -2269,7 +2269,9 @@ impl Overlord {
reason: RelayConnectionReason::FetchDirectMessages,
payload: ToMinionPayload {
job_id: rand::random::<u64>(),
detail: ToMinionPayloadDetail::SubscribeDmChannel(dmchannel.clone()),
detail: ToMinionPayloadDetail::Subscribe(FilterSet::DmChannel(
dmchannel.clone(),
)),
},
}],
);