diff --git a/config.xml b/config.xml index 4d3d4ac..8de877f 100644 --- a/config.xml +++ b/config.xml @@ -77,7 +77,7 @@ - + @@ -88,13 +88,13 @@ - + - - + + @@ -112,4 +112,5 @@ + diff --git a/www/coffee/utils.coffee b/www/coffee/utils.coffee index 11e536e..0fad183 100644 --- a/www/coffee/utils.coffee +++ b/www/coffee/utils.coffee @@ -65,6 +65,14 @@ window.readFile = (directoryPath, fileName, cb) -> window.resolveLocalFileSystemURL directoryPath, resolveSuccess, fail +window.removeFile = (directoryPath, fileName, cb) -> + resolveSuccess = (dirEntry) -> + getFileSuccess = (fileEntry) -> + fileEntry.remove cb + + dirEntry.getFile fileName, {}, getFileSuccess + + window.resolveLocalFileSystemURL directoryPath, resolveSuccess window.writeDir = (directoryPath, dirName, cb) -> fail = (err) -> diff --git a/www/shared/js/share.js b/www/shared/js/share.js index f3324f1..4a7222e 100644 --- a/www/shared/js/share.js +++ b/www/shared/js/share.js @@ -7,47 +7,114 @@ Meteor.subscribe('subscription', { onReady: function() { - var roomPrefixes = { - d: '@', - p: '&', - c: '#' - }; + readFile(cordova.file.cacheDirectory, 'pendingShare.json', function(err, shareInfo) + { + if(err) + { + return; + } + + removeFile(cordova.file.cacheDirectory, 'pendingShare.json', function() { }); + selectRoom(JSON.parse(shareInfo)); + }); cordova.SharingReceptor.listen(function(data) { - var rooms = _.sortBy(ChatSubscription.find({open: true}).fetch(), function(room) + var serverOptions = ''; + if(Servers.getServers().length > 1) { - return [room.t, room.name].join('-'); - }); + serverOptions = _.reduce(Servers.getServers(), function(accString, server) + { + return accString + ''; + }, ''); - var innerString = _.reduce(rooms, function(accString, room) - { - return accString + ''; - }, ''); - - var tempString = ''; - - swal({ - title: 'Select room to share', - text: tempString, - html: true, - animation: true, - showCancelButton: true - }, function() - { - var roomName = $('#room-select')[0].value; - var roomModel = ChatSubscription.findOne({name: roomName}); + var serverString = ''; - if(roomModel) - { - doShare(roomModel, data); - } - }); + swal({ + title: 'Select server', + text: serverString, + html: true, + animation: true, + showCancelButton: true + }, + function() + { + var currentServerUrl = Servers.getActiveServer().url; + var serverUrl = $('#server-select')[0].value; + + if(serverUrl != currentServerUrl) + { + writeFile(cordova.file.cacheDirectory, 'pendingShare.json', JSON.stringify(data), function(err, data) + { + if(err) + { + console.log('Error saving share file', err); + return; + } + localStorage.setItem('pendingShare', JSON.stringify(data)); + + $(document.body).addClass('loading'); + $('.loading-text').text(cordovai18n("Loading_s", serverUrl)); + setTimeout(function() + { + Servers.setActiveServer(serverUrl); + Servers.startServer(serverUrl, function() { }); + }, 200); + }); + } + else + { + selectRoom(data); + } + }); + } + else + { + selectRoom(data); + } }); } }); +function selectRoom(data) +{ + var roomPrefixes = { + d: '@', + p: '&', + c: '#' + }; + + var rooms = _.sortBy(ChatSubscription.find({open: true}).fetch(), function(room) + { + return [room.t, room.name].join('-'); + }); + + var innerString = _.reduce(rooms, function(accString, room) + { + return accString + ''; + }, ''); + + var tempString = ''; + + swal({ + title: 'Select room to share', + text: tempString, + html: true, + animation: true, + showCancelButton: true + }, function() + { + var roomName = $('#room-select')[0].value; + var roomModel = ChatSubscription.findOne({name: roomName}); + + if(roomModel) + { + doShare(roomModel, data); + } + }); +} + function doShare(roomModel, data) { if(_.startsWith(data.intent.type, 'text'))