Added message drafts saved in localStorage
This commit is contained in:
parent
379abc778a
commit
7a62a2213c
@ -37,14 +37,14 @@
|
||||
|
||||
|
||||
<script type="text/javascript" src="js/lib/config.js"></script>
|
||||
<script type="text/javascript" src="js/lib/mtproto.js?10"></script>
|
||||
<script type="text/javascript" src="js/lib/mtproto.js?11"></script>
|
||||
|
||||
<script type="text/javascript" src="js/util.js"></script>
|
||||
<script type="text/javascript" src="js/app.js?5"></script>
|
||||
<script type="text/javascript" src="js/services.js?6"></script>
|
||||
<script type="text/javascript" src="js/controllers.js?10"></script>
|
||||
<script type="text/javascript" src="js/controllers.js?11"></script>
|
||||
<script type="text/javascript" src="js/filters.js?3"></script>
|
||||
<script type="text/javascript" src="js/directives.js?6"></script>
|
||||
<script type="text/javascript" src="js/directives.js?7"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
@ -329,6 +329,7 @@ angular.module('myApp.controllers', [])
|
||||
$scope.$broadcast('ui_history_change');
|
||||
|
||||
AppMessagesManager.readHistory($scope.curDialog.inputPeer);
|
||||
|
||||
}, function () {
|
||||
$scope.state = {error: true};
|
||||
});
|
||||
@ -408,7 +409,7 @@ angular.module('myApp.controllers', [])
|
||||
$scope.$on('user_update', angular.noop);
|
||||
})
|
||||
|
||||
.controller('AppImSendController', function ($scope, $timeout, MtpApiManager, AppPeersManager, AppMessagesManager, ApiUpdatesManager, MtpApiFileManager) {
|
||||
.controller('AppImSendController', function ($scope, $timeout, MtpApiManager, AppConfigManager, AppPeersManager, AppMessagesManager, ApiUpdatesManager, MtpApiFileManager) {
|
||||
|
||||
$scope.$watch('curDialog.peer', resetDraft);
|
||||
$scope.$on('user_update', angular.noop);
|
||||
@ -419,6 +420,16 @@ angular.module('myApp.controllers', [])
|
||||
$scope.$watch('draftMessage.text', function (newVal) {
|
||||
AppMessagesManager.readHistory($scope.curDialog.inputPeer);
|
||||
|
||||
if (newVal.length) {
|
||||
var backupDraftObj = {};
|
||||
backupDraftObj['draft' + $scope.curDialog.peerID] = newVal;
|
||||
AppConfigManager.set(backupDraftObj);
|
||||
// dLog('draft save', backupDraftObj);
|
||||
} else {
|
||||
AppConfigManager.remove('draft' + $scope.curDialog.peerID);
|
||||
// dLog('draft delete', 'draft' + $scope.curDialog.peerID);
|
||||
}
|
||||
|
||||
var now = +new Date();
|
||||
if (newVal === undefined || !newVal.length || now - lastTyping < 6000) {
|
||||
return;
|
||||
@ -461,10 +472,18 @@ angular.module('myApp.controllers', [])
|
||||
}
|
||||
|
||||
|
||||
function resetDraft () {
|
||||
$scope.draftMessage = {
|
||||
text: ''
|
||||
};
|
||||
function resetDraft (newPeer) {
|
||||
if (newPeer) {
|
||||
AppConfigManager.get('draft' + $scope.curDialog.peerID).then(function (draftText) {
|
||||
// dLog('Restore draft', 'draft' + $scope.curDialog.peerID, draftText);
|
||||
$scope.draftMessage.text = draftText || '';
|
||||
// dLog('send broadcast', $scope.draftMessage);
|
||||
$scope.$broadcast('ui_peer_draft');
|
||||
});
|
||||
} else {
|
||||
// dLog('Reset peer');
|
||||
$scope.draftMessage.text = '';
|
||||
}
|
||||
}
|
||||
|
||||
function onFilesSelected (newVal) {
|
||||
|
@ -282,20 +282,27 @@ angular.module('myApp.directives', ['myApp.filters'])
|
||||
|
||||
if (richTextarea) {
|
||||
scope.$watch('draftMessage.text', function (newVal) {
|
||||
dLog('on update', newVal);
|
||||
if (!newVal.length && !messageField.value.length) {
|
||||
$timeout(function () {
|
||||
$(richTextarea).html('');
|
||||
updateField();
|
||||
}, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateField () {
|
||||
dLog(scope.draftMessage);
|
||||
dLog('update field', scope.draftMessage.text);
|
||||
$(richTextarea).text(scope.draftMessage.text || '');
|
||||
}
|
||||
|
||||
$('body').on('dragenter dragleave dragover drop', onDragDropEvent);
|
||||
|
||||
scope.$on('ui_peer_change', focusField);
|
||||
scope.$on('ui_history_change', focusField);
|
||||
scope.$on('ui_message_send', focusField);
|
||||
scope.$on('ui_peer_draft', updateField);
|
||||
|
||||
scope.$on('$destroy', function cleanup() {
|
||||
$('body').off('dragenter dragleave dragover drop', onDragDropEvent);
|
||||
|
@ -351,7 +351,7 @@ function TLSerialization (options) {
|
||||
|
||||
this.createBuffer();
|
||||
|
||||
this.debug = options.debug !== undefined ? options.debug : window._debugMode;
|
||||
// this.debug = options.debug !== undefined ? options.debug : window._debugMode;
|
||||
this.mtproto = options.mtproto || false;
|
||||
return this;
|
||||
}
|
||||
@ -631,7 +631,7 @@ function TLDeserialization (buffer, options) {
|
||||
this.intView = new Uint32Array(this.buffer);
|
||||
this.byteView = new Uint8Array(this.buffer);
|
||||
|
||||
this.debug = options.debug !== undefined ? options.debug : window._debugMode;
|
||||
// this.debug = options.debug !== undefined ? options.debug : window._debugMode;
|
||||
this.mtproto = options.mtproto || false;
|
||||
return this;
|
||||
}
|
||||
@ -1021,7 +1021,7 @@ factory('MtpMessageIdGenerator', function (AppConfigManager) {
|
||||
});
|
||||
|
||||
function generateMessageID () {
|
||||
var timeTicks = +new Date() + timeOffset,
|
||||
var timeTicks = +new Date() + (timeOffset * 1000),
|
||||
timeSec = Math.floor(timeTicks / 1000),
|
||||
timeMSec = timeTicks % 1000,
|
||||
random = nextRandomInt(0xFFFF);
|
||||
@ -1042,6 +1042,7 @@ factory('MtpMessageIdGenerator', function (AppConfigManager) {
|
||||
|
||||
function applyServerTime (serverTime, localTime) {
|
||||
timeOffset = serverTime - Math.floor((localTime || +new Date()) / 1000);
|
||||
dLog('Apply server time', serverTime, localTime, timeOffset);
|
||||
AppConfigManager.set({server_time_offset: timeOffset});
|
||||
};
|
||||
|
||||
@ -1787,7 +1788,9 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato
|
||||
|
||||
this.sentMessages[message.msg_id] = containerSentMessage;
|
||||
|
||||
// dLog('Container', innerMessages, message.msg_id, message.seq_no);
|
||||
if (window._debugMode) {
|
||||
dLog('Container', innerMessages, message.msg_id, message.seq_no);
|
||||
}
|
||||
} else {
|
||||
if (message.noResponse) {
|
||||
noResponseMsgs.push(message.msg_id);
|
||||
@ -2035,7 +2038,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato
|
||||
break;
|
||||
|
||||
case 'bad_server_salt':
|
||||
dLog('bad server salt', message);
|
||||
dLog('Bad server salt', message);
|
||||
var sentMsg = this.sentMessages[message.bad_msg_id];
|
||||
if (!sentMsg || sentMsg.seq_no != message.bad_msg_seqno) {
|
||||
dLog(message.bad_msg_id, message.bad_msg_seqno);
|
||||
@ -2047,6 +2050,21 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato
|
||||
this.ackMessage(messageID);
|
||||
break;
|
||||
|
||||
case 'bad_msg_notification':
|
||||
dLog('Bad msg notification', message);
|
||||
var sentMsg = this.sentMessages[message.bad_msg_id];
|
||||
if (!sentMsg || sentMsg.seq_no != message.bad_msg_seqno) {
|
||||
dLog(message.bad_msg_id, message.bad_msg_seqno);
|
||||
throw new Error('Bad msg notification for invalid message');
|
||||
}
|
||||
|
||||
if (message.error_code == 16 || message.error_code == 17) {
|
||||
MtpMessageIdGenerator.applyServerTime((new BigInteger(messageID, 10)).shiftRight(32).toString(10));
|
||||
this.pushResend(message.bad_msg_id);
|
||||
this.ackMessage(messageID);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'message':
|
||||
this.serverMessages.push(message.msg_id);
|
||||
this.processMessage(message.body, message.msg_id, sessionID);
|
||||
@ -2439,7 +2457,7 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) {
|
||||
cacheFileWriter,
|
||||
errorHandler = function (error) {
|
||||
deferred.reject(error);
|
||||
if (cacheFileWriter) cacheFileWriter.truncate();
|
||||
if (cacheFileWriter) cacheFileWriter.truncate(0);
|
||||
errorHandler = angular.noop;
|
||||
};
|
||||
|
||||
@ -2474,7 +2492,7 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) {
|
||||
cacheFileWriter,
|
||||
errorHandler = function (error) {
|
||||
deferred.reject(error);
|
||||
if (cacheFileWriter) cacheFileWriter.truncate();
|
||||
if (cacheFileWriter) cacheFileWriter.truncate(0);
|
||||
errorHandler = angular.noop;
|
||||
},
|
||||
doDownload = function () {
|
||||
@ -2543,7 +2561,7 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) {
|
||||
console.error(error);
|
||||
// dLog('fail');
|
||||
deferred.reject(error);
|
||||
if (cacheFileWriter) cacheFileWriter.truncate();
|
||||
if (cacheFileWriter) cacheFileWriter.truncate(0);
|
||||
errorHandler = angular.noop;
|
||||
},
|
||||
saveToFileEntry = function (fileEntry) {
|
||||
@ -2685,7 +2703,7 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) {
|
||||
errorHandler = function (error) {
|
||||
dLog('fail');
|
||||
deferred.reject(error);
|
||||
if (cacheFileWriter) cacheFileWriter.truncate();
|
||||
if (cacheFileWriter) cacheFileWriter.truncate(0);
|
||||
errorHandler = angular.noop;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user