Implement get_about_message_stream #12
Reference in New Issue
Block a user
No description provided.
Delete Branch "about-stream"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR changes the get_subset and get_about_messages logic to use the latest stream code.
While working on this these other small changes slipped into this PR:
The get_subset_stream and get_about_messages logic can be completed and further refined once the get_subset regression is fixed and the latest changes are merged into kuska (allowing for passing descending flag).
But cool to see its pretty easy to work with these Stream objects for our different needs.
You could review this now, and we could merge it in, or I could add the other changes mentioned above, pending the go-sbot + kuska changes.
I think I will hold off on further golgi work until those changes are in.
cc @glyph
latest commit improved the code by using and_then
An explanation (from here: https://riptutorial.com/rust/example/9668/using-option-with-map-and-and-then)
// 'and_then' is very similar to 'map', but allows us to pass a
// function which returns an Option type itself. To ensure that we
// don't end up with Option<Option>, 'and_then' flattens the
// result (in other languages, 'and_then' is also known as 'flatmap').
The latest commit, changing to use ok_or_else was a suggestion by clippy (I believe the use of a closure makes the allocation lazy, only run if needed, which clippy prefers)
This PR now changes get_latest_about_message to use a stream, and to use find, instead of first converting the stream to a vector (so theoretically this will be more efficient, if there were many about messages, although the difference may in practice be negligble).
Changing to use a stream meant the filtering and mapping you did needed to be slightly reorganized. I had to use a match statement again, but atleast not nested match statements. Maybe there are further style optimizations possible, but I wasn't sure how to get it cleaner than this.
Ready for review @glyph
Added one more commit that gets rid of the match statement
hmm for some reason get_subset started returning SsbMessageValue instead of SsbMessageKVT ... do you know why this might be?
I updated the code to expect this now and its testing and working
@notplants
Yes, thankfully I know why this is. I noticed it when reading your example code last night.
In
get_about_message_stream()
you definedNone
for thekeys
field of the optionsstruct
:keys
controls the form of the returned message. If it's true, you get a message as a KVT. If it's false, you get it as a message value. So you could simply change L252 insrc/sbot.rs
to bekeys: Some(true),
and you will then get back messages as KVTs.@glyph aw cool, glad to have an explanation. I think I will keep it returning SsbMessageValue since that's what we need anyway, but good to know its not just a random ghost in the sbot
LGTM. Great work! 🟢