aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-02 16:27:59 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-02 16:27:59 +0200
commitd9cb6885ab741ba69a966109cb05e26692143ce0 (patch)
treee4e356c182011bc389bc895665dab1507ecdb767 /src/QuickMedia.cpp
parent9e68dfad4449d5c0180e252fada6de56b4f405d1 (diff)
Matrix: add video/regular file upload
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp42
1 files changed, 29 insertions, 13 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 8835b1d..fd49556 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -3117,6 +3117,7 @@ namespace QuickMedia {
if(attached_image_texture->loadFromMemory(image_data.data(), image_data.size())) {
attached_image_texture->setSmooth(true);
+ //attached_image_texture->generateMipmap();
attached_image_sprite.setTexture(*attached_image_texture, true);
} else {
BodyItem *selected_item = body->get_selected();
@@ -3280,14 +3281,17 @@ namespace QuickMedia {
source.a + diff_a * progress);
}
- static std::string extract_first_line(const std::string &str) {
+ static std::string extract_first_line(const std::string &str, size_t max_length) {
size_t index = str.find('\n');
- if(index == std::string::npos)
+ if(index == std::string::npos) {
+ if(str.size() > max_length)
+ return str.substr(0, max_length) + "...";
return str;
- else if(index == 0)
+ } else if(index == 0) {
return "";
- else
- return str.substr(0, index);
+ } else {
+ return str.substr(0, std::min(index, max_length)) + "...";
+ }
}
void Program::chat_page() {
@@ -3361,7 +3365,7 @@ namespace QuickMedia {
if(only_show_mentions) {
std::string room_desc;
if(!messages.empty())
- room_desc = matrix->message_get_author_displayname(room, messages.back().get()) + ": " + extract_first_line(messages.back()->body);
+ room_desc = matrix->message_get_author_displayname(room, messages.back().get()) + ": " + extract_first_line(messages.back()->body, 150);
if(was_mentioned) {
room_desc += "\n** You were mentioned **"; // TODO: Better notification?
room_body_item_it->second.body_item->title_color = sf::Color(255, 100, 100);
@@ -3369,7 +3373,7 @@ namespace QuickMedia {
}
room_body_item_it->second.body_item->set_description(std::move(room_desc));
} else if(!messages.empty()) {
- std::string room_desc = "Unread: " + matrix->message_get_author_displayname(room, messages.back().get()) + ": " + extract_first_line(messages.back()->body);
+ std::string room_desc = "Unread: " + matrix->message_get_author_displayname(room, messages.back().get()) + ": " + extract_first_line(messages.back()->body, 150);
if(was_mentioned)
room_desc += "\n** You were mentioned **"; // TODO: Better notification?
room_body_item_it->second.body_item->set_description(std::move(room_desc));
@@ -3409,7 +3413,7 @@ namespace QuickMedia {
if(text.isEmpty())
return false;
- if(text[0] == '/') {
+ if(chat_state == ChatState::TYPING_MESSAGE && text[0] == '/') {
std::string command = text;
strip(command);
if(command == "/upload") {
@@ -3432,7 +3436,7 @@ namespace QuickMedia {
if(chat_state == ChatState::TYPING_MESSAGE) {
// TODO: Make asynchronous
- if(matrix->post_message(current_room_id, text) == PluginResult::OK) {
+ if(matrix->post_message(current_room_id, text, std::nullopt, std::nullopt) == PluginResult::OK) {
chat_input.set_editable(false);
chat_state = ChatState::NAVIGATING;
return true;
@@ -3575,11 +3579,18 @@ namespace QuickMedia {
}
};
+ bool is_window_focused = true;
+
while (current_page == Page::CHAT) {
sf::Int32 frame_time_ms = frame_timer.restart().asMilliseconds();
while (window.pollEvent(event)) {
base_event_handler(event, Page::EXIT, false, false, false);
- if(event.type == sf::Event::Resized || event.type == sf::Event::GainedFocus) {
+ if(event.type == sf::Event::GainedFocus) {
+ is_window_focused = true;
+ redraw = true;
+ } else if(event.type == sf::Event::LostFocus) {
+ is_window_focused = false;
+ } else if(event.type == sf::Event::Resized || event.type == sf::Event::GainedFocus) {
redraw = true;
} else if(event.type == sf::Event::KeyPressed && chat_state == ChatState::NAVIGATING) {
if(event.key.code == sf::Keyboard::Up || event.key.code == sf::Keyboard::PageUp || event.key.code == sf::Keyboard::Home) {
@@ -3833,8 +3844,11 @@ namespace QuickMedia {
} else {
// TODO: Make asynchronous.
// TODO: Upload multiple files.
- if(matrix->post_file(current_room_id, selected_files[0]) != PluginResult::OK)
- show_notification("QuickMedia", "Failed to upload image to room", Urgency::CRITICAL);
+ std::string err_msg;
+ if(matrix->post_file(current_room_id, selected_files[0], err_msg) != PluginResult::OK) {
+ std::string desc = "Failed to upload image to room, error: " + err_msg;
+ show_notification("QuickMedia", desc.c_str(), Urgency::CRITICAL);
+ }
}
redraw = true;
break;
@@ -3887,6 +3901,8 @@ namespace QuickMedia {
if(room_avatar_thumbnail_data->loading_state == LoadingState::FINISHED_LOADING && room_avatar_thumbnail_data->image->getSize().x > 0 && room_avatar_thumbnail_data->image->getSize().y > 0) {
if(!room_avatar_thumbnail_data->texture.loadFromImage(*room_avatar_thumbnail_data->image))
fprintf(stderr, "Warning: failed to load texture for room avatar\n");
+ room_avatar_thumbnail_data->texture.setSmooth(true);
+ //room_avatar_thumbnail_data->texture.generateMipmap();
room_avatar_thumbnail_data->image.reset();
room_avatar_thumbnail_data->loading_state = LoadingState::APPLIED_TO_TEXTURE;
room_avatar_sprite.setTexture(room_avatar_thumbnail_data->texture, true);
@@ -4152,7 +4168,7 @@ namespace QuickMedia {
if(tabs[selected_tab].type == ChatTabType::MESSAGES) {
BodyItem *last_visible_item = tabs[selected_tab].body->get_last_fully_visible_item();
- if(chat_state != ChatState::URL_SELECTION && current_room_body_data && last_visible_item && !setting_read_marker && read_marker_timer.getElapsedTime().asMilliseconds() >= read_marker_timeout_ms) {
+ if(is_window_focused && chat_state != ChatState::URL_SELECTION && current_room_body_data && last_visible_item && !setting_read_marker && read_marker_timer.getElapsedTime().asMilliseconds() >= read_marker_timeout_ms) {
Message *message = (Message*)last_visible_item->userdata;
if(message->timestamp > current_room_body_data->last_read_message_timestamp) {
current_room_body_data->last_read_message_timestamp = message->timestamp;