ensure about stream returns correct msgs

This commit is contained in:
glyph 2022-02-26 14:15:58 +02:00
parent 935347ffcf
commit 45ad6b53cb
1 changed files with 5 additions and 3 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,
} }
} }
} }