VRFS-595 added session invitation notification
This commit is contained in:
parent
e4e1ed7459
commit
73dcac9a67
|
|
@ -278,7 +278,10 @@ message FriendUpdate {
|
|||
// route_to: user:[USER_ID]
|
||||
// let a user know they've been invited to a session
|
||||
message SessionInvitation {
|
||||
optional string invitation = 1;
|
||||
optional string sender_id = 1;
|
||||
optional string session_id = 2;
|
||||
optional string notification_id = 3;
|
||||
optional string created_at = 4;
|
||||
}
|
||||
|
||||
// route_to: client
|
||||
|
|
|
|||
|
|
@ -137,8 +137,8 @@
|
|||
return Jampb::ClientMessage.new(:type => ClientMessage::Type::TEST_SESSION_MESSAGE, :route_to => SESSION_TARGET_PREFIX + session_id, :test_session_message => test)
|
||||
end
|
||||
|
||||
def session_invitation(receiver_id, invitation_id)
|
||||
session_invitation = Jampb::SessionInvitation.new(:invitation => invitation_id)
|
||||
def session_invitation(receiver_id, sender_id, session_id, notification_id, created_at)
|
||||
session_invitation = Jampb::SessionInvitation.new(:sender_id => sender_id, :session_id => session_id, :notification_id => notification_id, :created_at => created_at)
|
||||
return Jampb::ClientMessage.new(:type => ClientMessage::Type::SESSION_INVITATION, :route_to => USER_TARGET_PREFIX + receiver_id, :session_invitation => session_invitation)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -128,10 +128,12 @@ module JamRuby
|
|||
when NotificationTypes::MUSICIAN_SESSION_DEPART
|
||||
return "#{user.name} has left the session."
|
||||
|
||||
when NotificationTypes::SESSION_INVITATION
|
||||
return "#{user.name} has invited you to a session."
|
||||
|
||||
# when "social_media_friend_joined"
|
||||
# when "join_request_approved"
|
||||
# when "join_request_rejected"
|
||||
# when "session_invitation"
|
||||
# when "band_invitation"
|
||||
# when "band_invitation_accepted"
|
||||
# when "recording_available"
|
||||
|
|
@ -199,17 +201,19 @@ module JamRuby
|
|||
end
|
||||
|
||||
################## SESSION INVITATION ##################
|
||||
def send_session_invitation(receiver_id, invitation_id)
|
||||
def send_session_invitation(receiver_id, sender_id, session_id)
|
||||
|
||||
# (1) save to database
|
||||
notification = Notification.new
|
||||
notification.description = NotificationTypes::SESSION_INVITATION
|
||||
notification.source_user_id = sender_id
|
||||
notification.target_user_id = receiver_id
|
||||
notification.session_id = session_id
|
||||
notification.save
|
||||
|
||||
# (2) create notification
|
||||
msg = @@message_factory.session_invitation(receiver_id, invitation_id)
|
||||
|
||||
msg = @@message_factory.session_invitation(receiver_id, sender_id, session_id, notification.id, notification.created_at.to_s)
|
||||
|
||||
# (3) send notification
|
||||
@@mq_router.publish_to_user(receiver_id, msg)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -22,6 +22,16 @@
|
|||
});
|
||||
}
|
||||
|
||||
function getSession(id) {
|
||||
var url = "/api/sessions/" + id;
|
||||
return $.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: url,
|
||||
async: false,
|
||||
processData: false
|
||||
});
|
||||
}
|
||||
|
||||
function getUserDetail(options) {
|
||||
var id = getId(options);
|
||||
|
|
@ -277,6 +287,7 @@
|
|||
this.getFilepickerPolicy = getFilepickerPolicy;
|
||||
this.getFriends = getFriends;
|
||||
this.updateSession = updateSession;
|
||||
this.getSession = getSession;
|
||||
this.getClientDownloads = getClientDownloads
|
||||
this.createInvitation = createInvitation;
|
||||
this.postFeedback = postFeedback;
|
||||
|
|
|
|||
|
|
@ -571,7 +571,7 @@
|
|||
function setNotificationInfo(message, descriptor) {
|
||||
var $notify = $('[layout="notify"]');
|
||||
$('h2', $notify).text(message.title);
|
||||
$('p', $notify).text(message.text);
|
||||
$('p', $notify).html(message.text);
|
||||
|
||||
if (message.icon_url) {
|
||||
$('#avatar', $notify).attr('src', message.icon_url);
|
||||
|
|
|
|||
|
|
@ -157,7 +157,8 @@
|
|||
text: "The session you attempted to join is over."
|
||||
},
|
||||
{ no_cancel: true });
|
||||
}else {
|
||||
}
|
||||
else {
|
||||
app.ajaxError(xhr, textStatus, errorMessage);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -140,23 +140,31 @@
|
|||
|
||||
$('#sidebar-notification-list').append(notificationHtml);
|
||||
|
||||
// val.description contains the notification record's description value from the DB (i.e., type)
|
||||
initializeActions(val, val.description);
|
||||
});
|
||||
}
|
||||
|
||||
function initializeActions(notification, type) {
|
||||
function initializeActions(payload, type) {
|
||||
// wire up "x" button to delete notification
|
||||
$('li[notification-id=' + notification.notification_id + ']').find('#img-delete-notification').click(deleteNotificationHandler);
|
||||
$('li[notification-id=' + payload.notification_id + ']').find('#img-delete-notification').click(deleteNotificationHandler);
|
||||
|
||||
if (type === context.JK.MessageType.FRIEND_REQUEST) {
|
||||
var $action_btn = $('li[notification-id=' + notification.notification_id + ']').find('#btn-notification-action');
|
||||
var $action_btn = $('li[notification-id=' + payload.notification_id + ']').find('#btn-notification-action');
|
||||
$action_btn.text('ACCEPT');
|
||||
$action_btn.click(function() {
|
||||
acceptFriendRequest({ "friend_request_id": notification.friend_request_id, "notification_id": notification.notification_id });
|
||||
acceptFriendRequest({ "friend_request_id": payload.friend_request_id, "notification_id": payload.notification_id });
|
||||
});
|
||||
}
|
||||
else if (type === context.JK.MessageType.FRIEND_REQUEST_ACCEPTED) {
|
||||
$('li[notification-id=' + notification.notification_id + ']').find('#div-actions').hide();
|
||||
$('li[notification-id=' + payload.notification_id + ']').find('#div-actions').hide();
|
||||
}
|
||||
else if (type === context.JK.MessageType.SESSION_INVITATION) {
|
||||
var $action_btn = $('li[notification-id=' + payload.notification_id + ']').find('#btn-notification-action');
|
||||
$action_btn.text('JOIN');
|
||||
$action_btn.click(function() {
|
||||
joinSession({ "session_id": payload.session_d, "notification_id": payload.notification_id });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -300,7 +308,12 @@
|
|||
|
||||
function decrementNotificationCount() {
|
||||
var count = parseInt($('#sidebar-notification-count').html());
|
||||
$('#sidebar-notification-count').html(count - 1);
|
||||
if (count === 0) {
|
||||
$('#sidebar-notification-count').html(0);
|
||||
}
|
||||
else {
|
||||
$('#sidebar-notification-count').html(count - 1);
|
||||
}
|
||||
}
|
||||
|
||||
function acceptFriendRequest(args) {
|
||||
|
|
@ -314,15 +327,35 @@
|
|||
}).error(app.ajaxError);
|
||||
}
|
||||
|
||||
function joinSession(args) {
|
||||
logger.debug("Joining session " + args.session_id);
|
||||
context.location = "#/session/" + args.session_id;
|
||||
}
|
||||
|
||||
// default handler for incoming notification
|
||||
function handleNotification(payload, type) {
|
||||
// update notifications panel in sidebar
|
||||
notifications[payload.notification_id] = {
|
||||
"id": payload.notification_id,
|
||||
"photo_url": payload.photo_url,
|
||||
"formatted_msg": payload.msg,
|
||||
"created_at": context.JK.formatDate(payload.created_at)
|
||||
};
|
||||
var sidebarText;
|
||||
if (type === context.JK.MessageType.SESSION_INVITATION) {
|
||||
sidebarText = "You have been invited to a session.";
|
||||
// update notifications panel in sidebar
|
||||
notifications[payload.notification_id] = {
|
||||
"id": payload.notification_id,
|
||||
"session_id": payload.session_id,
|
||||
"formatted_msg": sidebarText,
|
||||
"created_at": context.JK.formatDate(payload.created_at)
|
||||
};
|
||||
}
|
||||
else {
|
||||
sidebarText = payload.msg;
|
||||
|
||||
// update notifications panel in sidebar
|
||||
notifications[payload.notification_id] = {
|
||||
"id": payload.notification_id,
|
||||
"photo_url": payload.photo_url,
|
||||
"formatted_msg": sidebarText,
|
||||
"created_at": context.JK.formatDate(payload.created_at)
|
||||
};
|
||||
}
|
||||
|
||||
incrementNotificationCount();
|
||||
|
||||
|
|
@ -330,7 +363,7 @@
|
|||
var notificationHtml = context.JK.fillTemplate(template, {
|
||||
notificationId: payload.notification_id,
|
||||
avatar_url: context.JK.resolveAvatarUrl(payload.photo_url),
|
||||
text: payload.msg,
|
||||
text: sidebarText,
|
||||
date: context.JK.formatDate(payload.created_at)
|
||||
});
|
||||
|
||||
|
|
@ -488,6 +521,40 @@
|
|||
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
||||
});
|
||||
});
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// wire up SESSION_INVITATION handler
|
||||
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.SESSION_INVITATION, function(header, payload) {
|
||||
logger.debug("Handling SESSION_INVITATION msg " + JSON.stringify(payload));
|
||||
|
||||
handleNotification(payload, header.type);
|
||||
|
||||
var participants = [];
|
||||
rest.getSession(payload.session_id).done(function(response) {
|
||||
$.each(response.participants, function(index, val) {
|
||||
logger.debug(val.user.photo_url + "," + val.user.name);
|
||||
participants.push({"photo_url": val.user.photo_url, "name": val.user.name});
|
||||
});
|
||||
}).error(app.ajaxError);
|
||||
|
||||
var participantHtml = "You have been invited to join a session with: <br/><br/>";
|
||||
|
||||
$.each(participants, function(index, val) {
|
||||
participantHtml += "<img class='avatar_large' src='" + val.photo_url + "' /> " + val.name + "<br/>";
|
||||
});
|
||||
|
||||
// display notification
|
||||
app.notify({
|
||||
"title": "Session Invitation",
|
||||
"text": participantHtml
|
||||
},
|
||||
{
|
||||
"ok_text": "JOIN SESSION",
|
||||
"ok_callback": joinSession,
|
||||
"ok_callback_args": { "session_id": payload.session_id, "notification_id": payload.notification_id }
|
||||
}
|
||||
);
|
||||
});
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// watch for Invite More Users events
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class ApiInvitationsController < ApiController
|
|||
User.save_session_settings(current_user, music_session)
|
||||
|
||||
# send notification
|
||||
# Notification.send_session_invitation(receiver.id, @invitation.id)
|
||||
Notification.send_session_invitation(receiver.id, current_user.id, music_session.id)
|
||||
respond_with @invitation, :responder => ApiResponder, :location => api_invitation_detail_url(@invitation)
|
||||
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in New Issue