mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
Move FeedKind to its own module
This commit is contained in:
parent
8971888e77
commit
90258d6b88
49
gossip-lib/src/feed/feed_kind.rs
Normal file
49
gossip-lib/src/feed/feed_kind.rs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user