-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/bsky-webhook: add support for facets #11
Conversation
Reference: https://docs.bsky.app/docs/advanced-guides/post-richtext Fixes #9 Signed-off-by: Erisa A <[email protected]>
cmd/bsky-webhook/types.go
Outdated
type BskyFacetFeatures struct { | ||
Type string `json:"$type"` | ||
Uri string `json:"uri"` | ||
Did string `json:"did"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the names explicitly here? It appears we only use these for decoding, and the JSON decoder does a case-insensitive match anyway. (We do need $type
because of the spelling difference, but I mean the others)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think (personally) that being explicit is best because it doesn't result in confusion in naming or capitalisation later down the line if we do encode back again, especially since some other types SlackAttachment
and SlackBody
are used for encoding.
I'm willing to move on that if a Go convention says that they shouldn't be explicit, though!
return a.Index.ByteStart - b.Index.ByteStart | ||
}) | ||
|
||
textCursor := 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, the delicate dance with indices here is something to do with the fact that facets are specified by offsets into the base text?
Given that you went to the trouble of ordering them above, maybe this could be turned into a helper that uses slices.BinarySearch
(or even just scans them linearly—there aren't going to be that many, we don't need to worry about asymptotics I think) to find the relevant fragment for each facet? (Even if we do care, we already spent O(n lg n) to sort them, so spending another n lg n to probe them won't affect the underlying shape)
I am sort of convinced this does what I described above, but index dancing is hard to follow, so I would suggest we try to be more obvious here.
(Then too, I think maybe we don't need to do any additional appending, since the facet decorations could be glued directly into place on the facet fragment they belong to I think?)
Reference: https://docs.bsky.app/docs/advanced-guides/post-richtext
Fixes #9
Tested working with links, mentions, and tags. Seeking a quick review to ensure I didn't commit any Go crimes in the process.