From 935347ffcf167e6dd1def22b4618a1a7184efc96 Mon Sep 17 00:00:00 2001 From: glyph Date: Sat, 26 Feb 2022 14:15:27 +0200 Subject: [PATCH 1/2] fix msg type equality bug --- src/messages.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/messages.rs b/src/messages.rs index c26da6e..1e6f08e 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -32,7 +32,7 @@ pub struct SsbMessageValue { } /// Message content types. -#[derive(Debug)] +#[derive(Debug, PartialEq)] #[allow(missing_docs)] pub enum SsbMessageContentType { About, @@ -70,12 +70,10 @@ impl SsbMessageValue { /// 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. - 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(); match self_message_type { - Ok(mtype) => { - matches!(mtype, _message_type) - } + Ok(mtype) => mtype == message_type, Err(_err) => false, } } -- 2.40.1 From 45ad6b53cbebd03d13cb2c033251dc8478e5a0c7 Mon Sep 17 00:00:00 2001 From: glyph Date: Sat, 26 Feb 2022 14:15:58 +0200 Subject: [PATCH 2/2] ensure about stream returns correct msgs --- src/api/about.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/api/about.rs b/src/api/about.rs index 328b803..824d7f4 100644 --- a/src/api/about.rs +++ b/src/api/about.rs @@ -72,7 +72,7 @@ impl Sbot { // TODO: after fixing sbot regression, // change this subset query to filter by type about in addition to author // 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 { Ok(val) => val.is_message_type(SsbMessageContentType::About), Err(_err) => false, @@ -306,20 +306,22 @@ impl Sbot { // for each key we are searching for, check if this about // message contains a value for that key 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 .content .get(key) .and_then(|val| val.as_str()) .map(|val| val.to_string()); 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 profile_info.insert(key.to_string(), val); // remove this key from keys_to_search_for, // since we are no longer searching for it keys_to_search_for.retain(|val| val != key) } - None => continue, + _ => continue, } } } -- 2.40.1