2018-01-04 09:40:58 +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
|
|
|
|
*/
|
2019-04-15 11:54:03 +00:00
|
|
|
#include "data/data_folder.h"
|
2018-01-04 09:40:58 +00:00
|
|
|
|
2018-01-23 16:51:12 +00:00
|
|
|
#include "data/data_session.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
2020-02-21 07:58:50 +00:00
|
|
|
#include "data/data_histories.h"
|
2018-01-05 15:57:18 +00:00
|
|
|
#include "dialogs/dialogs_key.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "history/history_item.h"
|
2018-01-22 09:33:09 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2018-01-23 16:51:12 +00:00
|
|
|
#include "storage/storage_facade.h"
|
2019-04-22 14:22:39 +00:00
|
|
|
#include "core/application.h"
|
2019-07-24 08:46:23 +00:00
|
|
|
#include "main/main_account.h"
|
2019-04-15 11:54:03 +00:00
|
|
|
//#include "storage/storage_feed_messages.h" // #feed
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2019-04-23 13:28:44 +00:00
|
|
|
#include "observer_peer.h"
|
2018-01-29 17:13:24 +00:00
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "mainwidget.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "facades.h"
|
2019-04-23 13:28:44 +00:00
|
|
|
#include "styles/style_dialogs.h"
|
2018-01-05 15:57:18 +00:00
|
|
|
|
2018-01-04 09:40:58 +00:00
|
|
|
namespace Data {
|
2019-04-17 12:08:02 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kLoadedChatsMinCount = 20;
|
2019-05-08 08:50:39 +00:00
|
|
|
constexpr auto kShowChatNamesCount = 8;
|
2019-04-17 12:08:02 +00:00
|
|
|
|
2019-07-24 08:46:23 +00:00
|
|
|
rpl::producer<int> PinnedDialogsInFolderMaxValue(
|
2019-07-24 11:45:24 +00:00
|
|
|
not_null<Main::Session*> session) {
|
2019-04-22 14:22:39 +00:00
|
|
|
return rpl::single(
|
|
|
|
rpl::empty_value()
|
|
|
|
) | rpl::then(
|
2019-07-24 08:46:23 +00:00
|
|
|
session->account().configUpdates()
|
2019-04-22 14:22:39 +00:00
|
|
|
) | rpl::map([=] {
|
|
|
|
return Global::PinnedDialogsInFolderMax();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-17 12:08:02 +00:00
|
|
|
} // namespace
|
2018-01-04 09:40:58 +00:00
|
|
|
|
2018-03-06 17:07:42 +00:00
|
|
|
// #feed
|
|
|
|
//MessagePosition FeedPositionFromMTP(const MTPFeedPosition &position) {
|
|
|
|
// Expects(position.type() == mtpc_feedPosition);
|
|
|
|
//
|
|
|
|
// const auto &data = position.c_feedPosition();
|
2019-07-05 13:38:38 +00:00
|
|
|
// return MessagePosition(data.vdate().v, FullMsgId(
|
|
|
|
// peerToChannel(peerFromMTP(data.vpeer())),
|
|
|
|
// data.vid().v));
|
2018-03-06 17:07:42 +00:00
|
|
|
//}
|
2018-01-05 15:57:18 +00:00
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
Folder::Folder(not_null<Data::Session*> owner, FolderId id)
|
2019-04-16 14:05:56 +00:00
|
|
|
: Entry(owner, this)
|
2018-01-22 09:33:09 +00:00
|
|
|
, _id(id)
|
2019-07-24 08:46:23 +00:00
|
|
|
, _chatsList(PinnedDialogsInFolderMaxValue(&owner->session()))
|
2019-06-19 15:09:03 +00:00
|
|
|
, _name(tr::lng_archived_name(tr::now)) {
|
2018-01-22 09:33:09 +00:00
|
|
|
indexNameParts();
|
2019-04-23 13:28:44 +00:00
|
|
|
|
|
|
|
Notify::PeerUpdateViewer(
|
|
|
|
Notify::PeerUpdate::Flag::NameChanged
|
|
|
|
) | rpl::start_with_next([=](const Notify::PeerUpdate &update) {
|
2019-05-08 08:50:39 +00:00
|
|
|
for (const auto history : _lastHistories) {
|
2019-04-23 13:28:44 +00:00
|
|
|
if (history->peer == update.peer) {
|
|
|
|
++_chatListViewVersion;
|
|
|
|
updateChatListEntry();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, _lifetime);
|
2018-01-22 09:33:09 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
FolderId Folder::id() const {
|
2018-01-23 16:51:12 +00:00
|
|
|
return _id;
|
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
void Folder::indexNameParts() {
|
2019-05-03 10:55:44 +00:00
|
|
|
// We don't want archive to be filtered in the chats list.
|
|
|
|
//_nameWords.clear();
|
|
|
|
//_nameFirstLetters.clear();
|
|
|
|
//auto toIndexList = QStringList();
|
|
|
|
//auto appendToIndex = [&](const QString &value) {
|
|
|
|
// if (!value.isEmpty()) {
|
|
|
|
// toIndexList.push_back(TextUtilities::RemoveAccents(value));
|
|
|
|
// }
|
|
|
|
//};
|
|
|
|
|
|
|
|
//appendToIndex(_name);
|
|
|
|
//const auto appendTranslit = !toIndexList.isEmpty()
|
|
|
|
// && cRussianLetters().match(toIndexList.front()).hasMatch();
|
|
|
|
//if (appendTranslit) {
|
|
|
|
// appendToIndex(translitRusEng(toIndexList.front()));
|
|
|
|
//}
|
|
|
|
//auto toIndex = toIndexList.join(' ');
|
|
|
|
//toIndex += ' ' + rusKeyboardLayoutSwitch(toIndex);
|
|
|
|
|
|
|
|
//const auto namesList = TextUtilities::PrepareSearchWords(toIndex);
|
|
|
|
//for (const auto &name : namesList) {
|
|
|
|
// _nameWords.insert(name);
|
|
|
|
// _nameFirstLetters.insert(name[0]);
|
|
|
|
//}
|
2018-01-04 09:40:58 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 08:50:59 +00:00
|
|
|
void Folder::registerOne(not_null<History*> history) {
|
2019-04-22 14:22:39 +00:00
|
|
|
if (_chatsList.indexed()->size() == 1) {
|
2019-04-18 11:31:30 +00:00
|
|
|
updateChatListSortPosition();
|
2019-04-24 15:28:01 +00:00
|
|
|
if (!_cloudUnread.known) {
|
2020-02-21 07:58:50 +00:00
|
|
|
owner().histories().requestDialogEntry(this);
|
2019-04-24 14:53:12 +00:00
|
|
|
}
|
2019-04-23 12:29:23 +00:00
|
|
|
} else {
|
|
|
|
updateChatListEntry();
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
2019-04-22 15:09:03 +00:00
|
|
|
applyChatListMessage(history->chatListMessage());
|
2019-05-08 08:50:39 +00:00
|
|
|
reorderLastHistories();
|
2018-01-04 09:40:58 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 08:50:59 +00:00
|
|
|
void Folder::unregisterOne(not_null<History*> history) {
|
2019-04-16 14:05:56 +00:00
|
|
|
if (_chatsList.empty()) {
|
2019-04-16 08:50:59 +00:00
|
|
|
updateChatListExistence();
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
2019-04-22 15:09:03 +00:00
|
|
|
if (_chatListMessage && _chatListMessage->history() == history) {
|
|
|
|
computeChatListMessage();
|
|
|
|
}
|
2019-05-08 08:50:39 +00:00
|
|
|
reorderLastHistories();
|
2019-04-22 15:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Folder::oneListMessageChanged(HistoryItem *from, HistoryItem *to) {
|
|
|
|
if (!applyChatListMessage(to) && _chatListMessage == from) {
|
|
|
|
computeChatListMessage();
|
|
|
|
}
|
2019-04-23 12:29:23 +00:00
|
|
|
if (from || to) {
|
2019-05-08 08:50:39 +00:00
|
|
|
reorderLastHistories();
|
2019-04-23 12:29:23 +00:00
|
|
|
}
|
2019-04-22 15:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Folder::applyChatListMessage(HistoryItem *item) {
|
|
|
|
if (!item) {
|
|
|
|
return false;
|
|
|
|
} else if (_chatListMessage
|
|
|
|
&& _chatListMessage->date() >= item->date()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
_chatListMessage = item;
|
|
|
|
updateChatListEntry();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Folder::computeChatListMessage() {
|
|
|
|
auto &&items = ranges::view::all(
|
|
|
|
*_chatsList.indexed()
|
|
|
|
) | ranges::view::filter([](not_null<Dialogs::Row*> row) {
|
|
|
|
return row->entry()->chatListMessage() != nullptr;
|
|
|
|
});
|
|
|
|
const auto chatListDate = [](not_null<Dialogs::Row*> row) {
|
|
|
|
return row->entry()->chatListMessage()->date();
|
|
|
|
};
|
|
|
|
const auto top = ranges::max_element(
|
|
|
|
items,
|
|
|
|
ranges::less(),
|
|
|
|
chatListDate);
|
|
|
|
if (top == items.end()) {
|
|
|
|
_chatListMessage = nullptr;
|
|
|
|
} else {
|
|
|
|
_chatListMessage = (*top)->entry()->chatListMessage();
|
|
|
|
}
|
|
|
|
updateChatListEntry();
|
2019-04-16 14:05:56 +00:00
|
|
|
}
|
|
|
|
|
2019-05-08 08:50:39 +00:00
|
|
|
void Folder::reorderLastHistories() {
|
2019-04-23 12:29:23 +00:00
|
|
|
// We want first kShowChatNamesCount histories, by last message date.
|
2019-05-08 08:50:39 +00:00
|
|
|
const auto pred = [](not_null<History*> a, not_null<History*> b) {
|
2019-04-23 12:29:23 +00:00
|
|
|
const auto aItem = a->chatListMessage();
|
|
|
|
const auto bItem = b->chatListMessage();
|
|
|
|
const auto aDate = aItem ? aItem->date() : TimeId(0);
|
|
|
|
const auto bDate = bItem ? bItem->date() : TimeId(0);
|
|
|
|
return aDate > bDate;
|
|
|
|
};
|
2019-05-08 08:50:39 +00:00
|
|
|
_lastHistories.erase(_lastHistories.begin(), _lastHistories.end());
|
|
|
|
_lastHistories.reserve(kShowChatNamesCount + 1);
|
|
|
|
auto &&histories = ranges::view::all(
|
|
|
|
*_chatsList.indexed()
|
|
|
|
) | ranges::view::transform([](not_null<Dialogs::Row*> row) {
|
|
|
|
return row->history();
|
|
|
|
}) | ranges::view::filter([](History *history) {
|
|
|
|
return (history != nullptr);
|
|
|
|
}) | ranges::view::transform([](History *history) {
|
|
|
|
return not_null<History*>(history);
|
|
|
|
});
|
|
|
|
for (const auto history : histories) {
|
|
|
|
const auto i = ranges::upper_bound(_lastHistories, history, pred);
|
|
|
|
if (size(_lastHistories) < kShowChatNamesCount
|
|
|
|
|| i != end(_lastHistories)) {
|
|
|
|
_lastHistories.insert(i, history);
|
2019-04-23 12:29:23 +00:00
|
|
|
}
|
2019-05-08 08:50:39 +00:00
|
|
|
if (size(_lastHistories) > kShowChatNamesCount) {
|
|
|
|
_lastHistories.pop_back();
|
2019-04-23 12:29:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
++_chatListViewVersion;
|
|
|
|
updateChatListEntry();
|
|
|
|
}
|
|
|
|
|
2019-04-22 14:22:39 +00:00
|
|
|
not_null<Dialogs::MainList*> Folder::chatsList() {
|
|
|
|
return &_chatsList;
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
void Folder::loadUserpic() {
|
|
|
|
//constexpr auto kPaintUserpicsCount = 4; // #feed
|
|
|
|
//auto load = kPaintUserpicsCount;
|
2019-04-16 08:50:59 +00:00
|
|
|
//for (const auto history : _histories) {
|
2019-04-15 11:54:03 +00:00
|
|
|
// history->peer->loadUserpic();
|
|
|
|
// if (!--load) {
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
//}
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
void Folder::paintUserpic(
|
2018-01-05 15:57:18 +00:00
|
|
|
Painter &p,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int size) const {
|
2019-06-17 13:26:08 +00:00
|
|
|
paintUserpic(p, x, y, size, nullptr, nullptr);
|
2019-05-16 08:39:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Folder::paintUserpic(
|
|
|
|
Painter &p,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int size,
|
|
|
|
const style::color &bg,
|
|
|
|
const style::color &fg) const {
|
2019-06-17 13:26:08 +00:00
|
|
|
paintUserpic(p, x, y, size, &bg, &fg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Folder::paintUserpic(
|
|
|
|
Painter &p,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int size,
|
|
|
|
const style::color *overrideBg,
|
|
|
|
const style::color *overrideFg) const {
|
2019-04-16 08:50:59 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
2019-06-17 13:26:08 +00:00
|
|
|
p.setBrush(overrideBg ? *overrideBg : st::historyPeerArchiveUserpicBg);
|
2019-04-16 08:50:59 +00:00
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
2019-04-23 13:28:44 +00:00
|
|
|
p.drawEllipse(x, y, size, size);
|
|
|
|
}
|
|
|
|
if (size == st::dialogsPhotoSize) {
|
2019-06-17 13:26:08 +00:00
|
|
|
const auto rect = QRect{ x, y, size, size };
|
|
|
|
if (overrideFg) {
|
|
|
|
st::dialogsArchiveUserpic.paintInCenter(
|
|
|
|
p,
|
|
|
|
rect,
|
|
|
|
(*overrideFg)->c);
|
|
|
|
} else {
|
|
|
|
st::dialogsArchiveUserpic.paintInCenter(p, rect);
|
|
|
|
}
|
2019-04-23 13:28:44 +00:00
|
|
|
} else {
|
|
|
|
p.save();
|
|
|
|
const auto ratio = size / float64(st::dialogsPhotoSize);
|
|
|
|
p.translate(x + size / 2., y + size / 2.);
|
|
|
|
p.scale(ratio, ratio);
|
|
|
|
const auto skip = st::dialogsPhotoSize;
|
2019-06-17 13:26:08 +00:00
|
|
|
const auto rect = QRect{ -skip, -skip, 2 * skip, 2 * skip };
|
|
|
|
if (overrideFg) {
|
|
|
|
st::dialogsArchiveUserpic.paintInCenter(
|
|
|
|
p,
|
|
|
|
rect,
|
|
|
|
(*overrideFg)->c);
|
|
|
|
} else {
|
|
|
|
st::dialogsArchiveUserpic.paintInCenter(p, rect);
|
|
|
|
}
|
2019-04-23 13:28:44 +00:00
|
|
|
p.restore();
|
2019-04-16 08:50:59 +00:00
|
|
|
}
|
2019-04-15 11:54:03 +00:00
|
|
|
//const auto small = (size - st::lineWidth) / 2; // #feed
|
|
|
|
//const auto delta = size - small;
|
|
|
|
//auto index = 0;
|
2019-04-16 08:50:59 +00:00
|
|
|
//for (const auto history : _histories) {
|
2019-04-15 11:54:03 +00:00
|
|
|
// history->peer->paintUserpic(p, x, y, small);
|
|
|
|
// switch (++index) {
|
|
|
|
// case 1:
|
|
|
|
// case 3: x += delta; break;
|
|
|
|
// case 2: x -= delta; y += delta; break;
|
|
|
|
// case 4: return;
|
|
|
|
// }
|
|
|
|
//}
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 13:22:37 +00:00
|
|
|
bool Folder::chatsListLoaded() const {
|
2019-04-22 14:22:39 +00:00
|
|
|
return _chatsList.loaded();
|
2018-01-29 17:13:24 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 13:22:37 +00:00
|
|
|
void Folder::setChatsListLoaded(bool loaded) {
|
2019-04-22 14:22:39 +00:00
|
|
|
if (_chatsList.loaded() == loaded) {
|
|
|
|
return;
|
2018-02-07 16:37:05 +00:00
|
|
|
}
|
2019-04-22 14:22:39 +00:00
|
|
|
const auto notifier = unreadStateChangeNotifier(true);
|
|
|
|
_chatsList.setLoaded(loaded);
|
2018-01-30 12:13:46 +00:00
|
|
|
}
|
|
|
|
|
2019-04-23 12:29:23 +00:00
|
|
|
void Folder::setCloudChatsListSize(int size) {
|
|
|
|
_cloudChatsListSize = size;
|
|
|
|
updateChatListEntry();
|
|
|
|
}
|
|
|
|
|
|
|
|
int Folder::chatsListSize() const {
|
|
|
|
return std::max(
|
|
|
|
_chatsList.indexed()->size(),
|
|
|
|
_chatsList.loaded() ? 0 : _cloudChatsListSize);
|
|
|
|
}
|
|
|
|
|
2019-05-08 08:50:39 +00:00
|
|
|
const std::vector<not_null<History*>> &Folder::lastHistories() const {
|
|
|
|
return _lastHistories;
|
2019-04-23 12:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32 Folder::chatListViewVersion() const {
|
|
|
|
return _chatListViewVersion;
|
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
void Folder::requestChatListMessage() {
|
2019-01-15 11:57:45 +00:00
|
|
|
if (!chatListMessageKnown()) {
|
2020-02-21 07:58:50 +00:00
|
|
|
owner().histories().requestDialogEntry(this);
|
2019-01-15 11:57:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-18 09:00:38 +00:00
|
|
|
TimeId Folder::adjustedChatListTimeId() const {
|
2019-04-22 15:09:03 +00:00
|
|
|
return _chatListMessage ? _chatListMessage->date() : chatListTimeId();
|
2018-02-03 19:52:35 +00:00
|
|
|
}
|
2019-04-16 08:50:59 +00:00
|
|
|
|
|
|
|
void Folder::applyDialog(const MTPDdialogFolder &data) {
|
2019-04-24 14:53:12 +00:00
|
|
|
updateCloudUnread(data);
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto peerId = peerFromMTP(data.vpeer())) {
|
2019-04-17 13:22:37 +00:00
|
|
|
const auto history = owner().history(peerId);
|
2019-04-16 08:50:59 +00:00
|
|
|
const auto fullId = FullMsgId(
|
|
|
|
peerToChannel(peerId),
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vtop_message().v);
|
2019-04-25 12:45:15 +00:00
|
|
|
history->setFolder(this, owner().message(fullId));
|
2019-04-17 13:22:37 +00:00
|
|
|
} else {
|
|
|
|
_chatsList.clear();
|
|
|
|
updateChatListExistence();
|
2019-04-16 08:50:59 +00:00
|
|
|
}
|
2019-04-22 14:22:39 +00:00
|
|
|
if (_chatsList.indexed()->size() < kLoadedChatsMinCount) {
|
|
|
|
session().api().requestDialogs(this);
|
2019-04-19 08:47:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-22 14:22:39 +00:00
|
|
|
void Folder::updateCloudUnread(const MTPDdialogFolder &data) {
|
|
|
|
const auto notifier = unreadStateChangeNotifier(!_chatsList.loaded());
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
_cloudUnread.messages = data.vunread_muted_messages_count().v
|
|
|
|
+ data.vunread_unmuted_messages_count().v;
|
|
|
|
_cloudUnread.chats = data.vunread_muted_peers_count().v
|
|
|
|
+ data.vunread_unmuted_peers_count().v;
|
2019-04-25 10:01:09 +00:00
|
|
|
finalizeCloudUnread();
|
|
|
|
|
2019-04-24 15:28:01 +00:00
|
|
|
_cloudUnread.known = true;
|
2019-04-22 14:22:39 +00:00
|
|
|
}
|
|
|
|
|
2019-04-25 10:01:09 +00:00
|
|
|
void Folder::finalizeCloudUnread() {
|
|
|
|
// Cloud state for archive folder always counts everything as muted.
|
|
|
|
_cloudUnread.messagesMuted = _cloudUnread.messages;
|
|
|
|
_cloudUnread.chatsMuted = _cloudUnread.chats;
|
|
|
|
|
|
|
|
// We don't know the real value of marked chats counts in _cloudUnread.
|
|
|
|
_cloudUnread.marksMuted = _cloudUnread.marks = 0;
|
|
|
|
}
|
|
|
|
|
2019-04-22 14:22:39 +00:00
|
|
|
Dialogs::UnreadState Folder::chatListUnreadState() const {
|
2019-04-24 15:28:01 +00:00
|
|
|
const auto localUnread = _chatsList.unreadState();
|
|
|
|
auto result = _chatsList.loaded() ? localUnread : _cloudUnread;
|
|
|
|
result.messagesMuted = result.messages;
|
|
|
|
result.chatsMuted = result.chats;
|
|
|
|
|
2019-04-25 10:01:09 +00:00
|
|
|
// We don't know the real value of marked chats counts in _cloudUnread.
|
2019-04-24 15:28:01 +00:00
|
|
|
result.marksMuted = result.marks = localUnread.marks;
|
|
|
|
|
2019-04-22 14:22:39 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-04-19 08:47:49 +00:00
|
|
|
void Folder::applyPinnedUpdate(const MTPDupdateDialogPinned &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto folderId = data.vfolder_id().value_or_empty();
|
2019-04-19 08:47:49 +00:00
|
|
|
if (folderId != 0) {
|
|
|
|
LOG(("API Error: Nested folders detected."));
|
2019-04-17 12:08:02 +00:00
|
|
|
}
|
2019-04-19 08:47:49 +00:00
|
|
|
owner().setChatPinned(this, data.is_pinned());
|
2019-04-16 08:50:59 +00:00
|
|
|
}
|
2018-01-31 17:10:29 +00:00
|
|
|
|
2019-04-22 14:22:39 +00:00
|
|
|
void Folder::unreadStateChanged(
|
2019-04-23 12:29:23 +00:00
|
|
|
const Dialogs::Key &key,
|
2019-04-22 14:22:39 +00:00
|
|
|
const Dialogs::UnreadState &wasState,
|
|
|
|
const Dialogs::UnreadState &nowState) {
|
2019-05-08 09:05:15 +00:00
|
|
|
if (const auto history = key.history()) {
|
|
|
|
if (wasState.empty() != nowState.empty()) {
|
|
|
|
++_chatListViewVersion;
|
|
|
|
updateChatListEntry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 15:28:01 +00:00
|
|
|
const auto updateCloudUnread = _cloudUnread.known && wasState.known;
|
2019-04-22 14:22:39 +00:00
|
|
|
const auto notify = _chatsList.loaded() || updateCloudUnread;
|
|
|
|
const auto notifier = unreadStateChangeNotifier(notify);
|
2018-01-04 09:40:58 +00:00
|
|
|
|
2019-04-22 14:22:39 +00:00
|
|
|
_chatsList.unreadStateChanged(wasState, nowState);
|
2019-04-24 15:28:01 +00:00
|
|
|
if (updateCloudUnread) {
|
|
|
|
Assert(nowState.known);
|
|
|
|
_cloudUnread += nowState - wasState;
|
2019-04-25 10:01:09 +00:00
|
|
|
finalizeCloudUnread();
|
2019-04-24 15:28:01 +00:00
|
|
|
}
|
2019-04-22 14:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Folder::unreadEntryChanged(
|
2019-04-23 12:29:23 +00:00
|
|
|
const Dialogs::Key &key,
|
2019-04-22 14:22:39 +00:00
|
|
|
const Dialogs::UnreadState &state,
|
|
|
|
bool added) {
|
2019-04-24 15:28:01 +00:00
|
|
|
const auto updateCloudUnread = _cloudUnread.known && state.known;
|
2019-04-22 14:22:39 +00:00
|
|
|
const auto notify = _chatsList.loaded() || updateCloudUnread;
|
|
|
|
const auto notifier = unreadStateChangeNotifier(notify);
|
|
|
|
|
|
|
|
_chatsList.unreadEntryChanged(state, added);
|
2019-04-24 15:28:01 +00:00
|
|
|
if (updateCloudUnread) {
|
|
|
|
if (added) {
|
|
|
|
_cloudUnread += state;
|
|
|
|
} else {
|
|
|
|
_cloudUnread -= state;
|
|
|
|
}
|
2019-04-25 10:01:09 +00:00
|
|
|
finalizeCloudUnread();
|
2018-01-31 17:10:29 +00:00
|
|
|
}
|
2018-01-23 16:51:12 +00:00
|
|
|
}
|
2019-04-22 14:22:39 +00:00
|
|
|
|
2019-04-16 08:50:59 +00:00
|
|
|
// #feed
|
|
|
|
//MessagePosition Folder::unreadPosition() const {
|
|
|
|
// return _unreadPosition.current();
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//rpl::producer<MessagePosition> Folder::unreadPositionChanges() const {
|
|
|
|
// return _unreadPosition.changes();
|
|
|
|
//}
|
2018-01-23 16:51:12 +00:00
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
bool Folder::toImportant() const {
|
2019-04-22 14:22:39 +00:00
|
|
|
return false;
|
2018-01-23 16:51:12 +00:00
|
|
|
}
|
|
|
|
|
2019-04-18 11:31:30 +00:00
|
|
|
int Folder::fixedOnTopIndex() const {
|
|
|
|
return kArchiveFixOnTopIndex;
|
2018-05-11 14:03:53 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
bool Folder::shouldBeInChatList() const {
|
2019-04-16 14:05:56 +00:00
|
|
|
return !_chatsList.empty();
|
2018-01-23 16:51:12 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
int Folder::chatListUnreadCount() const {
|
2019-04-24 15:28:01 +00:00
|
|
|
const auto state = chatListUnreadState();
|
|
|
|
return state.marks
|
|
|
|
+ (session().settings().countUnreadMessages()
|
|
|
|
? state.messages
|
|
|
|
: state.chats);
|
2018-01-23 16:51:12 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
bool Folder::chatListUnreadMark() const {
|
2018-06-26 18:03:45 +00:00
|
|
|
return false; // #feed unread mark
|
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
bool Folder::chatListMutedBadge() const {
|
2019-04-22 14:22:39 +00:00
|
|
|
return true;
|
2018-01-23 16:51:12 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
HistoryItem *Folder::chatListMessage() const {
|
2019-04-22 15:09:03 +00:00
|
|
|
return _chatListMessage;
|
2019-01-15 11:57:45 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
bool Folder::chatListMessageKnown() const {
|
2019-04-22 15:09:03 +00:00
|
|
|
return true;
|
2018-01-23 16:51:12 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
const QString &Folder::chatListName() const {
|
2018-01-23 16:51:12 +00:00
|
|
|
return _name;
|
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
const base::flat_set<QString> &Folder::chatListNameWords() const {
|
2018-01-23 16:51:12 +00:00
|
|
|
return _nameWords;
|
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
const base::flat_set<QChar> &Folder::chatListFirstLetters() const {
|
2018-01-23 16:51:12 +00:00
|
|
|
return _nameFirstLetters;
|
|
|
|
}
|
|
|
|
|
2018-01-04 09:40:58 +00:00
|
|
|
} // namespace Data
|