diff --git a/apps/files_sharing/js/app.js b/apps/files_sharing/js/app.js index 447aaaf8ec28..7499399a7fb3 100644 --- a/apps/files_sharing/js/app.js +++ b/apps/files_sharing/js/app.js @@ -118,10 +118,16 @@ OCA.Sharing.App = { } }, + registerNotificationHandler: function() { + this._onNotificationEvent = _.bind(this._onNotificationEvent, this); + $('body').on('OCA.Notification.Action', this._onNotificationEvent); + }, + /** * Destroy the app */ destroy: function() { + $('body').off('OCA.Notification.Action', this._onNotificationEvent); OCA.Files.fileActions.off('setDefault.app-sharing', this._onActionsUpdated); OCA.Files.fileActions.off('registerAction.app-sharing', this._onActionsUpdated); this.removeSharingIn(); @@ -133,6 +139,19 @@ OCA.Sharing.App = { delete this._globalActionsInitialized; }, + _onNotificationEvent: function(e) { + if (e.notification.app === 'files_sharing') { + if (this._inFileList) { + this._inFileList.reload(); + } + if (e.action.type === 'POST' && OCA.Files && OCA.Files.App && OCA.Files.App.fileList) { + // reload the file list only if the share is accepted + // both internal sharing and remote sharing + OCA.Files.App.fileList.reload(); + } + } + }, + _createFileActions: function() { // inherit file actions from the files app var fileActions = new OCA.Files.FileActions(); @@ -319,5 +338,6 @@ $(document).ready(function() { $('#app-content-sharinglinks').on('hide', function() { OCA.Sharing.App.removeSharingLinks(); }); + OCA.Sharing.App.registerNotificationHandler(); }); diff --git a/apps/files_sharing/tests/js/appSpec.js b/apps/files_sharing/tests/js/appSpec.js index b4a5b31b6804..2ce38b0a1e84 100644 --- a/apps/files_sharing/tests/js/appSpec.js +++ b/apps/files_sharing/tests/js/appSpec.js @@ -161,7 +161,7 @@ describe('OCA.Sharing.App tests', function() { shareOwner: 'user2' }; }); - afterEach(function() { + afterEach(function() { showMenuStub.restore(); }); it('provides accept and reject actions for pending shares', function() { @@ -275,4 +275,90 @@ describe('OCA.Sharing.App tests', function() { }); }); }); + describe('Action events', function() { + var oldList; + var appReloadStub; + var fileListInReloadStub; + + beforeEach(function() { + oldList = OCA.Files.App.fileList; + // dummy new list to make sure it exists + OCA.Files.App.fileList = new OCA.Files.FileList($('