Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

Mention notifications.

Matt Roberts6b7b1945edc0
diff --git a/app/handlers/apiv1/post.go b/app/handlers/apiv1/post.go
index 68eb4e167..fffecc946 100644
--- a/app/handlers/apiv1/post.go
+++ b/app/handlers/apiv1/post.go
@@ -287,7 +287,7 @@ func PostComment() web.HandlerFunc {
return c.Failure(err)
}
- c.Enqueue(tasks.NotifyAboutNewComment(getPost.Result, action.Content))
+ c.Enqueue(tasks.NotifyAboutNewComment(getPost.Result, addNewComment.Result))
metrics.TotalComments.Inc()
return c.Ok(web.Map{
diff --git a/app/models/entity/comment.go b/app/models/entity/comment.go
index b0ef76b98..dcf63b6af 100644
--- a/app/models/entity/comment.go
+++ b/app/models/entity/comment.go
@@ -1,6 +1,11 @@
package entity
-import "time"
+import (
+ "encoding/json"
+ "regexp"
+ "strings"
+ "time"
+)
type ReactionCounts struct {
Emoji string `json:"emoji"`
@@ -8,6 +13,12 @@ type ReactionCounts struct {
IncludesMe bool `json:"includesMe"`
}
+type Mention struct {
+ ID int `json:"id"`
+ Name string `json:"name"`
+ IsNew bool `json:"isNew"`
+}
+
// Comment represents an user comment on an post
type Comment struct {
ID int `json:"id"`
@@ -18,4 +29,42 @@ type Comment struct {
EditedAt *time.Time `json:"editedAt,omitempty"`
EditedBy *User `json:"editedBy,omitempty"`
ReactionCounts []ReactionCounts `json:"reactionCounts,omitempty"`
+ Mentions []Mention `json:"_"`
+}
+
+func (c *Comment) ParseMentions() {
+ r, _ := regexp.Compile("@{([^}]+)}")
+
+ // Remove escaped quotes from the input string
+ input := strings.ReplaceAll(c.Content, `\"`, `"`)
+
+ matches := r.FindAllString(input, -1)
+
+ c.Mentions = []Mention{}
+
+ for _, match := range matches {
+
+ jsonMention := match[1:]
+
+ var dat map[string]interface{}
+
+ err := json.Unmarshal([]byte(jsonMention), &dat)
+ if err == nil {
+ name, nameExists := dat["name"]
+ id, idExists := dat["id"]
+ isNew, isNewExists := dat["isNew"]
+ if !isNewExists {
+ isNew = false
+ }
+
+ if nameExists && idExists {
+ mention := Mention{
+ ID: int(id.(float64)),
+ Name: name.(string),
+ IsNew: isNew.(bool),
+ }
+ c.Mentions = append(c.Mentions, mention)
+ }
+ }
+ }
}
diff --git a/app/models/entity/comment_test.go b/app/models/entity/comment_test.go
new file mode 100644
index 000000000..f59270981
--- /dev/null
+++ b/app/models/entity/comment_test.go
@@ -0,0 +1,52 @@
+package entity_test
+
+import (
+ "testing"
+
+ "github.com/getfider/fider/app/models/entity"
+
+ . "github.com/getfider/fider/app/pkg/assert"
+)
+
+func TestComment_ParseMentions(t *testing.T) {
+ RegisterT(t)
+ tests := []struct {
+ name string
+ content string
+ expected []entity.Mention
+ }{
+ {
+ name: "no mentions",
+ content: "This is a regular comment \\\" just here",
+ expected: []entity.Mention{},
+ },
+ {
+ name: "Simple mention",
+ content: `Hello there @{"id":1,"name":"John Doe","isNew":false} how are you`,
+ expected: []entity.Mention{{ID: 1, Name: "John Doe", IsNew: false}},
+ },
+ {
+ name: "Simple mention 2",
+ content: `Hello there @{"id":2,"name":"John Doe Smith","isNew":true} how are you`,
+ expected: []entity.Mention{{ID: 2, Name: "John Doe Smith", IsNew: true}},
+ },
+ {
+ name: "Multiple mentions",
+ content: `Hello there @{"id":2,"name":"John Doe Smith","isNew":true} and @{"id":1,"name":"John Doe","isNew":false} how are you`,
+ expected: []entity.Mention{{ID: 2, Name: "John Doe Smith", IsNew: true}, {ID: 1, Name: "John Doe", IsNew: false}},
+ },
+ {
+ name: "Some odd JSON",
+ content: `Hello there @{"id":2,name:"John Doe Smith","isNew":true} how are you`,
+ expected: []entity.Mention{},
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ comment := &entity.Comment{Content: tt.content}
+ comment.ParseMentions()
+ Expect(comment.Mentions).Equals(tt.expected)
+ })
+ }
+}
diff --git a/app/pkg/assert/assert.go b/app/pkg/assert/assert.go
index 9c77bf841..87a12ac51 100644
--- a/app/pkg/assert/assert.go
+++ b/app/pkg/assert/assert.go
@@ -40,7 +40,7 @@ func describeProps(props dto.Props) string {
return str
}
-//Fail the current test case with given message
+// Fail the current test case with given message
func Fail(msg string, args ...any) {
if currentT == nil {
panic("Did you forget to call RegisterT(t)?")
@@ -51,7 +51,7 @@ func Fail(msg string, args ...any) {
var currentT *testing.T
var envVariables map[string]string
-//RegisterT saves current testing.T for further usage by Expect
+// RegisterT saves current testing.T for further usage by Expect
func RegisterT(t *testing.T) {
bus.Reset()
if currentT == nil {
@@ -77,12 +77,12 @@ func restartEnv() {
env.Reload()
}
-//AnyAssertions is used to assert any kind of value
+// AnyAssertions is used to assert any kind of value
type AnyAssertions struct {
actual any
}
-//Expect starts new assertions on given value
+// Expect starts new assertions on given value
func Expect(actual any) *AnyAssertions {
if currentT == nil {
panic("Did you forget to call RegisterT(t)?")
@@ -92,7 +92,7 @@ func Expect(actual any) *AnyAssertions {
}
}
-//Equals asserts that actual value equals expected value
+// Equals asserts that actual value equals expected value
func (a *AnyAssertions) Equals(expected any) bool {
if reflect.DeepEqual(expected, a.actual) {
return true
@@ -102,7 +102,7 @@ func (a *AnyAssertions) Equals(expected any) bool {
return false
}
-//ContainsSubstring asserts that actual value contains given substring
+// ContainsSubstring asserts that actual value contains given substring
func (a *AnyAssertions) ContainsSubstring(substr string) bool {
if strings.Contains(a.actual.(string), substr) {
return true
@@ -112,7 +112,7 @@ func (a *AnyAssertions) ContainsSubstring(substr string) bool {
return false
}
-//NotEquals asserts that actual value is different than given value
+// NotEquals asserts that actual value is different than given value
func (a *AnyAssertions) NotEquals(other any) bool {
if !reflect.DeepEqual(other, a.actual) {
return true
@@ -122,27 +122,27 @@ func (a *AnyAssertions) NotEquals(other any) bool {
return false
}
-//IsTrue asserts that actual value is true
+// IsTrue asserts that actual value is true
func (a *AnyAssertions) IsTrue() bool {
return a.Equals(true)
}
-//IsFalse asserts that actual value is false
+// IsFalse asserts that actual value is false
func (a *AnyAssertions) IsFalse() bool {
return a.Equals(false)
}
-//IsEmpty asserts that actual value is empty
+// IsEmpty asserts that actual value is empty
func (a *AnyAssertions) IsEmpty() bool {
return a.Equals("")
}
-//IsNotEmpty asserts that actual value is not empty
+// IsNotEmpty asserts that actual value is not empty
func (a *AnyAssertions) IsNotEmpty() bool {
return a.NotEquals("")
}
-//IsNotNil asserts that actual value is not nil
+// IsNotNil asserts that actual value is not nil
func (a *AnyAssertions) IsNotNil() bool {
if a.actual != nil && !reflect.ValueOf(a.actual).IsNil() {
return true
@@ -152,7 +152,7 @@ func (a *AnyAssertions) IsNotNil() bool {
return false
}
-//IsNil asserts that actual value is nil
+// IsNil asserts that actual value is nil
func (a *AnyAssertions) IsNil() bool {
if a.actual == nil || reflect.ValueOf(a.actual).IsNil() {
return true
@@ -162,7 +162,7 @@ func (a *AnyAssertions) IsNil() bool {
return false
}
-//HasLen asserts that actual value has an expected length
+// HasLen asserts that actual value has an expected length
func (a *AnyAssertions) HasLen(expected int) bool {
length := reflect.ValueOf(a.actual).Len()
if expected == length {
@@ -173,7 +173,7 @@ func (a *AnyAssertions) HasLen(expected int) bool {
return false
}
-//Panics asserts that actual value panics whenever called
+// Panics asserts that actual value panics whenever called
func (a *AnyAssertions) Panics() (panicked bool) {
mustBeFunction(a.actual)
defer func() {
@@ -189,7 +189,7 @@ func (a *AnyAssertions) Panics() (panicked bool) {
return
}
-//EventuallyEquals asserts that, within 30 seconds, the actual function will return same value as expected value
+// EventuallyEquals asserts that, within 30 seconds, the actual function will return same value as expected value
func (a *AnyAssertions) EventuallyEquals(expected any) bool {
mustBeFunction(a.actual)
@@ -213,7 +213,7 @@ func (a *AnyAssertions) EventuallyEquals(expected any) bool {
}
}
-//TemporarilySimilar asserts that actual value is between a range of other time value
+// TemporarilySimilar asserts that actual value is between a range of other time value
func (a *AnyAssertions) TemporarilySimilar(other time.Time, diff time.Duration) bool {
actual, ok := a.actual.(time.Time)
if !ok {
diff --git a/app/pkg/markdown/markdown.go b/app/pkg/markdown/markdown.go
index 502473b93..3fb55e5df 100644
--- a/app/pkg/markdown/markdown.go
+++ b/app/pkg/markdown/markdown.go
@@ -79,7 +79,15 @@ func StripMentionMetaData(input string) string {
if err != nil {
return match
}
- return "@" + dat["name"].(string)
+
+ name, nameExists := dat["name"]
+ _, idExists := dat["id"]
+
+ if !nameExists || !idExists {
+ return match
+ }
+
+ return "@" + name.(string)
})
}
diff --git a/app/pkg/markdown/markdown_test.go b/app/pkg/markdown/markdown_test.go
index e39e75027..0b472f28a 100644
--- a/app/pkg/markdown/markdown_test.go
+++ b/app/pkg/markdown/markdown_test.go
@@ -100,3 +100,19 @@ func TestStripMentionMetaData(t *testing.T) {
Expect(output).Equals(expected)
}
}
+
+func TestStripMentionMetaDataDoesntBreakUserInput(t *testing.T) {
+ RegisterT(t)
+
+ for input, expected := range map[string]string{
+ `There is nothing here`: "There is nothing here",
+ `There is nothing here {ok}`: "There is nothing here {ok}",
+ `This is a message for {{matt}}`: "This is a message for {{matt}}",
+ `This is a message for {{id:1,wiggles:true}}`: "This is a message for {{id:1,wiggles:true}}",
+ `Although uncommon, someone could enter @{something} like this`: "Although uncommon, someone could enter @{something} like this",
+ `Or @{"id":100,"wiggles":"yes"} something like this`: `Or @{"id":100,"wiggles":"yes"} something like this`,
+ } {
+ output := markdown.StripMentionMetaData(input)
+ Expect(output).Equals(expected)
+ }
+}
diff --git a/app/services/email/mailgun/sendmail_test.go b/app/services/email/mailgun/sendmail_test.go
index ca5c839ef..075b5c671 100644
--- a/app/services/email/mailgun/sendmail_test.go
+++ b/app/services/email/mailgun/sendmail_test.go
@@ -44,7 +44,11 @@ func TestSend_Success(t *testing.T) {
},
TemplateName: "echo_test",
Props: dto.Props{
- "name": "Hello",
+ "name": "Hello",
+ "userName": "Jon Snow",
+ "title": "Add support for TypeScript",
+ "postLink": "https://test.com/posts/1",
+ "locale": "email.new_mention.text",
},
})
diff --git a/app/tasks/new_comment.go b/app/tasks/new_comment.go
index 9a19cc839..7dd6ace55 100644
--- a/app/tasks/new_comment.go
+++ b/app/tasks/new_comment.go
@@ -16,8 +16,11 @@ import (
)
// NotifyAboutNewComment sends a notification (web and email) to subscribers
-func NotifyAboutNewComment(post *entity.Post, comment string) worker.Task {
+func NotifyAboutNewComment(post *entity.Post, comment *entity.Comment) worker.Task {
return describe("Notify about new comment", func(c *worker.Context) error {
+
+ comment.ParseMentions()
+
// Web notification
users, err := getActiveSubscribers(c, post, enum.NotificationChannelWeb, enum.NotificationEventNewComment)
if err != nil {
@@ -41,7 +44,39 @@ func NotifyAboutNewComment(post *entity.Post, comment string) worker.Task {
}
}
- // Email notification
+ // Web notification - mentions
+ title = fmt.Sprintf("**%s** mentioned you in **%s**", author.Name, post.Title)
+
+ if comment.Mentions != nil {
+
+ users, err = getActiveSubscribers(c, post, enum.NotificationChannelWeb, enum.NotificationEventMention)
+ if err != nil {
+ return c.Failure(err)
+ }
+
+ // Iterate the mentions
+ for _, mention := range comment.Mentions {
+ // Check if the user is in the list of mention subscribers (users)
+ for _, u := range users {
+ if u.ID == mention.ID && mention.IsNew {
+ err = bus.Dispatch(c, &cmd.AddNewNotification{
+ User: u,
+ Title: title,
+ Link: link,
+ PostID: post.ID,
+ })
+ if err != nil {
+ return c.Failure(err)
+ }
+ }
+ }
+ }
+
+ }
+
+ strippedContent := markdown.StripMentionMetaData(comment.Content)
+
+ // Standard email notitifications
users, err = getActiveSubscribers(c, post, enum.NotificationChannelEmail, enum.NotificationEventNewComment)
if err != nil {
return c.Failure(err)
@@ -54,29 +89,37 @@ func NotifyAboutNewComment(post *entity.Post, comment string) worker.Task {
}
}
- tenant := c.Tenant()
- baseURL, logoURL := web.BaseURL(c), web.LogoURL(c)
+ sendEmailNotifications(c, post, to, strippedContent, enum.NotificationEventNewComment)
+
+ // Mentions
+ to = make([]dto.Recipient, 0)
+ if comment.Mentions != nil {
+
+ users, err = getActiveSubscribers(c, post, enum.NotificationChannelEmail, enum.NotificationEventMention)
+ if err != nil {
+ return c.Failure(err)
+ }
+
+ // Iterate the mentions
+ for _, mention := range comment.Mentions {
+
+ // Check if the user is in the list of mention subscribers (users)
+ for _, u := range users {
+ if u.ID == mention.ID && mention.IsNew {
+ to = append(to, dto.NewRecipient(u.Name, u.Email, dto.Props{}))
+ break
+ }
+ }
+ }
- mailProps := dto.Props{
- "title": post.Title,
- "siteName": tenant.Name,
- "userName": author.Name,
- "content": markdown.Full(comment),
- "postLink": linkWithText(fmt.Sprintf("#%d", post.Number), baseURL, "/posts/%d/%s", post.Number, post.Slug),
- "view": linkWithText(i18n.T(c, "email.subscription.view"), baseURL, "/posts/%d/%s", post.Number, post.Slug),
- "unsubscribe": linkWithText(i18n.T(c, "email.subscription.unsubscribe"), baseURL, "/posts/%d/%s", post.Number, post.Slug),
- "change": linkWithText(i18n.T(c, "email.subscription.change"), baseURL, "/settings"),
- "logo": logoURL,
}
- bus.Publish(c, &cmd.SendMail{
- From: dto.Recipient{Name: author.Name},
- To: to,
- TemplateName: "new_comment",
- Props: mailProps,
- })
+ sendEmailNotifications(c, post, to, strippedContent, enum.NotificationEventMention)
- webhookProps := webhook.Props{"comment": markdown.StripMentionMetaData(comment)}
+ tenant := c.Tenant()
+ baseURL, logoURL := web.BaseURL(c), web.LogoURL(c)
+
+ webhookProps := webhook.Props{"comment": strippedContent}
webhookProps.SetPost(post, "post", baseURL, true, true)
webhookProps.SetUser(author, "author")
webhookProps.SetTenant(tenant, "tenant", baseURL, logoURL)
@@ -92,3 +135,42 @@ func NotifyAboutNewComment(post *entity.Post, comment string) worker.Task {
return nil
})
}
+
+func sendEmailNotifications(c *worker.Context, post *entity.Post, to []dto.Recipient, comment string, event enum.NotificationEvent) error {
+
+ // Short circuit if there is no one to notify
+ if len(to) == 0 {
+ return nil
+ }
+
+ author := c.User()
+ tenant := c.Tenant()
+ baseURL, logoURL := web.BaseURL(c), web.LogoURL(c)
+ messaleLocaleString := "email.new_comment.text"
+ if event.UserSettingsKeyName == enum.NotificationEventMention.UserSettingsKeyName {
+ messaleLocaleString = "email.new_mention.text"
+ }
+
+ mailProps := dto.Props{
+ "title": post.Title,
+ "messageLocaleString": messaleLocaleString,
+ "siteName": tenant.Name,
+ "userName": author.Name,
+ "content": markdown.Full(comment),
+ "postLink": linkWithText(fmt.Sprintf("#%d", post.Number), baseURL, "/posts/%d/%s", post.Number, post.Slug),
+ "view": linkWithText(i18n.T(c, "email.subscription.view"), baseURL, "/posts/%d/%s", post.Number, post.Slug),
+ "unsubscribe": linkWithText(i18n.T(c, "email.subscription.unsubscribe"), baseURL, "/posts/%d/%s", post.Number, post.Slug),
+ "change": linkWithText(i18n.T(c, "email.subscription.change"), baseURL, "/settings"),
+ "logo": logoURL,
+ }
+
+ bus.Publish(c, &cmd.SendMail{
+ From: dto.Recipient{Name: author.Name},
+ To: to,
+ TemplateName: "new_comment",
+ Props: mailProps,
+ })
+
+ return nil
+
+}
diff --git a/app/tasks/new_comment_test.go b/app/tasks/new_comment_test.go
index 177e009de..6cc7ea6e2 100644
--- a/app/tasks/new_comment_test.go
+++ b/app/tasks/new_comment_test.go
@@ -31,8 +31,12 @@ func TestNotifyAboutNewCommentTask(t *testing.T) {
})
bus.AddHandler(func(ctx context.Context, q *query.GetActiveSubscribers) error {
- q.Result = []*entity.User{
- mock.JonSnow,
+ if q.Event.UserSettingsKeyName == "event_notification_new_comment" {
+ q.Result = []*entity.User{
+ mock.JonSnow,
+ }
+ } else {
+ q.Result = []*entity.User{}
}
return nil
})
@@ -52,7 +56,7 @@ func TestNotifyAboutNewCommentTask(t *testing.T) {
Description: "TypeScript is great, please add support for it",
User: mock.JonSnow,
}
- task := tasks.NotifyAboutNewComment(post, "I agree")
+ task := tasks.NotifyAboutNewComment(post, &entity.Comment{Content: "I agree"})
err := worker.
OnTenant(mock.DemoTenant).
@@ -65,15 +69,16 @@ func TestNotifyAboutNewCommentTask(t *testing.T) {
Expect(emailmock.MessageHistory[0].TemplateName).Equals("new_comment")
Expect(emailmock.MessageHistory[0].Tenant).Equals(mock.DemoTenant)
Expect(emailmock.MessageHistory[0].Props).Equals(dto.Props{
- "title": "Add support for TypeScript",
- "postLink": "<a href='http://domain.com/posts/1/add-support-for-typescript'>#1</a>",
- "siteName": "Demonstration",
- "userName": "Arya Stark",
- "content": template.HTML("<p>I agree</p>"),
- "view": "<a href='http://domain.com/posts/1/add-support-for-typescript'>view it on your browser</a>",
- "change": "<a href='http://domain.com/settings'>change your notification preferences</a>",
- "unsubscribe": "<a href='http://domain.com/posts/1/add-support-for-typescript'>unsubscribe from it</a>",
- "logo": "https://fider.io/images/logo-100x100.png",
+ "title": "Add support for TypeScript",
+ "messageLocaleString": "email.new_comment.text",
+ "postLink": "<a href='http://domain.com/posts/1/add-support-for-typescript'>#1</a>",
+ "siteName": "Demonstration",
+ "userName": "Arya Stark",
+ "content": template.HTML("<p>I agree</p>"),
+ "view": "<a href='http://domain.com/posts/1/add-support-for-typescript'>view it on your browser</a>",
+ "change": "<a href='http://domain.com/settings'>change your notification preferences</a>",
+ "unsubscribe": "<a href='http://domain.com/posts/1/add-support-for-typescript'>unsubscribe from it</a>",
+ "logo": "https://fider.io/images/logo-100x100.png",
})
Expect(emailmock.MessageHistory[0].From).Equals(dto.Recipient{
Name: "Arya Stark",
@@ -128,8 +133,12 @@ func TestNotifyAboutNewCommentTask_WithMention(t *testing.T) {
})
bus.AddHandler(func(ctx context.Context, q *query.GetActiveSubscribers) error {
- q.Result = []*entity.User{
- mock.JonSnow,
+ if q.Event.UserSettingsKeyName == "event_notification_mention" {
+ q.Result = []*entity.User{
+ mock.JonSnow,
+ }
+ } else {
+ q.Result = []*entity.User{}
}
return nil
})
@@ -149,7 +158,7 @@ func TestNotifyAboutNewCommentTask_WithMention(t *testing.T) {
Description: "TypeScript is great, please add support for it",
User: mock.JonSnow,
}
- task := tasks.NotifyAboutNewComment(post, `I agree, what about you @{"id":1, "name":"Jon Snow"}?`)
+ task := tasks.NotifyAboutNewComment(post, &entity.Comment{Content: "I agree with @{\"id\":1,\"name\":\"Jon Snow\",\"isNew\":true}"})
err := worker.
OnTenant(mock.DemoTenant).
@@ -158,15 +167,59 @@ func TestNotifyAboutNewCommentTask_WithMention(t *testing.T) {
Execute(task)
Expect(err).IsNil()
+ Expect(emailmock.MessageHistory).HasLen(1)
+ Expect(emailmock.MessageHistory[0].TemplateName).Equals("new_comment")
+ Expect(emailmock.MessageHistory[0].Tenant).Equals(mock.DemoTenant)
+ Expect(emailmock.MessageHistory[0].Props).Equals(dto.Props{
+ "title": "Add support for TypeScript",
+ "messageLocaleString": "email.new_mention.text",
+ "postLink": "<a href='http://domain.com/posts/1/add-support-for-typescript'>#1</a>",
+ "siteName": "Demonstration",
+ "userName": "Arya Stark",
+ "content": template.HTML("<p>I agree with @Jon Snow</p>"),
+ "view": "<a href='http://domain.com/posts/1/add-support-for-typescript'>view it on your browser</a>",
+ "change": "<a href='http://domain.com/settings'>change your notification preferences</a>",
+ "unsubscribe": "<a href='http://domain.com/posts/1/add-support-for-typescript'>unsubscribe from it</a>",
+ "logo": "https://fider.io/images/logo-100x100.png",
+ })
+ Expect(emailmock.MessageHistory[0].From).Equals(dto.Recipient{
+ Name: "Arya Stark",
+ })
+ Expect(emailmock.MessageHistory[0].To).HasLen(1)
+ Expect(emailmock.MessageHistory[0].To[0]).Equals(dto.Recipient{
+ Name: "Jon Snow",
+ Address: "[email protected]",
+ Props: dto.Props{},
+ })
+
Expect(addNewNotification).IsNotNil()
Expect(addNewNotification.PostID).Equals(post.ID)
Expect(addNewNotification.Link).Equals("/posts/1/add-support-for-typescript")
- Expect(addNewNotification.Title).Equals("**Arya Stark** left a comment on **Add support for TypeScript**")
+ Expect(addNewNotification.Title).Equals("**Arya Stark** mentioned you in **Add support for TypeScript**")
Expect(addNewNotification.User).Equals(mock.JonSnow)
Expect(triggerWebhooks).IsNotNil()
Expect(triggerWebhooks.Type).Equals(enum.WebhookNewComment)
Expect(triggerWebhooks.Props).ContainsProps(webhook.Props{
- "comment": "I agree, what about you @Jon Snow?",
+ "comment": "I agree with @Jon Snow",
+ "post_id": post.ID,
+ "post_number": post.Number,
+ "post_title": post.Title,
+ "post_slug": post.Slug,
+ "post_description": post.Description,
+ "post_url": "http://domain.com/posts/1/add-support-for-typescript",
+ "post_author_id": mock.JonSnow.ID,
+ "post_author_name": mock.JonSnow.Name,
+ "post_author_email": mock.JonSnow.Email,
+ "post_author_role": mock.JonSnow.Role.String(),
+ "author_id": mock.AryaStark.ID,
+ "author_name": mock.AryaStark.Name,
+ "author_email": mock.AryaStark.Email,
+ "author_role": mock.AryaStark.Role.String(),
+ "tenant_id": mock.DemoTenant.ID,
+ "tenant_name": mock.DemoTenant.Name,
+ "tenant_subdomain": mock.DemoTenant.Subdomain,
+ "tenant_status": mock.DemoTenant.Status.String(),
+ "tenant_url": "http://domain.com",
})
}
diff --git a/public/components/common/form/CommentEditor.tsx b/public/components/common/form/CommentEditor.tsx
index c41e3503b..59df11bfc 100644
--- a/public/components/common/form/CommentEditor.tsx
+++ b/public/components/common/form/CommentEditor.tsx
@@ -244,10 +244,11 @@ const withMentions = (editor: CustomEditor) => {
}
const insertMention = (editor: Editor, user: UserNames) => {
+ const newMention = { ...user, isNew: true }
const mention: MentionElement = {
type: "mention",
character: user.name,
- children: [{ text: "@" + JSON.stringify(user) }],
+ children: [{ text: "@" + JSON.stringify(newMention) }],
}
Transforms.insertNodes(editor, mention)
Transforms.move(editor)
@@ -307,7 +308,7 @@ const serialize = (nodes: Descendant[]): string => {
const deserialize = (markdown: string): Descendant[] => {
return markdown.split("\n").map((line) => {
const children: Descendant[] = []
- const regex = /@{\\?"id":\\?\d+,\\?"name":\\?"[^"]+\\?"}/g
+ const regex = /@{\\?"id\\?":\d+,\\?"name\\?":\\?"[^"]+\\?"(,\\?"isNew\\?":[^}]+)?}/g
let lastIndex = 0
let match
diff --git a/views/email/echo_test.html b/views/email/echo_test.html
index 218319812..35c405942 100644
--- a/views/email/echo_test.html
+++ b/views/email/echo_test.html
@@ -1,5 +1,5 @@
{{define "subject"}}Message to: {{ .name }}{{end}}
{{define "body"}}
-Hello World {{ .name }}!
+Hello World {{ translate .locale (dict "userName" .userName "title" (.title | stripHtml) "postLink" .postLink) | html }}!
{{end}}
\ No newline at end of file
diff --git a/views/email/new_comment.html b/views/email/new_comment.html
index aa96adc33..d82959c40 100644
--- a/views/email/new_comment.html
+++ b/views/email/new_comment.html
@@ -4,7 +4,7 @@
<tr>
<td>
<p style="padding-bottom:10px;border-bottom:1px solid #efefef;color:#1c262d">
- {{ translate "email.new_comment.text" (dict "userName" .userName "title" (.title | stripHtml) "postLink" .postLink) | html }}
+ {{ translate .messageLocaleString (dict "userName" .userName "title" (.title | stripHtml) "postLink" .postLink) | html }}
</p>
{{ .content }}
<p style="color:#666;font-size:14px">