Cleanup
This commit is contained in:
parent
c4b57ae813
commit
5927b7dfe6
|
@ -34,53 +34,53 @@ async fn run() -> Result<(), GolgiError> {
|
||||||
}
|
}
|
||||||
println!("reached end of stream");
|
println!("reached end of stream");
|
||||||
|
|
||||||
// create a history stream and convert it into a Vec<SsbMessageValue> using try_collect
|
// // create a history stream and convert it into a Vec<SsbMessageValue> using try_collect
|
||||||
// (if there is any error in the results, it will be raised)
|
// // (if there is any error in the results, it will be raised)
|
||||||
let mut history_stream = sbot_client.create_history_stream(author.to_string()).await?;
|
// let mut history_stream = sbot_client.create_history_stream(author.to_string()).await?;
|
||||||
let results : Vec<SsbMessageValue> = history_stream.try_collect().await?;
|
// let results : Vec<SsbMessageValue> = history_stream.try_collect().await?;
|
||||||
for x in results {
|
// for x in results {
|
||||||
println!("x: {:?}", x);
|
// println!("x: {:?}", x);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// example to create a history stream and use a map to convert stream of SsbMessageValue
|
// // example to create a history stream and use a map to convert stream of SsbMessageValue
|
||||||
// into a stream of KeyTypeTuple (local struct for storing message_key and message_type)
|
// // into a stream of KeyTypeTuple (local struct for storing message_key and message_type)
|
||||||
#[derive(Debug)]
|
// #[derive(Debug)]
|
||||||
struct KeyTypeTuple {
|
// struct KeyTypeTuple {
|
||||||
message_key: String,
|
// message_key: String,
|
||||||
message_type: SsbMessageContentType,
|
// message_type: SsbMessageContentType,
|
||||||
};
|
// };
|
||||||
let mut history_stream = sbot_client.create_history_stream(author.to_string()).await?;
|
// let mut history_stream = sbot_client.create_history_stream(author.to_string()).await?;
|
||||||
let type_stream = history_stream.map(|msg| {
|
// let type_stream = history_stream.map(|msg| {
|
||||||
match msg {
|
// match msg {
|
||||||
Ok(val) => {
|
// Ok(val) => {
|
||||||
let message_type = val.get_message_type()?;
|
// let message_type = val.get_message_type()?;
|
||||||
let tuple = KeyTypeTuple {
|
// let tuple = KeyTypeTuple {
|
||||||
message_key: val.signature,
|
// message_key: val.signature,
|
||||||
message_type: message_type,
|
// message_type: message_type,
|
||||||
};
|
// };
|
||||||
Ok(tuple)
|
// Ok(tuple)
|
||||||
}
|
// }
|
||||||
Err(err) => {
|
// Err(err) => {
|
||||||
Err(err)
|
// Err(err)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
pin_mut!(type_stream); // needed for iteration
|
// pin_mut!(type_stream); // needed for iteration
|
||||||
println!("looping through type stream");
|
// println!("looping through type stream");
|
||||||
while let Some(res) = type_stream.next().await {
|
// while let Some(res) = type_stream.next().await {
|
||||||
match res {
|
// match res {
|
||||||
Ok(value) => {
|
// Ok(value) => {
|
||||||
println!("value: {:?}", value);
|
// println!("value: {:?}", value);
|
||||||
},
|
// },
|
||||||
Err(err) => {
|
// Err(err) => {
|
||||||
println!("err: {:?}", err);
|
// println!("err: {:?}", err);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
println!("reached end of type stream");
|
// println!("reached end of type stream");
|
||||||
|
//
|
||||||
// return Ok
|
// // return Ok
|
||||||
Ok(())
|
// Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_std::main]
|
#[async_std::main]
|
||||||
|
|
|
@ -62,11 +62,11 @@ impl SsbMessageValue {
|
||||||
|
|
||||||
/// Helper function which returns true if this message is of the given type,
|
/// Helper function which returns true if this message is of the given type,
|
||||||
/// and false if the type does not match or is not found
|
/// and false if the type does not match or is not found
|
||||||
pub fn is_message_type(&self, message_type: SsbMessageContentType) -> bool {
|
pub fn is_message_type(&self, _message_type: SsbMessageContentType) -> bool {
|
||||||
let self_message_type = self.get_message_type();
|
let self_message_type = self.get_message_type();
|
||||||
match self_message_type {
|
match self_message_type {
|
||||||
Ok(mtype) => {
|
Ok(mtype) => {
|
||||||
matches!(mtype, message_type)
|
matches!(mtype, _message_type)
|
||||||
}
|
}
|
||||||
Err(_err) => {
|
Err(_err) => {
|
||||||
false
|
false
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Sbot type and associated methods.
|
//! Sbot type and associated methods.
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use async_std::net::TcpStream;
|
use async_std::net::TcpStream;
|
||||||
use futures::pin_mut;
|
|
||||||
use async_std::stream::{Stream, StreamExt};
|
use async_std::stream::{Stream, StreamExt};
|
||||||
use async_stream::stream;
|
use async_stream::stream;
|
||||||
|
|
||||||
|
|
12
src/utils.rs
12
src/utils.rs
|
@ -1,12 +1,12 @@
|
||||||
//! Utility methods for `golgi`.
|
//! Utility methods for `golgi`.
|
||||||
use async_std::io::Read;
|
use async_std::io::Read;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use async_std::task;
|
|
||||||
use std::time::Duration;
|
|
||||||
use async_std::net::TcpStream;
|
|
||||||
use async_std::stream::Stream;
|
|
||||||
use async_stream::stream;
|
|
||||||
use rand::distributions::{Distribution, Uniform};
|
|
||||||
|
|
||||||
use kuska_ssb::rpc::{RecvMsg, RequestNo, RpcReader};
|
use kuska_ssb::rpc::{RecvMsg, RequestNo, RpcReader};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
Loading…
Reference in New Issue