From fef4457417006ea35a5e20ae9ce5eef89b460a86 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Mon, 7 Jul 2014 12:55:46 +0400 Subject: [PATCH] Fixed conversation w/ deleted message on top Closes #349 Closes #326 --- app/js/controllers.js | 15 ++++++- app/js/lib/mtproto.js | 35 ++++++++++------- app/js/services.js | 6 +-- app/partials/dialog.html | 85 +++++++++++++++++++++------------------- 4 files changed, 81 insertions(+), 60 deletions(-) diff --git a/app/js/controllers.js b/app/js/controllers.js index 013967bb..07966859 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -399,12 +399,23 @@ angular.module('myApp.controllers', []) $scope.$on('dialog_flush', function (e, dialog) { for (var i = 0; i < $scope.dialogs.length; i++) { if ($scope.dialogs[i].peerID == dialog.peerID) { - $scope.dialogs.splice(i, 1); + $scope.dialogs[i].deleted = true; break; } } }); + $scope.$on('history_delete', function (e, historyUpdate) { + for (var i = 0; i < $scope.dialogs.length; i++) { + if ($scope.dialogs[i].peerID == historyUpdate.peerID) { + if (historyUpdate.msgs[$scope.dialogs[i].id]) { + $scope.dialogs[i].deleted = true; + } + break; + } + } + }); + $scope.$on('contact_imported', function () { if (contactsShown) { loadDialogs(); @@ -1091,7 +1102,7 @@ angular.module('myApp.controllers', []) $scope.history = newHistory; updateHistoryGroups(); } - }) + }); $scope.$on('dialog_flush', function (e, dialog) { if (dialog.peerID == $scope.curDialog.peerID) { diff --git a/app/js/lib/mtproto.js b/app/js/lib/mtproto.js index 9382e747..19050ab1 100644 --- a/app/js/lib/mtproto.js +++ b/app/js/lib/mtproto.js @@ -118,7 +118,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) return new SecureRandom(); }) -.factory('MtpMessageIdGenerator', function (Storage) { +.factory('MtpDateManager', function (Storage) { var lastMessageID = [0, 0], timeOffset = 0; @@ -155,18 +155,23 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) lastMessageID = [0, 0]; timeOffset = newTimeOffset; - console.log('Apply server time', serverTime, localTime, newTimeOffset, changed); + console.log(dT(), 'Apply server time', serverTime, localTime, newTimeOffset, changed); return changed; }; + function getTimeOffset () { + return timeOffset; + }; + return { generateID: generateMessageID, - applyServerTime: applyServerTime + applyServerTime: applyServerTime, + getTimeOffset: getTimeOffset }; }) -.factory('MtpAuthorizer', function (MtpDcConfigurator, MtpRsaKeysManager, MtpSecureRandom, MtpMessageIdGenerator, CryptoWorker, $http, $q, $timeout) { +.factory('MtpAuthorizer', function (MtpDcConfigurator, MtpRsaKeysManager, MtpSecureRandom, MtpDateManager, CryptoWorker, $http, $q, $timeout) { function mtpSendPlainRequest (dcID, requestBuffer) { var requestLength = requestBuffer.byteLength, @@ -174,7 +179,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) var header = new TLSerialization(); header.storeLongP(0, 0, 'auth_key_id'); // Auth key - header.storeLong(MtpMessageIdGenerator.generateID(), 'msg_id'); // Msg_id + header.storeLong(MtpDateManager.generateID(), 'msg_id'); // Msg_id header.storeInt(requestLength, 'request_length'); var headerBuffer = header.getBuffer(), @@ -386,7 +391,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) throw new Error('server_DH_inner_data SHA1-hash mismatch'); } - MtpMessageIdGenerator.applyServerTime(auth.serverTime, auth.localTime); + MtpDateManager.applyServerTime(auth.serverTime, auth.localTime); }; function mtpSendSetClientDhParams(auth) { @@ -534,7 +539,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) }) -.factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerator, MtpSecureRandom, Storage, CryptoWorker, $http, $q, $timeout, $interval, $rootScope) { +.factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpDateManager, MtpSecureRandom, Storage, CryptoWorker, $http, $q, $timeout, $interval, $rootScope) { var updatesProcessor, iii = 0, @@ -637,7 +642,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) sentMessage.inner = newInner; } - sentMessage.msg_id = MtpMessageIdGenerator.generateID(); + sentMessage.msg_id = MtpDateManager.generateID(); sentMessage.seq_no = this.generateSeqNo( sentMessage.notContentRelated || sentMessage.container @@ -664,7 +669,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) serializer.storeMethod(method, params); - var messageID = MtpMessageIdGenerator.generateID(), + var messageID = MtpDateManager.generateID(), seqNo = this.generateSeqNo(), message = { msg_id: messageID, @@ -685,7 +690,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) var serializer = new TLSerialization({mtproto: true}); serializer.storeObject(object, 'Object'); - var messageID = MtpMessageIdGenerator.generateID(), + var messageID = MtpDateManager.generateID(), seqNo = this.generateSeqNo(options.notContentRelated), message = { msg_id: messageID, @@ -720,7 +725,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) options.resultType = serializer.storeMethod(method, params); - var messageID = MtpMessageIdGenerator.generateID(), + var messageID = MtpDateManager.generateID(), seqNo = this.generateSeqNo(), message = { msg_id: messageID, @@ -844,7 +849,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) serializer.storeMethod('ping', {ping_id: pingID}); var pingMessage = { - msg_id: MtpMessageIdGenerator.generateID(), + msg_id: MtpDateManager.generateID(), seq_no: this.generateSeqNo(true), body: serializer.getBytes() }; @@ -959,7 +964,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) var serializer = new TLSerialization({mtproto: true}); serializer.storeMethod('http_wait', {max_delay: 0, wait_after: 0, max_wait: 1000}); messages.push({ - msg_id: MtpMessageIdGenerator.generateID(), + msg_id: MtpDateManager.generateID(), seq_no: this.generateSeqNo(), body: serializer.getBytes() }); @@ -990,7 +995,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) } var containerSentMessage = { - msg_id: MtpMessageIdGenerator.generateID(), + msg_id: MtpDateManager.generateID(), seq_no: this.generateSeqNo(true), container: true, inner: innerMessages @@ -1340,7 +1345,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) } if (message.error_code == 16 || message.error_code == 17) { - if (MtpMessageIdGenerator.applyServerTime( + if (MtpDateManager.applyServerTime( bigStringInt(messageID).shiftRight(32).toString(10) )) { this.updateSession(); diff --git a/app/js/services.js b/app/js/services.js index 43b282a5..88555cc4 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -1992,14 +1992,14 @@ angular.module('myApp.services', []) history.msgs[messageID] = true; if (messagesForHistory[messageID]) { - messagesForHistory[messageID].DELETED = true; + messagesForHistory[messageID].deleted = true; delete messagesForHistory[messageID]; } if (messagesForDialogs[messageID]) { - messagesForDialogs[messageID].DELETED = true; + messagesForDialogs[messageID].deleted = true; delete messagesForDialogs[messageID]; } - message.DELETED = true; + message.deleted = true; delete messagesStorage[messageID]; } } diff --git a/app/partials/dialog.html b/app/partials/dialog.html index 603bc638..8f17d7ab 100644 --- a/app/partials/dialog.html +++ b/app/partials/dialog.html @@ -30,53 +30,58 @@ -
- - You{{((dialogMessage.out || dialogMessage.peerID < 0) && (dialogMessage.message.length || dialogMessage.media && dialogMessage.media._ != 'messageMediaEmpty')) ? ':' : ''}} - +
+
+ deleted message +
+
+ + You{{((dialogMessage.out || dialogMessage.peerID < 0) && (dialogMessage.message.length || dialogMessage.media && dialogMessage.media._ != 'messageMediaEmpty')) ? ':' : ''}} + - - Photo - Video - Document - Audio - Location - Contact - + + Photo + Video + Document + Audio + Location + Contact + - - created the group - changed group name - changed group photo - removed group photo + + created the group + changed group name + changed group photo + removed group photo - - - returned to group + + + returned to group + + + invited + - - invited + + + + left group + + + kicked + - - - left group - - - kicked - - - - - + +