aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp33
1 files changed, 29 insertions, 4 deletions
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);