notifications for mentions
This commit is contained in:
parent
7b1abacfe6
commit
d1771bbe17
12 changed files with 121 additions and 20 deletions
|
|
@ -3,6 +3,13 @@ module NotificationsHelper
|
|||
target_type = note.action
|
||||
translation = t("notifications.#{target_type}")
|
||||
case target_type
|
||||
when 'mentioned'
|
||||
post = Mention.find(note.target_id).post
|
||||
if post
|
||||
"#{translation} #{link_to t('notifications.post'), object_path(post)}".html_safe
|
||||
else
|
||||
"#{translation} #{t('notifications.deleted')} #{t('notifications.post')}"
|
||||
end
|
||||
when 'request_accepted'
|
||||
translation
|
||||
when 'new_request'
|
||||
|
|
@ -40,7 +47,7 @@ module NotificationsHelper
|
|||
end
|
||||
|
||||
def notification_people_link(note)
|
||||
note.actors.collect{ |person| link_to("#{person.name.titlecase}", person_path(person))}.join(" , ").html_safe
|
||||
note.actors.collect{ |person| link_to("#{h(person.name.titlecase)}", person_path(person))}.join(", ").html_safe
|
||||
end
|
||||
|
||||
def peoples_names(note)
|
||||
|
|
|
|||
|
|
@ -46,6 +46,19 @@ class Notifier < ActionMailer::Base
|
|||
:subject => I18n.t('notifier.request_accepted.subject', :name => @sender.name), :host => AppConfig[:pod_uri].host)
|
||||
end
|
||||
|
||||
def mentioned(recipient_id, sender_id, target_id)
|
||||
@receiver = User.find_by_id(recipient_id)
|
||||
@sender = Person.find_by_id(sender_id)
|
||||
@post = Mention.find_by_id(target_id).post
|
||||
|
||||
log_mail(recipient_id, sender_id, 'mentioned')
|
||||
|
||||
attachments.inline['logo_caps.png'] = ATTACHMENT
|
||||
|
||||
mail(:to => "\"#{@receiver.name}\" <#{@receiver.email}>",
|
||||
:subject => I18n.t('notifier.mentioned.subject', :name => @sender.name), :host => AppConfig[:pod_uri].host)
|
||||
end
|
||||
|
||||
def comment_on_post(recipient_id, sender_id, comment_id)
|
||||
@receiver = User.find_by_id(recipient_id)
|
||||
@sender = Person.find_by_id(sender_id)
|
||||
|
|
|
|||
15
app/models/jobs/mail_mentioned.rb
Normal file
15
app/models/jobs/mail_mentioned.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
|
||||
module Job
|
||||
class MailMentioned < Base
|
||||
@queue = :mail
|
||||
def self.perform_delegate(recipient_id, actor_id, target_id)
|
||||
|
||||
Notifier.mentioned( recipient_id, actor_id, target_id).deliver
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -15,7 +15,7 @@ class Mention < ActiveRecord::Base
|
|||
end
|
||||
|
||||
|
||||
def notification_type
|
||||
def notification_type(recipient,actor)
|
||||
'mentioned'
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class StatusMessage < Post
|
|||
write_attribute(:message, text)
|
||||
end
|
||||
|
||||
def formatted_message
|
||||
def formatted_message(opts = {})
|
||||
return self.raw_message unless self.raw_message
|
||||
people = self.mentioned_people
|
||||
regex = /@\{([^;]+); ([^\}]+)\}/
|
||||
|
|
@ -43,7 +43,12 @@ class StatusMessage < Post
|
|||
person = people.detect{ |p|
|
||||
p.diaspora_handle == inner_captures.last
|
||||
}
|
||||
person ? "<a href=\"/people/#{person.id}\" class=\"mention\">#{ERB::Util.h(person.name)}</a>" : ERB::Util.h(inner_captures.first)
|
||||
|
||||
if opts[:plain_text]
|
||||
person ? ERB::Util.h(person.name) : ERB::Util.h(inner_captures.first)
|
||||
else
|
||||
person ? "<a href=\"/people/#{person.id}\" class=\"mention\">#{ERB::Util.h(person.name)}</a>" : ERB::Util.h(inner_captures.first)
|
||||
end
|
||||
end
|
||||
form_message
|
||||
end
|
||||
|
|
|
|||
15
app/views/notifier/mentioned.html.haml
Normal file
15
app/views/notifier/mentioned.html.haml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
%p
|
||||
= t('notifier.hello', :name => @receiver.profile.first_name)
|
||||
%p
|
||||
= "#{@sender.name} (#{@sender.diaspora_handle})"
|
||||
= t('.mentioned')
|
||||
|
||||
= @post.message
|
||||
|
||||
%br
|
||||
= link_to t('.sign_in'), status_message_url(@post)
|
||||
|
||||
%br
|
||||
= t('notifier.love')
|
||||
%br
|
||||
= t('notifier.diaspora')
|
||||
8
app/views/notifier/mentioned.text.haml
Normal file
8
app/views/notifier/mentioned.text.haml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
= t('notifier.hello', :name => @receiver.profile.first_name)
|
||||
= "#{@sender.name} (#{@sender.diaspora_handle})"
|
||||
= t('notifier.mentioned.mentioned')
|
||||
|
||||
= @post.formatted_message(:plain_text => true)
|
||||
|
||||
= "#{t('notifier.love')} \n"
|
||||
= t('notifier.diaspora')
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
-# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
-# licensed under the Affero General Public License version 3 or later. See
|
||||
-# the COPYRIGHT file.
|
||||
|
||||
= link_to t('.new', :type => object.class.to_s, :from => peoples_names(note)), object_path(object.post)
|
||||
|
||||
|
||||
= link_to "#{note.actor.name.titelize}", person_path(note.actor)
|
||||
= object_link(note)
|
||||
|
|
@ -204,6 +204,7 @@ en:
|
|||
new_request: "offered to share with you."
|
||||
comment_on_post: "commented on your"
|
||||
also_commented: "also commented on your contact's"
|
||||
mentioned: "has mentioned you their"
|
||||
post: 'post'
|
||||
deleted: 'deleted'
|
||||
index:
|
||||
|
|
@ -457,9 +458,12 @@ en:
|
|||
commented: "has commented on your post:"
|
||||
sign_in: "Sign in to view it."
|
||||
also_commented:
|
||||
subject: "%{name} has also commented."
|
||||
subject: "%{name} has also commented on your contact's post."
|
||||
commented: "has also commented on %{post_author}'s post:"
|
||||
sign_in: "Sign in to view it."
|
||||
mentioned:
|
||||
subject: "%{name} has mentioned you on Diaspora*"
|
||||
mentioned: "mentioned you in a post:"
|
||||
home:
|
||||
show:
|
||||
share_what_you_want: "Share what you want, with whom you want."
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ describe Notifier do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#single_admin' do
|
||||
describe '.single_admin' do
|
||||
it 'mails a user' do
|
||||
mail = Notifier.single_admin("Welcome to bureaucracy!", user)
|
||||
mail.to.should == [user.email]
|
||||
|
|
@ -45,7 +45,7 @@ describe Notifier do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#new_request" do
|
||||
describe ".new_request" do
|
||||
let!(:request_mail) {Notifier.new_request(user.id, person.id)}
|
||||
it 'goes to the right person' do
|
||||
request_mail.to.should == [user.email]
|
||||
|
|
@ -65,7 +65,7 @@ describe Notifier do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#request_accepted" do
|
||||
describe ".request_accepted" do
|
||||
let!(:request_accepted_mail) {Notifier.request_accepted(user.id, person.id)}
|
||||
it 'goes to the right person' do
|
||||
request_accepted_mail.to.should == [user.email]
|
||||
|
|
@ -80,11 +80,42 @@ describe Notifier do
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
describe ".mentioned" do
|
||||
before do
|
||||
@user = alice
|
||||
@sm = Factory(:status_message)
|
||||
@m = Mention.create(:person => @user.person, :post=> @sm)
|
||||
|
||||
@mail = Notifier.mentioned(@user.id, @sm.person.id, @m.id)
|
||||
end
|
||||
it 'goes to the right person' do
|
||||
@mail.to.should == [@user.email]
|
||||
end
|
||||
|
||||
it 'has the receivers name in the body' do
|
||||
@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.person.name).should be true
|
||||
end
|
||||
|
||||
it 'has the post text in the body' do
|
||||
@mail.body.encoded.should include(@sm.message)
|
||||
end
|
||||
|
||||
it 'should not include translation missing' 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, :message => "Sunny outside", :to => :all)}
|
||||
let!(:comment) { user2.comment("Totally is", :on => sm )}
|
||||
describe "#comment_on_post" do
|
||||
describe ".comment_on_post" do
|
||||
|
||||
let!(:comment_mail) {Notifier.comment_on_post(user.id, person.id, comment.id).deliver}
|
||||
|
||||
|
|
@ -105,7 +136,7 @@ describe Notifier do
|
|||
end
|
||||
|
||||
end
|
||||
describe "#also commented" do
|
||||
describe ".also commented" do
|
||||
|
||||
let!(:comment_mail) {Notifier.also_commented(user.id, person.id, comment.id)}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,11 @@ describe Job::MailMentioned do
|
|||
sm = Factory(:status_message)
|
||||
m = Mention.new(:person => user.person, :post=> sm)
|
||||
|
||||
Notification.notify(user, m, sm.person)
|
||||
mail_mock = mock()
|
||||
mail_mock.should_receive(:deliver)
|
||||
Notifier.should_receive(:mentioned).with(user.id, sm.person.id, m.id).and_return(mail_mock)
|
||||
|
||||
Job::MailMentioned.perform_delegate(user.id, sm.person.id, m.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -85,6 +85,14 @@ STR
|
|||
can mention people like Raphaellike Raphael #{link_to(@people[2].name, person_path(@people[2]), :class => 'mention')} can mention people like Raph
|
||||
STR
|
||||
end
|
||||
|
||||
context 'with :plain_text option' do
|
||||
it 'removes the mention syntax and displays the unformatted name' do
|
||||
status = Factory(:status_message, :message => "@{Barack Obama; barak@joindiaspora.com } is so cool @{Barack Obama; barak@joindiaspora.com } ")
|
||||
status.formatted_message(:plain_text => true).should == 'Barack Obama is so cool Barack Obama '
|
||||
end
|
||||
end
|
||||
|
||||
it 'leaves the name of people that cannot be found' do
|
||||
@sm.stub(:mentioned_people).and_return([])
|
||||
@sm.formatted_message.should == <<-STR
|
||||
|
|
|
|||
Loading…
Reference in a new issue