diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/QuickMedia.cpp | 30 | ||||
-rw-r--r-- | src/plugins/Matrix.cpp | 33 |
2 files changed, 36 insertions, 27 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 433442a..c94951d 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -5435,26 +5435,6 @@ namespace QuickMedia { return message; } - static std::string pantalaimon_image_proxy_url_to_remote_image_url(Matrix *matrix, const std::string &image_url) { - std::string remote_homeserver_url = matrix->get_remote_homeserver_url(); - if(!remote_homeserver_url.empty() && remote_homeserver_url.back() == '/') - remote_homeserver_url.pop_back(); - - std::string result_url = image_url; - - if(string_starts_with(result_url, "http://")) - result_url.erase(result_url.begin(), result_url.begin() + 7); - else if(string_starts_with(result_url, "https://")) - result_url.erase(result_url.begin(), result_url.begin() + 8); - - size_t path_index = result_url.find('/'); - if(path_index == std::string::npos) - return remote_homeserver_url; - - result_url.replace(0, path_index, remote_homeserver_url); - return result_url; - } - bool Program::chat_page(MatrixChatPage *matrix_chat_page, RoomData *current_room) { assert(current_room); assert(strcmp(plugin_name, "matrix") == 0); @@ -6117,10 +6097,14 @@ namespace QuickMedia { auto message = std::make_shared<Message>(); message->body_is_formatted = true; message->user = matrix->get_me(current_room); - if(msgtype == "m.emote") + if(msgtype == "m.emote") { message->body = "*" + current_room->get_user_display_name(me) + "* " + matrix->body_to_formatted_body(current_room, text); - else + } else if(msgtype == "m.reaction") { + message->body = text; + message->body_is_formatted = false; + } else { message->body = matrix->body_to_formatted_body(current_room, text); + } message->type = MessageType::TEXT; message->timestamp = time(NULL) * 1000; @@ -6910,7 +6894,7 @@ namespace QuickMedia { if(selected_item_message->type == MessageType::VIDEO) image_url = selected_item->thumbnail_url; - image_url = pantalaimon_image_proxy_url_to_remote_image_url(matrix, image_url); + image_url = pantalaimon_url_to_homeserver_url(matrix, image_url); std::vector<Tab> saucenao_tabs; saucenao_tabs.push_back(Tab{create_body(), std::make_unique<SaucenaoPage>(this, image_url, false), nullptr}); diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index c366569..1e8ee99 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -641,6 +641,26 @@ namespace QuickMedia { return message->body; } + std::string pantalaimon_url_to_homeserver_url(Matrix *matrix, const std::string &url) { + std::string remote_homeserver_url = matrix->get_remote_homeserver_url(); + if(!remote_homeserver_url.empty() && remote_homeserver_url.back() == '/') + remote_homeserver_url.pop_back(); + + std::string result_url = url; + + if(string_starts_with(result_url, "http://")) + result_url.erase(result_url.begin(), result_url.begin() + 7); + else if(string_starts_with(result_url, "https://")) + result_url.erase(result_url.begin(), result_url.begin() + 8); + + size_t path_index = result_url.find('/'); + if(path_index == std::string::npos) + return remote_homeserver_url; + + result_url.replace(0, path_index, remote_homeserver_url); + return result_url; + } + static std::string message_to_room_description_text(Matrix *matrix, Message *message, mgl::vec2i image_max_size = mgl::vec2i(0, 0)) { std::string body = strip(message_to_qm_text(matrix, message, true, image_max_size)); if(message->type == MessageType::REACTION) @@ -4376,8 +4396,7 @@ namespace QuickMedia { PluginResult Matrix::upload_custom_emoji(const std::string &filepath, const std::string &key, std::string &mxc_url, std::string &err_msg) { UploadInfo file_info; UploadInfo thumbnail_info; - // TODO: Do not create and upload thumbnail - PluginResult upload_file_result = upload_file(filepath, "", file_info, thumbnail_info, err_msg); + PluginResult upload_file_result = upload_file(filepath, "", file_info, thumbnail_info, err_msg, false, true); if(upload_file_result != PluginResult::OK) return upload_file_result; @@ -4560,7 +4579,9 @@ namespace QuickMedia { return post_message(room, filename, event_id_response, file_info_opt, thumbnail_info_opt); } - PluginResult Matrix::upload_file(const std::string &filepath, std::string filename, UploadInfo &file_info, UploadInfo &thumbnail_info, std::string &err_msg, bool upload_thumbnail) { + // |bypass_proxy| is used to use the remote homeserver url instead of pantalaimon (if pantalaimon is used) + // for uploading emoji. + PluginResult Matrix::upload_file(const std::string &filepath, std::string filename, UploadInfo &file_info, UploadInfo &thumbnail_info, std::string &err_msg, bool upload_thumbnail, bool bypass_proxy) { FileAnalyzer file_analyzer; if(!file_analyzer.load_file(filepath.c_str(), true)) { err_msg = "Failed to load " + filepath; @@ -4653,8 +4674,12 @@ namespace QuickMedia { std::string filename_escaped = url_param_encode(filename); + std::string remote_homeserver_url = homeserver; + if(bypass_proxy) + remote_homeserver_url = get_remote_homeserver_url(); + char url[512]; - snprintf(url, sizeof(url), "%s/_matrix/media/r0/upload?filename=%s", homeserver.c_str(), filename_escaped.c_str()); + snprintf(url, sizeof(url), "%s/_matrix/media/r0/upload?filename=%s", remote_homeserver_url.c_str(), filename_escaped.c_str()); rapidjson::Document json_root; DownloadResult download_result = download_json(json_root, url, std::move(additional_args), true, &err_msg); |