summaryrefslogtreecommitdiff
path: root/internal/api
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-08-22 19:47:10 +0200
committerLibravatar GitHub <noreply@github.com>2024-08-22 19:47:10 +0200
commit53fccb8af8943aa63e557cbd54d2c19c75b63174 (patch)
tree5a3dad5bfb03df895a1a45c69d8fe8acc33abab6 /internal/api
parent[bugfix/frontend] Small safari + gnome web fixes (#3219) (diff)
downloadgotosocial-53fccb8af8943aa63e557cbd54d2c19c75b63174.tar.xz
[feature] Use `local_only` field, deprecate `federated` field (#3222)
* [feature] Use `local_only` field, deprecate `federated` field * use `deprecated` comment for form.Federated * nolint
Diffstat (limited to 'internal/api')
-rw-r--r--internal/api/client/statuses/statuscreate.go37
-rw-r--r--internal/api/model/status.go24
2 files changed, 34 insertions, 27 deletions
diff --git a/internal/api/client/statuses/statuscreate.go b/internal/api/client/statuses/statuscreate.go
index 7b30e0ee6..de1581515 100644
--- a/internal/api/client/statuses/statuscreate.go
+++ b/internal/api/client/statuses/statuscreate.go
@@ -29,6 +29,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
+ "github.com/superseriousbusiness/gotosocial/internal/util"
"github.com/superseriousbusiness/gotosocial/internal/validate"
)
@@ -137,6 +138,24 @@ import (
// - direct
// in: formData
// -
+// name: local_only
+// x-go-name: LocalOnly
+// description: >-
+// If set to true, this status will be "local only" and will NOT be federated beyond the local timeline(s).
+// If set to false (default), this status will be federated to your followers beyond the local timeline(s).
+// type: boolean
+// in: formData
+// default: false
+// -
+// name: federated
+// x-go-name: Federated
+// description: >-
+// ***DEPRECATED***. Included for back compat only. Only used if set and local_only is not yet.
+// If set to true, this status will be federated beyond the local timeline(s).
+// If set to false, this status will NOT be federated beyond the local timeline(s).
+// in: formData
+// type: boolean
+// -
// name: scheduled_at
// x-go-name: ScheduledAt
// description: |-
@@ -162,12 +181,6 @@ import (
// - text/plain
// - text/markdown
// in: formData
-// -
-// name: federated
-// x-go-name: Federated
-// description: This status will be federated beyond the local timeline(s).
-// in: formData
-// type: boolean
//
// produces:
// - application/json
@@ -210,7 +223,7 @@ func (m *Module) StatusCreatePOSTHandler(c *gin.Context) {
return
}
- form := &apimodel.AdvancedStatusCreateForm{}
+ form := &apimodel.StatusCreateRequest{}
if err := c.ShouldBind(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return
@@ -249,7 +262,7 @@ func (m *Module) StatusCreatePOSTHandler(c *gin.Context) {
// overlength inputs.
//
// Side effect: normalizes the post's language tag.
-func validateNormalizeCreateStatus(form *apimodel.AdvancedStatusCreateForm) error {
+func validateNormalizeCreateStatus(form *apimodel.StatusCreateRequest) error {
hasStatus := form.Status != ""
hasMedia := len(form.MediaIDs) != 0
hasPoll := form.Poll != nil
@@ -286,10 +299,16 @@ func validateNormalizeCreateStatus(form *apimodel.AdvancedStatusCreateForm) erro
form.Language = language
}
+ // Check if the deprecated "federated" field was
+ // set in lieu of "local_only", and use it if so.
+ if form.LocalOnly == nil && form.Federated != nil { // nolint:staticcheck
+ form.LocalOnly = util.Ptr(!*form.Federated) // nolint:staticcheck
+ }
+
return nil
}
-func validateNormalizeCreatePoll(form *apimodel.AdvancedStatusCreateForm) error {
+func validateNormalizeCreatePoll(form *apimodel.StatusCreateRequest) error {
maxPollOptions := config.GetStatusesPollMaxOptions()
maxPollChars := config.GetStatusesPollOptionMaxChars()
diff --git a/internal/api/model/status.go b/internal/api/model/status.go
index b3ac746d7..d0acafae8 100644
--- a/internal/api/model/status.go
+++ b/internal/api/model/status.go
@@ -46,6 +46,8 @@ type Status struct {
// Visibility of this status.
// example: unlisted
Visibility Visibility `json:"visibility"`
+ // Set to "true" if status is not federated, ie., a "local only" status; omitted from response otherwise.
+ LocalOnly bool `json:"local_only,omitempty"`
// Primary language of this status (ISO 639 Part 1 two-letter language code).
// Will be null if language is not known.
// example: en
@@ -209,6 +211,10 @@ type StatusCreateRequest struct {
SpoilerText string `form:"spoiler_text" json:"spoiler_text" xml:"spoiler_text"`
// Visibility of the posted status.
Visibility Visibility `form:"visibility" json:"visibility" xml:"visibility"`
+ // Set to "true" if this status should not be federated, ie. it should be a "local only" status.
+ LocalOnly *bool `form:"local_only"`
+ // Deprecated: Only used if LocalOnly is not set.
+ Federated *bool `form:"federated"`
// ISO 8601 Datetime at which to schedule a status.
// Providing this parameter will cause ScheduledStatus to be returned instead of Status.
// Must be at least 5 minutes in the future.
@@ -238,24 +244,6 @@ const (
VisibilityDirect Visibility = "direct"
)
-// AdvancedStatusCreateForm wraps the mastodon-compatible status create form along with the GTS advanced
-// visibility settings.
-//
-// swagger:ignore
-type AdvancedStatusCreateForm struct {
- StatusCreateRequest
- AdvancedVisibilityFlagsForm
-}
-
-// AdvancedVisibilityFlagsForm allows a few more advanced flags to be set on new statuses, in addition
-// to the standard mastodon-compatible ones.
-//
-// swagger:ignore
-type AdvancedVisibilityFlagsForm struct {
- // This status will be federated beyond the local timeline(s).
- Federated *bool `form:"federated" json:"federated" xml:"federated"`
-}
-
// StatusContentType is the content type with which to parse the submitted status.
// Can be either text/plain or text/markdown. Empty will default to text/plain.
//