From d689ef25ccd1bcd1552d75cb74572b687fdc1fe0 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 20 Feb 2014 01:46:47 +0100 Subject: [PATCH] Offline mode bugfixes --- app/css/app.css | 2 + app/js/controllers.js | 97 ++++++++++++++++++++++++++----------------- app/js/lib/mtproto.js | 12 +++++- app/js/services.js | 18 ++++++-- 4 files changed, 84 insertions(+), 45 deletions(-) diff --git a/app/css/app.css b/app/css/app.css index 4466a3a2..48c621b8 100644 --- a/app/css/app.css +++ b/app/css/app.css @@ -1550,6 +1550,8 @@ img.img_fullsize { box-shadow: none; -webkit-transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s; transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s; + + -webkit-user-select: text; } .emoji-wysiwyg-editor img { width: 20px; diff --git a/app/js/controllers.js b/app/js/controllers.js index c0aaa764..b8889520 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -505,6 +505,7 @@ angular.module('myApp.controllers', []) $scope.missedCount = 0; } $scope.mediaType = mediaType || false; + $scope.history = []; loadHistory(); } @@ -719,19 +720,23 @@ angular.module('myApp.controllers', []) NotificationsManager.getPeerMuted($scope.userID).then(function (muted) { $scope.settings.notifications = !muted; - }); - $scope.$watch('settings.notifications', function(newValue) { - NotificationsManager.getPeerSettings($scope.userID).then(function (settings) { - if (newValue) { - settings.mute_until = 0; - } else { - settings.mute_until = 2000000000; + $scope.$watch('settings.notifications', function(newValue, oldValue) { + if (newValue === oldValue) { + return false; } - NotificationsManager.savePeerSettings($scope.userID, settings); + NotificationsManager.getPeerSettings($scope.userID).then(function (settings) { + if (newValue) { + settings.mute_until = 0; + } else { + settings.mute_until = 2000000000; + } + NotificationsManager.savePeerSettings($scope.userID, settings); + }); }); }); + $scope.goToHistory = function () { $rootScope.$broadcast('history_focus', {peerString: $scope.user.peerString}); }; @@ -763,19 +768,23 @@ angular.module('myApp.controllers', []) NotificationsManager.getPeerMuted(-$scope.chatID).then(function (muted) { $scope.settings.notifications = !muted; - }); - $scope.$watch('settings.notifications', function(newValue) { - NotificationsManager.getPeerSettings(-$scope.chatID).then(function (settings) { - if (newValue) { - settings.mute_until = 0; - } else { - settings.mute_until = 2000000000; + $scope.$watch('settings.notifications', function(newValue, oldValue) { + if (newValue === oldValue) { + return false; } - NotificationsManager.savePeerSettings(-$scope.chatID, settings); + NotificationsManager.getPeerSettings(-$scope.chatID).then(function (settings) { + if (newValue) { + settings.mute_until = 0; + } else { + settings.mute_until = 2000000000; + } + NotificationsManager.savePeerSettings(-$scope.chatID, settings); + }); }); }); + $scope.leaveGroup = function () { MtpApiManager.invokeApi('messages.deleteChatUser', { chat_id: $scope.chatID, @@ -843,34 +852,44 @@ angular.module('myApp.controllers', []) $scope.notify.desktop = !settings[0]; $scope.notify.sound = !settings[1]; $scope.send.enter = settings[2] ? '' : '1'; - }); - $scope.$watch('notify.sound', function(newValue) { - if (newValue) { - AppConfigManager.remove('notify_nosound'); - } else { - AppConfigManager.set({notify_nosound: true}); - NotificationsManager.clear(); - } - }); + $scope.$watch('notify.sound', function(newValue, oldValue) { + if (newValue === oldValue) { + return false; + } + if (newValue) { + AppConfigManager.remove('notify_nosound'); + } else { + AppConfigManager.set({notify_nosound: true}); + NotificationsManager.clear(); + } + }); - $scope.$watch('notify.desktop', function(newValue) { - if (newValue) { - AppConfigManager.remove('notify_nodesktop'); - } else { - AppConfigManager.set({notify_nodesktop: true}); - } - }); + $scope.$watch('notify.desktop', function(newValue, oldValue) { + if (newValue === oldValue) { + return false; + } + if (newValue) { + AppConfigManager.remove('notify_nodesktop'); + } else { + AppConfigManager.set({notify_nodesktop: true}); + } + }); - $scope.$watch('send.enter', function(newValue) { - if (newValue) { - AppConfigManager.remove('send_ctrlenter'); - } else { - AppConfigManager.set({send_ctrlenter: true}); - } - $rootScope.$broadcast('settings_changed'); + $scope.$watch('send.enter', function(newValue, oldValue) { + if (newValue === oldValue) { + return false; + } + if (newValue) { + AppConfigManager.remove('send_ctrlenter'); + } else { + AppConfigManager.set({send_ctrlenter: true}); + } + $rootScope.$broadcast('settings_changed'); + }); }); + $scope.error = {}; $scope.save = function (profileForm) { MtpApiManager.invokeApi('account.updateProfile', { diff --git a/app/js/lib/mtproto.js b/app/js/lib/mtproto.js index a98a5d0b..5b79145d 100644 --- a/app/js/lib/mtproto.js +++ b/app/js/lib/mtproto.js @@ -1637,13 +1637,18 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato if (!this.connectionInited) { serializer.storeInt(962726977, 'InokeWithLayer10'); serializer.storeInt(0x69796de9, 'initConnection'); - serializer.storeInt(777, 'api_id'); + serializer.storeInt(2496, 'api_id'); serializer.storeString(navigator.userAgent || 'Unknown UserAgent', 'device_model'); serializer.storeString(navigator.platform || 'Unknown Platform', 'system_version'); serializer.storeString('0.1', 'app_version'); serializer.storeString(navigator.language || 'en', 'lang_code'); } + if (options.afterMessageID) { + serializer.storeInt(0xcb9f372d, 'invokeAfterMsg'); + serializer.storeLong(options.afterMessageID, 'msg_id'); + } + serializer.storeMethod(method, params); var messageID = MtpMessageIdGenerator.generateID(), @@ -1656,7 +1661,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato }; if (window._debugMode) { - console.log('Api call', method, params, messageID, seqNo) + console.log('Api call', method, params, messageID, seqNo, options); } else { console.log('Api call', method, messageID, seqNo); } @@ -1711,6 +1716,9 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato if (!options || !options.noShedule) { this.sheduleRequest(); } + if (angular.isObject(options)) { + options.messageID = message.msg_id; + } return deferred.promise; }; diff --git a/app/js/services.js b/app/js/services.js index eaa67a68..a6cdf1e2 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -570,6 +570,7 @@ angular.module('myApp.services', []) var dialogsStorage = {count: null, dialogs: []}; var pendingByRandomID = {}; var pendingByMessageID = {}; + var pendingAfterMsgs = {}; var tempID = -1; @@ -958,11 +959,18 @@ angular.module('myApp.services', []) message.send = function () { toggleError(false); + var sentRequestOptions = {}; + if (pendingAfterMsgs[peerID]) { + sentRequestOptions.afterMessageID = pendingAfterMsgs[peerID].messageID; + } MtpApiManager.invokeApi('messages.sendMessage', { peer: inputPeer, message: text, random_id: randomID - }).then(function (result) { + }, sentRequestOptions).then(function (result) { + if (pendingAfterMsgs[peerID] === sentRequestOptions) { + delete pendingAfterMsgs[peerID]; + } if (ApiUpdatesManager.saveSeq(result.seq)) { ApiUpdatesManager.saveUpdate({ _: 'updateMessageID', @@ -981,6 +989,8 @@ angular.module('myApp.services', []) }, function (error) { toggleError(true); }); + + pendingAfterMsgs[peerID] = sentRequestOptions; }; saveMessages([message]); @@ -1016,8 +1026,6 @@ angular.module('myApp.services', []) attachType = 'doc'; } - console.log(11, options.isMedia, file.type, attachType); - if (historyStorage === undefined) { historyStorage = historiesStorage[peerID] = {count: null, history: [], pending: []}; } @@ -1347,7 +1355,9 @@ angular.module('myApp.services', []) } $rootScope.$on('apiUpdate', function (e, update) { - // console.log('on apiUpdate', update); + // if (update._ != 'updateUserStatus') { + // console.log('on apiUpdate', update); + // } switch (update._) { case 'updateMessageID': pendingByMessageID[update.id] = update.random_id;