this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add status subcommand to clear current status

+74 -7
+21
src/main.rs
··· 187 187 #[arg(short, long, action)] 188 188 full: bool, 189 189 }, 190 + 191 + /// Clear current playing status 192 + Clear, 190 193 } 191 194 192 195 fn get_auth() -> Result<Authenticator, OnyxError> { ··· 367 370 let status_man = StatusManager::new(&ident); 368 371 let status = status_man.get_status().await?; 369 372 status_man.display_status(&status, raw, full); 373 + } 374 + StatusCommands::Clear => { 375 + let auth = get_auth()?; 376 + let session_info = auth.get_session_info()?; 377 + let session = auth.restore().await?; 378 + 379 + let status_man = StatusManager::new(&session_info.did); 380 + status_man.clear_status(session).await?; 381 + 382 + println!( 383 + "{}: cleared status for {}, {}", 384 + "success".green().bold(), 385 + (session_info 386 + .handles 387 + .first() 388 + .unwrap_or(&"(no handle)".red().to_string())), 389 + session_info.did, 390 + ); 370 391 } 371 392 }, 372 393 }
+4 -4
src/record.rs
··· 1 1 use chrono::{DateTime, FixedOffset}; 2 2 use jacquard::{CowStr, smol_str::ToSmolStr, types::string::Datetime}; 3 3 4 - #[derive(Debug)] 4 + #[derive(Debug, Default)] 5 5 pub struct Artist { 6 6 pub artist_name: String, 7 7 pub artist_mb_id: Option<String>, 8 8 } 9 9 10 - #[derive(Debug)] 10 + #[derive(Debug, Default)] 11 11 pub struct Play { 12 12 pub track_name: String, 13 13 pub track_mb_id: Option<String>, ··· 27 27 pub release_discriminant: Option<String>, 28 28 } 29 29 30 - #[derive(Debug)] 30 + #[derive(Debug, Default)] 31 31 pub struct PlayView { 32 32 pub track_name: String, 33 33 pub track_mb_id: Option<String>, ··· 43 43 pub played_time: Option<DateTime<FixedOffset>>, 44 44 } 45 45 46 - #[derive(Debug)] 46 + #[derive(Debug, Default)] 47 47 pub struct Status { 48 48 pub time: DateTime<FixedOffset>, 49 49 pub expiry: Option<DateTime<FixedOffset>>,
+49 -3
src/status.rs
··· 1 + use chrono::{DateTime, Duration, FixedOffset}; 1 2 use jacquard::{ 2 - client::{AgentSessionExt, BasicClient}, 3 + client::{Agent, AgentSessionExt, BasicClient}, 3 4 prelude::IdentityResolver, 4 - types::{did::Did, string::Handle}, 5 + types::{aturi::AtUri, did::Did, string::Handle}, 5 6 }; 6 7 use jacquard_api::fm_teal::alpha::actor::status as fm_teal_status; 7 8 use jacquard_identity::{JacquardResolver, PublicResolver}; 8 9 9 - use crate::{error::OnyxError, record::Status}; 10 + use crate::{ 11 + auth::GenericSession, 12 + error::OnyxError, 13 + record::{PlayView, Status}, 14 + }; 10 15 11 16 fn get_status_endpoint(did: String) -> String { 12 17 format!("at://{}/fm.teal.alpha.actor.status/self", did) ··· 54 59 .value; 55 60 56 61 Ok(status_rec.into()) 62 + } 63 + 64 + pub async fn set_status( 65 + &self, 66 + session: GenericSession, 67 + status: Status, 68 + ) -> Result<(), OnyxError> { 69 + let did = self.resolve_did(&self.ident).await?; 70 + let endpoint = get_status_endpoint(did.to_string()); 71 + let uri = AtUri::new(&endpoint)?; 72 + 73 + let agent = Agent::from(session); 74 + agent 75 + .update_record::<fm_teal_status::Status>(&uri, |stat| { 76 + let status: fm_teal_status::Status = status.into(); 77 + stat.time = status.time; 78 + stat.expiry = status.expiry; 79 + stat.item = status.item; 80 + }) 81 + .await?; 82 + 83 + Ok(()) 84 + } 85 + 86 + pub async fn clear_status(&self, session: GenericSession) -> Result<(), OnyxError> { 87 + let now: DateTime<FixedOffset> = chrono::Local::now().into(); 88 + let expiry = now - Duration::minutes(1); 89 + 90 + self.set_status( 91 + session, 92 + Status { 93 + time: now, 94 + expiry: Some(expiry), 95 + item: PlayView { 96 + track_name: "".to_string(), 97 + artists: Vec::new(), 98 + ..Default::default() 99 + }, 100 + }, 101 + ) 102 + .await 57 103 } 58 104 59 105 pub fn display_status(&self, status: &Status, raw: bool, full: bool) {