···32#[derive(Debug, Deserialize, Clone)]
33struct Like {
34 did: String,
35- #[serde(rename = "commit.record.subject.uri")]
36 uri: String,
37}
38···89 });
90 },
91 Some(Ok(record)) = like_stream.next() => {
92- let like: Like = serde_json::from_slice(record.value()).unwrap();
93- lcc.entry(like.uri)
94- .and_compute_with(|maybe_entry| {
95- if let Some(entry) = maybe_entry {
96- let mut post = entry.into_value();
97- if post.count < 2 {
98- post.count +=1;
99- warn!("Incread counter for {:#?}", post);
100- Op::Put(post)
000101 } else {
102- Op::Remove
103 }
104- } else {
105- Op::Nop // Skip as post is out of cache
106- }
107- });
108 }
109 }
110 }
···32#[derive(Debug, Deserialize, Clone)]
33struct Like {
34 did: String,
035 uri: String,
36}
37···88 });
89 },
90 Some(Ok(record)) = like_stream.next() => {
91+ if let Ok(like) = serde_json::from_slice::<Like>(record.value()) {
92+ lcc.entry(like.uri)
93+ .and_compute_with(|maybe_entry| {
94+ if let Some(entry) = maybe_entry {
95+ let mut post = entry.into_value();
96+ if post.count < 20 {
97+ post.count +=1;
98+ warn!("Incread counter for {:#?}", post);
99+ Op::Put(post)
100+ } else {
101+ Op::Remove
102+ }
103 } else {
104+ Op::Nop // Skip as post is out of cache
105 }
106+ });
107+ } else {
108+ warn!("Failed deserializing, likely not like commit");
109+ };
110 }
111 }
112 }
+35-13
smart-modules/construct-post-uri/src/lib.rs
···23}
2425fn get_uri(obj: &Map<String, Value>) -> Result<String> {
26- let did = obj
27- .get("did")
028 .and_then(|v| v.as_str())
29- .ok_or(eyre!("did missing or not a string"))?;
0000003031- let commit = obj.get("commit").ok_or(eyre!("commit missing"))?;
3233- let collection = commit
34- .get("collection")
35- .and_then(|v| v.as_str())
36- .ok_or(eyre!("commit.collection missing or not a string"))?;
3738- let rkey = commit
39- .get("rkey")
40- .and_then(|v| v.as_str())
41- .ok_or(eyre!("commit.rkey missing or not a string"))?;
4243- Ok(format!("at://{did}/{collection}/{rkey}"))
00000000000000044}
···23}
2425fn get_uri(obj: &Map<String, Value>) -> Result<String> {
26+ let collection = obj
27+ .get("commit")
28+ .and_then(|v| v.get("collection"))
29 .and_then(|v| v.as_str())
30+ .ok_or(eyre!("Missing commit.collection"))?;
31+ match collection {
32+ "app.bsky.feed.post" => {
33+ let did = obj
34+ .get("did")
35+ .and_then(|v| v.as_str())
36+ .ok_or(eyre!("did missing or not a string"))?;
3738+ let commit = obj.get("commit").ok_or(eyre!("commit missing"))?;
3940+ let collection = commit
41+ .get("collection")
42+ .and_then(|v| v.as_str())
43+ .ok_or(eyre!("commit.collection missing or not a string"))?;
4445+ let rkey = commit
46+ .get("rkey")
47+ .and_then(|v| v.as_str())
48+ .ok_or(eyre!("commit.rkey missing or not a string"))?;
4950+ Ok(format!("at://{did}/{collection}/{rkey}"))
51+ },
52+ "app.bsky.feed.like" => {
53+ let uri = obj
54+ .get("commit")
55+ .and_then(|v| v.get("record"))
56+ .and_then(|v| v.get("subject"))
57+ .and_then(|v| v.get("uri"))
58+ .and_then(|v| v.as_str())
59+ .ok_or(eyre!("Likely not commit message"))?;
60+ Ok(uri.to_string())
61+ }
62+ &_ => {
63+ Err(eyre!("Not supported yet"))
64+ }
65+ }
66}