From 74bc0feee76a60f2ea2524915064fae4ec8de1b6 Mon Sep 17 00:00:00 2001 From: tsmethurst Date: Fri, 2 Apr 2021 21:15:17 +0200 Subject: [PATCH] renaming --- internal/apimodule/status/statuscreate.go | 16 ++++++++-- internal/db/pg.go | 8 ++--- internal/util/parse.go | 37 ++++++++++++++--------- 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/internal/apimodule/status/statuscreate.go b/internal/apimodule/status/statuscreate.go index ad6c619..a309239 100644 --- a/internal/apimodule/status/statuscreate.go +++ b/internal/apimodule/status/statuscreate.go @@ -25,6 +25,7 @@ import ( "net/http" "github.com/gin-gonic/gin" + "github.com/google/uuid" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db/model" @@ -73,9 +74,20 @@ func (m *statusModule) statusCreatePOSTHandler(c *gin.Context) { return } - // newStatus := &model.Status{ + uris := util.GenerateURIs(authed.Account.Username, m.config.Protocol, m.config.Host) + newStatusID := uuid.NewString() - // } + newStatus := &model.Status{ + ID: newStatusID, + URI: fmt.Sprintf("%s/%s", uris.StatusesURI, newStatusID), + URL: fmt.Sprintf("%s/%s", uris.StatusesURL, newStatusID), + Content: util.HTMLFormat(form.Status), + Local: true, // will always be true if this status is being created through the client API + AccountID: authed.Account.ID, + InReplyToID: form.InReplyToID, + ContentWarning: form.SpoilerText, + ActivityStreamsType: "Note", + } } diff --git a/internal/db/pg.go b/internal/db/pg.go index df01132..4ea963a 100644 --- a/internal/db/pg.go +++ b/internal/db/pg.go @@ -453,10 +453,10 @@ func (ps *postgresService) NewSignup(username string, reason string, requireAppr PublicKey: &key.PublicKey, ActorType: "Person", URI: uris.UserURI, - InboxURL: uris.InboxURL, - OutboxURL: uris.OutboxURL, - FollowersURL: uris.FollowersURL, - FeaturedCollectionURL: uris.CollectionURL, + InboxURL: uris.InboxURI, + OutboxURL: uris.OutboxURI, + FollowersURL: uris.FollowersURI, + FeaturedCollectionURL: uris.CollectionURI, } if _, err = ps.conn.Model(a).Insert(); err != nil { return nil, err diff --git a/internal/util/parse.go b/internal/util/parse.go index fec88e7..89be053 100644 --- a/internal/util/parse.go +++ b/internal/util/parse.go @@ -21,30 +21,39 @@ package util import "fmt" type URIs struct { - HostURL string - UserURL string + HostURL string + UserURL string + StatusesURL string + UserURI string - InboxURL string - OutboxURL string - FollowersURL string - CollectionURL string + StatusesURI string + InboxURI string + OutboxURI string + FollowersURI string + CollectionURI string } func GenerateURIs(username string, protocol string, host string) *URIs { hostURL := fmt.Sprintf("%s://%s", protocol, host) userURL := fmt.Sprintf("%s/@%s", hostURL, username) + statusesURL := fmt.Sprintf("%s/statuses", userURL) + userURI := fmt.Sprintf("%s/users/%s", hostURL, username) - inboxURL := fmt.Sprintf("%s/inbox", userURI) - outboxURL := fmt.Sprintf("%s/outbox", userURI) - followersURL := fmt.Sprintf("%s/followers", userURI) - collectionURL := fmt.Sprintf("%s/collections/featured", userURI) + statusesURI := fmt.Sprintf("%s/statuses", userURI) + inboxURI := fmt.Sprintf("%s/inbox", userURI) + outboxURI := fmt.Sprintf("%s/outbox", userURI) + followersURI := fmt.Sprintf("%s/followers", userURI) + collectionURI := fmt.Sprintf("%s/collections/featured", userURI) return &URIs{ HostURL: hostURL, UserURL: userURL, + StatusesURL: statusesURL, + UserURI: userURI, - InboxURL: inboxURL, - OutboxURL: outboxURL, - FollowersURL: followersURL, - CollectionURL: collectionURL, + StatusesURI: statusesURI, + InboxURI: inboxURI, + OutboxURI: outboxURI, + FollowersURI: followersURI, + CollectionURI: collectionURI, } }