2021-06-13 16:42:28 +00:00
|
|
|
package status
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/id"
|
2021-07-26 18:25:54 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/text"
|
2021-06-13 16:42:28 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (p *processor) Create(account *gtsmodel.Account, application *gtsmodel.Application, form *apimodel.AdvancedStatusCreateForm) (*apimodel.Status, gtserror.WithCode) {
|
|
|
|
uris := util.GenerateURIsForAccount(account.Username, p.config.Protocol, p.config.Host)
|
|
|
|
thisStatusID, err := id.NewULID()
|
|
|
|
if err != nil {
|
|
|
|
return nil, gtserror.NewErrorInternalError(err)
|
|
|
|
}
|
|
|
|
thisStatusURI := fmt.Sprintf("%s/%s", uris.StatusesURI, thisStatusID)
|
|
|
|
thisStatusURL := fmt.Sprintf("%s/%s", uris.StatusesURL, thisStatusID)
|
|
|
|
|
|
|
|
newStatus := >smodel.Status{
|
|
|
|
ID: thisStatusID,
|
|
|
|
URI: thisStatusURI,
|
|
|
|
URL: thisStatusURL,
|
|
|
|
CreatedAt: time.Now(),
|
|
|
|
UpdatedAt: time.Now(),
|
|
|
|
Local: true,
|
|
|
|
AccountID: account.ID,
|
2021-06-17 16:02:33 +00:00
|
|
|
AccountURI: account.URI,
|
2021-07-26 18:25:54 +00:00
|
|
|
ContentWarning: text.RemoveHTML(form.SpoilerText),
|
2021-06-13 16:42:28 +00:00
|
|
|
ActivityStreamsType: gtsmodel.ActivityStreamsNote,
|
|
|
|
Sensitive: form.Sensitive,
|
|
|
|
Language: form.Language,
|
|
|
|
CreatedWithApplicationID: application.ID,
|
|
|
|
Text: form.Status,
|
|
|
|
}
|
|
|
|
|
2021-08-11 14:54:54 +00:00
|
|
|
if err := p.ProcessReplyToID(form, account.ID, newStatus); err != nil {
|
2021-06-13 16:42:28 +00:00
|
|
|
return nil, gtserror.NewErrorInternalError(err)
|
|
|
|
}
|
|
|
|
|
2021-08-11 14:54:54 +00:00
|
|
|
if err := p.ProcessMediaIDs(form, account.ID, newStatus); err != nil {
|
2021-06-13 16:42:28 +00:00
|
|
|
return nil, gtserror.NewErrorInternalError(err)
|
|
|
|
}
|
|
|
|
|
2021-08-11 14:54:54 +00:00
|
|
|
if err := p.ProcessVisibility(form, account.Privacy, newStatus); err != nil {
|
2021-06-13 16:42:28 +00:00
|
|
|
return nil, gtserror.NewErrorInternalError(err)
|
|
|
|
}
|
|
|
|
|
2021-08-11 14:54:54 +00:00
|
|
|
if err := p.ProcessLanguage(form, account.Language, newStatus); err != nil {
|
2021-06-13 16:42:28 +00:00
|
|
|
return nil, gtserror.NewErrorInternalError(err)
|
|
|
|
}
|
|
|
|
|
2021-08-11 14:54:54 +00:00
|
|
|
if err := p.ProcessMentions(form, account.ID, newStatus); err != nil {
|
2021-06-13 16:42:28 +00:00
|
|
|
return nil, gtserror.NewErrorInternalError(err)
|
|
|
|
}
|
|
|
|
|
2021-08-11 14:54:54 +00:00
|
|
|
if err := p.ProcessTags(form, account.ID, newStatus); err != nil {
|
2021-06-13 16:42:28 +00:00
|
|
|
return nil, gtserror.NewErrorInternalError(err)
|
|
|
|
}
|
|
|
|
|
2021-08-11 14:54:54 +00:00
|
|
|
if err := p.ProcessEmojis(form, account.ID, newStatus); err != nil {
|
2021-06-13 16:42:28 +00:00
|
|
|
return nil, gtserror.NewErrorInternalError(err)
|
|
|
|
}
|
|
|
|
|
2021-08-11 14:54:54 +00:00
|
|
|
if err := p.ProcessContent(form, account.ID, newStatus); err != nil {
|
2021-06-13 16:42:28 +00:00
|
|
|
return nil, gtserror.NewErrorInternalError(err)
|
|
|
|
}
|
|
|
|
|
2021-08-20 10:26:56 +00:00
|
|
|
// put the new status in the database
|
|
|
|
if err := p.db.PutStatus(newStatus); err != nil {
|
2021-06-13 16:42:28 +00:00
|
|
|
return nil, gtserror.NewErrorInternalError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// send it back to the processor for async processing
|
|
|
|
p.fromClientAPI <- gtsmodel.FromClientAPI{
|
|
|
|
APObjectType: gtsmodel.ActivityStreamsNote,
|
|
|
|
APActivityType: gtsmodel.ActivityStreamsCreate,
|
|
|
|
GTSModel: newStatus,
|
|
|
|
OriginAccount: account,
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the frontend representation of the new status to the submitter
|
2021-06-17 16:02:33 +00:00
|
|
|
mastoStatus, err := p.tc.StatusToMasto(newStatus, account)
|
2021-06-13 16:42:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", newStatus.ID, err))
|
|
|
|
}
|
|
|
|
|
|
|
|
return mastoStatus, nil
|
|
|
|
}
|