diff --git a/app/helpers/likes_helper.rb b/app/helpers/likes_helper.rb index 77e5a603e3a6e3812dcd113eeeda608166f6c4bd..cec61f5b48a5a12fc71e7566e6d2da0434ed40e3 100644 --- a/app/helpers/likes_helper.rb +++ b/app/helpers/likes_helper.rb @@ -8,7 +8,7 @@ module LikesHelper links.join(", ").html_safe end - def like_action(post) + def like_action(post, current_user=current_user) if current_user.liked?(post) link_to t('shared.stream_element.unlike'), like_path(:post_id => post.id, :id => 'xxx'), :method => :delete, :class => 'unlike', :remote => true else diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 8cb7d8b105c1b2b927862493642002577785faaa..4b9a83a85b154f79e7eeafa2c123842fac2be4f9 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -49,6 +49,21 @@ class Notifier < ActionMailer::Base end end + def liked(recipient_id, sender_id, like_id) + @receiver = User.find_by_id(recipient_id) + @sender = Person.find_by_id(sender_id) + @like = Like.find(like_id) + + log_mail(recipient_id, sender_id, 'liked') + + attachments.inline['logo_caps.png'] = ATTACHMENT + + I18n.with_locale(@receiver.language) do + mail(:to => "\"#{@receiver.name}\" <#{@receiver.email}>", + :subject => I18n.t('notifier.liked.subject', :name => @sender.name), :host => AppConfig[:pod_uri].host) + end + end + def mentioned(recipient_id, sender_id, target_id) @receiver = User.find_by_id(recipient_id) @sender = Person.find_by_id(sender_id) diff --git a/app/models/jobs/mail_liked.rb b/app/models/jobs/mail_liked.rb new file mode 100644 index 0000000000000000000000000000000000000000..5837619aeb9a3ca163b6c26e2728b34326bdf10b --- /dev/null +++ b/app/models/jobs/mail_liked.rb @@ -0,0 +1,9 @@ +module Job + class MailLiked < Base + @queue = :mail + def self.perform_delegate(recipient_id, sender_id, like_id) + Notifier.liked(recipient_id, sender_id, like_id).deliver + end + end +end + diff --git a/app/models/like.rb b/app/models/like.rb index 60ac461d9ad43065faa05c6ab8a5d3262666c73e..84acba523c4d282020afe80f64ac4ac00e8cf9de 100644 --- a/app/models/like.rb +++ b/app/models/like.rb @@ -39,4 +39,8 @@ class Like < ActiveRecord::Base def parent= parent self.post = parent end + + def notification_type(user, person) + Notifications::Liked unless user.person == person + end end diff --git a/app/models/notifications/liked.rb b/app/models/notifications/liked.rb new file mode 100644 index 0000000000000000000000000000000000000000..1039edbc9f0e94e985bd6fcdf9ac47536c2140dd --- /dev/null +++ b/app/models/notifications/liked.rb @@ -0,0 +1,8 @@ +class Notifications::Liked < Notification + def mail_job + Job::MailLiked + end + def translation_key + 'liked' + end +end diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index 7d5501ca480208c936f70fde9c98d9379dec92a3..83d69d1758d00d1d0902f619bd6a16dce1c72fa0 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -10,7 +10,8 @@ class UserPreference < ActiveRecord::Base "private_message", "request_acceptance", "request_received", - "also_commented"] + "also_commented", + "liked"] def must_be_valid_email_type unless VALID_EMAIL_TYPES.include?(self.email_type) diff --git a/app/views/notifier/liked.html.haml b/app/views/notifier/liked.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..5b52c3db44de8e10c98d58aee60c9c359998c668 --- /dev/null +++ b/app/views/notifier/liked.html.haml @@ -0,0 +1,12 @@ +%p + = t('notifier.hello', :name => @receiver.profile.first_name) +%p + = t('.liked', :name => "#{@sender.name} (#{@sender.diaspora_handle})") + + %br + = link_to t('.sign_in'), status_message_url(@like.post) + + %br + = t('notifier.love') + %br + = t('notifier.diaspora') diff --git a/app/views/notifier/liked.text.haml b/app/views/notifier/liked.text.haml new file mode 100644 index 0000000000000000000000000000000000000000..1a8e523d8eda2d5873ad430615adc667eddbceca --- /dev/null +++ b/app/views/notifier/liked.text.haml @@ -0,0 +1,7 @@ +!= t('notifier.hello', :name => @receiver.profile.first_name) +!= t('.liked', :name => "#{@sender.name} (#{@sender.diaspora_handle})") + +!= link_to t('.sign_in'), status_message_url(@like.post) + +!= t('notifier.love') +!= t('notifier.diaspora') diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index 22b8f27c3cbf79c75c9ed7b55132cf281083f57c..ad7e063441468f26f11d849620a4bdaa34215e48 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -39,7 +39,7 @@ - unless (defined?(@commenting_disabled) && @commenting_disabled) | %span.like_action - = like_action(post) + = like_action(post, current_user) | = link_to t('comments.new_comment.comment'), '#', :class => 'focus_comment_textarea' diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index 929f9122cff1d709e663128081ac5bb72680d89e..e214588b99dfacaa40a51dc12f309a40be050c60 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -105,6 +105,11 @@ = type.label t('.request_acceptence') = type.check_box :request_acceptance, {:checked => @email_prefs['request_acceptance']}, false, true + %br + %p.checkbox_select + = type.label t('.liked') + = type.check_box :liked, {:checked => @email_prefs['liked']}, false, true + %br = f.submit t('.change') diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 8104b69a0a70b4b0902c85db78cf6698792b6d0c..fd6f7959cc35b2c820b93ab9f9d471a2c22efec2 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -341,6 +341,10 @@ en: private_message: "has sent you a private message:" message_subject: "Subject: %{subject}" sign_in: "Sign in to view it." + liked: + subject: "%{name} has just liked your post" + liked: "%{name} has just liked your post" + sign_in: "Sign to view it" people: zero: "no people" @@ -620,6 +624,7 @@ en: request_received: "...you receive a new share request?" request_acceptence: "...your share request is accepted?" private_message: "...you receive a private message?" + liked: "...someone likes your post?" change: "Change" destroy: "Account successfully closed." getting_started: diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index da2b815d52d51124773d34fda9cde615516ab245..728c9a837cac6a6ab72a3d3d34a5300dfb677364 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -86,7 +86,6 @@ describe Notifier do end end - describe ".mentioned" do before do @user = alice @@ -100,11 +99,11 @@ describe Notifier do end it 'has the receivers name in the body' do - @mail.body.encoded.include?(@user.person.profile.first_name).should be true + @mail.body.encoded.include?(@user.person.profile.first_name).should be_true end it 'has the name of person mentioning in the body' do - @mail.body.encoded.include?(@sm.author.name).should be true + @mail.body.encoded.include?(@sm.author.name).should be_true end it 'has the post text in the body' do @@ -116,6 +115,30 @@ describe Notifier do end end + describe ".liked" do + before do + @sm = Factory(:status_message, :author => alice.person) + @like = @sm.likes.create(:author => bob.person) + @mail = Notifier.liked(alice.id, @like.author.id, @like.id) + end + + it 'goes to the right person' do + @mail.to.should == [alice.email] + end + + it 'has the receivers name in the body' do + @mail.body.encoded.include?(alice.person.profile.first_name).should be true + end + + it 'has the name of person liking in the body' do + @mail.body.encoded.include?(@like.author.name).should be_true + end + + it 'should not include translation missing' do + @mail.body.encoded.should_not include("missing") + end + end + describe ".private_message" do before do @user2 = bob @@ -152,6 +175,7 @@ describe Notifier do @mail.body.encoded.should_not include("missing") end end + context "comments" do let!(:connect) { connect_users(user, aspect, user2, aspect2)} let!(:sm) {user.post(:status_message, :text => "Sunny outside", :to => :all)} diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index dd4453fe01353524ad9a6e7ebe2c3312fd42172e..aa073afbfb7064ea8f86bfd1c8bbe9c6be292327 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -242,13 +242,13 @@ describe User do alice.disable_mail = true proc { alice.update_user_preferences({}) - }.should change(alice.user_preferences, :count).by(6) + }.should change(alice.user_preferences, :count).by(7) end it 'still sets new prefs to false on update' do alice.disable_mail = true proc { alice.update_user_preferences({'mentioned' => false}) - }.should change(alice.user_preferences, :count).by(5) + }.should change(alice.user_preferences, :count).by(6) alice.reload.disable_mail.should be_false end end