VRFS-933 notification work
This commit is contained in:
parent
051b8eec5e
commit
07abf26ced
|
|
@ -150,5 +150,29 @@
|
|||
@user = user
|
||||
end
|
||||
|
||||
def band_invitation(target_user, msg)
|
||||
@body = msg
|
||||
|
||||
sendgrid_category "Notification"
|
||||
sendgrid_unique_args :type => "band_invitation"
|
||||
|
||||
mail(:to => target_user.email, :subject => "You have been invited to join a band on JamKazam") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def band_invitation_accepted(msg)
|
||||
@body = msg
|
||||
|
||||
sendgrid_category "Notification"
|
||||
sendgrid_unique_args :type => "band_invitation_accepted"
|
||||
|
||||
mail(:to => target_user.email, :subject => "Your band invitation was accepted") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
<% provide(:title, 'New Band Session') %>
|
||||
|
||||
<p><%= @band.name %> is now in a session on JamKazam.</p>
|
||||
|
|
@ -0,0 +1 @@
|
|||
<%= @band.name %> is now in a session on JamKazam.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<% provide(:title, 'Musician in Session') %>
|
||||
|
||||
<p><%= @user.name %> is now in a session on JamKazam.</p>
|
||||
|
|
@ -0,0 +1 @@
|
|||
<%= @user.name %> is now in a session on JamKazam.
|
||||
|
|
@ -446,6 +446,23 @@
|
|||
)
|
||||
end
|
||||
|
||||
def band_session_join(session_id, receiver_id, band_name, photo_url, msg, notification_id, created_at)
|
||||
band_session_join = Jampb::BandSessionJoin.new(
|
||||
:session_id => session_id,
|
||||
:band_name => band_name,
|
||||
:photo_url => photo_url,
|
||||
:msg => msg,
|
||||
:notification_id => notification_id,
|
||||
:created_at => created_at
|
||||
)
|
||||
|
||||
return Jampb::ClientMessage.new(
|
||||
:type => ClientMessage::Type::BAND_SESSION_JOIN,
|
||||
:route_to => USER_TARGET_PREFIX + receiver_id,
|
||||
:band_session_join => band_session_join
|
||||
)
|
||||
end
|
||||
|
||||
# create a musician fresh session message
|
||||
def musician_session_fresh(session_id, user_id, username, photo_url)
|
||||
fresh = Jampb::MusicianSessionFresh.new(
|
||||
|
|
|
|||
|
|
@ -91,6 +91,17 @@ module JamRuby
|
|||
return follower_ids
|
||||
end
|
||||
|
||||
def retrieve_friends_not_in_session(connection, user_id, session_id)
|
||||
ids = retrieve_friends(connection, user_id)
|
||||
connection.exec("SELECT c.user_id as musician_id FROM connections c WHERE c.music_session_id = $1", [session_id]) do |musicians|
|
||||
musicians.each do |musician_result|
|
||||
# remove users who are in the session
|
||||
ids.reject! {|item| item == musician_result['musician_id']}
|
||||
end
|
||||
end
|
||||
return ids
|
||||
end
|
||||
|
||||
def retrieve_friends_and_followers(connection, user_id)
|
||||
ids = retrieve_friends(connection, user_id)
|
||||
ids.concat(retrieve_user_followers(connection, user_id))
|
||||
|
|
@ -164,7 +175,7 @@ module JamRuby
|
|||
|
||||
# musician notifications
|
||||
when NotificationTypes::MUSICIAN_SESSION_JOIN
|
||||
return "#{name} has joined the session."
|
||||
return "#{name} is now in a session."
|
||||
|
||||
when NotificationTypes::MUSICIAN_SESSION_DEPART
|
||||
return "#{name} has left the session."
|
||||
|
|
@ -296,7 +307,7 @@ module JamRuby
|
|||
|
||||
################## FRIEND SESSION JOIN ##################
|
||||
def send_friend_session_join(db_conn, connection, user)
|
||||
ids = retrieve_friends_and_followers_not_in_session(db_conn, user.id, connection.music_session.id)
|
||||
ids = retrieve_friends_not_in_session(db_conn, user.id, connection.music_session.id)
|
||||
|
||||
unless ids.empty?
|
||||
# (1) bulk save to database
|
||||
|
|
@ -589,21 +600,25 @@ module JamRuby
|
|||
notification.save
|
||||
|
||||
# (2) create notification
|
||||
notification_msg = format_msg(notification.description, band)
|
||||
msg = @@message_factory.band_invitation(
|
||||
band_invitation.id,
|
||||
band.id,
|
||||
receiver.id,
|
||||
sender.name,
|
||||
sender.photo_url,
|
||||
band.name,
|
||||
notification_msg,
|
||||
notification.id,
|
||||
notification.created_at.to_s
|
||||
)
|
||||
if receiver.online
|
||||
notification_msg = format_msg(notification.description, band)
|
||||
msg = @@message_factory.band_invitation(
|
||||
band_invitation.id,
|
||||
band.id,
|
||||
receiver.id,
|
||||
sender.name,
|
||||
sender.photo_url,
|
||||
band.name,
|
||||
notification_msg,
|
||||
notification.id,
|
||||
notification.created_at.to_s
|
||||
)
|
||||
|
||||
# (3) send notification
|
||||
@@mq_router.publish_to_user(receiver.id, msg)
|
||||
# (3) send notification
|
||||
@@mq_router.publish_to_user(receiver.id, msg)
|
||||
else
|
||||
UserMailer.band_invitation(receiver, band)
|
||||
end
|
||||
end
|
||||
|
||||
################## BAND INVITATION ACCEPTED ##################
|
||||
|
|
@ -617,10 +632,40 @@ module JamRuby
|
|||
notification.target_user_id = receiver.id
|
||||
notification.save
|
||||
|
||||
# (2) create notification
|
||||
if receiver.online
|
||||
notification_msg = format_msg(notification.description, sender)
|
||||
msg = @@message_factory.band_invitation_accepted(
|
||||
band_invitation.id,
|
||||
receiver.id,
|
||||
sender.name,
|
||||
sender.photo_url,
|
||||
band.name,
|
||||
notification_msg,
|
||||
notification.id,
|
||||
notification.created_at.to_s
|
||||
)
|
||||
@@mq_router.publish_to_user(receiver.id, msg)
|
||||
else
|
||||
# (2b) send email if user is offline
|
||||
UserMailer.band_invitation_accepted(sender, receiver, band)
|
||||
end
|
||||
end
|
||||
|
||||
################## BAND SESSION JOIN ##################
|
||||
def send_band_session_join(music_session, band)
|
||||
# (1) save to database
|
||||
notification = Notification.new
|
||||
notification.band_id = band.id
|
||||
notification.description = NotificationTypes::BAND_SESSION_JOIN
|
||||
notification.source_user_id = sender.id
|
||||
notification.target_user_id = receiver.id
|
||||
notification.save
|
||||
|
||||
# (2) create notification
|
||||
notification_msg = format_msg(notification.description, sender)
|
||||
msg = @@message_factory.band_invitation_accepted(
|
||||
band_invitation.id,
|
||||
msg = @@message_factory.band_session_join(
|
||||
music_session.id,
|
||||
receiver.id,
|
||||
sender.name,
|
||||
sender.photo_url,
|
||||
|
|
@ -634,8 +679,6 @@ module JamRuby
|
|||
@@mq_router.publish_to_user(receiver.id, msg)
|
||||
end
|
||||
|
||||
################## BAND SESSION JOIN ##################
|
||||
|
||||
################## MUSICIAN SESSION FRESH ##################
|
||||
def send_musician_session_fresh(music_session, client_id, user)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue