diff --git a/web/app/assets/javascripts/acceptFriendRequestDialog.js b/web/app/assets/javascripts/acceptFriendRequestDialog.js index 4706105ca..66a4fe2f2 100644 --- a/web/app/assets/javascripts/acceptFriendRequestDialog.js +++ b/web/app/assets/javascripts/acceptFriendRequestDialog.js @@ -19,6 +19,7 @@ var user = null; var sending = false; var friendRequest = null; + var sidebar = null; function reset() { sending = false; @@ -52,6 +53,7 @@ rest.acceptFriendRequest(buildAcceptRequest()) .done(function() { app.layout.closeDialog('accept-friend-request') + sidebar.refreshFriends(); }) .fail(function(jqXHR) { app.notifyServerError(jqXHR, 'Unable to Accept Friend Request'); @@ -167,7 +169,7 @@ reset(); } - function initialize() { + function initialize(sidebarInstance) { var dialogBindings = { 'beforeShow' : beforeShow, 'afterHide': afterHide @@ -176,6 +178,7 @@ app.bindDialog('accept-friend-request', dialogBindings); + sidebar = sidebarInstance; $dialog = $('#accept-friend-request-dialog'); $dialogContents = $dialog.find('.dialog-inner'); $notFriendsTemplate = $('#template-friend-request-not-friends'); diff --git a/web/app/assets/javascripts/sidebar.js b/web/app/assets/javascripts/sidebar.js index 6e4f49831..00807f517 100644 --- a/web/app/assets/javascripts/sidebar.js +++ b/web/app/assets/javascripts/sidebar.js @@ -22,48 +22,20 @@ emptySearchResults(); } + function refreshFriends() { + rest.getFriends(). + done(function(response) { + friends = response; + updateFriendList(response); + // set friend count + $('#sidebar-friend-count').html(response.length); + }) + } + function initializeFriendsPanel() { - ///////////////////////////////////////////////////////////// - // THIS IS TEST CODE TO GENERATE BACK TO BACK NOTIFICATIONS - // app.notify({ - // "title": "TEST 1", - // "text": "Test 1", - // "icon_url": context.JK.resolveAvatarUrl("") - // }); - - // app.notify({ - // "title": "TEST 2", - // "text": "Test 2", - // "icon_url": context.JK.resolveAvatarUrl("") - // }); - - // app.notify({ - // "title": "TEST 3", - // "text": "Test 3", - // "icon_url": context.JK.resolveAvatarUrl("") - // }); - ///////////////////////////////////////////////////////////// - $('#sidebar-search-header').hide(); - - var url = "/api/users/" + context.JK.currentUserId + "/friends" - $.ajax({ - type: "GET", - dataType: "json", - contentType: 'application/json', - url: url, - processData: false, - success: function(response) { - friends = response; - updateFriendList(response); - - // set friend count - $('#sidebar-friend-count').html(response.length); - }, - error: app.ajaxError - }); - + refreshFriends(); return false; } @@ -1182,5 +1154,7 @@ invitationDialog = invitationDialogInstance; textMessageDialog = textMessageDialogInstance; }; + + this.refreshFriends = refreshFriends; } })(window,jQuery); \ No newline at end of file diff --git a/web/app/views/clients/index.html.erb b/web/app/views/clients/index.html.erb index d28fd6ae5..68b765856 100644 --- a/web/app/views/clients/index.html.erb +++ b/web/app/views/clients/index.html.erb @@ -135,7 +135,6 @@ textMessageDialog.initialize(); var acceptFriendRequestDialog = new JK.AcceptFriendRequestDialog(JK.app); - acceptFriendRequestDialog.initialize(); var localRecordingsDialog = new JK.LocalRecordingsDialog(JK.app); localRecordingsDialog.initialize(); @@ -155,6 +154,7 @@ header.initialize(); var sidebar = new JK.Sidebar(JK.app); + acceptFriendRequestDialog.initialize(sidebar); sidebar.initialize(invitationDialog, textMessageDialog); var homeScreen = new JK.HomeScreen(JK.app); diff --git a/web/spec/features/accept_friend_request_dialog_spec.rb b/web/spec/features/accept_friend_request_dialog_spec.rb index dd9376da5..6fdc81b64 100644 --- a/web/spec/features/accept_friend_request_dialog_spec.rb +++ b/web/spec/features/accept_friend_request_dialog_spec.rb @@ -30,6 +30,9 @@ describe "Accept Friend Request", :js => true, :type => :feature, :capybara_feat page.should_not have_selector('h1', text: 'friend request') friend_request.reload friend_request.status.should == 'accept' + + # make sure the friend list is refreshed + find("[layout-id=\"panelFriends\"] .friend-name[user-id=\"#{@user2.id}\"]", visible: false) end it "already accepted" do