pseudo-online for hidden last-seen done

This commit is contained in:
John Preston 2015-01-23 14:02:45 +03:00
parent bbcca80503
commit da48c2141c
8 changed files with 36 additions and 8 deletions

View File

@ -170,6 +170,9 @@ namespace App {
int32 onlineForSort(int32 online, int32 now) {
if (online <= 0) {
switch (online) {
case 0:
case -1: return online;
case -2: {
QDate yesterday(date(now).date());
yesterday.addDays(-3);
@ -188,6 +191,7 @@ namespace App {
return int32(QDateTime(monthago).toTime_t());
} break;
}
return -online;
}
return online;
}
@ -259,6 +263,20 @@ namespace App {
return lng_status_lastseen_date(lt_date, dOnline.date().toString(qsl("dd.MM.yy")));
}
bool onlineColorUse(int32 online, int32 now) {
if (online <= 0) {
switch (online) {
case 0:
case -1:
case -2:
case -3:
case -4: return false;
}
return (-online > now);
}
return (online > now);
}
UserData *feedUsers(const MTPVector<MTPUser> &users) {
UserData *data = 0;
const QVector<MTPUser> &v(users.c_vector().v);
@ -366,7 +384,11 @@ namespace App {
data->loaded = true;
if (status) switch (status->type()) {
case mtpc_userStatusEmpty: data->onlineTill = 0; break;
case mtpc_userStatusRecently: data->onlineTill = -2; break;
case mtpc_userStatusRecently:
if (data->onlineTill > -10) { // don't modify pseudo-online
data->onlineTill = -2;
}
break;
case mtpc_userStatusLastWeek: data->onlineTill = -3; break;
case mtpc_userStatusLastMonth: data->onlineTill = -4; break;
case mtpc_userStatusOffline: data->onlineTill = status->c_userStatusOffline().vwas_online.v; break;

View File

@ -66,6 +66,7 @@ namespace App {
int32 onlineForSort(int32 online, int32 now);
int32 onlineWillChangeIn(int32 onlineOnServer, int32 nowOnServer);
QString onlineText(UserData *user, int32 nowOnServer, bool precise = false);
bool onlineColorUse(int32 online, int32 now);
UserData *feedUsers(const MTPVector<MTPUser> &users); // returnes last user
void feedChats(const MTPVector<MTPChat> &chats);

View File

@ -165,7 +165,7 @@ void AddParticipantInner::paintDialog(QPainter &p, DialogRow *row, bool sel) {
if (data->inchat || data->check) {
p.setPen(st::white->p);
} else {
p.setPen((user->onlineTill >= _time ? st::profileOnlineColor : st::profileOfflineColor)->p);
p.setPen((App::onlineColorUse(user->onlineTill, _time) ? st::profileOnlineColor : st::profileOfflineColor)->p);
}
p.drawText(left + st::profileListPhotoSize + st::profileListPadding.width(), st::profileListPadding.height() + st::profileListPhotoSize - st::profileListStatusBottom, data->online);
}

View File

@ -135,7 +135,7 @@ void ContactsInner::paintDialog(QPainter &p, DialogRow *row, bool sel) {
}
p.setFont(st::profileSubFont->f);
p.setPen((user->onlineTill >= _time ? st::profileOnlineColor : st::profileOfflineColor)->p);
p.setPen((App::onlineColorUse(user->onlineTill, _time) ? st::profileOnlineColor : st::profileOfflineColor)->p);
p.drawText(left + st::profileListPhotoSize + st::participantDelta, st::profileListPadding.height() + st::profileListPhotoSize - st::profileListStatusBottom, data->online);
}

View File

@ -151,7 +151,7 @@ void NewGroupInner::paintDialog(QPainter &p, DialogRow *row, bool sel) {
if (data->check) {
p.setPen(st::white->p);
} else {
p.setPen((user->onlineTill >= _time ? st::profileOnlineColor : st::profileOfflineColor)->p);
p.setPen((App::onlineColorUse(user->onlineTill, _time) ? st::profileOnlineColor : st::profileOfflineColor)->p);
}
p.drawText(left + st::profileListPhotoSize + st::participantDelta, st::profileListPadding.height() + st::profileListPhotoSize - 6, data->online);
}

View File

@ -1413,7 +1413,8 @@ void History::newItemAdded(HistoryItem *item) {
if (item->from()) {
unregTyping(item->from());
if (item->from()->onlineTill < 0) {
item->from()->onlineTill = -unixtime() - HiddenIsOnlineAfterMessage;
item->from()->onlineTill = -unixtime() - HiddenIsOnlineAfterMessage; // pseudo-online
if (App::main()) App::main()->peerUpdated(item->from());
}
}
if (item->out()) {

View File

@ -2676,7 +2676,11 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
if (user) {
switch (d.vstatus.type()) {
case mtpc_userStatusEmpty: user->onlineTill = 0; break;
case mtpc_userStatusRecently: user->onlineTill = -2; break;
case mtpc_userStatusRecently:
if (user->onlineTill > -10) { // don't modify pseudo-online
user->onlineTill = -2;
}
break;
case mtpc_userStatusLastWeek: user->onlineTill = -3; break;
case mtpc_userStatusLastMonth: user->onlineTill = -4; break;
case mtpc_userStatusOffline: user->onlineTill = d.vstatus.c_userStatusOffline().vwas_online.v; break;

View File

@ -422,7 +422,7 @@ void ProfileInner::paintEvent(QPaintEvent *e) {
p.setPen(st::black->p);
p.drawText(_left + st::profilePhotoSize + st::profileStatusLeft, top + st::profileStatusTop + st::linkFont->ascent, '@' + _peerUser->username);
}
p.setPen((_peerUser && _peerUser->onlineTill >= l_time ? st::profileOnlineColor : st::profileOfflineColor)->p);
p.setPen((_peerUser && App::onlineColorUse(_peerUser->onlineTill, l_time) ? st::profileOnlineColor : st::profileOfflineColor)->p);
p.drawText(_left + st::profilePhotoSize + st::profileStatusLeft, top + addbyname + st::profileStatusTop + st::linkFont->ascent, _onlineText);
if (!_cancelPhoto.isHidden()) {
p.drawText(_left + st::profilePhotoSize + st::profilePhoneLeft, _cancelPhoto.y() + addbyname + st::linkFont->ascent, lang(lng_settings_uploading_photo));
@ -529,7 +529,7 @@ void ProfileInner::paintEvent(QPaintEvent *e) {
p.setFont(st::linkFont->f);
data->name.drawElided(p, _left + st::profileListPhotoSize + st::profileListPadding.width(), top + st::profileListNameTop, _width - _kickWidth - st::profileListPadding.width() - st::profileListPhotoSize - st::profileListPadding.width());
p.setFont(st::profileSubFont->f);
p.setPen((user->onlineTill >= l_time ? st::profileOnlineColor : st::profileOfflineColor)->p);
p.setPen((App::onlineColorUse(user->onlineTill, l_time) ? st::profileOnlineColor : st::profileOfflineColor)->p);
p.drawText(_left + st::profileListPhotoSize + st::profileListPadding.width(), top + st::profileListPadding.height() + st::profileListPhotoSize - st::profileListStatusBottom, data->online);
if (data->cankick) {