Remove locally saved empty histories.

This commit is contained in:
John Preston 2019-05-03 15:18:18 +04:00
parent 39b7f307a4
commit 0247e876df
10 changed files with 9 additions and 173 deletions

View File

@ -719,9 +719,6 @@ void ApiWrap::requestDialogs(Data::Folder *folder) {
void ApiWrap::requestMoreDialogs(Data::Folder *folder) {
const auto state = dialogsLoadState(folder);
if (!state) {
if (!folder) {
_session->data().addAllSavedPeers();
}
return;
} else if (state->requestId) {
return;
@ -2444,9 +2441,6 @@ void ApiWrap::clearHistory(not_null<PeerData*> peer, bool revoke) {
if (const auto last = history->lastMessage()) {
deleteTillId = last->id;
}
if (const auto last = history->chatListMessage()) {
Local::addSavedPeer(history->peer, ItemDateTime(last));
}
history->clear(History::ClearType::ClearHistory);
}
if (const auto channel = peer->asChannel()) {

View File

@ -189,8 +189,6 @@ void Session::clear() {
base::take(_channelMessages);
_messageByRandomId.clear();
_sentMessagesData.clear();
cSetSavedPeers(SavedPeers());
cSetSavedPeersByTime(SavedPeersByTime());
cSetRecentInlineBots(RecentInlineBots());
cSetRecentStickers(RecentStickerPack());
cSetReportSpamStatuses(ReportSpamStatuses());
@ -1415,12 +1413,6 @@ void Session::applyDialog(
history->applyDialog(requestFolder, data);
setPinnedFromDialog(history, data.is_pinned());
if (!history->fixedOnTopIndex() && !history->isPinnedDialog()) {
const auto date = history->chatListTimeId();
if (date != 0) {
addSavedPeersAfter(ParseDateTime(date));
}
}
if (const auto from = history->peer->migrateFrom()) {
if (const auto historyFrom = from->owner().historyLoaded(from)) {
App::main()->removeDialog(historyFrom);
@ -1441,31 +1433,6 @@ void Session::applyDialog(
const auto folder = processFolder(data.vfolder);
folder->applyDialog(data);
setPinnedFromDialog(folder, data.is_pinned());
if (!folder->fixedOnTopIndex() && !folder->isPinnedDialog()) {
const auto date = folder->chatListTimeId();
if (date != 0) {
addSavedPeersAfter(ParseDateTime(date));
}
}
}
void Session::addSavedPeersAfter(const QDateTime &date) {
auto &saved = cRefSavedPeersByTime();
while (!saved.isEmpty() && (date.isNull() || date < saved.lastKey())) {
const auto lastDate = saved.lastKey();
const auto lastPeer = saved.last();
saved.remove(lastDate, lastPeer);
const auto history = session().data().history(lastPeer);
if (!history->chatListTimeId()) {
history->setChatListTimeId(ServerTimeFromParsed(lastDate));
}
}
}
void Session::addAllSavedPeers() {
addSavedPeersAfter(QDateTime());
}
int Session::pinnedChatsCount(Data::Folder *folder) const {

View File

@ -305,8 +305,6 @@ public:
const QVector<MTPMessage> &messages,
const QVector<MTPDialog> &dialogs,
std::optional<int> count = std::nullopt);
void addSavedPeersAfter(const QDateTime &date);
void addAllSavedPeers();
int pinnedChatsCount(Data::Folder *folder) const;
int pinnedChatsLimit(Data::Folder *folder) const;

View File

@ -1426,7 +1426,6 @@ void InnerWidget::removeDialog(Key key) {
session().data().removeChatListEntry(key);
if (const auto history = key.history()) {
session().notifications().clearFromHistory(history);
Local::removeSavedPeer(history->peer);
}
const auto i = ranges::find(_filterResults, key, &Row::key);
if (i != _filterResults.end()) {

View File

@ -2257,9 +2257,9 @@ void History::setChatListMessage(HistoryItem *item) {
}
const auto was = _chatListMessage.value_or(nullptr);
if (item) {
if (!_chatListMessage || !*_chatListMessage) {
Local::removeSavedPeer(peer);
} else if (!IsServerMsgId((*_chatListMessage)->id)
if (_chatListMessage
&& *_chatListMessage
&& !IsServerMsgId((*_chatListMessage)->id)
&& (*_chatListMessage)->date() > item->date()) {
return;
}

View File

@ -3203,7 +3203,6 @@ void MainWidget::start() {
session().api().requestNotifySettings(MTP_inputNotifyChats());
session().api().requestNotifySettings(MTP_inputNotifyBroadcasts());
Local::readSavedPeers();
cSetOtherOnline(0);
session().user()->loadUserpic();

View File

@ -86,9 +86,6 @@ bool gIsSnowLeopard = false;
int gOtherOnline = 0;
SavedPeers gSavedPeers;
SavedPeersByTime gSavedPeersByTime;
ReportSpamStatuses gReportSpamStatuses;
int32 gAutoDownloadPhoto = 0; // all auto download

View File

@ -164,12 +164,6 @@ DeclareReadSetting(bool, IsSnowLeopard);
DeclareSetting(int, OtherOnline);
class PeerData;
typedef QMap<PeerData*, QDateTime> SavedPeers;
typedef QMultiMap<QDateTime, PeerData*> SavedPeersByTime;
DeclareRefSetting(SavedPeers, SavedPeers);
DeclareRefSetting(SavedPeersByTime, SavedPeersByTime);
typedef QMap<uint64, DBIPeerReportSpamStatus> ReportSpamStatuses;
DeclareRefSetting(ReportSpamStatuses, ReportSpamStatuses);

View File

@ -517,7 +517,7 @@ enum { // Local Storage Keys
lskUserSettings = 0x09, // no data
lskRecentHashtagsAndBots = 0x0a, // no data
lskStickersOld = 0x0b, // no data
lskSavedPeers = 0x0c, // no data
lskSavedPeersOld = 0x0c, // no data
lskReportSpamStatuses = 0x0d, // no data
lskSavedGifsOld = 0x0e, // no data
lskSavedGifs = 0x0f, // no data
@ -686,7 +686,6 @@ bool NoTimeLimit(qint32 storedLimitValue) {
FileKey _exportSettingsKey = 0;
FileKey _savedPeersKey = 0;
FileKey _langPackKey = 0;
FileKey _languagesKey = 0;
@ -2303,7 +2302,7 @@ ReadMapState _readMap(const QByteArray &pass) {
quint64 installedStickersKey = 0, featuredStickersKey = 0, recentStickersKey = 0, favedStickersKey = 0, archivedStickersKey = 0;
quint64 savedGifsKey = 0;
quint64 backgroundKeyDay = 0, backgroundKeyNight = 0;
quint64 userSettingsKey = 0, recentHashtagsAndBotsKey = 0, savedPeersKey = 0, exportSettingsKey = 0;
quint64 userSettingsKey = 0, recentHashtagsAndBotsKey = 0, exportSettingsKey = 0;
while (!map.stream.atEnd()) {
quint32 keyType;
map.stream >> keyType;
@ -2387,8 +2386,9 @@ ReadMapState _readMap(const QByteArray &pass) {
case lskSavedGifs: {
map.stream >> savedGifsKey;
} break;
case lskSavedPeers: {
map.stream >> savedPeersKey;
case lskSavedPeersOld: {
quint64 key;
map.stream >> key;
} break;
case lskExportSettings: {
map.stream >> exportSettingsKey;
@ -2416,7 +2416,6 @@ ReadMapState _readMap(const QByteArray &pass) {
_favedStickersKey = favedStickersKey;
_archivedStickersKey = archivedStickersKey;
_savedGifsKey = savedGifsKey;
_savedPeersKey = savedPeersKey;
_backgroundKeyDay = backgroundKeyDay;
_backgroundKeyNight = backgroundKeyNight;
_userSettingsKey = userSettingsKey;
@ -2520,7 +2519,6 @@ void _writeMap(WriteMapWhen when) {
}
if (_favedStickersKey) mapSize += sizeof(quint32) + sizeof(quint64);
if (_savedGifsKey) mapSize += sizeof(quint32) + sizeof(quint64);
if (_savedPeersKey) mapSize += sizeof(quint32) + sizeof(quint64);
if (_backgroundKeyDay || _backgroundKeyNight) mapSize += sizeof(quint32) + sizeof(quint64) + sizeof(quint64);
if (_userSettingsKey) mapSize += sizeof(quint32) + sizeof(quint64);
if (_recentHashtagsAndBotsKey) mapSize += sizeof(quint32) + sizeof(quint64);
@ -2564,9 +2562,6 @@ void _writeMap(WriteMapWhen when) {
if (_savedGifsKey) {
mapData.stream << quint32(lskSavedGifs) << quint64(_savedGifsKey);
}
if (_savedPeersKey) {
mapData.stream << quint32(lskSavedPeers) << quint64(_savedPeersKey);
}
if (_backgroundKeyDay || _backgroundKeyNight) {
mapData.stream
<< quint32(lskBackground)
@ -2843,7 +2838,7 @@ void reset() {
_savedGifsKey = 0;
_backgroundKeyDay = _backgroundKeyNight = 0;
Window::Theme::Background()->reset();
_userSettingsKey = _recentHashtagsAndBotsKey = _savedPeersKey = _exportSettingsKey = 0;
_userSettingsKey = _recentHashtagsAndBotsKey = _exportSettingsKey = 0;
_oldMapVersion = _oldSettingsVersion = 0;
_cacheTotalSizeLimit = Database::Settings().totalSizeLimit;
_cacheTotalTimeLimit = Database::Settings().totalTimeLimit;
@ -2892,7 +2887,6 @@ base::flat_set<QString> CollectGoodNames() {
_backgroundKeyDay,
_recentHashtagsAndBotsKey,
_exportSettingsKey,
_savedPeersKey,
_trustedBotsKey
};
auto result = base::flat_set<QString>{ "map0", "map1" };
@ -4817,104 +4811,6 @@ Export::Settings ReadExportSettings() {
: Export::Settings();
}
void writeSavedPeers() {
if (!_working()) return;
const SavedPeers &saved(cSavedPeers());
if (saved.isEmpty()) {
if (_savedPeersKey) {
clearKey(_savedPeersKey);
_savedPeersKey = 0;
_mapChanged = true;
}
_writeMap();
} else {
if (!_savedPeersKey) {
_savedPeersKey = genKey();
_mapChanged = true;
_writeMap(WriteMapWhen::Fast);
}
quint32 size = sizeof(quint32);
for (SavedPeers::const_iterator i = saved.cbegin(); i != saved.cend(); ++i) {
size += Serialize::peerSize(i.key()) + Serialize::dateTimeSize();
}
EncryptedDescriptor data(size);
data.stream << quint32(saved.size());
for (SavedPeers::const_iterator i = saved.cbegin(); i != saved.cend(); ++i) {
Serialize::writePeer(data.stream, i.key());
data.stream << i.value();
}
FileWriteDescriptor file(_savedPeersKey);
file.writeEncrypted(data);
}
}
void readSavedPeers() {
if (!_savedPeersKey) return;
FileReadDescriptor saved;
if (!readEncryptedFile(saved, _savedPeersKey)) {
clearKey(_savedPeersKey);
_savedPeersKey = 0;
_writeMap();
return;
}
if (saved.version == 9011) { // broken dev version
clearKey(_savedPeersKey);
_savedPeersKey = 0;
_writeMap();
return;
}
quint32 count = 0;
saved.stream >> count;
cRefSavedPeers().clear();
cRefSavedPeersByTime().clear();
QList<PeerData*> peers;
peers.reserve(count);
for (uint32 i = 0; i < count; ++i) {
const auto peer = Serialize::readPeer(saved.version, saved.stream);
if (!peer) break;
QDateTime t;
saved.stream >> t;
cRefSavedPeers().insert(peer, t);
cRefSavedPeersByTime().insert(t, peer);
peers.push_back(peer);
}
Auth().api().requestPeers(peers);
}
void addSavedPeer(PeerData *peer, const QDateTime &position) {
auto &savedPeers = cRefSavedPeers();
auto i = savedPeers.find(peer);
if (i == savedPeers.cend()) {
savedPeers.insert(peer, position);
} else if (i.value() != position) {
cRefSavedPeersByTime().remove(i.value(), peer);
i.value() = position;
cRefSavedPeersByTime().insert(i.value(), peer);
}
writeSavedPeers();
}
void removeSavedPeer(PeerData *peer) {
auto &savedPeers = cRefSavedPeers();
if (savedPeers.isEmpty()) return;
auto i = savedPeers.find(peer);
if (i != savedPeers.cend()) {
cRefSavedPeersByTime().remove(i.value(), peer);
savedPeers.erase(i);
writeSavedPeers();
}
}
void writeReportSpamStatuses() {
_writeReportSpamStatuses();
}
@ -5073,10 +4969,6 @@ bool ClearManager::addTask(int task) {
_recentHashtagsAndBotsKey = 0;
_mapChanged = true;
}
if (_savedPeersKey) {
_savedPeersKey = 0;
_mapChanged = true;
}
_writeMap();
} else {
for (int32 i = 0, l = data->tasks.size(); i < l; ++i) {

View File

@ -168,10 +168,6 @@ void saveRecentSearchHashtags(const QString &text);
void WriteExportSettings(const Export::Settings &settings);
Export::Settings ReadExportSettings();
void addSavedPeer(PeerData *peer, const QDateTime &position);
void removeSavedPeer(PeerData *peer);
void readSavedPeers();
void writeReportSpamStatuses();
void writeSelf();