diff --git a/internal/db/pg/pg.go b/internal/db/pg/pg.go index 15360bc..b029b10 100644 --- a/internal/db/pg/pg.go +++ b/internal/db/pg/pg.go @@ -1300,12 +1300,14 @@ func (ps *postgresService) MentionStringsToMentions(targetAccounts []string, ori // okay we're good now, we can start pulling accounts out of the database mentionedAccount := >smodel.Account{} var err error + + // match username + account, case insensitive if local { // local user -- should have a null domain - err = ps.conn.Model(mentionedAccount).Where("username = ?", username).Where("? IS NULL", pg.Ident("domain")).Select() + err = ps.conn.Model(mentionedAccount).Where("LOWER(?) = LOWER(?)", pg.Ident("username"), username).Where("? IS NULL", pg.Ident("domain")).Select() } else { // remote user -- should have domain defined - err = ps.conn.Model(mentionedAccount).Where("username = ?", username).Where("? = ?", pg.Ident("domain"), domain).Select() + err = ps.conn.Model(mentionedAccount).Where("LOWER(?) = LOWER(?)", pg.Ident("username"), username).Where("LOWER(?) = LOWER(?)", pg.Ident("domain"), domain).Select() } if err != nil { @@ -1326,6 +1328,7 @@ func (ps *postgresService) MentionStringsToMentions(targetAccounts []string, ori TargetAccountID: mentionedAccount.ID, NameString: a, MentionedAccountURI: mentionedAccount.URI, + MentionedAccountURL: mentionedAccount.URL, GTSAccount: mentionedAccount, }) } diff --git a/internal/gtsmodel/mention.go b/internal/gtsmodel/mention.go index 3abe9c9..013e9cc 100644 --- a/internal/gtsmodel/mention.go +++ b/internal/gtsmodel/mention.go @@ -56,6 +56,10 @@ type Mention struct { // // This will not be put in the database, it's just for convenience. MentionedAccountURI string `pg:"-"` + // MentionedAccountURL is the web url of the user mentioned. + // + // This will not be put in the database, it's just for convenience. + MentionedAccountURL string `pg:"-"` // A pointer to the gtsmodel account of the mentioned account. GTSAccount *Account `pg:"-"` } diff --git a/internal/processing/synchronous/status/create.go b/internal/processing/synchronous/status/create.go index e90855a..a5aa7a4 100644 --- a/internal/processing/synchronous/status/create.go +++ b/internal/processing/synchronous/status/create.go @@ -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) diff --git a/internal/processing/synchronous/status/util.go b/internal/processing/synchronous/status/util.go index 71ecac6..0f2e9f6 100644 --- a/internal/processing/synchronous/status/util.go +++ b/internal/processing/synchronous/status/util.go @@ -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 '
' + content := fmt.Sprintf(`
%s
`, 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(`@%s`, targetAccount.URL, targetAccount.Username) + content = strings.ReplaceAll(content, menchie.NameString, mentionContent) + } + } + + // replace newlines with breaks + content = strings.ReplaceAll(content, "\n", "