Browse Source

Fixed last seen time with incorrect timezone selected

master
Igor Zhukov 9 years ago
parent
commit
d277a59094
  1. 13
      app/js/filters.js
  2. 26
      app/js/services.js

13
app/js/filters.js

@ -235,18 +235,17 @@ angular.module('myApp.filters', ['myApp.i18n'])
dateOrTimeFilter = $filter('dateOrTime'); dateOrTimeFilter = $filter('dateOrTime');
return function (timestamp) { return function (timestamp) {
var ticks = timestamp * 1000, var diff = Math.abs(tsNow(true) - timestamp);
diff = Math.abs(tsNow() - ticks);
if (diff < 60000) { if (diff < 60) {
return _('relative_time_just_now'); return _('relative_time_just_now');
} }
if (diff < 3600000) { if (diff < 3600) {
var minutes = Math.floor(diff / 60000); var minutes = Math.floor(diff / 60);
return langMinutesPluralize(minutes); return langMinutesPluralize(minutes);
} }
if (diff < 86400000) { if (diff < 86400) {
var hours = Math.floor(diff / 3600000); var hours = Math.floor(diff / 3600);
return langHoursPluralize(hours); return langHoursPluralize(hours);
} }
return dateOrTimeFilter(timestamp, true); return dateOrTimeFilter(timestamp, true);

26
app/js/services.js

@ -124,6 +124,14 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
var lastWord = nameWords.pop(); var lastWord = nameWords.pop();
apiUser.initials = firstWord.charAt(0) + (lastWord ? lastWord.charAt(0) : firstWord.charAt(1)); apiUser.initials = firstWord.charAt(0) + (lastWord ? lastWord.charAt(0) : firstWord.charAt(1));
if (apiUser.status) {
if (apiUser.status.expires) {
apiUser.status.expires -= serverTimeOffset;
}
if (apiUser.status.was_online) {
apiUser.status.was_online -= serverTimeOffset;
}
}
if (apiUser.pFlags.bot) { if (apiUser.pFlags.bot) {
apiUser.sortStatus = -1; apiUser.sortStatus = -1;
} else { } else {
@ -149,7 +157,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
if (expires) { if (expires) {
return expires; return expires;
} }
var timeNow = tsNow(true) + serverTimeOffset; var timeNow = tsNow(true);
switch (status._) { switch (status._) {
case 'userStatusRecently': case 'userStatusRecently':
return timeNow - 86400 * 3; return timeNow - 86400 * 3;
@ -220,7 +228,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
} }
function updateUsersStatuses () { function updateUsersStatuses () {
var timestampNow = tsNow(true) + serverTimeOffset; var timestampNow = tsNow(true);
angular.forEach(users, function (user) { angular.forEach(users, function (user) {
if (user.status && if (user.status &&
user.status._ == 'userStatusOnline' && user.status._ == 'userStatusOnline' &&
@ -250,7 +258,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
} }
user.status = { user.status = {
_: 'userStatusOnline', _: 'userStatusOnline',
expires: tsNow(true) + serverTimeOffset + 60, expires: tsNow(true) + 60,
wasStatus: wasStatus wasStatus: wasStatus
}; };
user.sortStatus = getUserStatusForSort(user.status); user.sortStatus = getUserStatusForSort(user.status);
@ -384,10 +392,10 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
if (user) { if (user) {
var status = offline ? { var status = offline ? {
_: 'userStatusOffline', _: 'userStatusOffline',
was_online: tsNow(true) + serverTimeOffset was_online: tsNow(true)
} : { } : {
_: 'userStatusOnline', _: 'userStatusOnline',
expires: tsNow(true) + serverTimeOffset + 500 expires: tsNow(true) + 500
}; };
user.status = status; user.status = status;
@ -405,6 +413,14 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
user = users[userID]; user = users[userID];
if (user) { if (user) {
user.status = update.status; user.status = update.status;
if (user.status) {
if (user.status.expires) {
user.status.expires -= serverTimeOffset;
}
if (user.status.was_online) {
user.status.was_online -= serverTimeOffset;
}
}
user.sortStatus = getUserStatusForSort(user.status); user.sortStatus = getUserStatusForSort(user.status);
$rootScope.$broadcast('user_update', userID); $rootScope.$broadcast('user_update', userID);
} }

Loading…
Cancel
Save