2018-01-04 12:40:58 +03: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 15:54:03 +04:00
|
|
|
#include "data/data_folder.h"
|
2018-01-04 12:40:58 +03:00
|
|
|
|
2018-01-23 19:51:12 +03:00
|
|
|
#include "data/data_session.h"
|
2019-01-04 15:09:48 +04:00
|
|
|
#include "data/data_channel.h"
|
2018-01-05 18:57:18 +03:00
|
|
|
#include "dialogs/dialogs_key.h"
|
2018-01-13 15:45:11 +03:00
|
|
|
#include "history/history.h"
|
2018-01-11 22:33:26 +03:00
|
|
|
#include "history/history_item.h"
|
2018-01-22 12:33:09 +03:00
|
|
|
#include "lang/lang_keys.h"
|
2018-01-23 19:51:12 +03:00
|
|
|
#include "storage/storage_facade.h"
|
2019-04-15 15:54:03 +04:00
|
|
|
//#include "storage/storage_feed_messages.h" // #feed
|
2018-01-23 19:51:12 +03:00
|
|
|
#include "auth_session.h"
|
2018-01-29 20:13:24 +03:00
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "mainwidget.h"
|
2019-04-16 12:50:59 +04:00
|
|
|
#include "styles/style_dialogs.h" // st::dialogsArchiveUserpic
|
2018-01-05 18:57:18 +03:00
|
|
|
|
2018-01-04 12:40:58 +03:00
|
|
|
namespace Data {
|
2019-04-17 16:08:02 +04:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kLoadedChatsMinCount = 20;
|
|
|
|
|
|
|
|
} // namespace
|
2018-01-04 12:40:58 +03:00
|
|
|
|
2018-03-06 20:07:42 +03:00
|
|
|
// #feed
|
|
|
|
//MessagePosition FeedPositionFromMTP(const MTPFeedPosition &position) {
|
|
|
|
// Expects(position.type() == mtpc_feedPosition);
|
|
|
|
//
|
|
|
|
// const auto &data = position.c_feedPosition();
|
|
|
|
// return MessagePosition(data.vdate.v, FullMsgId(
|
|
|
|
// peerToChannel(peerFromMTP(data.vpeer)),
|
|
|
|
// data.vid.v));
|
|
|
|
//}
|
2018-01-05 18:57:18 +03:00
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
Folder::Folder(not_null<Data::Session*> owner, FolderId id)
|
2019-04-16 18:05:56 +04:00
|
|
|
: Entry(owner, this)
|
2018-01-22 12:33:09 +03:00
|
|
|
, _id(id)
|
2019-04-16 18:05:56 +04:00
|
|
|
, _chatsList(Dialogs::SortMode::Date)
|
2019-04-17 17:22:37 +04:00
|
|
|
, _importantChatsList(Dialogs::SortMode::Date)
|
2019-04-19 12:47:49 +04:00
|
|
|
, _pinnedChatsList(Global::PinnedDialogsInFolderMax())
|
2019-04-16 12:50:59 +04:00
|
|
|
, _name(lang(lng_archived_chats)) {
|
2018-01-22 12:33:09 +03:00
|
|
|
indexNameParts();
|
|
|
|
}
|
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
FolderId Folder::id() const {
|
2018-01-23 19:51:12 +03:00
|
|
|
return _id;
|
|
|
|
}
|
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
void Folder::indexNameParts() {
|
2018-01-22 12:33:09 +03:00
|
|
|
_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 12:40:58 +03:00
|
|
|
}
|
|
|
|
|
2019-04-16 12:50:59 +04:00
|
|
|
void Folder::registerOne(not_null<History*> history) {
|
|
|
|
//session().storage().invalidate( // #feed
|
|
|
|
// Storage::FeedMessagesInvalidate(_id));
|
2018-02-05 17:37:22 +03:00
|
|
|
|
2019-04-16 12:50:59 +04:00
|
|
|
if (unreadCountKnown()) {
|
|
|
|
if (history->unreadCountKnown()) {
|
|
|
|
// If history unreadCount is known that means that we've
|
|
|
|
// already had the channel information and if it was in the
|
|
|
|
// feed already (not yet known) it wouldn't get here.
|
|
|
|
// That means here we get if we add a new channel to feed.
|
|
|
|
if (const auto count = history->unreadCount()) {
|
|
|
|
unreadCountChanged(count, history->mute() ? count : 0);
|
2018-02-08 12:20:14 +03:00
|
|
|
}
|
2019-04-17 17:22:37 +04:00
|
|
|
} else {
|
2019-04-16 12:50:59 +04:00
|
|
|
session().api().requestDialogEntry(this);
|
2018-02-08 12:20:14 +03:00
|
|
|
}
|
2019-04-16 12:50:59 +04:00
|
|
|
}
|
2019-04-17 17:22:37 +04:00
|
|
|
if (_chatsList.size() == 1) {
|
2019-04-18 15:31:30 +04:00
|
|
|
updateChatListSortPosition();
|
2018-01-05 18:57:18 +03:00
|
|
|
}
|
2019-04-16 18:05:56 +04:00
|
|
|
owner().notifyFolderUpdated(this, FolderUpdateFlag::List);
|
2018-01-04 12:40:58 +03:00
|
|
|
}
|
|
|
|
|
2019-04-16 12:50:59 +04:00
|
|
|
void Folder::unregisterOne(not_null<History*> history) {
|
|
|
|
//session().storage().remove( // #feed
|
|
|
|
// Storage::FeedMessagesRemoveAll(_id, channel->bareId()));
|
|
|
|
|
|
|
|
if (unreadCountKnown()) {
|
|
|
|
if (history->unreadCountKnown()) {
|
|
|
|
if (const auto delta = -history->unreadCount()) {
|
|
|
|
unreadCountChanged(delta, history->mute() ? delta : 0);
|
2018-01-29 16:52:09 +03:00
|
|
|
}
|
2018-01-29 20:13:24 +03:00
|
|
|
} else {
|
2019-04-16 12:50:59 +04:00
|
|
|
session().api().requestDialogEntry(this);
|
|
|
|
}
|
|
|
|
}
|
2019-04-16 18:05:56 +04:00
|
|
|
if (_chatsList.empty()) {
|
2019-04-16 12:50:59 +04:00
|
|
|
updateChatListExistence();
|
2018-01-05 18:57:18 +03:00
|
|
|
}
|
2019-04-16 18:05:56 +04:00
|
|
|
owner().notifyFolderUpdated(this, FolderUpdateFlag::List);
|
|
|
|
}
|
|
|
|
|
2019-04-17 17:22:37 +04:00
|
|
|
not_null<Dialogs::IndexedList*> Folder::chatsList(Dialogs::Mode list) {
|
|
|
|
return (list == Dialogs::Mode::All)
|
|
|
|
? &_chatsList
|
|
|
|
: &_importantChatsList;
|
2018-01-05 18:57:18 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
void Folder::loadUserpic() {
|
|
|
|
//constexpr auto kPaintUserpicsCount = 4; // #feed
|
|
|
|
//auto load = kPaintUserpicsCount;
|
2019-04-16 12:50:59 +04:00
|
|
|
//for (const auto history : _histories) {
|
2019-04-15 15:54:03 +04:00
|
|
|
// history->peer->loadUserpic();
|
|
|
|
// if (!--load) {
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
//}
|
2018-01-05 18:57:18 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
void Folder::paintUserpic(
|
2018-01-05 18:57:18 +03:00
|
|
|
Painter &p,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int size) const {
|
2019-04-16 12:50:59 +04:00
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(st::historyPeerArchiveUserpicBg);
|
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.drawRoundedRect(x, y, size, size, size / 3., size / 3.);
|
|
|
|
}
|
|
|
|
st::dialogsArchiveUserpic.paintInCenter(p, { x, y, size, size });
|
2019-04-15 15:54:03 +04:00
|
|
|
//const auto small = (size - st::lineWidth) / 2; // #feed
|
|
|
|
//const auto delta = size - small;
|
|
|
|
//auto index = 0;
|
2019-04-16 12:50:59 +04:00
|
|
|
//for (const auto history : _histories) {
|
2019-04-15 15:54:03 +04: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 18:57:18 +03:00
|
|
|
}
|
|
|
|
|
2019-04-17 17:22:37 +04:00
|
|
|
bool Folder::chatsListLoaded() const {
|
|
|
|
return _chatsListLoaded;
|
2018-01-29 20:13:24 +03:00
|
|
|
}
|
|
|
|
|
2019-04-17 17:22:37 +04:00
|
|
|
void Folder::setChatsListLoaded(bool loaded) {
|
|
|
|
if (_chatsListLoaded != loaded) {
|
|
|
|
_chatsListLoaded = loaded;
|
2019-04-16 18:05:56 +04:00
|
|
|
owner().notifyFolderUpdated(this, FolderUpdateFlag::List);
|
2018-02-07 19:37:05 +03:00
|
|
|
}
|
2018-01-30 15:13:46 +03:00
|
|
|
}
|
2019-04-16 12:50:59 +04:00
|
|
|
// // #feed
|
|
|
|
//int32 Folder::chatsHash() const {
|
|
|
|
// const auto ordered = ranges::view::all(
|
|
|
|
// _histories
|
|
|
|
// ) | ranges::view::transform([](not_null<History*> history) {
|
|
|
|
// return history->peer->bareId();
|
|
|
|
// }) | ranges::to_vector | ranges::action::sort;
|
|
|
|
// return Api::CountHash(ordered);
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//void Folder::setChats(std::vector<not_null<PeerData*>> chats) {
|
|
|
|
// const auto remove = ranges::view::all(
|
|
|
|
// _histories
|
|
|
|
// ) | ranges::view::transform([](not_null<History*> history) {
|
|
|
|
// return history->peer;
|
|
|
|
// }) | ranges::view::filter([&](not_null<PeerData*> peer) {
|
|
|
|
// return !base::contains(chats, peer);
|
|
|
|
// }) | ranges::to_vector;
|
|
|
|
//
|
|
|
|
// const auto add = ranges::view::all(
|
|
|
|
// chats
|
|
|
|
// ) | ranges::view::filter([&](not_null<PeerData*> peer) {
|
|
|
|
// return ranges::find(
|
|
|
|
// _histories,
|
|
|
|
// peer,
|
|
|
|
// [](auto history) { return history->peer; }
|
|
|
|
// ) == end(_histories);
|
|
|
|
// }) | ranges::view::transform([](PeerData *peer) {
|
|
|
|
// return not_null<PeerData*>(peer);
|
|
|
|
// }) | ranges::to_vector;
|
|
|
|
//
|
|
|
|
// changeChatsList(add, remove);
|
|
|
|
//
|
|
|
|
// setChatsLoaded(true);
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//void Folder::changeChatsList(
|
|
|
|
// const std::vector<not_null<PeerData*>> &add,
|
|
|
|
// const std::vector<not_null<PeerData*>> &remove) {
|
|
|
|
// _settingChats = true;
|
|
|
|
// const auto restore = gsl::finally([&] { _settingChats = false; });
|
|
|
|
//
|
|
|
|
// for (const auto channel : remove) {
|
|
|
|
// channel->clearFeed();
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// //// We assume the last message was correct before requesting the list.
|
|
|
|
// //// So we save it and don't allow channels from the list to change it.
|
|
|
|
// //// After that we restore it.
|
|
|
|
// const auto oldChatListMessage = base::take(_chatListMessage);
|
|
|
|
// for (const auto channel : add) {
|
|
|
|
// _chatListMessage = std::nullopt;
|
|
|
|
// channel->setFeed(this);
|
|
|
|
// }
|
|
|
|
// _chatListMessage = oldChatListMessage;
|
|
|
|
//}
|
2018-01-30 15:13:46 +03:00
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
void Folder::requestChatListMessage() {
|
2019-01-15 15:57:45 +04:00
|
|
|
if (!chatListMessageKnown()) {
|
|
|
|
session().api().requestDialogEntry(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-19 12:47:49 +04:00
|
|
|
void Folder::setPinnedChatsLimit(int limit) {
|
|
|
|
_pinnedChatsList.setLimit(limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Folder::setChatPinned(const Dialogs::Key &key, bool pinned) {
|
|
|
|
_pinnedChatsList.setPinned(key, pinned);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Folder::addPinnedChat(const Dialogs::Key &key) {
|
|
|
|
_pinnedChatsList.addPinned(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Folder::applyPinnedChats(const QVector<MTPDialogPeer> &list) {
|
|
|
|
_pinnedChatsList.applyList(&owner(), list);
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<Dialogs::Key> &Folder::pinnedChatsOrder() const {
|
|
|
|
return _pinnedChatsList.order();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Folder::clearPinnedChats() {
|
|
|
|
_pinnedChatsList.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Folder::reorderTwoPinnedChats(
|
|
|
|
const Dialogs::Key &key1,
|
|
|
|
const Dialogs::Key &key2) {
|
|
|
|
_pinnedChatsList.reorder(key1, key2);
|
|
|
|
}
|
|
|
|
|
2019-04-18 13:00:38 +04:00
|
|
|
TimeId Folder::adjustedChatListTimeId() const {
|
|
|
|
return _chatsList.empty()
|
|
|
|
? TimeId(0)
|
|
|
|
: (*_chatsList.begin())->entry()->adjustedChatListTimeId();
|
|
|
|
}
|
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
int Folder::unreadCount() const {
|
2019-04-18 13:00:38 +04:00
|
|
|
return _unreadCount.value_or(0);
|
2018-02-03 22:52:35 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
rpl::producer<int> Folder::unreadCountValue() const {
|
2018-02-04 22:57:03 +03:00
|
|
|
return rpl::single(
|
|
|
|
unreadCount()
|
|
|
|
) | rpl::then(_unreadCountChanges.events());
|
|
|
|
}
|
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
bool Folder::unreadCountKnown() const {
|
2018-02-03 22:52:35 +03:00
|
|
|
return !!_unreadCount;
|
|
|
|
}
|
2019-04-16 12:50:59 +04:00
|
|
|
|
|
|
|
void Folder::applyDialog(const MTPDdialogFolder &data) {
|
|
|
|
//const auto addChannel = [&](ChannelId channelId) { // #feed
|
|
|
|
// if (const auto channel = owner().channelLoaded(channelId)) {
|
|
|
|
// channel->setFeed(this);
|
|
|
|
// }
|
|
|
|
//};
|
|
|
|
//for (const auto &channelId : data.vfeed_other_channels.v) {
|
|
|
|
// addChannel(channelId.v);
|
|
|
|
//}
|
|
|
|
|
|
|
|
if (const auto peerId = peerFromMTP(data.vpeer)) {
|
2019-04-17 17:22:37 +04:00
|
|
|
const auto history = owner().history(peerId);
|
2019-04-16 12:50:59 +04:00
|
|
|
const auto fullId = FullMsgId(
|
|
|
|
peerToChannel(peerId),
|
|
|
|
data.vtop_message.v);
|
2019-04-17 17:22:37 +04:00
|
|
|
history->setFolder(this, App::histItemById(fullId));
|
|
|
|
} else {
|
|
|
|
_chatsList.clear();
|
|
|
|
_importantChatsList.clear();
|
|
|
|
updateChatListExistence();
|
2019-04-16 12:50:59 +04:00
|
|
|
}
|
|
|
|
setUnreadCounts(
|
|
|
|
data.vunread_unmuted_messages_count.v,
|
|
|
|
data.vunread_muted_messages_count.v);
|
|
|
|
//setUnreadMark(data.is_unread_mark());
|
|
|
|
//setUnreadMentionsCount(data.vunread_mentions_count.v);
|
|
|
|
|
|
|
|
//if (data.has_read_max_position()) { // #feed
|
|
|
|
// setUnreadPosition(FeedPositionFromMTP(data.vread_max_position));
|
|
|
|
//}
|
2019-04-17 16:08:02 +04:00
|
|
|
|
|
|
|
if (_chatsList.size() < kLoadedChatsMinCount) {
|
2019-04-19 12:47:49 +04:00
|
|
|
session().api().requestDialogs(_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Folder::applyPinnedUpdate(const MTPDupdateDialogPinned &data) {
|
|
|
|
const auto folderId = data.has_folder_id() ? data.vfolder_id.v : 0;
|
|
|
|
if (folderId != 0) {
|
|
|
|
LOG(("API Error: Nested folders detected."));
|
2019-04-17 16:08:02 +04:00
|
|
|
}
|
2019-04-19 12:47:49 +04:00
|
|
|
owner().setChatPinned(this, data.is_pinned());
|
2019-04-16 12:50:59 +04:00
|
|
|
}
|
2018-01-31 20:10:29 +03:00
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
void Folder::changedInChatListHook(Dialogs::Mode list, bool added) {
|
2018-12-04 14:32:06 +04:00
|
|
|
if (list != Dialogs::Mode::All) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (const auto count = unreadCount()) {
|
2018-02-20 20:53:55 +03:00
|
|
|
const auto mutedCount = _unreadMutedCount;
|
2018-12-04 14:32:06 +04:00
|
|
|
const auto nonMutedCount = count - mutedCount;
|
2018-02-20 20:53:55 +03:00
|
|
|
const auto mutedDelta = added ? mutedCount : -mutedCount;
|
|
|
|
const auto nonMutedDelta = added ? nonMutedCount : -nonMutedCount;
|
2019-04-16 18:05:56 +04:00
|
|
|
owner().unreadIncrement(nonMutedDelta, false);
|
|
|
|
owner().unreadIncrement(mutedDelta, true);
|
2018-12-04 14:32:06 +04:00
|
|
|
|
|
|
|
const auto fullMuted = (nonMutedCount == 0);
|
|
|
|
const auto entriesWithUnreadDelta = added ? 1 : -1;
|
|
|
|
const auto mutedEntriesWithUnreadDelta = fullMuted
|
|
|
|
? entriesWithUnreadDelta
|
|
|
|
: 0;
|
2019-04-16 18:05:56 +04:00
|
|
|
owner().unreadEntriesChanged(
|
2018-12-04 14:32:06 +04:00
|
|
|
entriesWithUnreadDelta,
|
|
|
|
mutedEntriesWithUnreadDelta);
|
2018-02-20 20:53:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-04 14:32:06 +04:00
|
|
|
template <typename PerformUpdate>
|
2019-04-15 15:54:03 +04:00
|
|
|
void Folder::updateUnreadCounts(PerformUpdate &&performUpdate) {
|
2018-12-04 14:32:06 +04:00
|
|
|
const auto wasUnreadCount = _unreadCount ? *_unreadCount : 0;
|
|
|
|
const auto wasUnreadMutedCount = _unreadMutedCount;
|
|
|
|
const auto wasFullMuted = (wasUnreadMutedCount > 0)
|
|
|
|
&& (wasUnreadCount == wasUnreadMutedCount);
|
|
|
|
|
|
|
|
performUpdate();
|
|
|
|
Assert(_unreadCount.has_value());
|
2018-02-04 22:57:03 +03:00
|
|
|
|
|
|
|
_unreadCountChanges.fire(unreadCount());
|
2018-02-03 22:52:35 +03:00
|
|
|
updateChatListEntry();
|
2018-02-20 20:53:55 +03:00
|
|
|
|
|
|
|
if (inChatList(Dialogs::Mode::All)) {
|
2018-12-04 14:32:06 +04:00
|
|
|
const auto nowUnreadCount = *_unreadCount;
|
|
|
|
const auto nowUnreadMutedCount = _unreadMutedCount;
|
|
|
|
const auto nowFullMuted = (nowUnreadMutedCount > 0)
|
|
|
|
&& (nowUnreadCount == nowUnreadMutedCount);
|
|
|
|
|
2019-04-16 18:05:56 +04:00
|
|
|
owner().unreadIncrement(
|
2018-12-04 14:32:06 +04:00
|
|
|
(nowUnreadCount - nowUnreadMutedCount)
|
|
|
|
- (wasUnreadCount - wasUnreadMutedCount),
|
2018-02-20 20:53:55 +03:00
|
|
|
false);
|
2019-04-16 18:05:56 +04:00
|
|
|
owner().unreadIncrement(
|
2018-12-04 14:32:06 +04:00
|
|
|
nowUnreadMutedCount - wasUnreadMutedCount,
|
2018-02-20 20:53:55 +03:00
|
|
|
true);
|
2018-12-04 14:32:06 +04:00
|
|
|
|
|
|
|
const auto entriesDelta = (nowUnreadCount && !wasUnreadCount)
|
|
|
|
? 1
|
|
|
|
: (wasUnreadCount && !nowUnreadCount)
|
|
|
|
? -1
|
|
|
|
: 0;
|
|
|
|
const auto mutedEntriesDelta = (!wasFullMuted && nowFullMuted)
|
|
|
|
? 1
|
|
|
|
: (wasFullMuted && !nowFullMuted)
|
|
|
|
? -1
|
|
|
|
: 0;
|
2019-04-16 18:05:56 +04:00
|
|
|
owner().unreadEntriesChanged(
|
2018-12-04 14:32:06 +04:00
|
|
|
entriesDelta,
|
|
|
|
mutedEntriesDelta);
|
2018-02-20 20:53:55 +03:00
|
|
|
}
|
2018-01-04 12:40:58 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
void Folder::setUnreadCounts(int unreadNonMutedCount, int unreadMutedCount) {
|
2018-12-04 14:32:06 +04:00
|
|
|
if (unreadCountKnown()
|
|
|
|
&& (*_unreadCount == unreadNonMutedCount + unreadMutedCount)
|
|
|
|
&& (_unreadMutedCount == unreadMutedCount)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
updateUnreadCounts([&] {
|
|
|
|
_unreadCount = unreadNonMutedCount + unreadMutedCount;
|
|
|
|
_unreadMutedCount = unreadMutedCount;
|
|
|
|
});
|
|
|
|
}
|
2019-04-16 12:50:59 +04:00
|
|
|
// #feed
|
|
|
|
//void Folder::setUnreadPosition(const MessagePosition &position) {
|
|
|
|
// if (_unreadPosition.current() < position) {
|
|
|
|
// _unreadPosition = position;
|
|
|
|
// }
|
|
|
|
//}
|
2018-01-31 20:10:29 +03:00
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
void Folder::unreadCountChanged(int unreadCountDelta, int mutedCountDelta) {
|
2018-02-12 14:10:40 +03:00
|
|
|
if (!unreadCountKnown()) {
|
2018-01-31 20:10:29 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-12-04 14:32:06 +04:00
|
|
|
updateUnreadCounts([&] {
|
|
|
|
accumulate_max(unreadCountDelta, -*_unreadCount);
|
|
|
|
*_unreadCount += unreadCountDelta;
|
|
|
|
|
|
|
|
mutedCountDelta = snap(
|
|
|
|
mutedCountDelta,
|
|
|
|
-_unreadMutedCount,
|
|
|
|
*_unreadCount - _unreadMutedCount);
|
|
|
|
_unreadMutedCount += mutedCountDelta;
|
|
|
|
});
|
2018-01-23 19:51:12 +03:00
|
|
|
}
|
2019-04-16 12:50:59 +04:00
|
|
|
//
|
|
|
|
//void Folder::setUnreadMark(bool unread) {
|
|
|
|
// if (_unreadMark != unread) {
|
|
|
|
// _unreadMark = unread;
|
|
|
|
// if (!_unreadCount || !*_unreadCount) {
|
|
|
|
// if (inChatList(Dialogs::Mode::All)) {
|
|
|
|
// const auto delta = _unreadMark ? 1 : -1;
|
2019-04-16 18:05:56 +04:00
|
|
|
// owner().unreadIncrement(delta, mute());
|
|
|
|
// owner().unreadEntriesChanged(
|
2019-04-16 12:50:59 +04:00
|
|
|
// delta,
|
|
|
|
// mute() ? delta : 0);
|
|
|
|
//
|
|
|
|
// updateChatListEntry();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// Notify::peerUpdatedDelayed(
|
|
|
|
// peer,
|
|
|
|
// Notify::PeerUpdate::Flag::UnreadViewChanged);
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//bool Folder::unreadMark() const {
|
|
|
|
// return _unreadMark;
|
|
|
|
//}
|
|
|
|
// #feed
|
|
|
|
//MessagePosition Folder::unreadPosition() const {
|
|
|
|
// return _unreadPosition.current();
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//rpl::producer<MessagePosition> Folder::unreadPositionChanges() const {
|
|
|
|
// return _unreadPosition.changes();
|
|
|
|
//}
|
2018-01-23 19:51:12 +03:00
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
bool Folder::toImportant() const {
|
2019-04-17 17:22:37 +04:00
|
|
|
return !_importantChatsList.empty();
|
2018-01-23 19:51:12 +03:00
|
|
|
}
|
|
|
|
|
2019-04-18 15:31:30 +04:00
|
|
|
int Folder::fixedOnTopIndex() const {
|
|
|
|
return kArchiveFixOnTopIndex;
|
2018-05-11 17:03:53 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
bool Folder::shouldBeInChatList() const {
|
2019-04-16 18:05:56 +04:00
|
|
|
return !_chatsList.empty();
|
2018-01-23 19:51:12 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
int Folder::chatListUnreadCount() const {
|
2018-02-03 22:52:35 +03:00
|
|
|
return unreadCount();
|
2018-01-23 19:51:12 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
bool Folder::chatListUnreadMark() const {
|
2018-06-26 19:03:45 +01:00
|
|
|
return false; // #feed unread mark
|
|
|
|
}
|
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
bool Folder::chatListMutedBadge() const {
|
2018-01-31 20:10:29 +03:00
|
|
|
return _unreadCount ? (*_unreadCount <= _unreadMutedCount) : false;
|
2018-01-23 19:51:12 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
HistoryItem *Folder::chatListMessage() const {
|
2019-04-17 17:22:37 +04:00
|
|
|
return _chatsList.empty()
|
|
|
|
? nullptr
|
|
|
|
: (*_chatsList.begin())->key().entry()->chatListMessage();
|
2019-01-15 15:57:45 +04:00
|
|
|
}
|
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
bool Folder::chatListMessageKnown() const {
|
2019-04-17 17:22:37 +04:00
|
|
|
return _chatsList.empty()
|
|
|
|
|| (*_chatsList.begin())->key().entry()->chatListMessageKnown();
|
2018-01-23 19:51:12 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
const QString &Folder::chatListName() const {
|
2018-01-23 19:51:12 +03:00
|
|
|
return _name;
|
|
|
|
}
|
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
const base::flat_set<QString> &Folder::chatListNameWords() const {
|
2018-01-23 19:51:12 +03:00
|
|
|
return _nameWords;
|
|
|
|
}
|
|
|
|
|
2019-04-15 15:54:03 +04:00
|
|
|
const base::flat_set<QChar> &Folder::chatListFirstLetters() const {
|
2018-01-23 19:51:12 +03:00
|
|
|
return _nameFirstLetters;
|
|
|
|
}
|
|
|
|
|
2018-01-04 12:40:58 +03:00
|
|
|
} // namespace Data
|