Skip to content

Commit

Permalink
chore: add related urls
Browse files Browse the repository at this point in the history
  • Loading branch information
polebug committed Dec 16, 2024
1 parent 5150e12 commit cc0a88b
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions internal/node/component/federated/transformer_social_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strings"

"github.com/rss3-network/node/schema/worker/federated"
"github.com/rss3-network/protocol-go/schema/activity"
"github.com/rss3-network/protocol-go/schema/metadata"
"github.com/rss3-network/protocol-go/schema/network"
Expand All @@ -15,7 +16,7 @@ import (
// TransformSocialType adds author url and note url to social actions based on type, network and platform
func (c *Component) TransformSocialType(ctx context.Context, network network.Network, platform string, action activity.Action) (activity.Action, error) {
switch action.Type {
case typex.SocialPost, typex.SocialComment, typex.SocialShare:
case typex.SocialPost, typex.SocialComment, typex.SocialShare, typex.SocialLike:
return c.TransformSocialPost(ctx, network, platform, action)
}

Expand Down Expand Up @@ -55,14 +56,21 @@ func (c *Component) buildSocialAuthorURL(_ context.Context, platform, handle str
return ""
}

parts := strings.SplitN(handle, "@", 3)
if len(parts) != 3 {
return ""
}
switch platform {
case federated.PlatformMastodon.String():
parts := strings.SplitN(handle, "@", 3)
if len(parts) != 3 {
return ""
}

username, domain := parts[1], parts[2]
username, domain := parts[1], parts[2]

return fmt.Sprintf("https://%s/users/%s", domain, username)
return fmt.Sprintf("https://%s/users/%s", domain, username)
case federated.PlatformBluesky.String():
return fmt.Sprintf("https://bsky.app/profile/%s", handle)
default:
return ""
}
}

// buildSocialNoteURL returns note url based on domain, handle, profileID and pubID
Expand All @@ -71,12 +79,19 @@ func (c *Component) buildSocialNoteURL(_ context.Context, _ network.Network, pla
return ""
}

parts := strings.SplitN(handle, "@", 3)
if len(parts) != 3 {
return ""
}
switch platform {
case federated.PlatformMastodon.String():
parts := strings.SplitN(handle, "@", 3)
if len(parts) != 3 {
return ""
}

username, domain := parts[1], parts[2]
username, domain := parts[1], parts[2]

return fmt.Sprintf("https://%s/users/%s/statuses/%s", domain, username, pubID)
return fmt.Sprintf("https://%s/users/%s/statuses/%s", domain, username, pubID)
case federated.PlatformBluesky.String():
return fmt.Sprintf("https://bsky.app/profile/%s/post/%s", handle, pubID)
default:
return ""
}
}

0 comments on commit cc0a88b

Please sign in to comment.