Remove KVT to Value map and retrieve sequence number directly from KVT
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
mycognosist 2022-07-07 15:54:19 +01:00
parent 9704269c8a
commit eddb167c4c
1 changed files with 3 additions and 8 deletions

View File

@ -8,12 +8,11 @@ use std::{
process::{Command, Output}, process::{Command, Output},
}; };
use async_std::stream::StreamExt;
use async_std::task; use async_std::task;
use dirs; use dirs;
use futures::stream::TryStreamExt; use futures::stream::TryStreamExt;
use golgi::{ use golgi::{
api::friends::RelationshipQuery, blobs, messages::SsbMessageValue, sbot::Keystore, Sbot, api::friends::RelationshipQuery, blobs, messages::SsbMessageKVT, sbot::Keystore, Sbot,
}; };
use log::debug; use log::debug;
use peach_lib::config_manager; use peach_lib::config_manager;
@ -135,11 +134,7 @@ pub fn latest_sequence_number() -> Result<u64, Box<dyn Error>> {
let id = sbot_client.whoami().await?; let id = sbot_client.whoami().await?;
let history_stream = sbot_client.create_history_stream(id).await?; let history_stream = sbot_client.create_history_stream(id).await?;
let msg_stream = history_stream.map(|res| match res { let mut msgs: Vec<SsbMessageKVT> = history_stream.try_collect().await?;
Ok(kvt) => Ok(kvt.value),
Err(err) => Err(err),
});
let mut msgs: Vec<SsbMessageValue> = msg_stream.try_collect().await?;
// there will be zero messages when the sbot is run for the first time // there will be zero messages when the sbot is run for the first time
if msgs.is_empty() { if msgs.is_empty() {
@ -149,7 +144,7 @@ pub fn latest_sequence_number() -> Result<u64, Box<dyn Error>> {
msgs.reverse(); msgs.reverse();
// return the sequence number of the latest msg // return the sequence number of the latest msg
Ok(msgs[0].sequence) Ok(msgs[0].value.sequence)
} }
}) })
} }