aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Matrix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/Matrix.cpp')
-rw-r--r--src/plugins/Matrix.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index e0a9a4b..21459d0 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -6,6 +6,7 @@
#include "../../include/Program.hpp"
#include "../../include/base64_url.hpp"
#include "../../include/Json.hpp"
+#include "../../include/AsyncImageLoader.hpp"
#include "../../include/Utils.hpp"
#include <rapidjson/document.h>
#include <rapidjson/writer.h>
@@ -3133,7 +3134,7 @@ namespace QuickMedia {
return post_message(room, filename, event_id_response, file_info_opt, thumbnail_info_opt);
}
- PluginResult Matrix::upload_file(RoomData *room, const std::string &filepath, UploadInfo &file_info, UploadInfo &thumbnail_info, std::string &err_msg) {
+ PluginResult Matrix::upload_file(RoomData *room, const std::string &filepath, UploadInfo &file_info, UploadInfo &thumbnail_info, std::string &err_msg, bool upload_thumbnail) {
FileAnalyzer file_analyzer;
if(!file_analyzer.load_file(filepath.c_str())) {
err_msg = "Failed to load " + filepath;
@@ -3163,8 +3164,7 @@ namespace QuickMedia {
return PluginResult::ERR;
}
- if(is_content_type_video(file_analyzer.get_content_type())) {
- // TODO: Also upload thumbnail for images. Take into consideration below upload_file, we dont want to upload thumbnail of thumbnail
+ if(upload_thumbnail && is_content_type_video(file_analyzer.get_content_type())) {
char tmp_filename[] = "/tmp/quickmedia_video_frame_XXXXXX";
int tmp_file = mkstemp(tmp_filename);
if(tmp_file != -1) {
@@ -3184,6 +3184,29 @@ namespace QuickMedia {
} else {
fprintf(stderr, "Failed to create temporary file for video thumbnail, ignoring thumbnail...\n");
}
+ } else if(upload_thumbnail && is_content_type_image(file_analyzer.get_content_type())) {
+ char tmp_filename[] = "/tmp/quickmedia_thumbnail_XXXXXX";
+ int tmp_file = mkstemp(tmp_filename);
+ if(tmp_file != -1) {
+ std::string thumbnail_path;
+ if(create_thumbnail(filepath, tmp_filename, sf::Vector2i(600, 337)))
+ thumbnail_path = tmp_filename;
+ else
+ thumbnail_path = filepath;
+
+ UploadInfo upload_info_ignored; // Ignore because it wont be set anyways. Thumbnails dont have thumbnails.
+ PluginResult upload_thumbnail_result = upload_file(room, thumbnail_path, thumbnail_info, upload_info_ignored, err_msg, false);
+ if(upload_thumbnail_result != PluginResult::OK) {
+ close(tmp_file);
+ remove(tmp_filename);
+ return upload_thumbnail_result;
+ }
+
+ close(tmp_file);
+ remove(tmp_filename);
+ } else {
+ fprintf(stderr, "Failed to create temporary file for image thumbnail, ignoring thumbnail...\n");
+ }
}
std::vector<CommandArg> additional_args = {