From 89cdf1101adf25be32232ca543822fd7a24486a9 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Wed, 19 Feb 2014 12:49:12 -0600 Subject: [PATCH] add a story-only mailing list mode closes #131 --- app/controllers/settings_controller.rb | 2 +- app/views/settings/index.html.erb | 5 +++-- db/migrate/20140219183804_change_mailing_list_enabled.rb | 6 ++++++ db/schema.rb | 6 +++--- script/mail_new_activity | 7 ++++++- 5 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20140219183804_change_mailing_list_enabled.rb diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index 203976c..945324f 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -38,7 +38,7 @@ private :email_replies, :email_messages, :email_mentions, :pushover_replies, :pushover_messages, :pushover_mentions, :pushover_user_key, :pushover_device, :pushover_sound, - :mailing_list_enabled, + :mailing_list_mode, ) end end diff --git a/app/views/settings/index.html.erb b/app/views/settings/index.html.erb index 62fc16d..640f50b 100644 --- a/app/views/settings/index.html.erb +++ b/app/views/settings/index.html.erb @@ -151,9 +151,10 @@

- <%= f.label :mailing_list_enabled, "Receive List E-mails:", + <%= f.label :mailing_list_mode, "Receive List E-mails:", :class => "required" %> - <%= f.check_box :mailing_list_enabled%> + <%= f.select :mailing_list_mode, [ [ "No e-mails", 0 ], + [ "All stories and comments", 1 ], [ "Only stories", 2 ] ] %>
diff --git a/db/migrate/20140219183804_change_mailing_list_enabled.rb b/db/migrate/20140219183804_change_mailing_list_enabled.rb new file mode 100644 index 0000000..e9cb912 --- /dev/null +++ b/db/migrate/20140219183804_change_mailing_list_enabled.rb @@ -0,0 +1,6 @@ +class ChangeMailingListEnabled < ActiveRecord::Migration + def change + rename_column :users, :mailing_list_enabled, :mailing_list_mode + change_column :users, :mailing_list_mode, :integer, :default => 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index dc21884..cc28bb6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140121063641) do +ActiveRecord::Schema.define(version: 20140219183804) do create_table "comments", force: true do |t| t.datetime "created_at", null: false @@ -156,7 +156,7 @@ ActiveRecord::Schema.define(version: 20140121063641) do t.boolean "pushover_mentions", default: false t.string "rss_token", limit: 75 t.string "mailing_list_token", limit: 75 - t.boolean "mailing_list_enabled", default: false + t.integer "mailing_list_mode", default: 0 t.integer "karma", default: 0, null: false t.datetime "banned_at" t.integer "banned_by_user_id" @@ -165,7 +165,7 @@ ActiveRecord::Schema.define(version: 20140121063641) do t.string "pushover_sound" end - add_index "users", ["mailing_list_enabled"], name: "mailing_list_enabled", using: :btree + add_index "users", ["mailing_list_mode"], name: "mailing_list_enabled", using: :btree add_index "users", ["mailing_list_token"], name: "mailing_list_token", unique: true, using: :btree add_index "users", ["password_reset_token"], name: "password_reset_token", unique: true, using: :btree add_index "users", ["rss_token"], name: "rss_token", unique: true, using: :btree diff --git a/script/mail_new_activity b/script/mail_new_activity index 96a48a9..2ec9892 100755 --- a/script/mail_new_activity +++ b/script/mail_new_activity @@ -44,7 +44,7 @@ EMAIL_WIDTH = 72 LAST_STORY_KEY = "mailing:last_story_id" LAST_COMMENT_KEY = "mailing:last_comment_id" -mailing_list_users = User.where(:mailing_list_enabled => true).select{|u| +mailing_list_users = User.where("mailing_list_mode > 0").select{|u| u.is_active? } last_story_id = (Keystore.value_for(LAST_STORY_KEY) || Story.last.id).to_i @@ -127,6 +127,11 @@ last_comment_id, false, false).order(:id).each do |c| end mailing_list_users.each do |u| + if u.mailing_list_mode == 2 + # stories only + next + end + if (c.story.tags.map{|t| t.id } & u.tag_filters.map{|t| t.tag_id }).any? next end