summaryrefslogtreecommitdiff
path: root/internal/processing/account
diff options
context:
space:
mode:
authorLibravatar Michael Manfre <mmanfre@gmail.com>2022-11-19 04:07:51 -0500
committerLibravatar GitHub <noreply@github.com>2022-11-19 10:07:51 +0100
commit67106c9dc4b2139878ba1fc44ef268f0a4efd804 (patch)
treef338cf04f46b4246f6dc85a1b6f3be133f483531 /internal/processing/account
parent[docs] Move and document logs (#1076) (diff)
downloadgotosocial-67106c9dc4b2139878ba1fc44ef268f0a4efd804.tar.xz
[feature] Support markdown format for Account bio/note (#1037)
* [feature] Status format also controls bio format * test
Diffstat (limited to 'internal/processing/account')
-rw-r--r--internal/processing/account/update.go12
-rw-r--r--internal/processing/account/update_test.go38
2 files changed, 46 insertions, 4 deletions
diff --git a/internal/processing/account/update.go b/internal/processing/account/update.go
index bc4570c76..ed9fa6d4d 100644
--- a/internal/processing/account/update.go
+++ b/internal/processing/account/update.go
@@ -66,7 +66,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
account.NoteRaw = *form.Note
// Process note to generate a valid HTML representation
- note, err := p.processNote(ctx, *form.Note, account.ID)
+ note, err := p.processNote(ctx, *form.Note, account)
if err != nil {
return nil, gtserror.NewErrorBadRequest(err)
}
@@ -241,13 +241,13 @@ func (p *processor) UpdateHeader(ctx context.Context, header *multipart.FileHead
return processingMedia.LoadAttachment(ctx)
}
-func (p *processor) processNote(ctx context.Context, note string, accountID string) (string, error) {
+func (p *processor) processNote(ctx context.Context, note string, account *gtsmodel.Account) (string, error) {
if note == "" {
return "", nil
}
tagStrings := util.DeriveHashtagsFromText(note)
- tags, err := p.db.TagStringsToTags(ctx, tagStrings, accountID)
+ tags, err := p.db.TagStringsToTags(ctx, tagStrings, account.ID)
if err != nil {
return "", err
}
@@ -255,7 +255,7 @@ func (p *processor) processNote(ctx context.Context, note string, accountID stri
mentionStrings := util.DeriveMentionNamesFromText(note)
mentions := []*gtsmodel.Mention{}
for _, mentionString := range mentionStrings {
- mention, err := p.parseMention(ctx, mentionString, accountID, "")
+ mention, err := p.parseMention(ctx, mentionString, account.ID, "")
if err != nil {
continue
}
@@ -266,5 +266,9 @@ func (p *processor) processNote(ctx context.Context, note string, accountID stri
// emojiStrings := util.DeriveEmojisFromText(note)
// emojis, err := p.db.EmojiStringsToEmojis(ctx, emojiStrings)
+ if account.StatusFormat == "markdown" {
+ return p.formatter.FromMarkdown(ctx, note, mentions, tags, nil), nil
+ }
+
return p.formatter.FromPlain(ctx, note, mentions, tags), nil
}
diff --git a/internal/processing/account/update_test.go b/internal/processing/account/update_test.go
index 0483154c6..3f6c338e8 100644
--- a/internal/processing/account/update_test.go
+++ b/internal/processing/account/update_test.go
@@ -112,6 +112,44 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateWithMention() {
suite.Equal(noteExpected, dbAccount.Note)
}
+func (suite *AccountUpdateTestSuite) TestAccountUpdateWithMarkdownNote() {
+ testAccount := suite.testAccounts["local_account_1"]
+
+ note := "*hello* ~~here~~ i am!"
+ expectedNote := `<p><em>hello</em> <del>here</del> i am!</p>`
+
+ form := &apimodel.UpdateCredentialsRequest{
+ Note: &note,
+ }
+
+ // set default post language of account 1 to markdown
+ testAccount.StatusFormat = "markdown"
+
+ // should get no error from the update function, and an api model account returned
+ apiAccount, errWithCode := suite.accountProcessor.Update(context.Background(), testAccount, form)
+ // reset test account to avoid breaking other tests
+ testAccount.StatusFormat = "plain"
+ suite.NoError(errWithCode)
+ suite.NotNil(apiAccount)
+
+ // fields on the profile should be updated
+ suite.Equal(expectedNote, apiAccount.Note)
+
+ // we should have an update in the client api channel
+ msg := <-suite.fromClientAPIChan
+ suite.Equal(ap.ActivityUpdate, msg.APActivityType)
+ suite.Equal(ap.ObjectProfile, msg.APObjectType)
+ suite.NotNil(msg.OriginAccount)
+ suite.Equal(testAccount.ID, msg.OriginAccount.ID)
+ suite.Nil(msg.TargetAccount)
+
+ // fields should be updated in the database as well
+ dbAccount, err := suite.db.GetAccountByID(context.Background(), testAccount.ID)
+ suite.NoError(err)
+ suite.Equal(expectedNote, dbAccount.Note)
+
+}
+
func TestAccountUpdateTestSuite(t *testing.T) {
suite.Run(t, new(AccountUpdateTestSuite))
}