Browse Source

Fixed time offsets

master
Igor Zhukov 10 years ago
parent
commit
0e658af1e3
  1. 5
      app/js/lib/mtproto.js
  2. 23
      app/js/services.js

5
app/js/lib/mtproto.js

@ -160,14 +160,9 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
return changed; return changed;
}; };
function getTimeOffset () {
return timeOffset;
};
return { return {
generateID: generateMessageID, generateID: generateMessageID,
applyServerTime: applyServerTime, applyServerTime: applyServerTime,
getTimeOffset: getTimeOffset
}; };
}) })

23
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 messagesStorage = {};
var messagesForHistory = {}; var messagesForHistory = {};
@ -692,12 +692,18 @@ angular.module('myApp.services', [])
var lastSearchFilter = {}, var lastSearchFilter = {},
lastSearchResults = []; lastSearchResults = [];
var serverTimeOffset = MtpTimeManager.getTimeOffset(), var serverTimeOffset = 0,
timestampNow = tsNow(true), timestampNow = tsNow(true),
midnightNoOffset = timestampNow - (timestampNow % 86400), midnightNoOffset = timestampNow - (timestampNow % 86400),
midnightOffseted = new Date(), midnightOffseted = new Date(),
midnightOffset; midnightOffset;
Storage.get('server_time_offset').then(function (to) {
if (to) {
serverTimeOffset = to;
}
});
midnightOffseted.setHours(0); midnightOffseted.setHours(0);
midnightOffseted.setMinutes(0); midnightOffseted.setMinutes(0);
midnightOffseted.setSeconds(0); midnightOffseted.setSeconds(0);
@ -1190,6 +1196,8 @@ angular.module('myApp.services', [])
angular.forEach(apiMessages, function (apiMessage) { angular.forEach(apiMessages, function (apiMessage) {
messagesStorage[apiMessage.id] = apiMessage; messagesStorage[apiMessage.id] = apiMessage;
apiMessage.date -= serverTimeOffset;
if (apiMessage.media && apiMessage.media._ == 'messageMediaPhoto') { if (apiMessage.media && apiMessage.media._ == 'messageMediaPhoto') {
AppPhotosManager.savePhoto(apiMessage.media.photo); AppPhotosManager.savePhoto(apiMessage.media.photo);
} }
@ -1228,7 +1236,7 @@ angular.module('myApp.services', [])
to_id: AppPeersManager.getOutputPeer(peerID), to_id: AppPeersManager.getOutputPeer(peerID),
out: true, out: true,
unread: true, unread: true,
date: tsNow() / 1000, date: tsNow(true) + serverTimeOffset,
message: text, message: text,
media: {_: 'messageMediaEmpty'}, media: {_: 'messageMediaEmpty'},
random_id: randomIDS, random_id: randomIDS,
@ -1352,7 +1360,7 @@ angular.module('myApp.services', [])
to_id: AppPeersManager.getOutputPeer(peerID), to_id: AppPeersManager.getOutputPeer(peerID),
out: true, out: true,
unread: true, unread: true,
date: tsNow() / 1000, date: tsNow(true) + serverTimeOffset,
message: '', message: '',
media: media, media: media,
random_id: randomIDS, random_id: randomIDS,
@ -1493,7 +1501,7 @@ angular.module('myApp.services', [])
to_id: AppPeersManager.getOutputPeer(peerID), to_id: AppPeersManager.getOutputPeer(peerID),
out: true, out: true,
unread: true, unread: true,
date: tsNow() / 1000, date: tsNow(true) + serverTimeOffset,
message: '', message: '',
media: media, media: media,
random_id: randomIDS, random_id: randomIDS,
@ -1939,9 +1947,6 @@ angular.module('myApp.services', [])
historyStorage = historiesStorage[peerID] = {count: null, history: [message.id], pending: []}; historyStorage = historiesStorage[peerID] = {count: null, history: [message.id], pending: []};
} }
// Fix time offset
message.date -= serverTimeOffset;
saveMessages([message]); saveMessages([message]);
if (historyStorage.count !== null) { if (historyStorage.count !== null) {
@ -3233,7 +3238,6 @@ angular.module('myApp.services', [])
var notificationsUiSupport = 'Notification' in window; var notificationsUiSupport = 'Notification' in window;
var notificationsShown = {}; var notificationsShown = {};
// var lastClosed = [];
var notificationIndex = 0; var notificationIndex = 0;
var notificationsCount = 0; var notificationsCount = 0;
var peerSettings = {}; var peerSettings = {};
@ -3428,7 +3432,6 @@ angular.module('myApp.services', [])
notification.onclose = function () { notification.onclose = function () {
delete notificationsShown[key]; delete notificationsShown[key];
// lastClosed.push(tsNow());
notificationsClear(); notificationsClear();
}; };

Loading…
Cancel
Save