From 28019fc67a19d9dead2883bac2f569c9a11c539d Mon Sep 17 00:00:00 2001 From: famfo Date: Wed, 26 Feb 2025 02:32:30 +0100 Subject: [PATCH] user: move ActivityPub related functions to own file --- models/user/activitypub.go | 25 +++++++++++++++++++++++++ models/user/user.go | 14 -------------- 2 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 models/user/activitypub.go diff --git a/models/user/activitypub.go b/models/user/activitypub.go new file mode 100644 index 0000000000..a73e799818 --- /dev/null +++ b/models/user/activitypub.go @@ -0,0 +1,25 @@ +// Copyright 2025 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package user + +import ( + "fmt" + "net/url" + + "forgejo.org/modules/setting" +) + +// APActorID returns the IRI to the api endpoint of the user +func (u *User) APActorID() string { + if u.ID == APActorUserID { + return fmt.Sprintf("%vapi/v1/activitypub/actor", setting.AppURL) + } + + return fmt.Sprintf("%vapi/v1/activitypub/user-id/%v", setting.AppURL, url.PathEscape(fmt.Sprintf("%v", u.ID))) +} + +// APActorKeyID returns the ID of the user's public key +func (u *User) APActorKeyID() string { + return u.APActorID() + "#main-key" +} diff --git a/models/user/user.go b/models/user/user.go index fe7eb8791e..900878768e 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -311,20 +311,6 @@ func (u *User) HTMLURL() string { return setting.AppURL + url.PathEscape(u.Name) } -// APActorID returns the IRI to the api endpoint of the user -func (u *User) APActorID() string { - if u.ID == APActorUserID { - return fmt.Sprintf("%vapi/v1/activitypub/actor", setting.AppURL) - } - - return fmt.Sprintf("%vapi/v1/activitypub/user-id/%v", setting.AppURL, url.PathEscape(fmt.Sprintf("%v", u.ID))) -} - -// APActorKeyID returns the ID of the user's public key -func (u *User) APActorKeyID() string { - return u.APActorID() + "#main-key" -} - // OrganisationLink returns the organization sub page link. func (u *User) OrganisationLink() string { return setting.AppSubURL + "/org/" + url.PathEscape(u.Name)