mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Handle documentLoadProgress instead of itemRepaintRequest.
This commit is contained in:
parent
1f38ab1690
commit
0192edbe84
11 changed files with 109 additions and 59 deletions
|
@ -369,6 +369,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_settings_section_general" = "General";
|
||||
"lng_settings_change_lang" = "Change language";
|
||||
"lng_languages" = "Languages";
|
||||
"lng_languages_none" = "No languages found.";
|
||||
"lng_sure_save_language" = "Telegram will restart in order to change language";
|
||||
"lng_settings_update_automatically" = "Update automatically";
|
||||
"lng_settings_install_beta" = "Install beta versions";
|
||||
|
@ -1844,6 +1845,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_downloads_delete_sure_one" = "Do you want to delete this file?";
|
||||
"lng_downloads_delete_sure#one" = "Do you want to delete {count} file?";
|
||||
"lng_downloads_delete_sure#other" = "Do you want to delete {count} files?";
|
||||
"lng_downloads_delete_in_cloud_one" = "It will be deleted from your disk, but will remain accessible in the cloud.";
|
||||
"lng_downloads_delete_in_cloud" = "They will be deleted from your disk, but will remain accessible in the cloud.";
|
||||
|
||||
"lng_send_image_empty" = "Could not send an empty file: {name}";
|
||||
"lng_send_image_too_large" = "Could not send a file, because it is larger than 1500 MB: {name}";
|
||||
|
|
|
@ -167,7 +167,7 @@ LocalStorageBox::Row::Row(
|
|||
sizeText(data),
|
||||
st::localStorageRowSize)
|
||||
, _clear(this, std::move(clear), st::localStorageClear) {
|
||||
_clear->setTextTransform(RoundButton::TextTransform::NoTransform);
|
||||
_clear->setTextTransform(Ui::RoundButton::TextTransform::NoTransform);
|
||||
_clear->setVisible(data.count != 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,10 @@ constexpr auto ByItem = [](const auto &entry) {
|
|||
}
|
||||
};
|
||||
|
||||
constexpr auto ByDocument = [](const auto &entry) {
|
||||
return entry.object.document;
|
||||
};
|
||||
|
||||
[[nodiscard]] uint64 PeerAccessHash(not_null<PeerData*> peer) {
|
||||
if (const auto user = peer->asUser()) {
|
||||
return user->accessHash();
|
||||
|
@ -66,11 +70,11 @@ void DownloadManager::trackSession(not_null<Main::Session*> session) {
|
|||
data.downloaded = deserialize(session);
|
||||
data.resolveNeeded = data.downloaded.size();
|
||||
|
||||
session->data().itemRepaintRequest(
|
||||
) | rpl::filter([=](not_null<const HistoryItem*> item) {
|
||||
return _loading.contains(item);
|
||||
}) | rpl::start_with_next([=](not_null<const HistoryItem*> item) {
|
||||
check(item);
|
||||
session->data().documentLoadProgress(
|
||||
) | rpl::filter([=](not_null<DocumentData*> document) {
|
||||
return _loadingDocuments.contains(document);
|
||||
}) | rpl::start_with_next([=](not_null<DocumentData*> document) {
|
||||
check(document);
|
||||
}, data.lifetime);
|
||||
|
||||
session->data().itemLayoutChanged(
|
||||
|
@ -141,6 +145,7 @@ void DownloadManager::addLoading(DownloadObject object) {
|
|||
.total = size,
|
||||
});
|
||||
_loading.emplace(item);
|
||||
_loadingDocuments.emplace(object.document);
|
||||
_loadingProgress = DownloadProgress{
|
||||
.ready = _loadingProgress.current().ready,
|
||||
.total = _loadingProgress.current().total + size,
|
||||
|
@ -155,9 +160,25 @@ void DownloadManager::check(not_null<const HistoryItem*> item) {
|
|||
auto &data = sessionData(item);
|
||||
const auto i = ranges::find(data.downloading, item, ByItem);
|
||||
Assert(i != end(data.downloading));
|
||||
check(data, i);
|
||||
}
|
||||
|
||||
void DownloadManager::check(not_null<DocumentData*> document) {
|
||||
auto &data = sessionData(document);
|
||||
const auto i = ranges::find(
|
||||
data.downloading,
|
||||
document.get(),
|
||||
ByDocument);
|
||||
Assert(i != end(data.downloading));
|
||||
check(data, i);
|
||||
}
|
||||
|
||||
void DownloadManager::check(
|
||||
SessionData &data,
|
||||
std::vector<DownloadingId>::iterator i) {
|
||||
auto &entry = *i;
|
||||
|
||||
const auto media = item->media();
|
||||
const auto media = entry.object.item->media();
|
||||
const auto photo = media ? media->photo() : nullptr;
|
||||
const auto document = media ? media->document() : nullptr;
|
||||
if (entry.object.photo != photo || entry.object.document != document) {
|
||||
|
@ -169,7 +190,7 @@ void DownloadManager::check(not_null<const HistoryItem*> item) {
|
|||
|
||||
const auto path = document->filepath(true);
|
||||
if (!path.isEmpty()) {
|
||||
if (_loading.contains(item)) {
|
||||
if (_loading.contains(entry.object.item)) {
|
||||
addLoaded(entry.object, path, entry.started);
|
||||
}
|
||||
} else if (!document->loading()) {
|
||||
|
@ -224,11 +245,14 @@ void DownloadManager::addLoaded(
|
|||
const auto i = ranges::find(data.downloading, item, ByItem);
|
||||
if (i != end(data.downloading)) {
|
||||
auto &entry = *i;
|
||||
const auto document = entry.object.document;
|
||||
if (document) {
|
||||
_loadingDocuments.remove(document);
|
||||
}
|
||||
const auto j = _loading.find(entry.object.item);
|
||||
if (j == end(_loading)) {
|
||||
return;
|
||||
}
|
||||
const auto document = entry.object.document;
|
||||
const auto totalChange = document->size - entry.total;
|
||||
const auto readyChange = document->size - entry.ready;
|
||||
entry.ready += readyChange;
|
||||
|
@ -531,6 +555,9 @@ void DownloadManager::remove(
|
|||
};
|
||||
_loading.remove(i->object.item);
|
||||
_loadingDone.remove(i->object.item);
|
||||
if (const auto document = i->object.document) {
|
||||
_loadingDocuments.remove(document);
|
||||
}
|
||||
data.downloading.erase(i);
|
||||
_loadingListChanges.fire({});
|
||||
_loadingProgress = now;
|
||||
|
@ -672,6 +699,11 @@ DownloadManager::SessionData &DownloadManager::sessionData(
|
|||
return sessionData(&item->history()->session());
|
||||
}
|
||||
|
||||
DownloadManager::SessionData &DownloadManager::sessionData(
|
||||
not_null<DocumentData*> document) {
|
||||
return sessionData(&document->session());
|
||||
}
|
||||
|
||||
void DownloadManager::writePostponed(not_null<Main::Session*> session) {
|
||||
session->account().local().updateDownloads(serializator(session));
|
||||
}
|
||||
|
|
|
@ -117,6 +117,10 @@ private:
|
|||
};
|
||||
|
||||
void check(not_null<const HistoryItem*> item);
|
||||
void check(not_null<DocumentData*> document);
|
||||
void check(
|
||||
SessionData &data,
|
||||
std::vector<DownloadingId>::iterator i);
|
||||
void changed(not_null<const HistoryItem*> item);
|
||||
void removed(not_null<const HistoryItem*> item);
|
||||
void detach(DownloadedId &id);
|
||||
|
@ -134,6 +138,7 @@ private:
|
|||
not_null<Main::Session*> session) const;
|
||||
[[nodiscard]] SessionData &sessionData(
|
||||
not_null<const HistoryItem*> item);
|
||||
[[nodiscard]] SessionData &sessionData(not_null<DocumentData*> document);
|
||||
|
||||
void resolve(not_null<Main::Session*> session, SessionData &data);
|
||||
void resolveRequestsFinished(
|
||||
|
@ -157,6 +162,7 @@ private:
|
|||
|
||||
base::flat_map<not_null<Main::Session*>, SessionData> _sessions;
|
||||
base::flat_set<not_null<const HistoryItem*>> _loading;
|
||||
base::flat_set<not_null<DocumentData*>> _loadingDocuments;
|
||||
base::flat_set<not_null<const HistoryItem*>> _loadingDone;
|
||||
base::flat_set<not_null<const HistoryItem*>> _loaded;
|
||||
base::flat_set<not_null<HistoryItem*>> _generated;
|
||||
|
|
|
@ -1281,21 +1281,19 @@ void Session::requestPollViewRepaint(not_null<const PollData*> poll) {
|
|||
|
||||
void Session::documentLoadProgress(not_null<DocumentData*> document) {
|
||||
requestDocumentViewRepaint(document);
|
||||
session().documentUpdated.notify(document, true);
|
||||
|
||||
if (document->isAudioFile()) {
|
||||
::Media::Player::instance()->documentLoadProgress(document);
|
||||
}
|
||||
_documentLoadProgress.fire_copy(document);
|
||||
}
|
||||
|
||||
void Session::documentLoadDone(not_null<DocumentData*> document) {
|
||||
notifyDocumentLayoutChanged(document);
|
||||
_documentLoadProgress.fire_copy(document);
|
||||
}
|
||||
|
||||
void Session::documentLoadFail(
|
||||
not_null<DocumentData*> document,
|
||||
bool started) {
|
||||
notifyDocumentLayoutChanged(document);
|
||||
_documentLoadProgress.fire_copy(document);
|
||||
}
|
||||
|
||||
void Session::photoLoadProgress(not_null<PhotoData*> photo) {
|
||||
|
|
|
@ -416,6 +416,11 @@ public:
|
|||
void documentLoadDone(not_null<DocumentData*> document);
|
||||
void documentLoadFail(not_null<DocumentData*> document, bool started);
|
||||
|
||||
[[nodiscard]] auto documentLoadProgress() const
|
||||
-> rpl::producer<not_null<DocumentData*>> {
|
||||
return _documentLoadProgress.events();
|
||||
}
|
||||
|
||||
HistoryItem *addNewMessage(
|
||||
const MTPMessage &data,
|
||||
MessageFlags localFlags,
|
||||
|
@ -930,6 +935,7 @@ private:
|
|||
|
||||
rpl::event_stream<not_null<WebPageData*>> _webpageUpdates;
|
||||
rpl::event_stream<not_null<ChannelData*>> _channelDifferenceTooLong;
|
||||
rpl::event_stream<not_null<DocumentData*>> _documentLoadProgress;
|
||||
base::flat_set<not_null<ChannelData*>> _suggestToGigagroup;
|
||||
|
||||
base::flat_multi_map<TimeId, not_null<PollData*>> _pollsClosings;
|
||||
|
|
|
@ -167,11 +167,9 @@ public:
|
|||
return _lifetime;
|
||||
}
|
||||
|
||||
base::Observable<DocumentData*> documentUpdated;
|
||||
|
||||
bool supportMode() const;
|
||||
Support::Helper &supportHelper() const;
|
||||
Support::Templates &supportTemplates() const;
|
||||
[[nodiscard]] bool supportMode() const;
|
||||
[[nodiscard]] Support::Helper &supportHelper() const;
|
||||
[[nodiscard]] Support::Templates &supportTemplates() const;
|
||||
|
||||
private:
|
||||
static constexpr auto kDefaultSaveDelay = crl::time(1000);
|
||||
|
|
|
@ -217,23 +217,27 @@ void Instance::setCurrent(const AudioMsgId &audioId) {
|
|||
if (item) {
|
||||
setHistory(data, item->history());
|
||||
} else {
|
||||
data->history = nullptr;
|
||||
data->migrated = nullptr;
|
||||
data->session = nullptr;
|
||||
setHistory(
|
||||
data,
|
||||
nullptr,
|
||||
audioId.audio() ? &audioId.audio()->session() : nullptr);
|
||||
}
|
||||
_trackChanged.fire_copy(data->type);
|
||||
refreshPlaylist(data);
|
||||
}
|
||||
}
|
||||
|
||||
void Instance::setHistory(not_null<Data*> data, History *history) {
|
||||
void Instance::setHistory(
|
||||
not_null<Data*> data,
|
||||
History *history,
|
||||
Main::Session *sessionFallback) {
|
||||
if (history) {
|
||||
data->history = history->migrateToOrMe();
|
||||
data->migrated = data->history->migrateFrom();
|
||||
setSession(data, &history->session());
|
||||
} else {
|
||||
data->history = data->migrated = nullptr;
|
||||
setSession(data, nullptr);
|
||||
setSession(data, sessionFallback);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -250,6 +254,18 @@ void Instance::setSession(not_null<Data*> data, Main::Session *session) {
|
|||
) | rpl::start_with_next([=] {
|
||||
setSession(data, nullptr);
|
||||
}, data->sessionLifetime);
|
||||
|
||||
session->data().documentLoadProgress(
|
||||
) | rpl::filter([=](not_null<DocumentData*> document) {
|
||||
// Before refactoring it was called only for audio files.
|
||||
return document->isAudioFile();
|
||||
}) | rpl::start_with_next([=](not_null<DocumentData*> document) {
|
||||
const auto type = AudioMsgId::Type::Song;
|
||||
emitUpdate(type, [&](const AudioMsgId &audioId) {
|
||||
return (audioId.audio() == document);
|
||||
});
|
||||
}, data->sessionLifetime);
|
||||
|
||||
session->data().itemRemoved(
|
||||
) | rpl::filter([=](not_null<const HistoryItem*> item) {
|
||||
return (data->current.contextId() == item->fullId());
|
||||
|
@ -1114,15 +1130,6 @@ void Instance::updateVoicePlaybackSpeed() {
|
|||
}
|
||||
}
|
||||
|
||||
void Instance::documentLoadProgress(DocumentData *document) {
|
||||
const auto type = document->isAudioFile()
|
||||
? AudioMsgId::Type::Song
|
||||
: AudioMsgId::Type::Voice;
|
||||
emitUpdate(type, [&](const AudioMsgId &audioId) {
|
||||
return (audioId.audio() == document);
|
||||
});
|
||||
}
|
||||
|
||||
void Instance::emitUpdate(AudioMsgId::Type type) {
|
||||
emitUpdate(type, [](const AudioMsgId &playing) { return true; });
|
||||
}
|
||||
|
|
|
@ -165,8 +165,6 @@ public:
|
|||
|
||||
[[nodiscard]] bool pauseGifByRoundVideo() const;
|
||||
|
||||
void documentLoadProgress(DocumentData *document);
|
||||
|
||||
private:
|
||||
using SharedMediaType = Storage::SharedMediaType;
|
||||
using SliceKey = SparseIdsMergedSlice::Key;
|
||||
|
@ -293,7 +291,10 @@ private:
|
|||
void requestRoundVideoResize() const;
|
||||
void requestRoundVideoRepaint() const;
|
||||
|
||||
void setHistory(not_null<Data*> data, History *history);
|
||||
void setHistory(
|
||||
not_null<Data*> data,
|
||||
History *history,
|
||||
Main::Session *sessionFallback = nullptr);
|
||||
void setSession(not_null<Data*> data, Main::Session *session);
|
||||
|
||||
Data _songData;
|
||||
|
|
|
@ -679,23 +679,23 @@ void OverlayWidget::clearStreaming(bool savePosition) {
|
|||
_streamed = nullptr;
|
||||
}
|
||||
|
||||
void OverlayWidget::documentUpdated(DocumentData *doc) {
|
||||
if (_document && _document == doc) {
|
||||
if (documentBubbleShown()) {
|
||||
if ((_document->loading() && _docCancel->isHidden()) || (!_document->loading() && !_docCancel->isHidden())) {
|
||||
updateControls();
|
||||
} else if (_document->loading()) {
|
||||
updateDocSize();
|
||||
_widget->update(_docRect);
|
||||
}
|
||||
} else if (_streamed) {
|
||||
const auto ready = _documentMedia->loaded()
|
||||
? _document->size
|
||||
: _document->loading()
|
||||
? std::clamp(_document->loadOffset(), 0, _document->size)
|
||||
: 0;
|
||||
_streamed->controls.setLoadingProgress(ready, _document->size);
|
||||
void OverlayWidget::documentUpdated(not_null<DocumentData*> document) {
|
||||
if (_document != document) {
|
||||
return;
|
||||
} else if (documentBubbleShown()) {
|
||||
if ((_document->loading() && _docCancel->isHidden()) || (!_document->loading() && !_docCancel->isHidden())) {
|
||||
updateControls();
|
||||
} else if (_document->loading()) {
|
||||
updateDocSize();
|
||||
_widget->update(_docRect);
|
||||
}
|
||||
} else if (_streamed) {
|
||||
const auto ready = _documentMedia->loaded()
|
||||
? _document->size
|
||||
: _document->loading()
|
||||
? std::clamp(_document->loadOffset(), 0, _document->size)
|
||||
: 0;
|
||||
_streamed->controls.setLoadingProgress(ready, _document->size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4109,12 +4109,11 @@ void OverlayWidget::setSession(not_null<Main::Session*> session) {
|
|||
}
|
||||
}, _sessionLifetime);
|
||||
|
||||
base::ObservableViewer(
|
||||
session->documentUpdated
|
||||
) | rpl::start_with_next([=](DocumentData *document) {
|
||||
if (!isHidden()) {
|
||||
documentUpdated(document);
|
||||
}
|
||||
session->data().documentLoadProgress(
|
||||
) | rpl::filter([=] {
|
||||
return !isHidden();
|
||||
}) | rpl::start_with_next([=](not_null<DocumentData*> document) {
|
||||
documentUpdated(document);
|
||||
}, _sessionLifetime);
|
||||
|
||||
session->data().itemIdChanged(
|
||||
|
|
|
@ -327,7 +327,7 @@ private:
|
|||
void destroyThemePreview();
|
||||
void updateThemePreviewGeometry();
|
||||
|
||||
void documentUpdated(DocumentData *doc);
|
||||
void documentUpdated(not_null<DocumentData*> document);
|
||||
void changingMsgId(not_null<HistoryItem*> row, MsgId oldId);
|
||||
|
||||
[[nodiscard]] int finalContentRotation() const;
|
||||
|
|
Loading…
Add table
Reference in a new issue