diff --git a/www/plugins/es/js/controllers/app-controllers.js b/www/plugins/es/js/controllers/app-controllers.js index 03429e6dbc9d0cd3798fd0616780e588be1861c1..f595e7930ba2ca60501768d64ce12270e40d1279 100644 --- a/www/plugins/es/js/controllers/app-controllers.js +++ b/www/plugins/es/js/controllers/app-controllers.js @@ -74,7 +74,14 @@ function ESMenuExtendController($scope, $state, $controller, UIUtils, csWallet) return UIUtils.popover.show(event, { templateUrl :'plugins/es/templates/notification/popover_notification.html', scope: $scope, - autoremove: false // reuse popover + autoremove: false, // reuse popover + // Auto-close if open when un-authenticate + afterShow: function(popover) { + var listener = csWallet.api.data.on.unauth(popover.scope, function() { + popover.scope.closePopover(); + listener(); + }); + } }); }; @@ -90,7 +97,14 @@ function ESMenuExtendController($scope, $state, $controller, UIUtils, csWallet) return UIUtils.popover.show(event, { templateUrl :'plugins/es/templates/message/popover_message.html', scope: $scope, - autoremove: false // reuse popover + autoremove: false, // reuse popover + // Auto-close if open when un-authenticate + afterShow: function(popover) { + var listener = csWallet.api.data.on.unauth(popover.scope, function() { + popover.scope.closePopover(); + listener(); + }); + } }); }; diff --git a/www/plugins/es/js/controllers/message-controllers.js b/www/plugins/es/js/controllers/message-controllers.js index 811646f748b2c2607f2e3d0e0bb6995e26481299..511f6722b99e42185632de69faf9c5a395a327f4 100644 --- a/www/plugins/es/js/controllers/message-controllers.js +++ b/www/plugins/es/js/controllers/message-controllers.js @@ -58,8 +58,53 @@ angular.module('cesium.es.message.controllers', ['cesium.es.services']) } }) + .state('app.user_messages_by_id', { + url: "/wallets/:id/message", + views: { + 'menuContent': { + templateUrl: "plugins/es/templates/message/lookup.html" + } + } + }) + + .state('app.user_messages_by_id.tab_inbox', { + url: "/inbox", + views: { + 'tab_inbox': { + controller: 'ESMessageInboxListCtrl', + templateUrl: "plugins/es/templates/message/tabs/tab_list.html" + } + }, + data: { + large: 'app.user_messages_lg_inbox_by_id' + } + }) + + .state('app.user_messages_by_id.tab_outbox', { + url: "/outbox", + views: { + 'tab_outbox': { + controller: 'ESMessageOutboxListCtrl', + templateUrl: "plugins/es/templates/message/tabs/tab_list.html" + } + }, + data: { + large: 'app.user_messages_lg_outbox_by_id' + } + }) + + .state('app.user_messages_lg_inbox_by_id', { + url: "/wallets/:id/message/lg/inbox", + views: { + 'menuContent': { + templateUrl: "plugins/es/templates/message/lookup_lg.html", + controller: 'ESMessageInboxListCtrl' + } + } + }) + .state('app.user_messages_lg_outbox', { - url: "/user/message/lg/outbox", + url: "/wallets/:id/message/lg/outbox", views: { 'menuContent': { templateUrl: "plugins/es/templates/message/lookup_lg.html", @@ -72,9 +117,19 @@ angular.module('cesium.es.message.controllers', ['cesium.es.services']) } }) + .state('app.user_messages_lg_outbox_by_id', { + url: "/user/message/lg/outbox", + views: { + 'menuContent': { + templateUrl: "plugins/es/templates/message/lookup_lg.html", + controller: 'ESMessageOutboxListCtrl' + } + } + }) + .state('app.user_new_message', { cache: false, - url: "/user/message/new?pubkey&uid&title&content", + url: "/user/message/new?pubkey&uid&title&content&isReply", views: { 'menuContent': { templateUrl: "plugins/es/templates/message/compose.html", @@ -85,7 +140,7 @@ angular.module('cesium.es.message.controllers', ['cesium.es.services']) .state('app.user_view_message', { cache: false, - url: "/user/message/view/:type/:id", + url: "/user/message/view/:type/:messageId", views: { 'menuContent': { templateUrl: "plugins/es/templates/message/view_message.html", @@ -98,6 +153,17 @@ angular.module('cesium.es.message.controllers', ['cesium.es.services']) } }) + .state('app.user_view_message_by_id', { + cache: false, + url: "/wallets/:id/message/view/:type/:messageId", + views: { + 'menuContent': { + templateUrl: "plugins/es/templates/message/view_message.html", + controller: 'ESMessageViewCtrl' + } + } + }) + ; }) @@ -122,6 +188,7 @@ function ESMessageAbstractListController($scope, $state, $translate, $ionicHisto 'ngInject'; var defaultSearchLimit = 40; + var wallet; $scope.search = { loading: true, @@ -137,9 +204,17 @@ function ESMessageAbstractListController($scope, $state, $translate, $ionicHisto $scope.fabButtonNewMessageId = undefined; - $scope.$on('$ionicView.enter', function(e, state) { + $scope.enter = function(s, state) { + wallet = (state.stateParams && state.stateParams.id) ? csWallet.children.get(state.stateParams.id) : csWallet; + if (!wallet) { + UIUtils.alert.error('ERROR.UNKNOWN_WALLET_ID'); + return $scope.showHome(); + } + + $scope.isDefaultWallet = wallet.isDefault(); + $scope.walletId = wallet.id; - $scope.loadWallet({minData: true}) + wallet.auth({minData: true}) .then(function() { if (!$scope.entered) { $scope.entered = true; @@ -159,7 +234,9 @@ function ESMessageAbstractListController($scope, $state, $translate, $ionicHisto $state.go('app.home'); } }); - }); + }; + $scope.$on('$ionicView.enter', $scope.enter); + $scope.refresh = function(silent) { return $scope.load(undefined, undefined, silent); @@ -174,6 +251,7 @@ function ESMessageAbstractListController($scope, $state, $translate, $ionicHisto options.summary = false; options.filter = ($scope.search.type == 'text' && $scope.search.text && $scope.search.text.trim().length > 0) ? $scope.search.text : undefined; + options.wallet = wallet; $scope.search.loading = !silent; return esMessage.load(options) @@ -301,12 +379,25 @@ function ESMessageAbstractListController($scope, $state, $translate, $ionicHisto return $scope.load(); }; + $scope.select = function(message) { + if (!wallet || wallet.isDefault()) { + $state.go('app.user_view_message', {type: $scope.type, messageId:message.id}); + } + else { + $state.go('app.user_view_message_by_id', {type: $scope.type, messageId:message.id, id: $scope.walletId}); + } + }; + /* -- Modals -- */ $scope.showNewMessageModal = function(parameters) { - return $scope.loadWallet({minData: true}) + return wallet.login({minData: true}) .then(function() { UIUtils.loading.hide(); + + parameters = parameters ||Â {}; + parameters.wallet = $scope.walletId; + return esModals.showMessageCompose(parameters) .then(function(id) { if (id) UIUtils.toast.show('MESSAGE.INFO.MESSAGE_SENT'); @@ -328,7 +419,8 @@ function ESMessageAbstractListController($scope, $state, $translate, $ionicHisto destUid: message.name||message.uid, title: prefix + message.title, content: content, - isReply: true + isReply: true, + wallet: $scope.walletId }); }) .then(function(sent) { @@ -494,7 +586,7 @@ function ESMessageComposeModalController($scope, Modals, UIUtils, csWallet, esHt }; $scope.destUid = null; $scope.destPub = null; - $scope.isResponse = false; + $scope.isReply = false; $scope.enableSelectWallet = true; $scope.sending = false; @@ -521,7 +613,7 @@ function ESMessageComposeModalController($scope, Modals, UIUtils, csWallet, esHt $scope.formData.content = parameters.content; } - $scope.isResponse = parameters.isResponse || false; + $scope.isReply = parameters.isReply ||Â false; if (parameters.wallet) { $scope.formData.walletId = parameters.wallet; @@ -538,6 +630,9 @@ function ESMessageComposeModalController($scope, Modals, UIUtils, csWallet, esHt if (!wallet.isDefault()) { console.debug("[message] Using {" + wallet.id + "} wallet"); } + else { + console.debug("[message] Using default wallet"); + } return wallet.login({minData: true, silent: true}) .then(function(data) { @@ -654,63 +749,73 @@ function ESMessageComposeModalController($scope, Modals, UIUtils, csWallet, esHt function ESMessageViewController($scope, $state, $timeout, $translate, $ionicHistory, $ionicPopover, - UIUtils, esModals, esMessage) { + UIUtils, esModals, esMessage, csWallet) { 'ngInject'; $scope.formData = {}; $scope.id = null; $scope.loading = true; + var wallet; + $scope.$on('$ionicView.beforeEnter', function (event, viewData) { // Enable back button (workaround need for navigation outside tabs - https://stackoverflow.com/a/35064602) viewData.enableBack = UIUtils.screen.isSmall() ? true : viewData.enableBack; }); - $scope.$on('$ionicView.enter', function (e, state) { - if (state.stateParams && state.stateParams.id) { // Load by id - if ($scope.loading) { // prevent reload if same id - $scope.type = state.stateParams.type || 'inbox'; - - $scope.load(state.stateParams.id, $scope.type) - .then(function(message) { - $scope.loading = false; - UIUtils.loading.hide(); - if (!message) return; - - $scope.id = message.id; - $scope.formData = message; - $scope.canDelete = true; - $scope.motion.show({selector: '.view-message .list .item'}); - // Mark as read - if (!message.read) { - $timeout(function() { - // Message has NOT changed - if ($scope.id === message.id) { - esMessage.markAsRead(message, $scope.type) - .then(function() { - console.debug("[message] marked as read"); - }) - .catch(UIUtils.onError('MESSAGE.ERROR.MARK_AS_READ_FAILED')); - } - }, 2000); // 2s - } - }); - } + $scope.enter = function(e, state) { + if (!$scope.loading) return; // prevent reload if same id - $scope.showFab('fab-view-message-reply'); + wallet = (state.stateParams && state.stateParams.id) ? csWallet.children.get(state.stateParams.id) : csWallet; + if (!wallet) { + UIUtils.alert.error('ERROR.UNKNOWN_WALLET_ID'); + return $scope.showHome(); } - else { + + $scope.isDefaultWallet = wallet.isDefault(); + $scope.walletId = wallet.id; + + var messageId = state.stateParams && state.stateParams.messageId; + $scope.type = state.stateParams.type || 'inbox'; + + // No message id: redirect + if (angular.isUndefined(messageId)) { $state.go('app.user_message'); + return; } - }); - $scope.load = function(id, type) { - type = type || 'inbox'; + wallet.auth({minData: true}) + .then(function () { + return $scope.load(messageId, $scope.type); + }) + .then(function(message) { - return $scope.loadWallet({minData: true}) - .then(function() { - return esMessage.get(id, {type: type}); + UIUtils.loading.hide(); + if (!message) return; // SKip + + $scope.updateView(message); + $scope.showFab('fab-view-message-reply'); + + // Mark as read + if (!message.read) { + $timeout(function() { + // Message has NOT changed + if ($scope.id === message.id) { + esMessage.markAsRead(message, {type: $scope.type, wallet: wallet}) + .then(function() { + console.debug("[message] marked as read"); + }) + .catch(UIUtils.onError('MESSAGE.ERROR.MARK_AS_READ_FAILED')); + } + }, 2000); // 2s + } }) + }; + $scope.$on('$ionicView.enter', $scope.enter); + + $scope.load = function(id, type) { + type = type || 'inbox'; + return esMessage.get(id, {type: type, wallet: wallet}) .catch(UIUtils.onError('MESSAGE.ERROR.LOAD_MESSAGE_FAILED')) .then(function(message) { if (!message.valid) { @@ -724,6 +829,14 @@ function ESMessageViewController($scope, $state, $timeout, $translate, $ionicHis }); }; + $scope.updateView = function(message) { + $scope.loading = false; + $scope.id = message.id; + $scope.formData = message; + $scope.canDelete = true; + $scope.motion.show({selector: '.view-message .list .item'}); + }; + $scope.delete = function() { if ($scope.actionsPopover) { $scope.actionsPopover.hide(); @@ -781,7 +894,8 @@ function ESMessageViewController($scope, $state, $timeout, $translate, $ionicHis destUid: $scope.formData.name||$scope.formData.uid, title: prefix + $scope.formData.title, content: content, - isReply: true + isReply: true, + wallet: $scope.walletId }); }) .then(function(sent) { @@ -796,7 +910,7 @@ function ESMessageViewController($scope, $state, $timeout, $translate, $ionicHis }; } -function PopoverMessageController($scope, UIUtils, $state, csWallet, esHttp, esMessage, esModals) { +function PopoverMessageController($scope, UIUtils, $state, csWallet, esHttp, esMessage, esModals, $timeout) { 'ngInject'; var defaultSearchLimit = 40; @@ -872,7 +986,7 @@ function PopoverMessageController($scope, UIUtils, $state, csWallet, esHttp, esM $scope.select = function(notification) { if (!notification.read) notification.read = true; - $state.go('app.user_view_message', {id: notification.id}); + $state.go('app.user_view_message', {messageId: notification.id}); $scope.closePopover(notification); }; @@ -889,11 +1003,18 @@ function PopoverMessageController($scope, UIUtils, $state, csWallet, esHttp, esM /* -- Modals -- */ $scope.showNewMessageModal = function(parameters) { + $scope.closePopover(); - return esModals.showMessageCompose(parameters) - .then(function(id) { - if (id) UIUtils.toast.show('MESSAGE.INFO.MESSAGE_SENT'); - }); + + $timeout(function() { + parameters = parameters ||Â {}; + parameters.wallet = $scope.walletId; + + esModals.showMessageCompose(parameters) + .then(function(id) { + if (id) UIUtils.toast.show('MESSAGE.INFO.MESSAGE_SENT'); + }); + }, 500); // Timeout need, to avoid freeze }; /* -- listeners -- */ diff --git a/www/plugins/es/js/services/message-services.js b/www/plugins/es/js/services/message-services.js index b011479d1ef2437e001babc634af685f6d9f3021..192bb5059c5396e13a92b8ccf3f97592d2ad1216 100644 --- a/www/plugins/es/js/services/message-services.js +++ b/www/plugins/es/js/services/message-services.js @@ -66,7 +66,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', console.debug('[ES] [message] Loading count...'); // Count unread messages - countUnreadMessages(data.pubkey) + countUnreadMessages(data.pubkey, csWallet) .then(function(unreadCount){ data.messages = data.messages || {}; data.messages.unreadCount = unreadCount; @@ -81,8 +81,9 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', return deferred.promise; } - function countUnreadMessages(pubkey) { - pubkey = pubkey || (csWallet.isLogin() ? csWallet.data.pubkey : pubkey); + function countUnreadMessages(pubkey, wallet) { + wallet = wallet ||Â csWallet; + pubkey = pubkey || (wallet.isLogin() ? wallet.data.pubkey : pubkey); if (!pubkey) { throw new Error('no pubkey, and user not connected.'); } @@ -105,7 +106,8 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', } // Listen message changes - function onNewMessageEvent(event) { + function onNewMessageEvent(event, wallet) { + wallet = wallet ||Â csWallet; console.debug("[ES] [message] detected new message (from notification service)"); var notification = new EsNotification(event); @@ -115,8 +117,8 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', csWot.extend(notification, 'issuer') .then(function() { - csWallet.data.messages = csWallet.data.messages || {}; - csWallet.data.messages.unreadCount++; + wallet.data.messages = wallet.data.messages || {}; + wallet.data.messages.unreadCount++; // Raise event api.data.raise.new(notification); @@ -168,17 +170,19 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', } function loadMessageNotifications(options) { - if (!csWallet.isLogin()) { - return $q.when([]); // Should never happen - } options = options || {}; options.from = options.from || 0; options.size = options.size || constants.DEFAULT_LOAD_SIZE; + var wallet = options.wallet ||Â csWallet; + + if (!wallet.isLogin()) { + return $q.when([]); // Should never happen + } var request = { sort: { "time" : "desc" }, - query: {bool: {filter: {term: {recipient: csWallet.data.pubkey}}}}, + query: {bool: {filter: {term: {recipient: wallet.data.pubkey}}}}, from: options.from, size: options.size, _source: fields.notifications @@ -250,7 +254,9 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', options.filter = angular.isDefined(options.filter) ? options.filter : undefined; options.from = options.from || 0; - var promise = csWallet.auth() + var wallet = options.wallet || csWallet; + + var promise = wallet.auth() .then(function(walletData) { // Get encrypted message (with common fields) @@ -286,8 +292,8 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', } if (options.from === 0 && !options.filter) { - csWallet.data.messages = csWallet.data.messages || {}; - csWallet.data.messages.count = messages.length; + wallet.data.messages = wallet.data.messages || {}; + wallet.data.messages.count = messages.length; } return messages; @@ -305,8 +311,9 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', options = options || {}; options.type = options.type || 'inbox'; options.summary = angular.isDefined(options.summary) ? options.summary : false/*summary not need by default*/; + var wallet = options.wallet || csWallet; - return csWallet.auth() + return wallet.auth() .then(function(walletData) { return raw.getByTypeAndId({id: id, type: options.type}) .then(function(hit) { @@ -448,8 +455,9 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', } // Mark a message as read - function markMessageAsRead(message, type) { - type = type || 'inbox'; + function markMessageAsRead(message, options) { + var type = options && options.type || 'inbox'; + var wallet = options && options.wallet || csWallet; if (message.read) { var deferred = $q.defer(); deferred.resolve(); @@ -457,7 +465,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', } message.read = true; - return csWallet.getKeypair() + return wallet.getKeypair() // Prepare the read_signature to sent .then(function(keypair) { @@ -472,15 +480,16 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', // Update message count .then(function() { if (type == 'inbox') { - csWallet.data.messages = csWallet.data.messages || {}; - csWallet.data.messages.unreadCount = csWallet.data.messages.unreadCount ? csWallet.data.messages.unreadCount - 1 : 0; + wallet.data.messages = wallet.data.messages || {}; + wallet.data.messages.unreadCount = wallet.data.messages.unreadCount ? wallet.data.messages.unreadCount - 1 : 0; } }); } // Mark all messages as read - function markAllMessageAsRead() { - return csWallet.auth() + function markAllMessageAsRead(options) { + var wallet = options && options.wallet || csWallet; + return wallet.auth() .then(function(walletData) { // Get all messages hash @@ -510,8 +519,8 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', }) .then(function () { // update message count - csWallet.data.messages = csWallet.data.messages || {}; - csWallet.data.messages.unreadCount = 0; + wallet.data.messages = wallet.data.messages || {}; + wallet.data.messages.unreadCount = 0; }); }); } diff --git a/www/plugins/es/js/services/social-services.js b/www/plugins/es/js/services/social-services.js index ee9ad619df470eaf45da042706f94bc150cbfbd2..679afbd9b9d8ae41a542b71f418ea86386ea1b6e 100644 --- a/www/plugins/es/js/services/social-services.js +++ b/www/plugins/es/js/services/social-services.js @@ -1,6 +1,6 @@ angular.module('cesium.es.social.services', ['cesium.es.crypto.services']) - .factory('SocialUtils', function($filter, $q, CryptoUtils, BMA, csWallet, esCrypto) { + .factory('SocialUtils', function($filter, $q, CryptoUtils, BMA, csWallet, esCrypto, $timeout) { 'ngInject'; function SocialUtils() { diff --git a/www/plugins/es/templates/message/compose_form.html b/www/plugins/es/templates/message/compose_form.html index b06754f7f2a0439616179f8c3f8f97ecafc636b0..c8168edbaf1f657d934c4a7876b2a272fcd1ec1f 100644 --- a/www/plugins/es/templates/message/compose_form.html +++ b/www/plugins/es/templates/message/compose_form.html @@ -41,14 +41,14 @@ <!-- Object --> <div class="item item-input" ng-class="{'item-input-error': form.$submitted && form.title.$invalid}"> - <!--<span class="input-label">{{'MESSAGE.COMPOSE.OBJECT' | translate}}</span>--> <input type="text" + autocomplete="off" placeholder="{{'MESSAGE.COMPOSE.OBJECT_HELP' | translate}}" name="title" ng-model="formData.title" ng-maxlength="256" required> - </input> + <span class="badge item-note" ng-if="isReply">({{'MESSAGE.COMPOSE.OBJECT' | translate}})</span> </div> <div class="form-errors" ng-show="form.$submitted && form.title.$error" @@ -66,6 +66,7 @@ ng-class="{'item-input-error': form.$submitted && form.content.$invalid}"> <span class="input-label">{{'MESSAGE.COMPOSE.MESSAGE' | translate}}</span> <textarea placeholder="{{'MESSAGE.COMPOSE.MESSAGE_HELP' | translate}}" + autocomplete="off" name="content" ng-model="formData.content" rows="8" diff --git a/www/plugins/es/templates/message/list.html b/www/plugins/es/templates/message/list.html index 76ca49ef83f963ae6f559e06f31cddb9ed4f0978..a352f5d4c39e44ec8f3522d6c7e577368bb93395 100644 --- a/www/plugins/es/templates/message/list.html +++ b/www/plugins/es/templates/message/list.html @@ -9,7 +9,7 @@ <ion-item class="item item-border-large item-avatar item-icon-right ink" ng-repeat="msg in search.results" - ui-sref="app.user_view_message({type:type, id:msg.id})"> + ng-click="select(msg)"> <i ng-if="::!msg.avatar" class="item-image icon" ng-class="{'ion-person': msg.uid, 'ion-email': !msg.uid}"></i> <i ng-if="::msg.avatar" class="item-image avatar" style="background-image: url({{::msg.avatar.src}})"></i> diff --git a/www/plugins/es/templates/wallet/item_wallet_extend.html b/www/plugins/es/templates/wallet/item_wallet_extend.html index 9159ee814da1f80b0ad694bbfee3b19f52f83569..d3f3eb877466686db9913f321f28c5ff3804e9a8 100644 --- a/www/plugins/es/templates/wallet/item_wallet_extend.html +++ b/www/plugins/es/templates/wallet/item_wallet_extend.html @@ -3,7 +3,7 @@ <i class="dark ion-person-stalker"></i> {{walletData.invitations.unreadCount}} </a> - <a ng-if="walletData.messages.unreadCount" ui-sref="app.view_messages_by_id({id: wallet.id})"> + <a ng-if="walletData.messages.unreadCount" ui-sref="app.user_messages_by_id.tab_inbox({id: wallet.id})"> <i class="dark ion-email"></i> {{walletData.messages.unreadCount}} </a>