Merge pull request 'F ix get_about_message_stream incorrect messages bug' (#32) from fix_about_stream into main

Reviewed-on: #32
This commit is contained in:
glyph 2022-02-26 12:21:13 +00:00
commit 3148b0a632
2 changed files with 8 additions and 8 deletions

View File

@ -72,7 +72,7 @@ impl Sbot {
// TODO: after fixing sbot regression, // TODO: after fixing sbot regression,
// change this subset query to filter by type about in addition to author // change this subset query to filter by type about in addition to author
// and remove this filter section // and remove this filter section
// filter down to about messages // filter down to about messages
let about_message_stream = get_subset_stream.filter(|msg| match msg { let about_message_stream = get_subset_stream.filter(|msg| match msg {
Ok(val) => val.is_message_type(SsbMessageContentType::About), Ok(val) => val.is_message_type(SsbMessageContentType::About),
Err(_err) => false, Err(_err) => false,
@ -306,20 +306,22 @@ impl Sbot {
// for each key we are searching for, check if this about // for each key we are searching for, check if this about
// message contains a value for that key // message contains a value for that key
for key in &keys_to_search_for.clone() { for key in &keys_to_search_for.clone() {
let about_val = msg.content.get("about").and_then(|val| val.as_str());
let option_val = msg let option_val = msg
.content .content
.get(key) .get(key)
.and_then(|val| val.as_str()) .and_then(|val| val.as_str())
.map(|val| val.to_string()); .map(|val| val.to_string());
match option_val { match option_val {
Some(val) => { // only return val if this msg is about the given ssb_id
Some(val) if about_val == Some(ssb_id) => {
// if a value is found, then insert it // if a value is found, then insert it
profile_info.insert(key.to_string(), val); profile_info.insert(key.to_string(), val);
// remove this key from keys_to_search_for, // remove this key from keys_to_search_for,
// since we are no longer searching for it // since we are no longer searching for it
keys_to_search_for.retain(|val| val != key) keys_to_search_for.retain(|val| val != key)
} }
None => continue, _ => continue,
} }
} }
} }

View File

@ -32,7 +32,7 @@ pub struct SsbMessageValue {
} }
/// Message content types. /// Message content types.
#[derive(Debug)] #[derive(Debug, PartialEq)]
#[allow(missing_docs)] #[allow(missing_docs)]
pub enum SsbMessageContentType { pub enum SsbMessageContentType {
About, About,
@ -70,12 +70,10 @@ 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) => mtype == message_type,
matches!(mtype, _message_type)
}
Err(_err) => false, Err(_err) => false,
} }
} }