Skip to content

Commit 0c41c4c

Browse files
tyroneyehSysoev, Vladimir
authored and
Sysoev, Vladimir
committed
Added email notification option to receive all own messages (go-gitea#20179)
Sometimes users want to receive email notifications of messages they create or reply to, Added an option to personal preferences to allow users to choose Closes go-gitea#20149
1 parent 76da409 commit 0c41c4c

File tree

7 files changed

+18
-7
lines changed

7 files changed

+18
-7
lines changed

Diff for: models/user/user.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ var AvailableHashAlgorithms = []string{
6464
}
6565

6666
const (
67-
// EmailNotificationsEnabled indicates that the user would like to receive all email notifications
67+
// EmailNotificationsEnabled indicates that the user would like to receive all email notifications except your own
6868
EmailNotificationsEnabled = "enabled"
6969
// EmailNotificationsOnMention indicates that the user would like to be notified via email when mentioned.
7070
EmailNotificationsOnMention = "onmention"
7171
// EmailNotificationsDisabled indicates that the user would not like to be notified via email.
7272
EmailNotificationsDisabled = "disabled"
73+
// EmailNotificationsEnabled indicates that the user would like to receive all email notifications and your own
74+
EmailNotificationsAndYourOwn = "andyourown"
7375
)
7476

7577
// User represents the object of individual and member of organization.
@@ -1045,15 +1047,15 @@ func GetMaileableUsersByIDs(ids []int64, isMention bool) ([]*User, error) {
10451047
Where("`type` = ?", UserTypeIndividual).
10461048
And("`prohibit_login` = ?", false).
10471049
And("`is_active` = ?", true).
1048-
And("`email_notifications_preference` IN ( ?, ?)", EmailNotificationsEnabled, EmailNotificationsOnMention).
1050+
In("`email_notifications_preference`", EmailNotificationsEnabled, EmailNotificationsOnMention, EmailNotificationsAndYourOwn).
10491051
Find(&ous)
10501052
}
10511053

10521054
return ous, db.GetEngine(db.DefaultContext).In("id", ids).
10531055
Where("`type` = ?", UserTypeIndividual).
10541056
And("`prohibit_login` = ?", false).
10551057
And("`is_active` = ?", true).
1056-
And("`email_notifications_preference` = ?", EmailNotificationsEnabled).
1058+
In("`email_notifications_preference`", EmailNotificationsEnabled, EmailNotificationsAndYourOwn).
10571059
Find(&ous)
10581060
}
10591061

Diff for: models/user/user_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ func TestEmailNotificationPreferences(t *testing.T) {
153153

154154
assert.NoError(t, user_model.SetEmailNotifications(user, user_model.EmailNotificationsDisabled))
155155
assert.Equal(t, user_model.EmailNotificationsDisabled, user.EmailNotifications())
156+
157+
assert.NoError(t, user_model.SetEmailNotifications(user, user_model.EmailNotificationsAndYourOwn))
158+
assert.Equal(t, user_model.EmailNotificationsAndYourOwn, user.EmailNotifications())
156159
}
157160
}
158161

Diff for: modules/notification/mail/mail.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (m *mailNotifier) NotifyPullRequestCodeComment(pr *issues_model.PullRequest
126126

127127
func (m *mailNotifier) NotifyIssueChangeAssignee(doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) {
128128
// mail only sent to added assignees and not self-assignee
129-
if !removed && doer.ID != assignee.ID && (assignee.EmailNotifications() == user_model.EmailNotificationsEnabled || assignee.EmailNotifications() == user_model.EmailNotificationsOnMention) {
129+
if !removed && doer.ID != assignee.ID && assignee.EmailNotifications() != user_model.EmailNotificationsDisabled {
130130
ct := fmt.Sprintf("Assigned #%d.", issue.Index)
131131
if err := mailer.SendIssueAssignedMail(issue, doer, ct, comment, []*user_model.User{assignee}); err != nil {
132132
log.Error("Error in SendIssueAssignedMail for issue[%d] to assignee[%d]: %v", issue.ID, assignee.ID, err)
@@ -135,7 +135,7 @@ func (m *mailNotifier) NotifyIssueChangeAssignee(doer *user_model.User, issue *i
135135
}
136136

137137
func (m *mailNotifier) NotifyPullReviewRequest(doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) {
138-
if isRequest && doer.ID != reviewer.ID && (reviewer.EmailNotifications() == user_model.EmailNotificationsEnabled || reviewer.EmailNotifications() == user_model.EmailNotificationsOnMention) {
138+
if isRequest && doer.ID != reviewer.ID && reviewer.EmailNotifications() != user_model.EmailNotificationsDisabled {
139139
ct := fmt.Sprintf("Requested to review %s.", issue.HTMLURL())
140140
if err := mailer.SendIssueAssignedMail(issue, doer, ct, comment, []*user_model.User{reviewer}); err != nil {
141141
log.Error("Error in SendIssueAssignedMail for issue[%d] to reviewer[%d]: %v", issue.ID, reviewer.ID, err)

Diff for: options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,7 @@ settings.mirror_sync_in_progress = Mirror synchronization is in progress. Check
17871787
settings.email_notifications.enable = Enable Email Notifications
17881788
settings.email_notifications.onmention = Only Email on Mention
17891789
settings.email_notifications.disable = Disable Email Notifications
1790+
settings.email_notifications.andyourown = And Your Own Email Notifications
17901791
settings.email_notifications.submit = Set Email Preference
17911792
settings.site = Website
17921793
settings.update_settings = Update Settings

Diff for: routers/web/user/setting/account.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ func EmailPost(ctx *context.Context) {
156156
preference := ctx.FormString("preference")
157157
if !(preference == user_model.EmailNotificationsEnabled ||
158158
preference == user_model.EmailNotificationsOnMention ||
159-
preference == user_model.EmailNotificationsDisabled) {
159+
preference == user_model.EmailNotificationsDisabled ||
160+
preference == user_model.EmailNotificationsAndYourOwn) {
160161
log.Error("Email notifications preference change returned unrecognized option %s: %s", preference, ctx.Doer.Name)
161162
ctx.ServerError("SetEmailPreference", errors.New("option unrecognized"))
162163
return

Diff for: services/mailer/mail_issue.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo
9191
visited := make(map[int64]bool, len(unfiltered)+len(mentions)+1)
9292

9393
// Avoid mailing the doer
94-
visited[ctx.Doer.ID] = true
94+
if ctx.Doer.EmailNotificationsPreference != user_model.EmailNotificationsAndYourOwn {
95+
visited[ctx.Doer.ID] = true
96+
}
9597

9698
// =========== Mentions ===========
9799
if err = mailIssueCommentBatch(ctx, mentions, visited, true); err != nil {
@@ -133,6 +135,7 @@ func mailIssueCommentBatch(ctx *mailCommentContext, users []*user_model.User, vi
133135
// At this point we exclude:
134136
// user that don't have all mails enabled or users only get mail on mention and this is one ...
135137
if !(user.EmailNotificationsPreference == user_model.EmailNotificationsEnabled ||
138+
user.EmailNotificationsPreference == user_model.EmailNotificationsAndYourOwn ||
136139
fromMention && user.EmailNotificationsPreference == user_model.EmailNotificationsOnMention) {
137140
continue
138141
}

Diff for: templates/user/settings/account.tmpl

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<div class="text">{{$.locale.Tr "settings.email_notifications"}}</div>
6363
<div class="menu">
6464
<div data-value="enabled" class="{{if eq .EmailNotificationsPreference "enabled"}}active selected {{end}}item">{{$.locale.Tr "settings.email_notifications.enable"}}</div>
65+
<div data-value="andyourown" class="{{if eq .EmailNotificationsPreference "andyourown"}}active selected {{end}}item">{{$.locale.Tr "settings.email_notifications.andyourown"}}</div>
6566
<div data-value="onmention" class="{{if eq .EmailNotificationsPreference "onmention"}}active selected {{end}}item">{{$.locale.Tr "settings.email_notifications.onmention"}}</div>
6667
<div data-value="disabled" class="{{if eq .EmailNotificationsPreference "disabled"}}active selected {{end}}item">{{$.locale.Tr "settings.email_notifications.disable"}}</div>
6768
</div>

0 commit comments

Comments
 (0)