Browse Source

put current locale in consideration for various caches in filters/services

some local caches now need to be purged when the locale is changed on
runtime or else they'll still display strings in the wrong locale/language

Revert this commit once the locale loading is moved into init phase of
the page so it won't change during runtime anymore
master
Roman Anasal 10 years ago
parent
commit
37bb69a409
  1. 37
      app/js/filters.js
  2. 10
      app/js/services.js

37
app/js/filters.js

@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
/* Filters */
angular.module('myApp.filters', [])
angular.module('myApp.filters', ['myApp.i18n'])
.filter('userName', [function() {
return function (user) {
@ -51,14 +51,17 @@ angular.module('myApp.filters', []) @@ -51,14 +51,17 @@ angular.module('myApp.filters', [])
}
}])
.filter('dateOrTime', ['$filter', function($filter) {
.filter('dateOrTime', ['$filter', '_', function($filter, _) {
var cachedDates = {},
dateFilter = $filter('date');
return function (timestamp) {
if (!cachedDates.hasOwnProperty(_.locale())) {
cachedDates[_.locale()] = {};
}
if (cachedDates[timestamp]) {
return cachedDates[timestamp];
if (cachedDates[_.locale()][timestamp]) {
return cachedDates[_.locale()][timestamp];
}
var ticks = timestamp * 1000,
@ -71,34 +74,42 @@ angular.module('myApp.filters', []) @@ -71,34 +74,42 @@ angular.module('myApp.filters', [])
else if (diff > 43200000) { // 12 hours
format = 'EEE';
}
return cachedDates[timestamp] = dateFilter(ticks, format);
return cachedDates[_.locale()][timestamp] = dateFilter(ticks, format);
}
}])
.filter('time', ['$filter', function($filter) {
.filter('time', ['$filter', '_', function($filter, _) {
var cachedDates = {},
dateFilter = $filter('date'),
format = Config.Navigator.mobile ? 'HH:mm' : 'HH:mm:ss';
return function (timestamp) {
if (cachedDates[timestamp]) {
return cachedDates[timestamp];
if (!cachedDates.hasOwnProperty(_.locale())) {
cachedDates[_.locale()] = {};
}
if (cachedDates[_.locale()][timestamp]) {
return cachedDates[_.locale()][timestamp];
}
return cachedDates[timestamp] = dateFilter(timestamp * 1000, format);
return cachedDates[_.locale()][timestamp] = dateFilter(timestamp * 1000, format);
}
}])
.filter('myDate', ['$filter', function($filter) {
.filter('myDate', ['$filter', '_', function($filter, _) {
var cachedDates = {},
dateFilter = $filter('date');
return function (timestamp) {
if (cachedDates[timestamp]) {
return cachedDates[timestamp];
if (!cachedDates.hasOwnProperty(_.locale())) {
cachedDates[_.locale()] = {};
}
if (cachedDates[_.locale()][timestamp]) {
return cachedDates[_.locale()][timestamp];
}
return cachedDates[timestamp] = dateFilter(timestamp * 1000, 'fullDate');
return cachedDates[_.locale()][timestamp] = dateFilter(timestamp * 1000, 'fullDate');
}
}])

10
app/js/services.js

@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
/* Services */
angular.module('myApp.services', [])
angular.module('myApp.services', ['myApp.i18n'])
.service('AppUsersManager', function ($rootScope, $modal, $modalStack, $filter, $q, MtpApiFileManager, MtpApiManager, RichTextProcessor, SearchIndexManager, ErrorService, Storage) {
var users = {},
@ -729,11 +729,11 @@ angular.module('myApp.services', []) @@ -729,11 +729,11 @@ angular.module('myApp.services', [])
}
})
.service('AppMessagesManager', function ($q, $rootScope, $location, $filter, ApiUpdatesManager, AppUsersManager, AppChatsManager, AppPeersManager, AppPhotosManager, AppVideoManager, AppDocsManager, AppAudioManager, MtpApiManager, MtpApiFileManager, RichTextProcessor, NotificationsManager, SearchIndexManager, PeersSelectService,Storage) {
.service('AppMessagesManager', function ($q, $rootScope, $location, $filter, ApiUpdatesManager, AppUsersManager, AppChatsManager, AppPeersManager, AppPhotosManager, AppVideoManager, AppDocsManager, AppAudioManager, MtpApiManager, MtpApiFileManager, RichTextProcessor, NotificationsManager, SearchIndexManager, PeersSelectService,Storage, _) {
var messagesStorage = {};
var messagesForHistory = {};
var messagesForDialogs = {};
var messagesForDialogs = {locale: _.locale()};
var historiesStorage = {};
var dialogsStorage = {count: null, dialogs: []};
var pendingByRandomID = {};
@ -1748,6 +1748,10 @@ angular.module('myApp.services', []) @@ -1748,6 +1748,10 @@ angular.module('myApp.services', [])
function wrapForDialog (msgID, unreadCount) {
var useCache = unreadCount != -1;
if (messagesForDialogs.locale != _.locale()) {
messagesForDialogs = {locale: _.locale()};
}
if (useCache && messagesForDialogs[msgID] !== undefined) {
return messagesForDialogs[msgID];
}

Loading…
Cancel
Save