ReadMentions,
LogsMenu1,
LogsMenu2,
+ EgoLog,
ExitMenu,
ExamineUser(String),
ListUserFollowers(String),
use super::auth::{AuthConfig,AuthError};
use super::types::*;
-#[derive(Hash, PartialEq, Eq, Clone, Copy)]
+#[derive(Hash, Debug, PartialEq, Eq, Clone, Copy)]
pub enum Boosts { Show, Hide }
-#[derive(Hash, PartialEq, Eq, Clone, Copy)]
+#[derive(Hash, Debug, PartialEq, Eq, Clone, Copy)]
pub enum Replies { Show, Hide }
-#[derive(Hash, PartialEq, Eq, Clone)]
+#[derive(Hash, Debug, PartialEq, Eq, Clone)]
pub enum FeedId {
Home,
Local,
Hashtag(String),
User(String, Boosts, Replies),
Mentions,
+ Ego,
}
#[derive(Debug, PartialEq, Eq, Clone)]
FeedId::Mentions => {
Req::get("notifications").param("types[]", "mention")
},
+ FeedId::Ego => {
+ Req::get("notifications")
+ .param("types[]", "reblog")
+ .param("types[]", "follow")
+ .param("types[]", "favourite")
+ },
};
let req = match ext {
}
sts.iter().rev().map(|st| st.id.clone()).collect()
},
- FeedId::Mentions => {
+ FeedId::Mentions | FeedId::Ego => {
let mut nots: Vec<Notification> = match serde_json::from_str(
&body) {
Ok(nots) => Ok(nots),
},
}?;
- // According to the protocol spec, all notifications
- // of type Mention should have a status in them. We
- // double-check that here, so that the rest of our
- // code can safely .unwrap() or .expect() the status
- // from notifications they get via this feed.
- nots.retain(|not| {
- not.ntype == NotificationType::Mention &&
- not.status.is_some()
- });
+ match id {
+ FeedId::Mentions => {
+ // According to the protocol spec, all notifications
+ // of type Mention should have a status in them. We
+ // double-check that here, so that the rest of our
+ // code can safely .unwrap() or .expect() the status
+ // from notifications they get via this feed.
+ nots.retain(|not| {
+ not.ntype == NotificationType::Mention &&
+ not.status.is_some()
+ });
+ },
+ FeedId::Ego => {
+ nots.retain(|not| {
+ not.ntype == NotificationType::Reblog ||
+ not.ntype == NotificationType::Follow ||
+ not.ntype == NotificationType::Favourite
+ });
+ },
+ _ => panic!("outer match passed us {:?}", id),
+ }
for not in ¬s {
self.cache_notification(not);
}
// This stream interleaves updates to the home
// timeline with notifications, so it can cause an
// update in more than one thing we think of as a feed.
- for id in &[FeedId::Home, FeedId::Mentions] {
+ for id in &[FeedId::Home, FeedId::Mentions, FeedId::Ego] {
if self.fetch_feed(id, FeedExtend::Future)? {
updates.insert(id.clone());
}
}
}
+struct EgoNotificationFeedType {}
+impl FeedType for EgoNotificationFeedType {
+ type Item = NotificationLog;
+
+ fn get_from_client(id: &str, client: &mut Client) ->
+ Result<Self::Item, ClientError>
+ {
+ let not = client.notification_by_id(&id)?;
+ Ok(NotificationLog::from_notification(¬, client))
+ }
+}
+
struct FeedFileContents<Type: FeedType> {
id: FeedId,
header: FileHeader,
"HHHHHHHHHHHHKKKHHKH"))?;
Ok(Box::new(file))
}
+
+pub fn ego_log(client: &mut Client) ->
+ Result<Box<dyn ActivityState>, ClientError>
+{
+ let file = FeedFile::<EgoNotificationFeedType>::new(
+ client, FeedId::Ego, ColouredString::general(
+ "Ego Log [ESC][L][L][E]",
+ "HHHHHHHHHHHKKKHHKHHKHHKH"))?;
+ Ok(Box::new(file))
+}
"HHHHHHHHHHHHHKKKHHKHHKH"), false);
menu.add_action(Pr('E'), "Ego Log (Boosts, Follows and Faves)",
- LogicalAction::NYI);
+ LogicalAction::Goto(UtilityActivity::EgoLog.into()));
Box::new(menu.finalise())
}
});
}
-pub enum NotificationLogType {
- Favourited,
- Boosted,
- Followed,
-}
-
pub struct NotificationLog {
timestamp: DateTime<Utc>,
account_desc: String,
impl NotificationLog {
pub fn new(
timestamp: DateTime<Utc>, account: &str, nameline: &str,
- ntype: NotificationLogType, post: Option<&Vec<Paragraph>>)
+ ntype: NotificationType, post: Option<&Paragraph>)
-> Self {
let mut para = Paragraph::new();
let verb = match ntype {
- NotificationLogType::Favourited => "favourited: ",
- NotificationLogType::Boosted => "boosted: ",
- NotificationLogType::Followed => "followed you",
+ NotificationType::Favourite => "favourited: ",
+ NotificationType::Reblog => "boosted: ",
+ NotificationType::Follow => "followed you",
+ _ => panic!("bad type {:?} in NotificationLog::new", ntype),
};
para.push_text(&ColouredString::plain(verb), false);
- if let Some(paras) = post {
+ if let Some(cpara) = post {
let currlen = para.words.len();
- for cpara in paras {
- para.push_para(cpara);
- }
+ para.push_para(cpara);
para.delete_mention_words_from(currlen);
}
para: para,
}
}
+
+ pub fn from_notification(not: &Notification, client: &mut Client) -> Self {
+ let para = match ¬.status {
+ None => None,
+ Some(st) => Some(Html::new(&st.content).to_para()),
+ };
+ Self::new(
+ not.created_at,
+ &client.fq(¬.account.acct),
+ ¬.account.display_name,
+ not.ntype,
+ para.as_ref(),
+ )
+ }
}
impl TextFragment for NotificationLog {
"%Y-%m-%d %H:%M:%S")
.unwrap().and_local_timezone(Local).unwrap().with_timezone(&Utc);
- let post = vec! {
- Paragraph::new().add(&ColouredString::general(
- "@stoat @weasel take a look at this otter!",
- "@@@@@@ @@@@@@@ ")),
- Paragraph::new().add(&ColouredString::general(
- "@badger might also like it",
- "@@@@@@@ ")),
- };
+ let post = Paragraph::new().add(&ColouredString::general(
+ "@stoat @weasel take a look at this otter! @badger might also like it",
+ "@@@@@@ @@@@@@@ @@@@@@@ ",
+ ));
assert_eq!(NotificationLog::new(
t, "foo@example.com", "Foo Bar",
- NotificationLogType::Boosted, Some(&post)).render(80), vec! {
+ NotificationType::Reblog, Some(&post)).render(80), vec! {
ColouredString::general("Fri Aug 3 04:05:06 2001 Foo Bar (foo@example.com) boosted: take a look at this",
" "),
ColouredString::general(" otter! @badger might also like it",
assert_eq!(NotificationLog::new(
t, "foo@example.com", "Foo Bar",
- NotificationLogType::Favourited, Some(&post)).render(51), vec! {
+ NotificationType::Favourite, Some(&post)).render(51), vec! {
ColouredString::general("Fri Aug 3 04:05:06 2001 Foo Bar (foo@example.com)",
" "),
ColouredString::general(" favourited: take a look at this otter! @badger...",
assert_eq!(NotificationLog::new(
t, "foo@example.com", "Foo Bar",
- NotificationLogType::Followed, None).render(80), vec! {
+ NotificationType::Follow, None).render(80), vec! {
ColouredString::general("Fri Aug 3 04:05:06 2001 Foo Bar (foo@example.com) followed you",
" "),
});
local_timeline(client),
Activity::Util(UtilityActivity::ReadMentions) =>
mentions(client),
+ Activity::Util(UtilityActivity::EgoLog) =>
+ ego_log(client),
_ => panic!("FIXME"),
};