Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: User preference to always include context #3222

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions app/assets/javascripts/discourse/models/user.js
Expand Up @@ -186,6 +186,7 @@ Discourse.User = Discourse.Model.extend({
'email_digests',
'email_direct',
'email_always',
'email_force_context',
'email_private_messages',
'dynamic_favicon',
'digest_after_days',
Expand Down
Expand Up @@ -182,6 +182,7 @@
{{preference-checkbox labelKey="user.email_private_messages" checked=email_private_messages}}
{{preference-checkbox labelKey="user.email_direct" checked=email_direct}}
{{preference-checkbox labelKey="user.mailing_list_mode" checked=mailing_list_mode}}
{{preference-checkbox labelKey="user.email_force_context" checked=email_force_context}}
{{preference-checkbox labelKey="user.email_always" checked=email_always}}

<div class='instructions'>
Expand Down
6 changes: 3 additions & 3 deletions app/mailers/user_notifications.rb
Expand Up @@ -153,7 +153,7 @@ class UserNotificationRenderer < ActionView::Base
include UserNotificationsHelper
end

def self.get_context_posts(post, topic_user)
def self.get_context_posts(post, topic_user, force_context)

context_posts = Post.where(topic_id: post.topic_id)
.where("post_number < ?", post.post_number)
Expand All @@ -162,7 +162,7 @@ def self.get_context_posts(post, topic_user)
.order('created_at desc')
.limit(SiteSetting.email_posts_context)

if topic_user && topic_user.last_emailed_post_number
if topic_user && topic_user.last_emailed_post_number && !force_context
context_posts = context_posts.where("post_number > ?", topic_user.last_emailed_post_number)
end

Expand Down Expand Up @@ -230,7 +230,7 @@ def send_notification_email(opts)

context = ""
tu = TopicUser.get(post.topic_id, user)
context_posts = self.class.get_context_posts(post, tu)
context_posts = self.class.get_context_posts(post, tu, user.email_force_context)

# make .present? cheaper
context_posts = context_posts.to_a
Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Expand Up @@ -911,6 +911,7 @@ def update_previous_visit(timestamp)
# title :string(255)
# uploaded_avatar_id :integer
# email_always :boolean default(FALSE), not null
# email_force_context :boolean default(FALSE), not null
# mailing_list_mode :boolean default(FALSE), not null
# locale :string(10)
# primary_group_id :integer
Expand Down
1 change: 1 addition & 0 deletions app/serializers/user_serializer.rb
Expand Up @@ -76,6 +76,7 @@ def self.untrusted_attributes(*attrs)
:email_private_messages,
:email_direct,
:email_always,
:email_force_context,
:digest_after_days,
:mailing_list_mode,
:auto_track_topics_after_msecs,
Expand Down
1 change: 1 addition & 0 deletions app/services/user_updater.rb
Expand Up @@ -11,6 +11,7 @@ class UserUpdater
:email_always,
:email_direct,
:email_private_messages,
:email_force_context,
:external_links_in_new_tab,
:enable_quoting,
:dynamic_favicon,
Expand Down
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Expand Up @@ -457,6 +457,7 @@ en:
email_direct: "Send me an email when someone quotes me, replies to my post, or mentions my @username"
email_private_messages: "Send me an email when someone private messages me"
email_always: "Do not suppress email notifications when I am active on the site"
email_force_context: "Always include previous posts in notifications"

other_settings: "Other"
categories_settings: "Categories"
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20150221181500_add_email_force_context_to_users.rb
@@ -0,0 +1,5 @@
class AddEmailForceContextToUsers < ActiveRecord::Migration
def change
add_column :users, :email_force_context, :boolean, default: false, null: false
end
end
14 changes: 13 additions & 1 deletion spec/mailers/user_notifications_spec.rb
Expand Up @@ -20,7 +20,17 @@
reply3.hidden = true
reply3.save

expect(UserNotifications.get_context_posts(reply4, nil).count).to eq(1)
expect(UserNotifications.get_context_posts(reply4, nil, false).count).to eq(1)
end

it "respects the user option to always include context" do
post = create_post
reply1 = create_post(topic: post.topic)
reply2 = create_post(topic: post.topic)
reply3 = create_post(topic: post.topic)
reply4 = create_post(topic: post.topic)

expect(UserNotifications.get_context_posts(reply4, nil, true).count).to eq(4)
end
end

Expand Down Expand Up @@ -94,6 +104,8 @@
SiteSetting.display_name_on_posts = true
mail = UserNotifications.user_replied(response.user, post: response, notification: notification)

expect(response.user.email_force_context).to eql(false)

# from should include full user name
expect(mail[:from].display_names).to eql(['John Doe'])

Expand Down