summaryrefslogtreecommitdiff
path: root/internal/api/client
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api/client')
-rw-r--r--internal/api/client/statuses/statuscreate.go28
-rw-r--r--internal/api/client/statuses/statuscreate_test.go52
2 files changed, 77 insertions, 3 deletions
diff --git a/internal/api/client/statuses/statuscreate.go b/internal/api/client/statuses/statuscreate.go
index 167b59b23..de06d2d8b 100644
--- a/internal/api/client/statuses/statuscreate.go
+++ b/internal/api/client/statuses/statuscreate.go
@@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"net/http"
+ "time"
apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
apiutil "code.superseriousbusiness.org/gotosocial/internal/api/util"
@@ -259,8 +260,6 @@ import (
// description: unprocessable content
// '500':
// description: internal server error
-// '501':
-// description: scheduled_at was set, but this feature is not yet implemented
func (m *Module) StatusCreatePOSTHandler(c *gin.Context) {
authed, errWithCode := apiutil.TokenAuth(c,
true, true, true, true,
@@ -414,5 +413,30 @@ func parseStatusCreateForm(c *gin.Context) (*apimodel.StatusCreateRequest, gtser
form.Poll.ExpiresIn = util.PtrOrZero(expiresIn)
}
+ // Parse scheduled_at if given.
+ if form.ScheduledAtRaw != "" {
+ // Try RFC3339 initially, which
+ // is a stricter UTC subset of ISO8601.
+ scheduledAt, err := time.Parse(
+ time.RFC3339, form.ScheduledAtRaw,
+ )
+ if err != nil {
+ // Try ISO8601 with offset
+ // (many clients use this).
+ scheduledAt, err = time.Parse(
+ util.ISO8601Offset, form.ScheduledAtRaw,
+ )
+ }
+
+ // If we still have an error
+ // we can't use this time.
+ if err != nil {
+ text := "could not parse scheduled_at value " + form.ScheduledAtRaw + " as ISO8601 time"
+ return nil, gtserror.NewErrorBadRequest(errors.New(text), text)
+ }
+
+ form.ScheduledAt = &scheduledAt
+ }
+
return form, nil
}
diff --git a/internal/api/client/statuses/statuscreate_test.go b/internal/api/client/statuses/statuscreate_test.go
index 84a6622a2..ca82502c2 100644
--- a/internal/api/client/statuses/statuscreate_test.go
+++ b/internal/api/client/statuses/statuscreate_test.go
@@ -467,7 +467,7 @@ func (suite *StatusCreateTestSuite) TestPostNewStatusMessedUpIntPolicy() {
}`, out)
}
-func (suite *StatusCreateTestSuite) TestPostNewScheduledStatus() {
+func (suite *StatusCreateTestSuite) TestPostNewScheduledStatusRFC3339() {
out, recorder := suite.postStatus(map[string][]string{
"status": {"this is a brand new status! #helloworld"},
"spoiler_text": {"hello hello"},
@@ -497,6 +497,56 @@ func (suite *StatusCreateTestSuite) TestPostNewScheduledStatus() {
}`, out)
}
+func (suite *StatusCreateTestSuite) TestPostNewScheduledStatusISO8601Offset() {
+ out, recorder := suite.postStatus(map[string][]string{
+ "status": {"this is a brand new status! #helloworld"},
+ "spoiler_text": {"hello hello"},
+ "sensitive": {"true"},
+ "visibility": {string(apimodel.VisibilityMutualsOnly)},
+ "scheduled_at": {"2080-09-05T19:38:00+0400"},
+ }, "")
+
+ // We should have OK from
+ // our call to the function.
+ suite.Equal(http.StatusOK, recorder.Code)
+
+ // A scheduled status with scheduled_at and status params should be returned.
+ suite.Equal(`{
+ "id": "ZZZZZZZZZZZZZZZZZZZZZZZZZZ",
+ "media_attachments": [],
+ "params": {
+ "application_id": "01F8MGY43H3N2C8EWPR2FPYEXG",
+ "language": "",
+ "scheduled_at": null,
+ "sensitive": true,
+ "spoiler_text": "hello hello",
+ "text": "this is a brand new status! #helloworld",
+ "visibility": "private"
+ },
+ "scheduled_at": "2080-09-05T15:38:00.000Z"
+}`, out)
+}
+
+func (suite *StatusCreateTestSuite) TestPostNewScheduledStatusNonsenseTime() {
+ out, recorder := suite.postStatus(map[string][]string{
+ "status": {"this is a brand new status! #helloworld"},
+ "spoiler_text": {"hello hello"},
+ "sensitive": {"true"},
+ "visibility": {string(apimodel.VisibilityMutualsOnly)},
+ "scheduled_at": {"pee pee poo poo"},
+ }, "")
+
+ // We should have 400 from
+ // our call to the function.
+ suite.Equal(http.StatusBadRequest, recorder.Code)
+
+ // We should have a helpful error
+ // message telling us how we screwed up.
+ suite.Equal(`{
+ "error": "Bad Request: could not parse scheduled_at value pee pee poo poo as ISO8601 time"
+}`, out)
+}
+
func (suite *StatusCreateTestSuite) TestPostNewBackfilledStatus() {
// A time in the past.
scheduledAtStr := "2020-10-04T15:32:02.018Z"