VRFS-933 notification work
This commit is contained in:
parent
1806c5245f
commit
102306e4d1
|
|
@ -92,24 +92,42 @@
|
|||
|
||||
|
||||
def friend_request(source_user, target_user)
|
||||
end
|
||||
@user = source_user
|
||||
sendgrid_category "Notification"
|
||||
sendgrid_unique_args :type => "friend_request"
|
||||
|
||||
def friend_request_accepted(source_user, target_user)
|
||||
end
|
||||
|
||||
def new_user_follower(source_user, target_user)
|
||||
@user = target_user
|
||||
sendgrid_unique_args :type => "new_user_follower"
|
||||
mail(:to => @user.email, :subject => "You have a new follower on JamKazam") do |format|
|
||||
mail(:to => target_user.email, :subject => "You have a new JamKazam friend request") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def new_band_follower(source_user, target_users, band)
|
||||
sendgrid_unique_args :type => "new_band_follower"
|
||||
def friend_request_accepted(source_user, target_user)
|
||||
@user = source_user
|
||||
sendgrid_category "Notification"
|
||||
sendgrid_unique_args :type => "friend_request_accepted"
|
||||
|
||||
mail(:to => extract_emails(target_users), :subject => "Your band has a new follower on JamKazam") do |format|
|
||||
mail(:to => target_user.email, :subject => "#{@user.name} accepted your JamKazam friend request") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def new_user_follower(source_user, target_user)
|
||||
@user = source_user
|
||||
sendgrid_category "Notification"
|
||||
sendgrid_unique_args :type => "new_user_follower"
|
||||
mail(:to => target_user.email, :subject => "You have a new follower on JamKazam") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def new_band_follower(source_user, target_user, band)
|
||||
@user, @band = source_user, band
|
||||
sendgrid_category "Notification"
|
||||
sendgrid_unique_args :type => "new_band_follower"
|
||||
mail(:to => target_user, :subject => "Your band has a new follower on JamKazam") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
|
|
@ -123,9 +141,5 @@
|
|||
@user = user
|
||||
end
|
||||
|
||||
def extract_emails(users)
|
||||
users.map! { |u| u.email }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
<% provide(:title, 'New JamKazam Friend Request') %>
|
||||
|
||||
<p><% @user.name %> has sent you a friend request on JamKazam.</p>
|
||||
|
|
@ -0,0 +1 @@
|
|||
<% @user.name %> has sent you a friend request on JamKazam.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<% provide(:title, 'Friend Request Accepted') %>
|
||||
|
||||
<p><% @user.name %> has accepted your friend request on JamKazam.</p>
|
||||
|
|
@ -0,0 +1 @@
|
|||
<% @user.name %> has accepted your friend request on JamKazam.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<% provide(:title, 'New Band Follower on JamKazam') %>
|
||||
|
||||
<p><% @user.name %> is now following your band <%= @band.name %> on JamKazam.</p>
|
||||
|
|
@ -0,0 +1 @@
|
|||
<% @user.name %> is now following your band <%= @band.name %> on JamKazam.
|
||||
|
|
@ -296,7 +296,7 @@
|
|||
return Jampb::ClientMessage.new(
|
||||
:type => ClientMessage::Type::NEW_BAND_FOLLOWER,
|
||||
:route_to => USER_TARGET_PREFIX + receiver_id,
|
||||
:new_user_follower => new_band_follower
|
||||
:new_band_follower => new_band_follower
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -229,6 +229,7 @@ module JamRuby
|
|||
################### FRIEND REQUEST ###################
|
||||
def send_friend_request(friend_request_id, user_id, friend_id)
|
||||
user = User.find(user_id)
|
||||
friend = User.find(friend_id)
|
||||
|
||||
# (1) save to database
|
||||
notification = Notification.new
|
||||
|
|
@ -239,25 +240,31 @@ module JamRuby
|
|||
notification.save
|
||||
|
||||
# (2) create notification
|
||||
notification_msg = format_msg(notification.description, user)
|
||||
msg = @@message_factory.friend_request(
|
||||
friend_request_id,
|
||||
user_id,
|
||||
user.name,
|
||||
user.photo_url,
|
||||
friend_id,
|
||||
notification_msg,
|
||||
notification.id,
|
||||
notification.created_at.to_s
|
||||
)
|
||||
if user.online
|
||||
notification_msg = format_msg(notification.description, user)
|
||||
msg = @@message_factory.friend_request(
|
||||
friend_request_id,
|
||||
user_id,
|
||||
user.name,
|
||||
user.photo_url,
|
||||
friend_id,
|
||||
notification_msg,
|
||||
notification.id,
|
||||
notification.created_at.to_s
|
||||
)
|
||||
|
||||
# (3) send notification
|
||||
@@mq_router.publish_to_user(friend_id, msg)
|
||||
# (2a) send notification if user is online
|
||||
@@mq_router.publish_to_user(friend_id, msg)
|
||||
else
|
||||
# (2b) send email if user is offline
|
||||
UserMailer.friend_request(user, friend)
|
||||
end
|
||||
end
|
||||
|
||||
############### FRIEND REQUEST ACCEPTED ###############
|
||||
def send_friend_request_accepted(user_id, friend_id)
|
||||
friend = User.find(friend_id)
|
||||
user = User.find(user_id)
|
||||
|
||||
# (1) save to database
|
||||
notification = Notification.new
|
||||
|
|
@ -267,18 +274,23 @@ module JamRuby
|
|||
notification.save
|
||||
|
||||
# (2) create notification
|
||||
notification_msg = format_msg(notification.description, friend)
|
||||
msg = @@message_factory.friend_request_accepted(
|
||||
friend_id,
|
||||
friend.name,
|
||||
friend.photo_url,
|
||||
user_id, notification_msg,
|
||||
notification.id,
|
||||
notification.created_at.to_s
|
||||
)
|
||||
if friend.online
|
||||
notification_msg = format_msg(notification.description, friend)
|
||||
msg = @@message_factory.friend_request_accepted(
|
||||
friend_id,
|
||||
friend.name,
|
||||
friend.photo_url,
|
||||
user_id, notification_msg,
|
||||
notification.id,
|
||||
notification.created_at.to_s
|
||||
)
|
||||
|
||||
# (3) send notification
|
||||
@@mq_router.publish_to_user(user_id, msg)
|
||||
# (3) send notification
|
||||
@@mq_router.publish_to_user(user_id, msg)
|
||||
else
|
||||
# (2b) send email if user is offline
|
||||
UserMailer.friend_request(friend, user)
|
||||
end
|
||||
end
|
||||
|
||||
################## FRIEND SESSION JOIN ##################
|
||||
|
|
@ -321,41 +333,60 @@ module JamRuby
|
|||
notification.save
|
||||
|
||||
# (2) create notification
|
||||
notification_msg = format_msg(notification.description, follower)
|
||||
msg = @@message_factory.new_user_follower(
|
||||
user.id,
|
||||
follower.name,
|
||||
follower.photo_url,
|
||||
notification_msg,
|
||||
notification.id,
|
||||
notification.created_at.to_s
|
||||
)
|
||||
if user.online
|
||||
notification_msg = format_msg(notification.description, follower)
|
||||
|
||||
# (3) send notification
|
||||
@@mq_router.publish_to_user(user.id, msg)
|
||||
msg = @@message_factory.new_user_follower(
|
||||
user.id,
|
||||
follower.name,
|
||||
follower.photo_url,
|
||||
notification_msg,
|
||||
notification.id,
|
||||
notification.created_at.to_s
|
||||
)
|
||||
|
||||
# (2a) send notification if user is online
|
||||
@@mq_router.publish_to_user(user.id, msg)
|
||||
else
|
||||
# (2b) send email if user is offline
|
||||
UserMailer.new_user_follower(follower, user)
|
||||
end
|
||||
end
|
||||
|
||||
def send_new_band_follower(follower, band)
|
||||
# (1) save to database
|
||||
notification = Notification.new
|
||||
notification.description = NotificationTypes::NEW_BAND_FOLLOWER
|
||||
notification.source_user_id = follower.id
|
||||
notification.target_user_id = user.id
|
||||
notification.save
|
||||
|
||||
# (2) create notification
|
||||
notifications = []
|
||||
notification_msg = format_msg(notification.description, follower, band)
|
||||
msg = @@message_factory.new_user_follower(
|
||||
user.id,
|
||||
follower.name,
|
||||
follower.photo_url,
|
||||
notification_msg,
|
||||
notification.id,
|
||||
notification.created_at.to_s
|
||||
)
|
||||
|
||||
# (3) send notification
|
||||
@@mq_router.publish_to_user(user.id, msg)
|
||||
band.band_musicians.each.each do |bm|
|
||||
|
||||
# create notifications (saved below in bulk)
|
||||
notification = Notification.new
|
||||
notification.description = NotificationTypes::NEW_BAND_FOLLOWER
|
||||
notification.source_user_id = follower.id
|
||||
notification.target_user_id = bm.user.id
|
||||
notifications << notification
|
||||
|
||||
# send notification
|
||||
if bm.user.online
|
||||
msg = @@message_factory.new_user_follower(
|
||||
bm.user_id,
|
||||
follower.name,
|
||||
follower.photo_url,
|
||||
notification_msg,
|
||||
notification.id,
|
||||
notification.created_at.to_s
|
||||
)
|
||||
|
||||
# (2a) send notification if user is online
|
||||
@@mq_router.publish_to_user(user.id, msg)
|
||||
else
|
||||
# (2b) send email if user is offline
|
||||
UserMailer.new_band_follower(follower, user, band)
|
||||
end
|
||||
end
|
||||
|
||||
Notification.import notifications
|
||||
end
|
||||
|
||||
################## SESSION INVITATION ##################
|
||||
|
|
@ -371,7 +402,7 @@ module JamRuby
|
|||
|
||||
# (2) create notification
|
||||
msg = @@message_factory.session_invitation(
|
||||
receiver_id,
|
||||
receiver.id,
|
||||
sender.name,
|
||||
session_id,
|
||||
notification.id,
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@
|
|||
}
|
||||
|
||||
function isFollowing() {
|
||||
return getUser() ? user.is_following : false;
|
||||
return getUser() ? user.is_following : false;
|
||||
}
|
||||
|
||||
function configureFollowingButton(following) {
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ if @user == current_user
|
|||
attributes :email, :original_fpfile, :cropped_fpfile, :crop_selection, :session_settings, :show_whats_next, :subscribe_email
|
||||
elsif current_user
|
||||
node :is_friend do |uu|
|
||||
@user.friends?(current_user)
|
||||
current_user.friends?(@user)
|
||||
end
|
||||
node :is_following do |uu|
|
||||
@user.following?(current_user)
|
||||
current_user.following?(@user)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue