mirror of https://github.com/procxx/kepka.git
writing report spam statuses to local storage
This commit is contained in:
parent
ce678bad68
commit
0a80ef0006
|
@ -1743,6 +1743,7 @@ namespace App {
|
||||||
cSetStickerSets(StickerSets());
|
cSetStickerSets(StickerSets());
|
||||||
cSetStickerSetsOrder(StickerSetsOrder());
|
cSetStickerSetsOrder(StickerSetsOrder());
|
||||||
cSetLastStickersUpdate(0);
|
cSetLastStickersUpdate(0);
|
||||||
|
cSetReportSpamStatuses(ReportSpamStatuses());
|
||||||
::videoItems.clear();
|
::videoItems.clear();
|
||||||
::audioItems.clear();
|
::audioItems.clear();
|
||||||
::documentItems.clear();
|
::documentItems.clear();
|
||||||
|
|
|
@ -495,19 +495,20 @@ namespace {
|
||||||
FileKey _dataNameKey = 0;
|
FileKey _dataNameKey = 0;
|
||||||
|
|
||||||
enum { // Local Storage Keys
|
enum { // Local Storage Keys
|
||||||
lskUserMap = 0x00,
|
lskUserMap = 0x00,
|
||||||
lskDraft = 0x01, // data: PeerId peer
|
lskDraft = 0x01, // data: PeerId peer
|
||||||
lskDraftPosition = 0x02, // data: PeerId peer
|
lskDraftPosition = 0x02, // data: PeerId peer
|
||||||
lskImages = 0x03, // data: StorageKey location
|
lskImages = 0x03, // data: StorageKey location
|
||||||
lskLocations = 0x04, // no data
|
lskLocations = 0x04, // no data
|
||||||
lskStickerImages = 0x05, // data: StorageKey location
|
lskStickerImages = 0x05, // data: StorageKey location
|
||||||
lskAudios = 0x06, // data: StorageKey location
|
lskAudios = 0x06, // data: StorageKey location
|
||||||
lskRecentStickersOld = 0x07, // no data
|
lskRecentStickersOld = 0x07, // no data
|
||||||
lskBackground = 0x08, // no data
|
lskBackground = 0x08, // no data
|
||||||
lskUserSettings = 0x09, // no data
|
lskUserSettings = 0x09, // no data
|
||||||
lskRecentHashtags = 0x0a, // no data
|
lskRecentHashtags = 0x0a, // no data
|
||||||
lskStickers = 0x0b, // no data
|
lskStickers = 0x0b, // no data
|
||||||
lskSavedPeers = 0x0c, // no data
|
lskSavedPeers = 0x0c, // no data
|
||||||
|
lskReportSpamStatuses = 0x0d, // no data
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef QMap<PeerId, FileKey> DraftsMap;
|
typedef QMap<PeerId, FileKey> DraftsMap;
|
||||||
|
@ -522,7 +523,7 @@ namespace {
|
||||||
FileLocationPairs _fileLocationPairs;
|
FileLocationPairs _fileLocationPairs;
|
||||||
typedef QMap<MediaKey, MediaKey> FileLocationAliases;
|
typedef QMap<MediaKey, MediaKey> FileLocationAliases;
|
||||||
FileLocationAliases _fileLocationAliases;
|
FileLocationAliases _fileLocationAliases;
|
||||||
FileKey _locationsKey = 0;
|
FileKey _locationsKey = 0, _reportSpamStatusesKey = 0;
|
||||||
|
|
||||||
FileKey _recentStickersKeyOld = 0, _stickersKey = 0;
|
FileKey _recentStickersKeyOld = 0, _stickersKey = 0;
|
||||||
|
|
||||||
|
@ -550,7 +551,7 @@ namespace {
|
||||||
};
|
};
|
||||||
|
|
||||||
void _writeMap(WriteMapWhen when = WriteMapSoon);
|
void _writeMap(WriteMapWhen when = WriteMapSoon);
|
||||||
|
|
||||||
void _writeLocations(WriteMapWhen when = WriteMapSoon) {
|
void _writeLocations(WriteMapWhen when = WriteMapSoon) {
|
||||||
if (when != WriteMapNow) {
|
if (when != WriteMapNow) {
|
||||||
_manager->writeLocations(when == WriteMapFast);
|
_manager->writeLocations(when == WriteMapFast);
|
||||||
|
@ -643,6 +644,63 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _writeReportSpamStatuses() {
|
||||||
|
if (!_working()) return;
|
||||||
|
|
||||||
|
if (cReportSpamStatuses().isEmpty()) {
|
||||||
|
if (_reportSpamStatusesKey) {
|
||||||
|
clearKey(_reportSpamStatusesKey);
|
||||||
|
_reportSpamStatusesKey = 0;
|
||||||
|
_mapChanged = true;
|
||||||
|
_writeMap();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!_reportSpamStatusesKey) {
|
||||||
|
_reportSpamStatusesKey = genKey();
|
||||||
|
_mapChanged = true;
|
||||||
|
_writeMap(WriteMapFast);
|
||||||
|
}
|
||||||
|
const ReportSpamStatuses &statuses(cReportSpamStatuses());
|
||||||
|
|
||||||
|
quint32 size = sizeof(qint32);
|
||||||
|
for (ReportSpamStatuses::const_iterator i = statuses.cbegin(), e = statuses.cend(); i != e; ++i) {
|
||||||
|
// peer + status
|
||||||
|
size += sizeof(quint64) + sizeof(qint32);
|
||||||
|
}
|
||||||
|
|
||||||
|
EncryptedDescriptor data(size);
|
||||||
|
data.stream << qint32(statuses.size());
|
||||||
|
for (ReportSpamStatuses::const_iterator i = statuses.cbegin(), e = statuses.cend(); i != e; ++i) {
|
||||||
|
data.stream << quint64(i.key()) << qint32(i.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
FileWriteDescriptor file(_reportSpamStatusesKey);
|
||||||
|
file.writeEncrypted(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _readReportSpamStatuses() {
|
||||||
|
FileReadDescriptor statuses;
|
||||||
|
if (!readEncryptedFile(statuses, _reportSpamStatusesKey)) {
|
||||||
|
clearKey(_reportSpamStatusesKey);
|
||||||
|
_reportSpamStatusesKey = 0;
|
||||||
|
_writeMap();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReportSpamStatuses &map(cRefReportSpamStatuses());
|
||||||
|
map.clear();
|
||||||
|
|
||||||
|
qint32 size = 0;
|
||||||
|
statuses.stream >> size;
|
||||||
|
for (int32 i = 0; i < size; ++i) {
|
||||||
|
quint64 peer = 0;
|
||||||
|
qint32 status = 0;
|
||||||
|
statuses.stream >> peer >> status;
|
||||||
|
map.insert(peer, DBIPeerReportSpamStatus(status));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mtpDcOptions *_dcOpts = 0;
|
mtpDcOptions *_dcOpts = 0;
|
||||||
bool _readSetting(quint32 blockId, QDataStream &stream, int version) {
|
bool _readSetting(quint32 blockId, QDataStream &stream, int version) {
|
||||||
switch (blockId) {
|
switch (blockId) {
|
||||||
|
@ -1458,7 +1516,7 @@ namespace {
|
||||||
DraftsNotReadMap draftsNotReadMap;
|
DraftsNotReadMap draftsNotReadMap;
|
||||||
StorageMap imagesMap, stickerImagesMap, audiosMap;
|
StorageMap imagesMap, stickerImagesMap, audiosMap;
|
||||||
qint64 storageImagesSize = 0, storageStickersSize = 0, storageAudiosSize = 0;
|
qint64 storageImagesSize = 0, storageStickersSize = 0, storageAudiosSize = 0;
|
||||||
quint64 locationsKey = 0, recentStickersKeyOld = 0, stickersKey = 0, backgroundKey = 0, userSettingsKey = 0, recentHashtagsKey = 0, savedPeersKey = 0;
|
quint64 locationsKey = 0, reportSpamStatusesKey = 0, recentStickersKeyOld = 0, stickersKey = 0, backgroundKey = 0, userSettingsKey = 0, recentHashtagsKey = 0, savedPeersKey = 0;
|
||||||
while (!map.stream.atEnd()) {
|
while (!map.stream.atEnd()) {
|
||||||
quint32 keyType;
|
quint32 keyType;
|
||||||
map.stream >> keyType;
|
map.stream >> keyType;
|
||||||
|
@ -1523,6 +1581,9 @@ namespace {
|
||||||
case lskLocations: {
|
case lskLocations: {
|
||||||
map.stream >> locationsKey;
|
map.stream >> locationsKey;
|
||||||
} break;
|
} break;
|
||||||
|
case lskReportSpamStatuses: {
|
||||||
|
map.stream >> reportSpamStatusesKey;
|
||||||
|
} break;
|
||||||
case lskRecentStickersOld: {
|
case lskRecentStickersOld: {
|
||||||
map.stream >> recentStickersKeyOld;
|
map.stream >> recentStickersKeyOld;
|
||||||
} break;
|
} break;
|
||||||
|
@ -1562,6 +1623,7 @@ namespace {
|
||||||
_storageAudiosSize = storageAudiosSize;
|
_storageAudiosSize = storageAudiosSize;
|
||||||
|
|
||||||
_locationsKey = locationsKey;
|
_locationsKey = locationsKey;
|
||||||
|
_reportSpamStatusesKey = reportSpamStatusesKey;
|
||||||
_recentStickersKeyOld = recentStickersKeyOld;
|
_recentStickersKeyOld = recentStickersKeyOld;
|
||||||
_stickersKey = stickersKey;
|
_stickersKey = stickersKey;
|
||||||
_savedPeersKey = savedPeersKey;
|
_savedPeersKey = savedPeersKey;
|
||||||
|
@ -1579,6 +1641,9 @@ namespace {
|
||||||
if (_locationsKey) {
|
if (_locationsKey) {
|
||||||
_readLocations();
|
_readLocations();
|
||||||
}
|
}
|
||||||
|
if (_reportSpamStatusesKey) {
|
||||||
|
_readReportSpamStatuses();
|
||||||
|
}
|
||||||
|
|
||||||
_readUserSettings();
|
_readUserSettings();
|
||||||
_readMtpData();
|
_readMtpData();
|
||||||
|
@ -1630,6 +1695,7 @@ namespace {
|
||||||
if (!_stickerImagesMap.isEmpty()) mapSize += sizeof(quint32) * 2 + _stickerImagesMap.size() * (sizeof(quint64) * 3 + sizeof(qint32));
|
if (!_stickerImagesMap.isEmpty()) mapSize += sizeof(quint32) * 2 + _stickerImagesMap.size() * (sizeof(quint64) * 3 + sizeof(qint32));
|
||||||
if (!_audiosMap.isEmpty()) mapSize += sizeof(quint32) * 2 + _audiosMap.size() * (sizeof(quint64) * 3 + sizeof(qint32));
|
if (!_audiosMap.isEmpty()) mapSize += sizeof(quint32) * 2 + _audiosMap.size() * (sizeof(quint64) * 3 + sizeof(qint32));
|
||||||
if (_locationsKey) mapSize += sizeof(quint32) + sizeof(quint64);
|
if (_locationsKey) mapSize += sizeof(quint32) + sizeof(quint64);
|
||||||
|
if (_reportSpamStatusesKey) mapSize += sizeof(quint32) + sizeof(quint64);
|
||||||
if (_recentStickersKeyOld) mapSize += sizeof(quint32) + sizeof(quint64);
|
if (_recentStickersKeyOld) mapSize += sizeof(quint32) + sizeof(quint64);
|
||||||
if (_stickersKey) mapSize += sizeof(quint32) + sizeof(quint64);
|
if (_stickersKey) mapSize += sizeof(quint32) + sizeof(quint64);
|
||||||
if (_savedPeersKey) mapSize += sizeof(quint32) + sizeof(quint64);
|
if (_savedPeersKey) mapSize += sizeof(quint32) + sizeof(quint64);
|
||||||
|
@ -1670,6 +1736,9 @@ namespace {
|
||||||
if (_locationsKey) {
|
if (_locationsKey) {
|
||||||
mapData.stream << quint32(lskLocations) << quint64(_locationsKey);
|
mapData.stream << quint32(lskLocations) << quint64(_locationsKey);
|
||||||
}
|
}
|
||||||
|
if (_reportSpamStatusesKey) {
|
||||||
|
mapData.stream << quint32(lskReportSpamStatuses) << quint64(_reportSpamStatusesKey);
|
||||||
|
}
|
||||||
if (_recentStickersKeyOld) {
|
if (_recentStickersKeyOld) {
|
||||||
mapData.stream << quint32(lskRecentStickersOld) << quint64(_recentStickersKeyOld);
|
mapData.stream << quint32(lskRecentStickersOld) << quint64(_recentStickersKeyOld);
|
||||||
}
|
}
|
||||||
|
@ -1938,7 +2007,7 @@ namespace Local {
|
||||||
_draftsNotReadMap.clear();
|
_draftsNotReadMap.clear();
|
||||||
_stickerImagesMap.clear();
|
_stickerImagesMap.clear();
|
||||||
_audiosMap.clear();
|
_audiosMap.clear();
|
||||||
_locationsKey = _recentStickersKeyOld = _stickersKey = _backgroundKey = _userSettingsKey = _recentHashtagsKey = _savedPeersKey = 0;
|
_locationsKey = _reportSpamStatusesKey = _recentStickersKeyOld = _stickersKey = _backgroundKey = _userSettingsKey = _recentHashtagsKey = _savedPeersKey = 0;
|
||||||
_mapChanged = true;
|
_mapChanged = true;
|
||||||
_writeMap(WriteMapNow);
|
_writeMap(WriteMapNow);
|
||||||
|
|
||||||
|
@ -2945,7 +3014,7 @@ namespace Local {
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeReportSpamStatuses() {
|
void writeReportSpamStatuses() {
|
||||||
|
_writeReportSpamStatuses();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ClearManagerData {
|
struct ClearManagerData {
|
||||||
|
@ -2995,6 +3064,10 @@ namespace Local {
|
||||||
_locationsKey = 0;
|
_locationsKey = 0;
|
||||||
_mapChanged = true;
|
_mapChanged = true;
|
||||||
}
|
}
|
||||||
|
if (_reportSpamStatusesKey) {
|
||||||
|
_reportSpamStatusesKey = 0;
|
||||||
|
_mapChanged = true;
|
||||||
|
}
|
||||||
if (_recentStickersKeyOld) {
|
if (_recentStickersKeyOld) {
|
||||||
_recentStickersKeyOld = 0;
|
_recentStickersKeyOld = 0;
|
||||||
_mapChanged = true;
|
_mapChanged = true;
|
||||||
|
|
Loading…
Reference in New Issue