add alias support for mentions

This commit is contained in:
Astra 2025-06-16 17:05:44 +01:00
parent fa0376bf3c
commit 164f3629ab
3 changed files with 53 additions and 7 deletions

View file

@ -133,7 +133,7 @@ func (b *BSky) ParsePost(post []byte) (*Post, error) {
return p, nil
}
func (post *Post) ProcessFacets() string {
func (post *Post) ProcessFacets(aliases []Records) string {
if post == nil {
return ""
}
@ -160,6 +160,14 @@ func (post *Post) ProcessFacets() string {
switch feature.Type {
case "app.bsky.richtext.facet#mention":
link := fmt.Sprintf(`<a href="https://bsky.app/profile/%s">%s</a>`, feature.Did, post.Text[start:end])
if aliases != nil {
for _, alias := range aliases {
if alias.Value.Subject == feature.Did {
link = fmt.Sprintf(`<a href="%s">%s</a>`,
strings.SplitN(alias.Value.Target, "#", 2)[0], strings.SplitN(alias.Value.Target, "#", 2)[1])
}
}
}
result.WriteString(link)
case "app.bsky.richtext.facet#link":
link := fmt.Sprintf(`<a href="%s">%s</a>`, feature.URI, post.Text[start:end])