mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 22:46:10 +00:00
Save last camera image as a placeholder.
This commit is contained in:
@@ -94,6 +94,7 @@ enum { // Local Storage Keys
|
||||
lskCustomEmojiKeys = 0x17, // no data
|
||||
lskSearchSuggestions = 0x18, // no data
|
||||
lskWebviewTokens = 0x19, // data: QByteArray bots, QByteArray other
|
||||
lskRoundPlaceholder = 0x1a, // no data
|
||||
};
|
||||
|
||||
auto EmptyMessageDraftSources()
|
||||
@@ -220,6 +221,7 @@ base::flat_set<QString> Account::collectGoodNames() const {
|
||||
_featuredCustomEmojiKey,
|
||||
_archivedCustomEmojiKey,
|
||||
_searchSuggestionsKey,
|
||||
_roundPlaceholderKey,
|
||||
};
|
||||
auto result = base::flat_set<QString>{
|
||||
"map0",
|
||||
@@ -306,6 +308,7 @@ Account::ReadMapResult Account::readMapWith(
|
||||
quint64 legacyBackgroundKeyDay = 0, legacyBackgroundKeyNight = 0;
|
||||
quint64 userSettingsKey = 0, recentHashtagsAndBotsKey = 0, exportSettingsKey = 0;
|
||||
quint64 searchSuggestionsKey = 0;
|
||||
quint64 roundPlaceholderKey = 0;
|
||||
QByteArray webviewStorageTokenBots, webviewStorageTokenOther;
|
||||
while (!map.stream.atEnd()) {
|
||||
quint32 keyType;
|
||||
@@ -415,6 +418,9 @@ Account::ReadMapResult Account::readMapWith(
|
||||
case lskSearchSuggestions: {
|
||||
map.stream >> searchSuggestionsKey;
|
||||
} break;
|
||||
case lskRoundPlaceholder: {
|
||||
map.stream >> roundPlaceholderKey;
|
||||
} break;
|
||||
case lskWebviewTokens: {
|
||||
map.stream
|
||||
>> webviewStorageTokenBots
|
||||
@@ -456,6 +462,7 @@ Account::ReadMapResult Account::readMapWith(
|
||||
_recentHashtagsAndBotsKey = recentHashtagsAndBotsKey;
|
||||
_exportSettingsKey = exportSettingsKey;
|
||||
_searchSuggestionsKey = searchSuggestionsKey;
|
||||
_roundPlaceholderKey = roundPlaceholderKey;
|
||||
_oldMapVersion = mapData.version;
|
||||
_webviewStorageIdBots.token = webviewStorageTokenBots;
|
||||
_webviewStorageIdOther.token = webviewStorageTokenOther;
|
||||
@@ -570,6 +577,7 @@ void Account::writeMap() {
|
||||
+ Serialize::bytearraySize(_webviewStorageIdBots.token)
|
||||
+ Serialize::bytearraySize(_webviewStorageIdOther.token);
|
||||
}
|
||||
if (_roundPlaceholderKey) mapSize += sizeof(quint32) + sizeof(quint64);
|
||||
|
||||
EncryptedDescriptor mapData(mapSize);
|
||||
if (!self.isEmpty()) {
|
||||
@@ -640,6 +648,10 @@ void Account::writeMap() {
|
||||
<< _webviewStorageIdBots.token
|
||||
<< _webviewStorageIdOther.token;
|
||||
}
|
||||
if (_roundPlaceholderKey) {
|
||||
mapData.stream << quint32(lskRoundPlaceholder);
|
||||
mapData.stream << quint64(_roundPlaceholderKey);
|
||||
}
|
||||
map.writeEncrypted(mapData, _localKey);
|
||||
|
||||
_mapChanged = false;
|
||||
@@ -669,6 +681,7 @@ void Account::reset() {
|
||||
_legacyBackgroundKeyDay = _legacyBackgroundKeyNight = 0;
|
||||
_settingsKey = _recentHashtagsAndBotsKey = _exportSettingsKey = 0;
|
||||
_searchSuggestionsKey = 0;
|
||||
_roundPlaceholderKey = 0;
|
||||
_oldMapVersion = 0;
|
||||
_fileLocations.clear();
|
||||
_fileLocationPairs.clear();
|
||||
@@ -3178,6 +3191,52 @@ Webview::StorageId Account::resolveStorageIdOther() {
|
||||
return _webviewStorageIdOther;
|
||||
}
|
||||
|
||||
QImage Account::readRoundPlaceholder() {
|
||||
if (!_roundPlaceholder.isNull()) {
|
||||
return _roundPlaceholder;
|
||||
} else if (!_roundPlaceholderKey) {
|
||||
return QImage();
|
||||
}
|
||||
|
||||
FileReadDescriptor placeholder;
|
||||
if (!ReadEncryptedFile(
|
||||
placeholder,
|
||||
_roundPlaceholderKey,
|
||||
_basePath,
|
||||
_localKey)) {
|
||||
ClearKey(_roundPlaceholderKey, _basePath);
|
||||
_roundPlaceholderKey = 0;
|
||||
writeMapDelayed();
|
||||
return QImage();
|
||||
}
|
||||
|
||||
auto bytes = QByteArray();
|
||||
placeholder.stream >> bytes;
|
||||
_roundPlaceholder = Images::Read({ .content = bytes }).image;
|
||||
return _roundPlaceholder;
|
||||
}
|
||||
|
||||
void Account::writeRoundPlaceholder(const QImage &placeholder) {
|
||||
if (placeholder.isNull()) {
|
||||
return;
|
||||
}
|
||||
_roundPlaceholder = placeholder;
|
||||
|
||||
auto bytes = QByteArray();
|
||||
auto buffer = QBuffer(&bytes);
|
||||
placeholder.save(&buffer, "JPG", 87);
|
||||
|
||||
quint32 size = Serialize::bytearraySize(bytes);
|
||||
if (!_roundPlaceholderKey) {
|
||||
_roundPlaceholderKey = GenerateKey(_basePath);
|
||||
writeMapQueued();
|
||||
}
|
||||
EncryptedDescriptor data(size);
|
||||
data.stream << bytes;
|
||||
FileWriteDescriptor file(_roundPlaceholderKey, _basePath);
|
||||
file.writeEncrypted(data, _localKey);
|
||||
}
|
||||
|
||||
bool Account::encrypt(
|
||||
const void *src,
|
||||
void *dst,
|
||||
|
Reference in New Issue
Block a user