2018-01-05 15:57:18 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "dialogs/dialogs_entry.h"
|
|
|
|
|
|
|
|
#include "dialogs/dialogs_key.h"
|
|
|
|
#include "dialogs/dialogs_indexed_list.h"
|
2019-04-16 14:05:56 +00:00
|
|
|
#include "data/data_session.h"
|
2019-04-17 13:22:37 +00:00
|
|
|
#include "data/data_folder.h"
|
2018-01-05 15:57:18 +00:00
|
|
|
#include "mainwidget.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "history/history_item.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "app.h"
|
2019-04-16 14:05:56 +00:00
|
|
|
#include "styles/style_dialogs.h" // st::dialogsTextWidthMin
|
2018-01-05 15:57:18 +00:00
|
|
|
|
|
|
|
namespace Dialogs {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
auto DialogsPosToTopShift = 0;
|
|
|
|
|
2018-07-31 14:34:14 +00:00
|
|
|
uint64 DialogPosFromDate(TimeId date) {
|
|
|
|
if (!date) {
|
2018-01-05 15:57:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-07-31 14:34:14 +00:00
|
|
|
return (uint64(date) << 32) | (++DialogsPosToTopShift);
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-18 11:31:30 +00:00
|
|
|
uint64 FixedOnTopDialogPos(int index) {
|
|
|
|
return 0xFFFFFFFFFFFF000FULL - index;
|
2018-05-11 14:03:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 15:57:18 +00:00
|
|
|
uint64 PinnedDialogPos(int pinnedIndex) {
|
2019-04-19 08:47:49 +00:00
|
|
|
return 0xFFFFFFFF000000FFULL - pinnedIndex;
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-04-16 14:05:56 +00:00
|
|
|
Entry::Entry(not_null<Data::Session*> owner, const Key &key)
|
2018-01-05 15:57:18 +00:00
|
|
|
: lastItemTextCache(st::dialogsTextWidthMin)
|
2019-04-16 14:05:56 +00:00
|
|
|
, _owner(owner)
|
2018-01-05 15:57:18 +00:00
|
|
|
, _key(key) {
|
|
|
|
}
|
|
|
|
|
2019-04-16 14:05:56 +00:00
|
|
|
Data::Session &Entry::owner() const {
|
|
|
|
return *_owner;
|
|
|
|
}
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
Main::Session &Entry::session() const {
|
2019-04-16 14:05:56 +00:00
|
|
|
return _owner->session();
|
|
|
|
}
|
|
|
|
|
2018-01-05 15:57:18 +00:00
|
|
|
void Entry::cachePinnedIndex(int index) {
|
|
|
|
if (_pinnedIndex != index) {
|
|
|
|
const auto wasPinned = isPinnedDialog();
|
|
|
|
_pinnedIndex = index;
|
2019-04-30 10:01:34 +00:00
|
|
|
if (session().supportMode()) {
|
|
|
|
// Force reorder in support mode.
|
|
|
|
_sortKeyInChatList = 0;
|
|
|
|
}
|
2018-01-05 15:57:18 +00:00
|
|
|
updateChatListSortPosition();
|
|
|
|
updateChatListEntry();
|
|
|
|
if (wasPinned != isPinnedDialog()) {
|
|
|
|
changedChatListPinHook();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:03:53 +00:00
|
|
|
void Entry::cacheProxyPromoted(bool promoted) {
|
|
|
|
if (_isProxyPromoted != promoted) {
|
|
|
|
_isProxyPromoted = promoted;
|
|
|
|
updateChatListSortPosition();
|
|
|
|
updateChatListEntry();
|
2018-05-15 16:38:27 +00:00
|
|
|
if (!_isProxyPromoted) {
|
|
|
|
updateChatListExistence();
|
|
|
|
}
|
2018-05-11 14:03:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-23 16:51:12 +00:00
|
|
|
bool Entry::needUpdateInChatList() const {
|
2019-04-22 14:22:39 +00:00
|
|
|
return inChatList() || shouldBeInChatList();
|
2018-01-23 16:51:12 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 15:57:18 +00:00
|
|
|
void Entry::updateChatListSortPosition() {
|
2019-04-30 10:01:34 +00:00
|
|
|
if (session().supportMode()
|
2018-09-29 12:18:26 +00:00
|
|
|
&& _sortKeyInChatList != 0
|
2019-04-30 10:01:34 +00:00
|
|
|
&& session().settings().supportFixChatsOrder()) {
|
2018-12-30 09:16:50 +00:00
|
|
|
updateChatListEntry();
|
2018-09-29 12:18:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-04-18 11:31:30 +00:00
|
|
|
const auto fixedIndex = fixedOnTopIndex();
|
|
|
|
_sortKeyInChatList = fixedIndex
|
|
|
|
? FixedOnTopDialogPos(fixedIndex)
|
2018-05-11 14:03:53 +00:00
|
|
|
: isPinnedDialog()
|
2018-01-05 15:57:18 +00:00
|
|
|
? PinnedDialogPos(_pinnedIndex)
|
2019-04-18 09:00:38 +00:00
|
|
|
: DialogPosFromDate(adjustedChatListTimeId());
|
2018-01-23 16:51:12 +00:00
|
|
|
if (needUpdateInChatList()) {
|
|
|
|
setChatListExistence(true);
|
2019-04-30 10:01:34 +00:00
|
|
|
} else {
|
|
|
|
_sortKeyInChatList = 0;
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-23 16:51:12 +00:00
|
|
|
void Entry::updateChatListExistence() {
|
|
|
|
setChatListExistence(shouldBeInChatList());
|
|
|
|
}
|
|
|
|
|
2019-04-22 14:22:39 +00:00
|
|
|
void Entry::notifyUnreadStateChange(const UnreadState &wasState) {
|
|
|
|
owner().unreadStateChanged(_key, wasState);
|
|
|
|
}
|
|
|
|
|
2018-01-23 16:51:12 +00:00
|
|
|
void Entry::setChatListExistence(bool exists) {
|
2018-01-05 15:57:18 +00:00
|
|
|
if (const auto main = App::main()) {
|
2018-01-23 16:51:12 +00:00
|
|
|
if (exists && _sortKeyInChatList) {
|
2019-04-16 14:05:56 +00:00
|
|
|
main->refreshDialog(_key);
|
2018-01-23 16:51:12 +00:00
|
|
|
updateChatListEntry();
|
|
|
|
} else {
|
|
|
|
main->removeDialog(_key);
|
|
|
|
}
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-18 09:00:38 +00:00
|
|
|
TimeId Entry::adjustedChatListTimeId() const {
|
2019-01-15 11:57:45 +00:00
|
|
|
return chatListTimeId();
|
2018-01-23 16:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::changedChatListPinHook() {
|
|
|
|
}
|
|
|
|
|
|
|
|
RowsByLetter &Entry::chatListLinks(Mode list) {
|
|
|
|
return _chatListLinks[static_cast<int>(list)];
|
|
|
|
}
|
|
|
|
|
|
|
|
const RowsByLetter &Entry::chatListLinks(Mode list) const {
|
|
|
|
return _chatListLinks[static_cast<int>(list)];
|
|
|
|
}
|
|
|
|
|
|
|
|
Row *Entry::mainChatListLink(Mode list) const {
|
|
|
|
auto it = chatListLinks(list).find(0);
|
|
|
|
Assert(it != chatListLinks(list).cend());
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2019-04-17 13:22:37 +00:00
|
|
|
PositionChange Entry::adjustByPosInChatList(Mode list) {
|
2018-01-05 15:57:18 +00:00
|
|
|
const auto lnk = mainChatListLink(list);
|
2019-04-16 14:05:56 +00:00
|
|
|
const auto from = lnk->pos();
|
2019-04-17 13:22:37 +00:00
|
|
|
myChatsList(list)->adjustByDate(chatListLinks(list));
|
2019-04-16 14:05:56 +00:00
|
|
|
const auto to = lnk->pos();
|
|
|
|
return { from, to };
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 11:57:45 +00:00
|
|
|
void Entry::setChatListTimeId(TimeId date) {
|
|
|
|
_timeId = date;
|
2018-01-05 15:57:18 +00:00
|
|
|
updateChatListSortPosition();
|
2019-04-18 09:00:38 +00:00
|
|
|
if (const auto folder = this->folder()) {
|
|
|
|
folder->updateChatListSortPosition();
|
|
|
|
}
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Entry::posInChatList(Dialogs::Mode list) const {
|
|
|
|
return mainChatListLink(list)->pos();
|
|
|
|
}
|
|
|
|
|
2019-04-17 13:22:37 +00:00
|
|
|
not_null<Row*> Entry::addToChatList(Mode list) {
|
2018-01-05 15:57:18 +00:00
|
|
|
if (!inChatList(list)) {
|
2019-04-17 13:22:37 +00:00
|
|
|
chatListLinks(list) = myChatsList(list)->addToEnd(_key);
|
2019-04-22 14:22:39 +00:00
|
|
|
if (list == Mode::All) {
|
|
|
|
owner().unreadEntryChanged(_key, true);
|
|
|
|
}
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
return mainChatListLink(list);
|
|
|
|
}
|
|
|
|
|
2019-04-17 13:22:37 +00:00
|
|
|
void Entry::removeFromChatList(Dialogs::Mode list) {
|
2018-01-05 15:57:18 +00:00
|
|
|
if (inChatList(list)) {
|
2019-04-17 13:22:37 +00:00
|
|
|
myChatsList(list)->del(_key);
|
2018-01-05 15:57:18 +00:00
|
|
|
chatListLinks(list).clear();
|
2019-04-22 14:22:39 +00:00
|
|
|
if (list == Mode::All) {
|
|
|
|
owner().unreadEntryChanged(_key, false);
|
|
|
|
}
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::removeChatListEntryByLetter(Mode list, QChar letter) {
|
|
|
|
Expects(letter != 0);
|
|
|
|
|
|
|
|
if (inChatList(list)) {
|
|
|
|
chatListLinks(list).remove(letter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::addChatListEntryByLetter(
|
|
|
|
Mode list,
|
|
|
|
QChar letter,
|
|
|
|
not_null<Row*> row) {
|
|
|
|
Expects(letter != 0);
|
|
|
|
|
|
|
|
if (inChatList(list)) {
|
|
|
|
chatListLinks(list).emplace(letter, row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::updateChatListEntry() const {
|
|
|
|
if (const auto main = App::main()) {
|
2019-04-22 14:22:39 +00:00
|
|
|
if (inChatList()) {
|
2018-01-22 17:39:20 +00:00
|
|
|
main->repaintDialogRow(
|
2018-01-05 15:57:18 +00:00
|
|
|
Mode::All,
|
|
|
|
mainChatListLink(Mode::All));
|
|
|
|
if (inChatList(Mode::Important)) {
|
2018-01-22 17:39:20 +00:00
|
|
|
main->repaintDialogRow(
|
2018-01-05 15:57:18 +00:00
|
|
|
Mode::Important,
|
|
|
|
mainChatListLink(Mode::Important));
|
|
|
|
}
|
|
|
|
}
|
2019-04-30 10:01:34 +00:00
|
|
|
if (session().supportMode()
|
|
|
|
&& !session().settings().supportAllSearchResults()) {
|
2018-12-30 09:16:50 +00:00
|
|
|
main->repaintDialogRow({ _key, FullMsgId() });
|
|
|
|
}
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 13:22:37 +00:00
|
|
|
not_null<IndexedList*> Entry::myChatsList(Mode list) const {
|
2019-04-22 14:22:39 +00:00
|
|
|
return owner().chatsList(folder())->indexed(list);
|
2019-04-17 13:22:37 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 15:57:18 +00:00
|
|
|
} // namespace Dialogs
|