Move FeedKind to its own module

This commit is contained in:
Mike Dilger 2024-06-07 10:58:44 +12:00
parent 8971888e77
commit 90258d6b88
3 changed files with 57 additions and 47 deletions

View File

@ -0,0 +1,49 @@
use crate::dm_channel::DmChannel;
use crate::globals::GLOBALS;
use crate::people::PersonList;
use nostr_types::{Id, PublicKey};
/// Kinds of feeds, with configuration parameteers
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum FeedKind {
List(PersonList, bool), // with replies
Inbox(bool), // indirect
Thread {
id: Id, // FIXME, should be an EventReference
referenced_by: Id,
author: Option<PublicKey>,
},
Person(PublicKey),
DmChat(DmChannel),
}
impl std::fmt::Display for FeedKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FeedKind::DmChat(channel) => write!(f, "{}", channel.name()),
FeedKind::List(pl, _) => match GLOBALS.storage.get_person_list_metadata(*pl) {
Ok(Some(md)) => write!(f, "{}", md.title),
_ => write!(f, "UNKNOWN"),
},
FeedKind::Inbox(_) => write!(f, "Inbox"),
FeedKind::Thread {
id,
referenced_by: _,
author: _,
} => write!(f, "Thread {}", crate::names::hex_id_short(&(*id).into())),
FeedKind::Person(pk) => write!(f, "{}", crate::names::best_name_from_pubkey_lookup(pk)),
}
}
}
impl FeedKind {
pub fn can_load_more(&self) -> bool {
match self {
Self::List(_, _) => true,
Self::Inbox(_) => true,
Self::Thread { .. } => false, // always full
Self::Person(_) => true,
Self::DmChat(_) => false, // always full
}
}
}

View File

@ -1,3 +1,6 @@
mod feed_kind;
pub use feed_kind::FeedKind;
use crate::comms::{ToMinionMessage, ToMinionPayload, ToMinionPayloadDetail, ToOverlordMessage};
use crate::dm_channel::DmChannel;
use crate::error::Error;
@ -12,51 +15,6 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::time::{Duration, Instant};
use tokio::task;
/// Kinds of feeds, with configuration parameteers
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum FeedKind {
List(PersonList, bool), // with replies
Inbox(bool), // indirect
Thread {
id: Id, // FIXME, should be an EventReference
referenced_by: Id,
author: Option<PublicKey>,
},
Person(PublicKey),
DmChat(DmChannel),
}
impl std::fmt::Display for FeedKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FeedKind::DmChat(channel) => write!(f, "{}", channel.name()),
FeedKind::List(pl, _) => match GLOBALS.storage.get_person_list_metadata(*pl) {
Ok(Some(md)) => write!(f, "{}", md.title),
_ => write!(f, "UNKNOWN"),
},
FeedKind::Inbox(_) => write!(f, "Inbox"),
FeedKind::Thread {
id,
referenced_by: _,
author: _,
} => write!(f, "Thread {}", crate::names::hex_id_short(&(*id).into())),
FeedKind::Person(pk) => write!(f, "{}", crate::names::best_name_from_pubkey_lookup(pk)),
}
}
}
impl FeedKind {
pub fn can_load_more(&self) -> bool {
match self {
Self::List(_, _) => true,
Self::Inbox(_) => true,
Self::Thread { .. } => false, // always full
Self::Person(_) => true,
Self::DmChat(_) => false, // always full
}
}
}
/// The system that computes feeds as an ordered list of event Ids.
pub struct Feed {
/// Consumers of gossip-lib should only read this, not write to it.

View File

@ -717,7 +717,8 @@ impl Overlord {
annotation,
dm_channel,
} => {
self.post(content, tags, in_reply_to, annotation, dm_channel).await?;
self.post(content, tags, in_reply_to, annotation, dm_channel)
.await?;
}
ToOverlordMessage::PostAgain(event) => {
self.post_again(event).await?;
@ -1854,7 +1855,9 @@ impl Overlord {
crate::post::prepare_post_nip04(author, content, channel, annotation)?
}
}
None => crate::post::prepare_post_normal(author, content, tags, in_reply_to, annotation)?,
None => {
crate::post::prepare_post_normal(author, content, tags, in_reply_to, annotation)?
}
};
// Post them