relay filter/appview bootstrap
at main 1.2 kB view raw
1use serde::Serialize; 2 3use super::Record; 4 5#[derive(Debug, Serialize)] 6pub struct MembershipView { 7 pub uri: String, 8 pub cid: String, 9 pub channel: String, 10 pub invite: String, 11 pub recipient: String, 12 pub state: String, 13 #[serde(rename = "createdAt")] 14 pub created_at: String, 15 #[serde(rename = "indexedAt")] 16 pub indexed_at: String, 17 #[serde(rename = "updatedAt", skip_serializing_if = "Option::is_none")] 18 pub updated_at: Option<String>, 19} 20 21impl From<Record> for MembershipView { 22 fn from(r: Record) -> Self { 23 let channel_cid = r.ref_cids.first().cloned().unwrap_or_default(); 24 let invite_cid = r.ref_cids.get(1).cloned().unwrap_or_default(); 25 let state = r.data.get("state").and_then(|v| v.as_str()).unwrap_or("unknown").to_string(); 26 let updated_at = r.data.get("updatedAt").and_then(|v| v.as_str()).map(String::from); 27 28 Self { 29 uri: r.uri, 30 cid: r.cid, 31 channel: channel_cid, 32 invite: invite_cid, 33 recipient: r.target_did.unwrap_or_default(), 34 state, 35 created_at: r.created_at.to_rfc3339(), 36 indexed_at: r.indexed_at.to_rfc3339(), 37 updated_at, 38 } 39 } 40}