Add saved GIF picker and docs
All checks were successful
Release App / release-app (push) Successful in 46s
All checks were successful
Release App / release-app (push) Successful in 46s
This commit is contained in:
@@ -37,6 +37,97 @@ bool App::process_updates() {
|
||||
return changed;
|
||||
}
|
||||
|
||||
void App::request_saved_animations(bool force) {
|
||||
if (saved_animations_loading_ && !force) {
|
||||
return;
|
||||
}
|
||||
saved_animations_loading_ = true;
|
||||
td_.send({
|
||||
{"@type", "getSavedAnimations"},
|
||||
{"@extra", "saved_animations"},
|
||||
});
|
||||
if (!saved_animation_menu_open_) {
|
||||
status_line_ = "Loading saved GIFs...";
|
||||
}
|
||||
}
|
||||
|
||||
void App::sync_saved_animations(const json &animations) {
|
||||
saved_animations_.clear();
|
||||
if (!animations.is_array()) {
|
||||
saved_animations_loading_ = false;
|
||||
saved_animations_loaded_ = true;
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto &item : animations) {
|
||||
if (!item.is_object()) {
|
||||
continue;
|
||||
}
|
||||
const json file = item.value("animation", json::object());
|
||||
const std::int32_t file_id = safe_i32(file, "id");
|
||||
if (file_id == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SavedAnimationInfo animation;
|
||||
animation.file_id = file_id;
|
||||
animation.name = safe_string(item, "file_name");
|
||||
if (animation.name.empty()) {
|
||||
animation.name = "animation";
|
||||
}
|
||||
animation.mime_type = safe_string(item, "mime_type");
|
||||
animation.size_bytes = std::max(safe_i64(file, "size"), safe_i64(file, "expected_size"));
|
||||
animation.downloaded_size = safe_i64(file.value("local", json::object()), "downloaded_size");
|
||||
animation.duration = safe_i32(item, "duration");
|
||||
animation.width = safe_i32(item, "width");
|
||||
animation.height = safe_i32(item, "height");
|
||||
animation.local_path = safe_string(file.value("local", json::object()), "path");
|
||||
animation.is_downloading_active =
|
||||
file.value("local", json::object()).value("is_downloading_active", false);
|
||||
animation.can_be_downloaded =
|
||||
file.value("local", json::object()).value("can_be_downloaded", false);
|
||||
animation.can_be_deleted =
|
||||
file.value("local", json::object()).value("can_be_deleted", false);
|
||||
animation.is_downloaded =
|
||||
file.value("local", json::object()).value("is_downloading_completed", false);
|
||||
saved_animations_.push_back(std::move(animation));
|
||||
}
|
||||
|
||||
if (saved_animation_selection_index_ < 0) {
|
||||
saved_animation_selection_index_ = 0;
|
||||
}
|
||||
if (saved_animation_selection_index_ >= static_cast<int>(saved_animations_.size())) {
|
||||
saved_animation_selection_index_ =
|
||||
std::max(0, static_cast<int>(saved_animations_.size()) - 1);
|
||||
}
|
||||
saved_animations_loading_ = false;
|
||||
saved_animations_loaded_ = true;
|
||||
ensure_saved_animation_preview();
|
||||
}
|
||||
|
||||
void App::ensure_saved_animation_preview() {
|
||||
if (saved_animation_selection_index_ < 0 ||
|
||||
saved_animation_selection_index_ >= static_cast<int>(saved_animations_.size())) {
|
||||
return;
|
||||
}
|
||||
|
||||
SavedAnimationInfo &animation =
|
||||
saved_animations_[static_cast<std::size_t>(saved_animation_selection_index_)];
|
||||
if (animation.file_id == 0 || animation.is_downloaded || animation.is_downloading_active ||
|
||||
!animation.can_be_downloaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
td_.send({
|
||||
{"@type", "downloadFile"},
|
||||
{"file_id", animation.file_id},
|
||||
{"priority", 1},
|
||||
{"offset", 0},
|
||||
{"limit", 0},
|
||||
{"synchronous", false},
|
||||
});
|
||||
}
|
||||
|
||||
void App::handle_td_object(const json &object) {
|
||||
const std::string type = safe_string(object, "@type");
|
||||
if (type == "updateAuthorizationState") {
|
||||
@@ -184,6 +275,10 @@ void App::handle_td_object(const json &object) {
|
||||
update_attachment_file(object.value("file", json::object()));
|
||||
return;
|
||||
}
|
||||
if (type == "updateSavedAnimations") {
|
||||
request_saved_animations(true);
|
||||
return;
|
||||
}
|
||||
if (type == "updateOption" || type == "ok" || type == "userFullInfo" ||
|
||||
type == "updateHavePendingNotifications" || type == "updateUnreadMessageCount" ||
|
||||
type == "updateUnreadChatCount") {
|
||||
@@ -224,6 +319,16 @@ void App::handle_td_object(const json &object) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (type == "animations") {
|
||||
const std::string extra = safe_string(object, "@extra");
|
||||
if (extra == "saved_animations") {
|
||||
sync_saved_animations(object.value("animations", json::array()));
|
||||
if (saved_animation_menu_open_) {
|
||||
status_line_ = saved_animations_.empty() ? "No saved GIFs." : "Saved GIFs.";
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (type == "updateMessageSendSucceeded") {
|
||||
const json message = object.value("message", json::object());
|
||||
const std::int64_t chat_id = safe_i64(message, "chat_id");
|
||||
@@ -509,6 +614,21 @@ void App::update_attachment_file(const json &file) {
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &animation : saved_animations_) {
|
||||
if (animation.file_id != file_id) {
|
||||
continue;
|
||||
}
|
||||
if (size_bytes > 0) {
|
||||
animation.size_bytes = size_bytes;
|
||||
}
|
||||
animation.downloaded_size = downloaded_size;
|
||||
animation.local_path = local_path;
|
||||
animation.is_downloading_active = is_downloading_active;
|
||||
animation.is_downloaded = is_downloaded;
|
||||
animation.can_be_downloaded = can_be_downloaded;
|
||||
animation.can_be_deleted = can_be_deleted;
|
||||
}
|
||||
|
||||
if (pending_attachment_open_.has_value() && pending_attachment_open_->file_id == file_id) {
|
||||
pending_attachment_open_->size_bytes =
|
||||
size_bytes > 0 ? size_bytes : pending_attachment_open_->size_bytes;
|
||||
|
||||
Reference in New Issue
Block a user