Message type considerations #2
Labels
No Label
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: golgi-ssb/golgi#2
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
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?
I'm using this issue to share some background knowledge on SSB data types and to document my thoughts about types in golgi.
Messages in SSB are formatted as key-value-timestamp (KVT) objects. The
value
portion of the message must contain the following fields:previous
,author
,sequence
,timestamp
,hash
,content
andsignature
. Thecontent
field contains different values depending on the message type. For example, apost
message is expected to have atext
field and amentions
field. Anyone is free to create new content types.So, in golgi, we need a way to represent a KVT (
SsbMessage
) and a value (SsbMessageValue
).Kuska provides a
Feed
type and aMessage
type:Feed
implements aninto_message()
method which returnsResult<Message>
. The downside is that this results in the message value being validated before theMessage
type is returned. Since we're relying on go-sbot to perform validation, we want to avoid this step (it is computationally intensive, relatively speaking).We need to consider these types in the context of end-user convenience; returning a generic JSON
Value
type leaves lots of work to be done before it is useful in an application. Ideally, I imagine we want to check thetype
field of a message valuecontent
object and serialize thecontent
to a matchingstruct
. Kuska provides some content types which might be useful.Here's an example of how this might play-out at the low-level in golgi:
Output from
println
:The next step would be to deserialize the
msg_value.content
into the appropriatestruct
usingserde_json::from_value
.We might match like so:
Of course, we need to comply with the borrow checker...
Deserializing messages into the correct
struct
is made simpler in cases where we know what type of messages we'll be receiving. ThegetSubset
queries are a good example of this; if we query for{"op": "type", "string": "post"}
then we can simply deserialize the results intoVec<Post>
(with an appropriate error for a deserialization failure).I think most of our queries will match the above pattern - where we know what we're expecting - especially for the first release of PeachPub.
Closing this since PR above is now merged.