From 0e658af1e3fe6af144f4fcfd766aab744a5d7a83 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sat, 12 Jul 2014 15:53:45 +0400 Subject: [PATCH] Fixed time offsets --- app/js/lib/mtproto.js | 5 ----- app/js/services.js | 23 +++++++++++++---------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/app/js/lib/mtproto.js b/app/js/lib/mtproto.js index 42ee4577..406545b0 100644 --- a/app/js/lib/mtproto.js +++ b/app/js/lib/mtproto.js @@ -160,14 +160,9 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) return changed; }; - function getTimeOffset () { - return timeOffset; - }; - return { generateID: generateMessageID, applyServerTime: applyServerTime, - getTimeOffset: getTimeOffset }; }) diff --git a/app/js/services.js b/app/js/services.js index fa3db00c..beb2ea6a 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -673,7 +673,7 @@ angular.module('myApp.services', []) } }) -.service('AppMessagesManager', function ($q, $rootScope, $location, $filter, ApiUpdatesManager, AppUsersManager, AppChatsManager, AppPeersManager, AppPhotosManager, AppVideoManager, AppDocsManager, AppAudioManager, MtpApiManager, MtpApiFileManager, MtpTimeManager, RichTextProcessor, NotificationsManager, SearchIndexManager) { +.service('AppMessagesManager', function ($q, $rootScope, $location, $filter, ApiUpdatesManager, AppUsersManager, AppChatsManager, AppPeersManager, AppPhotosManager, AppVideoManager, AppDocsManager, AppAudioManager, MtpApiManager, MtpApiFileManager, RichTextProcessor, NotificationsManager, SearchIndexManager, Storage) { var messagesStorage = {}; var messagesForHistory = {}; @@ -692,12 +692,18 @@ angular.module('myApp.services', []) var lastSearchFilter = {}, lastSearchResults = []; - var serverTimeOffset = MtpTimeManager.getTimeOffset(), + var serverTimeOffset = 0, timestampNow = tsNow(true), midnightNoOffset = timestampNow - (timestampNow % 86400), midnightOffseted = new Date(), midnightOffset; + Storage.get('server_time_offset').then(function (to) { + if (to) { + serverTimeOffset = to; + } + }); + midnightOffseted.setHours(0); midnightOffseted.setMinutes(0); midnightOffseted.setSeconds(0); @@ -1190,6 +1196,8 @@ angular.module('myApp.services', []) angular.forEach(apiMessages, function (apiMessage) { messagesStorage[apiMessage.id] = apiMessage; + apiMessage.date -= serverTimeOffset; + if (apiMessage.media && apiMessage.media._ == 'messageMediaPhoto') { AppPhotosManager.savePhoto(apiMessage.media.photo); } @@ -1228,7 +1236,7 @@ angular.module('myApp.services', []) to_id: AppPeersManager.getOutputPeer(peerID), out: true, unread: true, - date: tsNow() / 1000, + date: tsNow(true) + serverTimeOffset, message: text, media: {_: 'messageMediaEmpty'}, random_id: randomIDS, @@ -1352,7 +1360,7 @@ angular.module('myApp.services', []) to_id: AppPeersManager.getOutputPeer(peerID), out: true, unread: true, - date: tsNow() / 1000, + date: tsNow(true) + serverTimeOffset, message: '', media: media, random_id: randomIDS, @@ -1493,7 +1501,7 @@ angular.module('myApp.services', []) to_id: AppPeersManager.getOutputPeer(peerID), out: true, unread: true, - date: tsNow() / 1000, + date: tsNow(true) + serverTimeOffset, message: '', media: media, random_id: randomIDS, @@ -1939,9 +1947,6 @@ angular.module('myApp.services', []) historyStorage = historiesStorage[peerID] = {count: null, history: [message.id], pending: []}; } - // Fix time offset - message.date -= serverTimeOffset; - saveMessages([message]); if (historyStorage.count !== null) { @@ -3233,7 +3238,6 @@ angular.module('myApp.services', []) var notificationsUiSupport = 'Notification' in window; var notificationsShown = {}; - // var lastClosed = []; var notificationIndex = 0; var notificationsCount = 0; var peerSettings = {}; @@ -3428,7 +3432,6 @@ angular.module('myApp.services', []) notification.onclose = function () { delete notificationsShown[key]; - // lastClosed.push(tsNow()); notificationsClear(); };