Merge branch 'develop'

This commit is contained in:
Seth Call 2013-10-08 10:19:43 -05:00
commit 035a1213d7
19 changed files with 213 additions and 162 deletions

View File

@ -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_name = 1;
optional string session_id = 2;
optional string notification_id = 3;
optional string created_at = 4;
}
// route_to: client

View File

@ -8,6 +8,7 @@ module NotificationTypes
# session notifications
SESSION_INVITATION = "SESSION_INVITATION"
SESSION_ENDED = "SESSION_ENDED" # used to remove session-related notification from sidebar
# musician notifications
MUSICIAN_SESSION_JOIN = "MUSICIAN_SESSION_JOIN"

View File

@ -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_name, session_id, notification_id, created_at)
session_invitation = Jampb::SessionInvitation.new(:sender_name => sender_name, :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

View File

@ -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, 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.name, session_id, notification.id, notification.created_at.to_s)
# (3) send notification
@@mq_router.publish_to_user(receiver_id, msg)
end
@ -220,6 +224,7 @@ module JamRuby
msg = @@message_factory.musician_session_join(music_session.id, user.id, user.name, user.photo_url)
# (2) send notification
puts "CONNECTION.CLIENT_ID=#{connection.client_id}"
@@mq_router.server_publish_to_session(music_session, msg, sender = {:client_id => connection.client_id})
end

View File

@ -132,6 +132,9 @@
ellipsesJiggleTimer = setInterval(function() {
var count = $ellipses.data('count');
if(!count) {
count = 0; // only the real client sometimes returns undefined for count
}
count++;
if(count > 3) {
count = 1;

View File

@ -57,19 +57,9 @@
clearResults();
var queryString = '';
// musician filter
var musicians = getSelectedMusicians();
if (musicians !== null && musicians.length > 0) {
queryString += "participants=" + musicians.join(',');
}
// genre filter
var genres = context.JK.GenreSelectorHelper.getSelectedGenres('#find-session-genre');
if (genres !== null && genres.length > 0) {
if (queryString.length > 0) {
queryString += "&";
}
queryString += "genres=" + genres.join(',');
}
@ -133,20 +123,6 @@
}
}
function getSelectedMusicians() {
var selectedMusicians = [];
// $('#musician-list-items :checked').each(function() {
// selectedMusicians.push($(this).val());
// });
var selectedVal = $('#musician-list').val();
if (selectedVal !== '') {
selectedMusicians.push(selectedVal);
}
return selectedMusicians;
}
function afterLoadSessions(sessionList) {
// display the 'no sessions' banner if appropriate
@ -175,12 +151,15 @@
function containsInvitation(session) {
var i, invitation = null;
// user has invitations for this session
for (i=0; i < session.invitations.length; i++) {
invitation = session.invitations[i];
// session contains an invitation for this user
if (invitation.receiver_id == context.JK.currentUserId) {
return true;
if ("invitations" in session) {
// user has invitations for this session
for (i=0; i < session.invitations.length; i++) {
invitation = session.invitations[i];
// session contains an invitation for this user
if (invitation.receiver_id == context.JK.currentUserId) {
return true;
}
}
}
@ -190,11 +169,13 @@
function containsFriend(session) {
var i, participant = null;
for (i=0; i < session.participants.length; i++) {
participant = session.participants[i];
// this session participant is a friend
if (participant !== null && participant !== undefined && participant.user.is_friend) {
return true;
if ("participants" in session) {
for (i=0; i < session.participants.length; i++) {
participant = session.participants[i];
// this session participant is a friend
if (participant !== null && participant !== undefined && participant.user.is_friend) {
return true;
}
}
}
return false;
@ -268,38 +249,12 @@
}
if (!sessionAlreadyRendered) {
var row = sessionList.renderSession(session, sessionLatency, $tbGroup, $('#template-session-row').html(), $('#template-musician-info').html(),
// populate the musician filter with musicians that haven't already been added
function(musicianArray) {
var template = $('#template-musician-option').html();
$.each(musicianArray, function(index, val) {
// check if this musician is already in the filter
if ( $('#musician-list option[value=' + val.id + ']').length === 0 ) {
var musicianOptionHtml = context.JK.fillTemplate(template, {value: val.id, label: val.name});
$('#musician-list').append(musicianOptionHtml);
}
});
});
var row = sessionList.renderSession(session, sessionLatency, $tbGroup, $('#template-session-row').html(), $('#template-musician-info').html());
}
refreshDisplay();
}
// TODO: refactor this and GenreSelector into common code
// function toggleMusicianBox() {
// var boxHeight = $('#musician-list').css("height");
// // TODO: clean this up (check class name of arrow to determine current state)
// if (boxHeight == "20px") {
// $('#musician-list').css({height: "auto"});
// $('#musician-list-arrow').removeClass("arrow-down").addClass("arrow-up");
// }
// else {
// $('#musician-list').css({height: "20px"});
// $('#musician-list-arrow').removeClass("arrow-up").addClass("arrow-down");
// }
// }
function beforeShow(data) {
context.JK.GenreSelectorHelper.render('#find-session-genre');
}
@ -335,14 +290,18 @@
}
function events() {
//$('#findSession-tableBody').on("click", '[action="delete"]', deleteSession);
// $('#musician-list-header').on("click", toggleMusicianBox);
// $('#musician-list-arrow').on("click", toggleMusicianBox);
$('#session-keyword-srch').focus(function() {
$(this).val('');
});
$("#session-keyword-srch").keypress(function(evt) {
if (evt.which === 13) {
evt.preventDefault();
search();
}
});
$('#btn-refresh').on("click", search);
}

View File

@ -38,6 +38,7 @@
function render(parentSelector) {
$('select', parentSelector).empty();
$('select', parentSelector).append('<option value="">Select Genre</option>');
var template = $('#template-genre-option').html();
$.each(_genres, function(index, value) {
// value will be a dictionary entry from _genres:
@ -45,7 +46,6 @@
var genreOptionHtml = context.JK.fillTemplate(template, value);
$('select', parentSelector).append(genreOptionHtml);
});
}
function getSelectedGenres(parentSelector) {

View File

@ -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;

View File

@ -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);

View File

@ -146,7 +146,6 @@
);
sessionModel.subscribe('sessionScreen', sessionChanged);
logger.debug("sessionId=" + sessionId);
sessionModel.joinSession(sessionId)
.fail(function(xhr, textStatus, errorMessage) {
if(xhr.status == 404) {
@ -157,7 +156,8 @@
text: "The session you attempted to join is over."
},
{ no_cancel: true });
}else {
}
else {
app.ajaxError(xhr, textStatus, errorMessage);
}
});
@ -604,7 +604,7 @@
});
}
function handleVolumeChangeCallback(mixerId, isLeft, value) {
function handleVolumeChangeCallback(mixerId, isLeft, value, isMuted) {
// Visually update mixer
// There is no need to actually set the back-end mixer value as the
// back-end will already have updated the audio mixer directly prior to sending
@ -612,6 +612,8 @@
// TODO: Use mixer's range
var faderValue = percentFromMixerValue(-80, 20, value);
context.JK.FaderHelpers.setFaderValue(mixerId, faderValue);
var $muteControl = $('[control="mute"][mixer-id="' + mixerId + '"]');
_toggleVisualMuteControl($muteControl, isMuted);
}
function handleBridgeCallback() {

View File

@ -15,7 +15,7 @@
var AUDIENCE = {
OPEN_TO_FANS: "Open to Fans",
MUSICIANS_ONLY:"Musicians Only"
MUSICIANS_ONLY: "Musicians Only"
};
var instrument_logo_map = context.JK.getInstrumentIconMap24();
@ -25,7 +25,7 @@
* It will be inserted at the appropriate place according to the
* sortScore in sessionLatency.
*/
function renderSession(session, sessionLatency, tbGroup, rowTemplate, musicianTemplate, onMusiciansComplete) {
function renderSession(session, sessionLatency, tbGroup, rowTemplate, musicianTemplate) {
// latency
var latencyInfo = sessionLatency.sessionInfo(session.id);
var latencyDescription = "";
@ -67,46 +67,45 @@
var i, participant = null;
var musicians = '';
var musicianArray = [];
for (i=0; i < session.participants.length; i++) {
participant = session.participants[i];
var instrumentLogoHtml = '';
var j;
if ("participants" in session) {
for (i=0; i < session.participants.length; i++) {
participant = session.participants[i];
// loop through the tracks to get the instruments
for (j=0; j < participant.tracks.length; j++) {
var track = participant.tracks[j];
logger.debug("Find:Finding instruments. Participant tracks:");
logger.debug(participant.tracks);
var inst = '../assets/content/icon_instrument_default24.png';
if (track.instrument_id in instrument_logo_map) {
inst = instrument_logo_map[track.instrument_id];
var instrumentLogoHtml = '';
var j;
// loop through the tracks to get the instruments
for (j=0; j < participant.tracks.length; j++) {
var track = participant.tracks[j];
logger.debug("Find:Finding instruments. Participant tracks:");
logger.debug(participant.tracks);
var inst = '../assets/content/icon_instrument_default24.png';
if (track.instrument_id in instrument_logo_map) {
inst = instrument_logo_map[track.instrument_id];
}
instrumentLogoHtml += '<img src="' + inst + '" width="24" height="24" />&nbsp;';
}
instrumentLogoHtml += '<img src="' + inst + '" width="24" height="24" />&nbsp;';
var id = participant.user.id;
var name = participant.user.name;
var photoUrl = context.JK.resolveAvatarUrl(participant.user.photo_url);
var musicianVals = {
avatar_url: photoUrl,
profile_url: "/#/profile/" + id,
musician_name: name,
instruments: instrumentLogoHtml
};
var musician = {};
musician.id = id;
musician.name = name;
var musicianInfo = context.JK.fillTemplate(musicianTemplate, musicianVals);
musicians += musicianInfo;
}
var id = participant.user.id;
var name = participant.user.name;
var photoUrl = context.JK.resolveAvatarUrl(participant.user.photo_url);
var musicianVals = {
avatar_url: photoUrl,
profile_url: "/#/profile/" + id,
musician_name: name,
instruments: instrumentLogoHtml
};
var musician = {};
musician.id = id;
musician.name = name;
musicianArray[i] = musician;
var musicianInfo = context.JK.fillTemplate(musicianTemplate, musicianVals);
musicians += musicianInfo;
}
onMusiciansComplete(musicianArray);
var sessionVals = {
id: session.id,
genres: session.genres.join (', '),

View File

@ -6,7 +6,6 @@
context.JK.Sidebar = function(app) {
var logger = context.JK.logger;
var friends = [];
var notifications = [];
var invitationDialog = new context.JK.InvitationDialog(app);
var rest = context.JK.Rest();
@ -112,7 +111,6 @@
processData: false,
success: function(response) {
notifications = response;
updateNotificationList(response);
// set notification count
@ -127,8 +125,6 @@
$.each(response, function(index, val) {
notifications[val.notification_id] = val;
// fill in template for Connect pre-click
var template = $('#template-notification-panel').html();
var notificationHtml = context.JK.fillTemplate(template, {
@ -140,23 +136,33 @@
$('#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) {
// wire up "x" button to delete notification
$('li[notification-id=' + notification.notification_id + ']').find('#img-delete-notification').click(deleteNotificationHandler);
function initializeActions(payload, type) {
var $notification = $('li[notification-id=' + payload.notification_id + ']');
// wire up "x" button to delete notification
$notification.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 = $notification.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();
$notification.find('#div-actions').hide();
}
else if (type === context.JK.MessageType.SESSION_INVITATION) {
var $action_btn = $notification.find('#btn-notification-action');
$action_btn.text('JOIN');
$action_btn.click(function() {
joinSession({ "session_id": payload.session_id, "notification_id": payload.notification_id });
});
}
}
@ -175,7 +181,6 @@
url: url,
processData: false,
success: function(response) {
delete notifications[notificationId];
$('li[notification-id=' + notificationId + ']').hide();
decrementNotificationCount();
},
@ -225,12 +230,13 @@
$('div[layout=sidebar] div[user-id=' + val.id + '].sidebar-search-result').show();
// wire up button click handler if search result is not a friend or the current user
var $sidebar = $('div[layout=sidebar] div[user-id=' + val.id + ']');
if (!val.is_friend && val.id !== context.JK.currentUserId) {
$('div[layout=sidebar] div[user-id=' + val.id + ']').find('.btn-connect-friend').click(sendFriendRequest);
$sidebar.find('.btn-connect-friend').click(sendFriendRequest);
}
// hide the button if the search result is already a friend
else {
$('div[layout=sidebar] div[user-id=' + val.id + ']').find('.btn-connect-friend').hide();
$sidebar.find('.btn-connect-friend').hide();
}
});
@ -300,7 +306,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 +325,20 @@
}).error(app.ajaxError);
}
function joinSession(args) {
context.location = "#/session/" + args.session_id;
deleteNotification(args.notification_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 = payload.sender_name + " has invited you to a session.";
}
else {
sidebarText = payload.msg;
}
incrementNotificationCount();
@ -330,7 +346,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 +504,45 @@
"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/>";
participantHtml += "<table><tbody>";
$.each(participants, function(index, val) {
if (index < 4) {
participantHtml += "<tr><td><img class='avatar-small' src='" + val.photo_url + "' /></td><td>" + val.name + "</td></tr>";
}
});
participantHtml += "</tbody></table>";
// 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

View File

@ -67,6 +67,7 @@ a.arrow-down {
select {
padding:3px;
font-size:15px;
border-radius: 6px;
}
form .body {

View File

@ -98,7 +98,7 @@
ms-filter: "alpha(opacity=50)";
}
li .avatar-small {
.avatar-small {
float:left;
padding:1px;
width:36px;
@ -110,7 +110,7 @@
border-radius:18px;
}
li .avatar-small img {
.avatar-small img {
width: 36px;
height: 36px;
-webkit-border-radius:18px;

View File

@ -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, music_session.id)
respond_with @invitation, :responder => ApiResponder, :location => api_invitation_detail_url(@invitation)
else

View File

@ -200,7 +200,7 @@ class ApiMusicSessionsController < ApiController
bucket = s3.buckets[SampleApp::Application.config.aws_bucket]
read_url = bucket.objects[uri].url_for(:read,
# :expires => SampleApp::Application.config.perf_data_signed_url_timeout * 90,
:expires => Time.now + 90.days,
:'response_content_type' => 'text/csv').to_s
@perfdata.update_attribute(:uri, read_url)

View File

@ -15,22 +15,6 @@
<div style="min-width:770px;">
<div class="left ml35" style="padding-top:3px;">Filter Session List:</div>
<!-- musician filter -->
<div id="find-session-musician" class="ml10 left">
<select id="musician-list">
<option value="">All Musicians</option>
</select>
<!-- <div id="musician-list" class="multiselect-dropdown">
<div class="list-item-text">
<a id="musician-list-header">All musicians</a>
</div>
<a class="arrow-down" id="musician-list-arrow"></a>
<div id="musician-list-items" class="list-items">
</div>
</div> -->
</div>
<!-- genre filter -->
<div id="find-session-genre" class="left ml10">
<%= render "genreSelector" %>

View File

@ -45,12 +45,7 @@ MusicSessionManager < BaseManager
# auto-join this user into the newly created session
as_musician = true
connection = ConnectionManager.new.join_music_session(user, client_id, music_session, as_musician, tracks) do |db_conn, connection|
if as_musician && music_session.musician_access
Notification.send_musician_session_join(music_session, connection, user)
Notification.send_friend_session_join(db_conn, connection, user)
end
end
connection = ConnectionManager.new.join_music_session(user, client_id, music_session, as_musician, tracks)
unless connection.errors.any?
return_value = music_session
@ -106,8 +101,8 @@ MusicSessionManager < BaseManager
connection = ConnectionManager.new.join_music_session(user, client_id, music_session, as_musician, tracks) do |db_conn, connection|
if as_musician && music_session.musician_access
Notification.send_musician_session_join(music_session, connection, user)
Notification.send_friend_session_join(db_conn, connection, user)
Notification.send_musician_session_join(music_session, connection, user)
end
end

View File

@ -0,0 +1,33 @@
require 'spec_helper'
# this test currently amounts to the barest of smoke tests; log in, see the home screen, and click a tile
# https://jamkazam.atlassian.net/browse/VRFS-749 broke even this simple functionality
describe "Admin", :js => true, :type => :feature, :capybara_feature => true do
subject { page }
before(:all) do
Capybara.javascript_driver = :poltergeist
Capybara.current_driver = Capybara.javascript_driver
Capybara.default_wait_time = 10
end
let(:user) { FactoryGirl.create(:admin) }
before(:each) do
UserMailer.deliveries.clear
sign_in_poltergeist user
visit "/"
find('h2', text: 'musicians')
end
describe "click musician tile" do
before(:each) do
find("div.homecard.musicians").trigger(:click)
end
it { should have_selector('h1', text: 'musicians' ) }
end
end