mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
Block/unblock (#96)
* remote + local block logic, incl. federation * improve blocking stuff * fiddle with display of blocked profiles * go fmt
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user