Fix saved GIF preview rendering
All checks were successful
Release App / release-app (push) Successful in 48s

This commit is contained in:
2026-04-26 12:59:07 +03:00
parent 063e12a996
commit c2c9560e07
3 changed files with 53 additions and 11 deletions

View File

@@ -108,6 +108,8 @@ class App {
[[nodiscard]] bool has_inline_attachment_preview(const AttachmentInfo &attachment, [[nodiscard]] bool has_inline_attachment_preview(const AttachmentInfo &attachment,
int width, int height) const; int width, int height) const;
void clear_attachment_preview_graphics(); void clear_attachment_preview_graphics();
void render_attachment_preview_graphics(const AttachmentInfo &attachment, bool animated,
int top, int left, int width, int height);
void render_attachment_preview_graphics(int top, int left, int width, int height); void render_attachment_preview_graphics(int top, int left, int width, int height);
void reset_attachment_viewer_send_preview(); void reset_attachment_viewer_send_preview();
[[nodiscard]] std::vector<std::int64_t> forward_target_chat_ids() const; [[nodiscard]] std::vector<std::int64_t> forward_target_chat_ids() const;

View File

@@ -987,12 +987,19 @@ void App::render_attachment_preview_graphics(int top, int left, int width, int h
return; return;
} }
const AttachmentInfo &attachment = *attachment_viewer_attachment_; render_attachment_preview_graphics(*attachment_viewer_attachment_,
attachment_viewer_is_animated_, top, left, width,
height);
}
void App::render_attachment_preview_graphics(const AttachmentInfo &attachment, bool animated,
int top, int left, int width, int height) {
const std::string preview_path = attachment_preview_path(attachment); const std::string preview_path = attachment_preview_path(attachment);
if (preview_path.empty() || attachment_viewer_is_animated_) { if (preview_path.empty() || animated) {
clear_attachment_preview_graphics(); clear_attachment_preview_graphics();
return; return;
} }
const std::string forced_protocol = configured_image_protocol(); const std::string forced_protocol = configured_image_protocol();
const bool want_kitty = forced_protocol == "kitty" || const bool want_kitty = forced_protocol == "kitty" ||
(forced_protocol.empty() && terminal_supports_kitty_graphics()); (forced_protocol.empty() && terminal_supports_kitty_graphics());

View File

@@ -168,7 +168,6 @@ void App::draw() {
} else if (attachment_action_menu_open_) { } else if (attachment_action_menu_open_) {
draw_attachment_action_menu(height, width); draw_attachment_action_menu(height, width);
} else if (saved_animation_menu_open_) { } else if (saved_animation_menu_open_) {
clear_attachment_preview_graphics();
draw_saved_animation_menu(height, width); draw_saved_animation_menu(height, width);
} else if (attachments_menu_open_) { } else if (attachments_menu_open_) {
draw_attachments_menu(height, width); draw_attachments_menu(height, width);
@@ -335,6 +334,7 @@ void App::draw_saved_animation_menu(int height, int width) {
mvwvline(window, 3, preview_left - 1, ACS_VLINE, menu_height - 4); mvwvline(window, 3, preview_left - 1, ACS_VLINE, menu_height - 4);
if (saved_animations_.empty()) { if (saved_animations_.empty()) {
clear_attachment_preview_graphics();
mvwaddnstr(window, 4, preview_left, "No saved GIFs on this account.", preview_width); mvwaddnstr(window, 4, preview_left, "No saved GIFs on this account.", preview_width);
} else { } else {
const SavedAnimationInfo &animation = saved_animations_[static_cast<std::size_t>( const SavedAnimationInfo &animation = saved_animations_[static_cast<std::size_t>(
@@ -362,20 +362,53 @@ void App::draw_saved_animation_menu(int height, int width) {
preview_attachment.can_be_deleted = animation.can_be_deleted; preview_attachment.can_be_deleted = animation.can_be_deleted;
preview_attachment.is_downloaded = animation.is_downloaded; preview_attachment.is_downloaded = animation.is_downloaded;
const std::string preview = render_attachment_preview( const int preview_top = 6;
preview_attachment, preview_width, std::max(4, list_height - 4)); const int preview_height = std::max(4, list_height - 4);
if (has_inline_attachment_preview(preview_attachment, preview_width, preview_height)) {
for (int row = 0; row < preview_height; ++row) {
mvwhline(window, preview_top + row, preview_left, ' ', preview_width);
}
} else {
clear_attachment_preview_graphics();
const std::string preview =
render_attachment_preview(preview_attachment, preview_width, preview_height);
const std::vector<std::string> preview_lines = split_preview_lines(preview); const std::vector<std::string> preview_lines = split_preview_lines(preview);
for (std::size_t i = 0; i < preview_lines.size() && for (std::size_t i = 0; i < preview_lines.size() &&
static_cast<int>(i) < list_height - 3; static_cast<int>(i) < list_height - 3;
++i) { ++i) {
mvwaddnstr(window, 6 + static_cast<int>(i), preview_left, mvwaddnstr(window, preview_top + static_cast<int>(i), preview_left,
truncate_to_width(preview_lines[i], preview_width).c_str(), preview_width); truncate_to_width(preview_lines[i], preview_width).c_str(),
preview_width);
}
} }
} }
mvwaddnstr(window, menu_height - 2, 2, mvwaddnstr(window, menu_height - 2, 2,
"Enter send r refresh Up/Down move Esc close", menu_width - 4); "Enter send r refresh Up/Down move Esc close", menu_width - 4);
wrefresh(window); wrefresh(window);
if (!saved_animations_.empty()) {
const SavedAnimationInfo &animation = saved_animations_[static_cast<std::size_t>(
saved_animation_selection_index_)];
AttachmentInfo preview_attachment;
preview_attachment.type = AttachmentType::Animation;
preview_attachment.name = animation.name;
preview_attachment.size_bytes = animation.size_bytes;
preview_attachment.downloaded_size = animation.downloaded_size;
preview_attachment.file_id = animation.file_id;
preview_attachment.local_path = animation.local_path;
preview_attachment.is_downloading_active = animation.is_downloading_active;
preview_attachment.can_be_downloaded = animation.can_be_downloaded;
preview_attachment.can_be_deleted = animation.can_be_deleted;
preview_attachment.is_downloaded = animation.is_downloaded;
if (has_inline_attachment_preview(preview_attachment, preview_width,
std::max(4, list_height - 4))) {
render_attachment_preview_graphics(preview_attachment, false, top + 6,
left + preview_left, preview_width,
std::max(4, list_height - 4));
} else {
clear_attachment_preview_graphics();
}
}
delwin(window); delwin(window);
} }