From a25619bf196d2fc7f219c405b2510f6be56ce749 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 2 Jul 2015 23:53:44 +0300 Subject: [PATCH] Start button draft --- app/js/controllers.js | 69 ++++++++++++++++++++++++++++-------- app/js/directives.js | 2 +- app/js/locales/en-us.json | 1 + app/partials/desktop/im.html | 12 +++++-- 4 files changed, 66 insertions(+), 18 deletions(-) diff --git a/app/js/controllers.js b/app/js/controllers.js index 9e0b489e..21e35461 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -407,9 +407,12 @@ angular.module('myApp.controllers', ['myApp.i18n']) $scope.$on('$routeUpdate', updateCurDialog); + var pendingParams = false; $scope.$on('history_focus', function (e, peerData) { $modalStack.dismissAll(); - if (peerData.peerString == $scope.curDialog.peer && peerData.messageID == $scope.curDialog.messageID) { + if (peerData.peerString == $scope.curDialog.peer && + peerData.messageID == $scope.curDialog.messageID && + !peerData.startParam) { $scope.$broadcast(peerData.messageID ? 'ui_history_change_scroll' : 'ui_history_focus'); } else { var peerID = AppPeersManager.getPeerID(peerData.peerString); @@ -420,7 +423,19 @@ angular.module('myApp.controllers', ['myApp.i18n']) peer = '@' + username; } } - $location.url('/im?p=' + peer + (peerData.messageID ? '&m=' + peerData.messageID : '')); + if (peerData.messageID || peerData.startParam) { + pendingParams = { + messageID: peerData.messageID, + startParam: peerData.startParam + }; + } else { + pendingParams = false; + } + if ($routeParams.p != peer) { + $location.url('/im?p=' + peer); + } else { + updateCurDialog(); + } } }); @@ -568,21 +583,24 @@ angular.module('myApp.controllers', ['myApp.i18n']) } else { lastSearch = false; } + var addParams = pendingParams || {}; + pendingParams = false; + addParams.messageID = parseInt(addParams.messageID) || false; + addParams.startParam = addParams.startParam || false; + if ($routeParams.p && $routeParams.p.charAt(0) == '@') { if ($scope.curDialog === undefined) { $scope.curDialog = {}; } AppUsersManager.resolveUsername($routeParams.p.substr(1)).then(function (userID) { - $scope.curDialog = { - peer: AppUsersManager.getUserString(userID), - messageID: parseInt($routeParams.m) || false - }; + $scope.curDialog = angular.extend({ + peer: AppUsersManager.getUserString(userID) + }, addParams); }); } else { - $scope.curDialog = { - peer: $routeParams.p || false, - messageID: parseInt($routeParams.m) || false - }; + $scope.curDialog = angular.extend({ + peer: $routeParams.p || false + }, addParams); } } @@ -740,8 +758,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) $location.url( '/im' + ($scope.curDialog.peer - ? '?p=' + $scope.curDialog.peer + - ($scope.curDialog.messageID ? '&m=' + $scope.curDialog.messageID : '') + ? '?p=' + $scope.curDialog.peer : '' ) ); @@ -1016,8 +1033,9 @@ angular.module('myApp.controllers', ['myApp.i18n']) var newPeer = newDialog.peer || $scope.curDialog.peer || ''; peerID = AppPeersManager.getPeerID(newPeer); - - if (peerID == $scope.curDialog.peerID && oldDialog.messageID == newDialog.messageID) { + if (peerID == $scope.curDialog.peerID && + oldDialog.messageID == newDialog.messageID && + oldDialog.startParam == newDialog.startParam) { return false; } @@ -1025,10 +1043,13 @@ angular.module('myApp.controllers', ['myApp.i18n']) $scope.curDialog.peerID = peerID; $scope.curDialog.inputPeer = AppPeersManager.getInputPeer(newPeer); $scope.historyFilter.mediaType = false; + $scope.historyState.startBot = newDialog.startParam ? 1 : false; selectedCancel(true); - if (oldDialog.peer && oldDialog.peer == newDialog.peer && newDialog.messageID) { + if (oldDialog.peer && + oldDialog.peer == newDialog.peer && + newDialog.messageID) { messageFocusHistory(); } else if (peerID) { @@ -1319,11 +1340,29 @@ angular.module('myApp.controllers', ['myApp.i18n']) AppMessagesManager.readHistory($scope.curDialog.inputPeer); + if (!$scope.curDialog.messageID && + !inputMediaFilter && + peerID > 0 && + AppUsersManager.isBot(peerID) && + (!peerHistory.ids.length || peerHistory.ids.length == 1 && peerHistory.ids[0] < 0) + ) { + $scope.historyState.startBot = 2; + } + }, function () { safeReplaceObject($scope.state, {error: true}); }); } + $scope.botStartCancel = function () { + delete $scope.curDialog.startParam; + } + + $scope.botStart = function () { + AppMessagesManager.startBot(peerID, 0, $scope.curDialog.startParam); + delete $scope.curDialog.startParam; + } + function showEmptyHistory () { jump++; safeReplaceObject($scope.historyPeer, {}); diff --git a/app/js/directives.js b/app/js/directives.js index 2251dd18..6166500e 100755 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -395,7 +395,7 @@ angular.module('myApp.directives', ['myApp.filters']) var peerID = AppMessagesManager.getMessagePeer(message); var peerString = AppPeersManager.getPeerString(peerID); - $rootScope.$broadcast('history_focus', {peerString: peerString, messageID: message.id}); + $rootScope.$broadcast('history_focus', {peerString: peerString, messageID: message.id}); }) } diff --git a/app/js/locales/en-us.json b/app/js/locales/en-us.json index d94006c5..52250f93 100644 --- a/app/js/locales/en-us.json +++ b/app/js/locales/en-us.json @@ -398,6 +398,7 @@ "im_delete": "Delete {count}", "im_forward": "Forward {count}", "im_reply": "Reply", + "im_start": "Start", "im_reply_loading": "Loading{dots}", "im_photos_drop_text": "Drop photos here to send", "im_message_field_placeholder": "Write a message...", diff --git a/app/partials/desktop/im.html b/app/partials/desktop/im.html index 96a587f4..39883689 100644 --- a/app/partials/desktop/im.html +++ b/app/partials/desktop/im.html @@ -140,7 +140,7 @@
-
+
@@ -151,7 +151,15 @@
-
+
+
+ +
+ +
+
+ +