aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-21 03:12:35 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-21 03:12:35 +0200
commitea6f1b425a6aa9b7145a00d81473ef9508279eec (patch)
tree61f3d59aa277b889ed149cf6ccd5fc9dc2b836c8 /src/QuickMedia.cpp
parentf126659965425ee5f5a3851fbe83ae532e48c478 (diff)
Fix thumbnail fallback size being incorrect, incorrect read marker for matrix
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp54
1 files changed, 24 insertions, 30 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index cde8cdb..90abfcc 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -284,7 +284,7 @@ namespace QuickMedia {
auto body_item = BodyItem::create(recommended_title_json.asString());
body_item->url = "https://www.youtube.com/watch?v=" + recommended_item_id;
body_item->thumbnail_url = "https://img.youtube.com/vi/" + recommended_item_id + "/hqdefault.jpg";
- body_item->thumbnail_size = sf::Vector2i(158, 119);
+ body_item->thumbnail_size = sf::Vector2i(175, 131);
body_items.push_back(std::move(body_item));
// We dont want more than 150 recommendations
@@ -746,7 +746,7 @@ namespace QuickMedia {
body_item->url = "https://www.youtube.com/watch?v=" + video_id_str;
body_item->thumbnail_url = "https://img.youtube.com/vi/" + video_id_str + "/hqdefault.jpg";
body_item->set_description(timestamp_to_relative_time_str(std::max(0l, time_now - timestamp.asInt64())));
- body_item->thumbnail_size = sf::Vector2i(158, 119);
+ body_item->thumbnail_size = sf::Vector2i(175, 131);
body_items.push_back(std::move(body_item));
}
@@ -925,6 +925,10 @@ namespace QuickMedia {
return;
}
+ for(Tab &tab : tabs) {
+ tab.body->thumbnail_resize_target_size = tab.page->get_max_thumbnail_size();
+ }
+
const Json::Value *json_chapters = &Json::Value::nullSingleton();
if(content_storage_json.isObject()) {
const Json::Value &chapters_json = content_storage_json["chapters"];
@@ -2886,14 +2890,6 @@ namespace QuickMedia {
return str;
}
- static sf::Vector2f to_vec2f(const sf::Vector2i &vec) {
- return sf::Vector2f(vec.x, vec.y);
- }
-
- static sf::Vector2i to_vec2i(const sf::Vector2f &vec) {
- return sf::Vector2i(vec.x, vec.y);
- }
-
static const sf::Vector2i CHAT_MESSAGE_THUMBNAIL_MAX_SIZE(600, 337);
static std::shared_ptr<BodyItem> message_to_body_item(Message *message, UserInfo *me) {
@@ -2906,9 +2902,10 @@ namespace QuickMedia {
body_item->set_timestamp(message->timestamp);
if(!message->thumbnail_url.empty()) {
body_item->thumbnail_url = message->thumbnail_url;
- body_item->thumbnail_size = to_vec2i(clamp_to_size(to_vec2f(message->thumbnail_size), to_vec2f(CHAT_MESSAGE_THUMBNAIL_MAX_SIZE)));
+ body_item->thumbnail_size = message->thumbnail_size;
} else if(!message->url.empty() && message->type == MessageType::IMAGE) {
body_item->thumbnail_url = message->url;
+ body_item->thumbnail_size = message->thumbnail_size;
} else {
body_item->thumbnail_url = message->user->avatar_url;
body_item->thumbnail_mask_type = ThumbnailMaskType::CIRCLE;
@@ -2970,8 +2967,7 @@ namespace QuickMedia {
RoomData *current_room = nullptr;
bool is_window_focused = window.hasFocus();
- auto process_new_room_messages = [this, &tabs, &current_room, &is_window_focused](RoomSyncMessages &room_sync_messages, bool is_first_sync) mutable {
- size_t room_swap_index = 0;
+ auto process_new_room_messages = [this, &selected_tab, &current_room, &is_window_focused](RoomSyncMessages &room_sync_messages, bool is_first_sync) mutable {
for(auto &[room, messages] : room_sync_messages) {
if(messages.empty())
continue;
@@ -2983,7 +2979,7 @@ namespace QuickMedia {
room->has_unread_mention = true;
//message->mentions_me = false;
// TODO: What if the message or username begins with "-"? also make the notification image be the avatar of the user
- if(!is_window_focused || room != current_room || is_first_sync)
+ if(!is_window_focused || room != current_room || is_first_sync || selected_tab == ROOMS_TAB_INDEX)
show_notification("QuickMedia matrix - " + matrix->message_get_author_displayname(message.get()) + " (" + room->name + ")", message->body);
}
}
@@ -3967,23 +3963,21 @@ namespace QuickMedia {
tabs[MESSAGES_TAB_INDEX].body->draw_item(window, currently_operating_on_item.get(), body_item_pos, body_item_size);
}
- if(tabs[selected_tab].type == ChatTabType::MESSAGES && current_room && current_room->userdata) {
+ if(tabs[selected_tab].type == ChatTabType::MESSAGES && current_room && current_room->userdata && !current_room->last_message_read) {
if(tabs[selected_tab].body->is_last_item_fully_visible()) {
- if(!current_room->last_message_read) {
- BodyItem *current_room_body_item = static_cast<BodyItem*>(current_room->userdata);
- std::string room_desc = current_room_body_item->get_description();
- if(strncmp(room_desc.c_str(), "Unread: ", 8) == 0)
- room_desc = room_desc.substr(8);
- if(room_desc.size() >= 25 && strncmp(room_desc.c_str() + room_desc.size() - 25, "\n** You were mentioned **", 25) == 0)
- room_desc = room_desc.substr(0, room_desc.size() - 25);
- current_room_body_item->set_description(std::move(room_desc));
- // TODO: Show a line like nheko instead for unread messages, or something else
- current_room_body_item->set_title_color(sf::Color::White);
- current_room->last_message_read = true;
- // TODO: Maybe set this instead when the mention is visible on the screen?
- current_room->has_unread_mention = false;
- }
- } else if(!current_room->last_message_read) {
+ BodyItem *current_room_body_item = static_cast<BodyItem*>(current_room->userdata);
+ std::string room_desc = current_room_body_item->get_description();
+ if(strncmp(room_desc.c_str(), "Unread: ", 8) == 0)
+ room_desc = room_desc.substr(8);
+ if(room_desc.size() >= 25 && strncmp(room_desc.c_str() + room_desc.size() - 25, "\n** You were mentioned **", 25) == 0)
+ room_desc = room_desc.substr(0, room_desc.size() - 25);
+ current_room_body_item->set_description(std::move(room_desc));
+ // TODO: Show a line like nheko instead for unread messages, or something else
+ current_room_body_item->set_title_color(sf::Color::White);
+ current_room->last_message_read = true;
+ // TODO: Maybe set this instead when the mention is visible on the screen?
+ current_room->has_unread_mention = false;
+ } else {
window.draw(more_messages_below_rect);
}
}