Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm
0
fork

Configure Feed

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

event kind and op

running a little ahead of what actually exists but there's a chance to minimize breaking the api. it will probably break anyway but hey.

phil 9a09802e a1f4a565

+26 -10
+12 -7
spacedust/src/lib.rs
··· 12 12 } 13 13 14 14 #[derive(Debug, Serialize)] 15 - struct ClientEvent { 15 + struct ClientLinkEvent { 16 + operation: String, 16 17 source: String, 17 - origin: String, 18 - target: String, 18 + source_record: String, 19 + subject: String, 19 20 // TODO: include the record too? would save clients a level of hydration 20 21 } 21 22 22 - impl From<LinkEvent> for ClientEvent { 23 + impl From<LinkEvent> for ClientLinkEvent { 23 24 fn from(link: LinkEvent) -> Self { 24 - let undotted = link.path.get(1..).unwrap_or(""); 25 + let undotted = link.path.strip_prefix('.').unwrap_or_else(|| { 26 + eprintln!("link path did not have expected '.' prefix: {}", link.path); 27 + "" 28 + }); 25 29 Self { 30 + operation: "create".to_string(), 26 31 source: format!("{}:{undotted}", link.collection), 27 - origin: link.origin, 28 - target: link.target, 32 + source_record: link.origin, 33 + subject: link.target, 29 34 } 30 35 } 31 36 }
+14 -3
spacedust/src/server.rs
··· 1 - use crate::{ClientEvent, LinkEvent}; 1 + use crate::{ClientLinkEvent, LinkEvent}; 2 2 use dropshot::{ 3 3 ApiDescription, ConfigDropshot, ConfigLogging, ConfigLoggingLevel, Query, RequestContext, 4 4 ServerBuilder, WebsocketConnection, channel, 5 5 }; 6 6 use futures::SinkExt; 7 7 use schemars::JsonSchema; 8 - use serde::Deserialize; 8 + use serde::{Deserialize, Serialize}; 9 9 use tokio::sync::broadcast; 10 10 use tokio_tungstenite::tungstenite::Message; 11 11 use tokio_tungstenite::tungstenite::protocol::Role; ··· 33 33 server.await 34 34 } 35 35 36 + #[derive(Debug, Serialize)] 37 + #[serde(rename_all="snake_case")] 38 + struct ClientEvent { 39 + r#type: String, 40 + link: ClientLinkEvent, 41 + } 42 + 36 43 #[derive(Deserialize, JsonSchema)] 37 44 struct QueryParams { 38 45 _hello: Option<String>, ··· 61 68 loop { 62 69 match sub.recv().await { 63 70 Ok(link) => { 64 - let json = serde_json::to_string::<ClientEvent>(&link.into())?; 71 + let ev = ClientEvent { 72 + r#type: "link".to_string(), 73 + link: link.into(), 74 + }; 75 + let json = serde_json::to_string(&ev)?; 65 76 if let Err(e) = ws.send(Message::Text(json.into())).await { 66 77 eprintln!("client: failed to send event: {e:?}"); 67 78 ws.close(None).await?; // TODO: do we need this one??