From cc0a88bbc6aa1e91b1b3d837217b96b7458712ec Mon Sep 17 00:00:00 2001 From: polebug Date: Tue, 17 Dec 2024 00:07:52 +0800 Subject: [PATCH] chore: add related urls --- .../federated/transformer_social_type.go | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/internal/node/component/federated/transformer_social_type.go b/internal/node/component/federated/transformer_social_type.go index 68ae0b0e7..a73ec4699 100644 --- a/internal/node/component/federated/transformer_social_type.go +++ b/internal/node/component/federated/transformer_social_type.go @@ -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" @@ -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) } @@ -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 @@ -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 "" + } }