diff options
author | 2021-07-11 16:22:21 +0200 | |
---|---|---|
committer | 2021-07-11 16:22:21 +0200 | |
commit | 846057f0d696fded87d105dec1245e9ba32763ce (patch) | |
tree | 9a4914c07bcf189a3eea0a2c091567c56cdf4963 /internal/util/uri.go | |
parent | favourites GET implementation (#95) (diff) | |
download | gotosocial-846057f0d696fded87d105dec1245e9ba32763ce.tar.xz |
Block/unblock (#96)
* remote + local block logic, incl. federation
* improve blocking stuff
* fiddle with display of blocked profiles
* go fmt
Diffstat (limited to 'internal/util/uri.go')
-rw-r--r-- | internal/util/uri.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/internal/util/uri.go b/internal/util/uri.go index 5eb291628..370b2fa6f 100644 --- a/internal/util/uri.go +++ b/internal/util/uri.go @@ -50,6 +50,8 @@ const ( FollowPath = "follow" // UpdatePath is used to generate the URI for an account update UpdatePath = "updates" + // BlocksPath is used to generate the URI for a block + BlocksPath = "blocks" ) // APContextKey is a type used specifically for settings values on contexts within go-fed AP request chains @@ -124,6 +126,12 @@ func GenerateURIForUpdate(username string, protocol string, host string, thisUpd return fmt.Sprintf("%s://%s/%s/%s#%s/%s", protocol, host, UsersPath, username, UpdatePath, thisUpdateID) } +// GenerateURIForBlock returns the AP URI for a new block activity -- something like: +// https://example.org/users/whatever_user/blocks/01F7XTH1QGBAPMGF49WJZ91XGC +func GenerateURIForBlock(username string, protocol string, host string, thisBlockID string) string { + return fmt.Sprintf("%s://%s/%s/%s/%s/%s", protocol, host, UsersPath, username, BlocksPath, thisBlockID) +} + // GenerateURIsForAccount throws together a bunch of URIs for the given username, with the given protocol and host. func GenerateURIsForAccount(username string, protocol string, host string) *UserURIs { // The below URLs are used for serving web requests @@ -214,6 +222,11 @@ func IsPublicKeyPath(id *url.URL) bool { return userPublicKeyPathRegex.MatchString(id.Path) } +// IsBlockPath returns true if the given URL path corresponds to eg /users/example_username/blocks/SOME_ULID_OF_A_BLOCK +func IsBlockPath(id *url.URL) bool { + return blockPathRegex.MatchString(id.Path) +} + // ParseStatusesPath returns the username and ulid from a path such as /users/example_username/statuses/SOME_ULID_OF_A_STATUS func ParseStatusesPath(id *url.URL) (username string, ulid string, err error) { matches := statusesPathRegex.FindStringSubmatch(id.Path) @@ -292,3 +305,15 @@ func ParseLikedPath(id *url.URL) (username string, ulid string, err error) { ulid = matches[2] return } + +// ParseBlockPath returns the username and ulid from a path such as /users/example_username/blocks/SOME_ULID_OF_A_BLOCK +func ParseBlockPath(id *url.URL) (username string, ulid string, err error) { + matches := blockPathRegex.FindStringSubmatch(id.Path) + if len(matches) != 3 { + err = fmt.Errorf("expected 3 matches but matches length was %d", len(matches)) + return + } + username = matches[1] + ulid = matches[2] + return +} |