mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Use server time in dialogs list sorting.
This way it won't mess up when you change your local time.
This commit is contained in:
@@ -19,11 +19,11 @@ namespace {
|
||||
|
||||
auto DialogsPosToTopShift = 0;
|
||||
|
||||
uint64 DialogPosFromDate(const QDateTime &date) {
|
||||
if (date.isNull()) {
|
||||
uint64 DialogPosFromDate(TimeId date) {
|
||||
if (!date) {
|
||||
return 0;
|
||||
}
|
||||
return (uint64(date.toTime_t()) << 32) | (++DialogsPosToTopShift);
|
||||
return (uint64(date) << 32) | (++DialogsPosToTopShift);
|
||||
}
|
||||
|
||||
uint64 ProxyPromotedDialogPos() {
|
||||
@@ -73,7 +73,7 @@ void Entry::updateChatListSortPosition() {
|
||||
? ProxyPromotedDialogPos()
|
||||
: isPinnedDialog()
|
||||
? PinnedDialogPos(_pinnedIndex)
|
||||
: DialogPosFromDate(adjustChatListDate());
|
||||
: DialogPosFromDate(adjustChatListTimeId());
|
||||
if (needUpdateInChatList()) {
|
||||
setChatListExistence(true);
|
||||
}
|
||||
@@ -94,8 +94,8 @@ void Entry::setChatListExistence(bool exists) {
|
||||
}
|
||||
}
|
||||
|
||||
QDateTime Entry::adjustChatListDate() const {
|
||||
return chatsListDate();
|
||||
TimeId Entry::adjustChatListTimeId() const {
|
||||
return chatsListTimeId();
|
||||
}
|
||||
|
||||
void Entry::changedInChatListHook(Dialogs::Mode list, bool added) {
|
||||
@@ -128,13 +128,13 @@ PositionChange Entry::adjustByPosInChatList(
|
||||
return { movedFrom, movedTo };
|
||||
}
|
||||
|
||||
void Entry::setChatsListDate(QDateTime date) {
|
||||
if (!_lastMessageDate.isNull() && _lastMessageDate >= date) {
|
||||
void Entry::setChatsListTimeId(TimeId date) {
|
||||
if (_lastMessageTimeId && _lastMessageTimeId >= date) {
|
||||
if (!inChatList(Dialogs::Mode::All)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
_lastMessageDate = date;
|
||||
_lastMessageTimeId = date;
|
||||
updateChatListSortPosition();
|
||||
}
|
||||
|
||||
|
@@ -65,7 +65,7 @@ public:
|
||||
return _sortKeyInChatList;
|
||||
}
|
||||
void updateChatListSortPosition();
|
||||
void setChatsListDate(QDateTime date);
|
||||
void setChatsListTimeId(TimeId date);
|
||||
virtual void updateChatListExistence();
|
||||
bool needUpdateInChatList() const;
|
||||
|
||||
@@ -94,8 +94,8 @@ public:
|
||||
paintUserpic(p, rtl() ? (w - x - size) : x, y, size);
|
||||
}
|
||||
|
||||
QDateTime chatsListDate() const {
|
||||
return _lastMessageDate;
|
||||
TimeId chatsListTimeId() const {
|
||||
return _lastMessageTimeId;
|
||||
}
|
||||
|
||||
virtual ~Entry() = default;
|
||||
@@ -104,7 +104,7 @@ public:
|
||||
mutable Text lastItemTextCache;
|
||||
|
||||
private:
|
||||
virtual QDateTime adjustChatListDate() const;
|
||||
virtual TimeId adjustChatListTimeId() const;
|
||||
virtual void changedInChatListHook(Dialogs::Mode list, bool added);
|
||||
virtual void changedChatListPinHook();
|
||||
|
||||
@@ -118,7 +118,7 @@ private:
|
||||
uint64 _sortKeyInChatList = 0;
|
||||
int _pinnedIndex = 0;
|
||||
bool _isProxyPromoted = false;
|
||||
QDateTime _lastMessageDate;
|
||||
TimeId _lastMessageTimeId = 0;
|
||||
|
||||
};
|
||||
|
||||
|
@@ -1784,9 +1784,9 @@ void DialogsInner::applyDialog(const MTPDdialog &dialog) {
|
||||
history->applyDialog(dialog);
|
||||
|
||||
if (!history->useProxyPromotion() && !history->isPinnedDialog()) {
|
||||
const auto date = history->chatsListDate();
|
||||
if (!date.isNull()) {
|
||||
addSavedPeersAfter(date);
|
||||
const auto date = history->chatsListTimeId();
|
||||
if (date != 0) {
|
||||
addSavedPeersAfter(ParseDateTime(date));
|
||||
}
|
||||
}
|
||||
_contactsNoDialogs->del(history);
|
||||
@@ -1818,7 +1818,7 @@ void DialogsInner::addSavedPeersAfter(const QDateTime &date) {
|
||||
auto &saved = cRefSavedPeersByTime();
|
||||
while (!saved.isEmpty() && (date.isNull() || date < saved.lastKey())) {
|
||||
const auto history = App::history(saved.last()->id);
|
||||
history->setChatsListDate(saved.lastKey());
|
||||
history->setChatsListTimeId(ServerTimeFromParsed(saved.lastKey()));
|
||||
_contactsNoDialogs->del(history);
|
||||
saved.remove(saved.lastKey(), saved.last());
|
||||
}
|
||||
|
Reference in New Issue
Block a user