FEATURE: warn about mailing list mode if it is checked

This commit is contained in:
Sam 2016-03-29 18:50:17 +11:00
parent ed750cac39
commit 95076050f4
6 changed files with 51 additions and 3 deletions

View file

@ -3,5 +3,17 @@ export default Em.Component.extend({
label: function() {
return I18n.t(this.get('labelKey'));
}.property('labelKey')
}.property('labelKey'),
click() {
const warning = this.get('warning');
if (warning && !this.get('checked')) {
debugger;
this.sendAction('warning');
return false;
}
return true;
}
});

View file

@ -106,6 +106,22 @@ export default Ember.Controller.extend(CanCheckEmails, {
actions: {
checkMailingList(){
Em.run.next(()=>{
const postsPerDay = this.get('model.mailing_list_posts_per_day');
if (!postsPerDay || postsPerDay < 2) {
this.set('model.user_option.mailing_list_mode', true);
return;
}
bootbox.confirm(I18n.t("user.enable_mailing_list", {count: postsPerDay}), I18n.t("no_value"), I18n.t("yes_value"), (success) => {
if (success) {
this.set('model.user_option.mailing_list_mode', true);
}
});
});
},
save() {
this.set('saved', false);

View file

@ -186,7 +186,7 @@
{{preference-checkbox labelKey="user.email_private_messages" checked=model.user_option.email_private_messages}}
{{preference-checkbox labelKey="user.email_direct" checked=model.user_option.email_direct}}
{{#unless siteSettings.disable_mailing_list_mode}}
{{preference-checkbox labelKey="user.mailing_list_mode" checked=model.user_option.mailing_list_mode}}
{{preference-checkbox warning="checkMailingList" labelKey="user.mailing_list_mode" checked=model.user_option.mailing_list_mode}}
{{/unless}}
{{preference-checkbox labelKey="user.email_always" checked=model.user_option.email_always}}
{{#unless model.user_option.email_always}}

View file

@ -451,6 +451,16 @@ class Post < ActiveRecord::Base
PostCreator.before_create_tasks(self)
end
def self.estimate_posts_per_day
val = $redis.get("estimated_posts_per_day")
return val.to_i if val
posts_per_day = Topic.listable_topics.secured.joins(:posts).merge(Post.created_since(30.days.ago)).count / 30
$redis.setex("estimated_posts_per_day", 1.day.to_i, posts_per_day.to_s)
posts_per_day
end
# This calculates the geometric mean of the post timings and stores it along with
# each post.
def self.calculate_avg_time(min_topic_age=nil)

View file

@ -95,7 +95,8 @@ class UserSerializer < BasicUserSerializer
:has_title_badges,
:card_image_badge,
:card_image_badge_id,
:muted_usernames
:muted_usernames,
:mailing_list_posts_per_day
untrusted_attributes :bio_raw,
:bio_cooked,
@ -109,6 +110,11 @@ class UserSerializer < BasicUserSerializer
### ATTRIBUTES
###
def mailing_list_posts_per_day
val = Post.estimate_posts_per_day
[val,SiteSetting.max_emails_per_day_per_user].min
end
def groups
if scope.is_admin? || object.id == scope.user.try(:id)
object.groups

View file

@ -661,6 +661,10 @@ en:
other_settings: "Other"
categories_settings: "Categories"
enable_mailing_list:
one: "Are you sure you want to be emailed for every new post?"
other: "Are you sure you want to be emailed for every new post?<br><br>This will result in approximately <b>{{count}} emails</b> per day."
new_topic_duration:
label: "Consider topics new when"
not_viewed: "I haven't viewed them yet"