diff --git a/app/models/dmail.rb b/app/models/dmail.rb index c7f48f830..003795069 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -8,7 +8,7 @@ class Dmail < ActiveRecord::Base belongs_to :owner, :class_name => "User" belongs_to :to, :class_name => "User" belongs_to :from, :class_name => "User" - before_create :auto_delete_if_filtered + before_create :auto_read_if_filtered after_create :update_recipient after_create :send_dmail attr_accessible :title, :body, :is_deleted, :to_id, :to, :to_name, :creator_ip_addr @@ -193,9 +193,12 @@ class Dmail < ActiveRecord::Base end end - def auto_delete_if_filtered - if owner_id != CurrentUser.user.id && to.dmail_filter.try(:filtered?, self) - self.is_deleted = true + def filtered? + CurrentUser.dmail_filter.try(:filtered?, self) + end + + def auto_read_if_filtered + if owner_id != CurrentUser.id && to.dmail_filter.try(:filtered?, self) self.is_read = true end end diff --git a/app/views/dmails/index.html.erb b/app/views/dmails/index.html.erb index 1b7dcce41..df04ee581 100644 --- a/app/views/dmails/index.html.erb +++ b/app/views/dmails/index.html.erb @@ -22,9 +22,21 @@ <% @dmails.each do |dmail| %> <%= compact_time(dmail.created_at) %> - <%= link_to_user dmail.from %> + + <% if dmail.filtered? %> + <%= link_to "[filtered]", user_path(dmail.from) %> + <% else %> + <%= link_to_user dmail.from %> + <% end %> + <%= link_to_user dmail.to %> - <%= link_to dmail.title, dmail_path(dmail) %> + + <% if dmail.filtered? %> + <%= link_to "[filtered]", dmail_path(dmail) %> + <% else %> + <%= link_to dmail.title, dmail_path(dmail) %> + <% end %> + <%= link_to "delete", dmail_path(dmail), :method => :delete, :data => {:confirm => "Are you sure you want to delete this Dmail?"} %> diff --git a/test/unit/dmail_test.rb b/test/unit/dmail_test.rb index bcd8a2a7d..5cc10c3df 100644 --- a/test/unit/dmail_test.rb +++ b/test/unit/dmail_test.rb @@ -27,9 +27,8 @@ class DmailTest < ActiveSupport::TestCase assert(@recipient.dmail_filter.filtered?(@dmail)) end - should "autodelete if it has a banned word" do + should "autoread if it has a banned word" do @dmail.save - assert_equal(true, @dmail.is_deleted?) assert_equal(true, @dmail.is_read?) end