mention regex better but not 100% there
This commit is contained in:
@ -16,6 +16,7 @@ func (p *processor) Create(account *gtsmodel.Account, application *gtsmodel.Appl
|
||||
thisStatusID := uuid.NewString()
|
||||
thisStatusURI := fmt.Sprintf("%s/%s", uris.StatusesURI, thisStatusID)
|
||||
thisStatusURL := fmt.Sprintf("%s/%s", uris.StatusesURL, thisStatusID)
|
||||
|
||||
newStatus := >smodel.Status{
|
||||
ID: thisStatusID,
|
||||
URI: thisStatusURI,
|
||||
@ -66,6 +67,10 @@ func (p *processor) Create(account *gtsmodel.Account, application *gtsmodel.Appl
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
|
||||
if err := p.processContent(form, account.ID, newStatus); err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
|
||||
// put the new status in the database, generating an ID for it in the process
|
||||
if err := p.db.Put(newStatus); err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
|
||||
@ -3,6 +3,7 @@ package status
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
@ -228,3 +229,28 @@ func (p *processor) processEmojis(form *apimodel.AdvancedStatusCreateForm, accou
|
||||
status.Emojis = emojis
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *processor) processContent(form *apimodel.AdvancedStatusCreateForm, accountID string, status *gtsmodel.Status) error {
|
||||
if form.Status == "" {
|
||||
status.Content = ""
|
||||
return nil
|
||||
}
|
||||
|
||||
// surround the whole status in '<p>'
|
||||
content := fmt.Sprintf(`<p>%s</p>`, form.Status)
|
||||
|
||||
// format mentions nicely
|
||||
for _, menchie := range status.GTSMentions {
|
||||
targetAccount := >smodel.Account{}
|
||||
if err := p.db.GetByID(menchie.TargetAccountID, targetAccount); err == nil {
|
||||
mentionContent := fmt.Sprintf(`<span class="h-card"><a href="%s" class="u-url mention">@<span>%s</span></a></span>`, targetAccount.URL, targetAccount.Username)
|
||||
content = strings.ReplaceAll(content, menchie.NameString, mentionContent)
|
||||
}
|
||||
}
|
||||
|
||||
// replace newlines with breaks
|
||||
content = strings.ReplaceAll(content, "\n", "<br />")
|
||||
|
||||
status.Content = content
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user