aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-11-11 19:40:30 +0100
committerdec05eba <dec05eba@protonmail.com>2022-11-11 19:40:30 +0100
commit2bddad9701422b9fcf01c547a10054eb17ccdceb (patch)
tree8f357d7ecac8c04a515be3b779c7c582efdf5ff5
parent4815b649c09fd461baf0e48306abab7f790f5ca5 (diff)
Dont format matrix reaction locally, bypass pantalaimon for custom emoji
-rw-r--r--README.md4
-rw-r--r--TODO3
-rw-r--r--plugins/Matrix.hpp3
-rw-r--r--src/QuickMedia.cpp30
-rw-r--r--src/plugins/Matrix.cpp33
5 files changed, 42 insertions, 31 deletions
diff --git a/README.md b/README.md
index 03f638e..ea1e71f 100644
--- a/README.md
+++ b/README.md
@@ -46,8 +46,8 @@ Installing `lld` (the LLVM linker) can improve compile times.
`source-highlight` needs to be installed for syntax highlighting in matrix codeblocks.\
`wget` needs to be installed for xxx plugins.
## Matrix
-QuickMedia does currently not support encryption in matrix. If you want encryption then you can use [pantalaimon](https://github.com/matrix-org/pantalaimon/).\
-There are some issues with using pantalaimon though, for example pantalaimon breaks custom emoji.\
+QuickMedia does currently not support encryption in matrix. If you want encryption then you can use [pantalaimon](https://github.com/matrix-org/pantalaimon/). Note that pantalaimon can be much much slower than quickmedia connecting directly to the homeserver.\
+Note that there might be some issues with pantalaimon that you wont have when not using pantalaimon.\
It's not recommended to run QuickMedia with matrix and element on the same account at the same time as read markers behave differently in the different clients so messages wont be properly marked as read.
## Controls
### General control
diff --git a/TODO b/TODO
index 1b5f85d..04e2f71 100644
--- a/TODO
+++ b/TODO
@@ -247,4 +247,5 @@ Text editing should take into consideration FORMATTED_TEXT_START/FORMATTED_TEXT_
4chan code syntax highlight. 4chan doesn't say what language it is so we have to somehow guess the language.
Matrix autocomplete for emoji (and custom emoji) and option show different sizes (for custom emoji).
Nicer custom emoji upload options - Selecting name, size, cropping.
-Add option to copy somebody else custom emoji in matrix by pressing enter to bring up message option and in that a list of every emoji in the message should be added with "Add (emoji)..." text to add the emoji. \ No newline at end of file
+Add option to copy somebody else custom emoji in matrix by pressing enter to bring up message option and in that a list of every emoji in the message should be added with "Add (emoji)..." text to add the emoji.
+Detect invidious urls too, even the ones that dont have watch?v=.. this could be done by downloading the webpage (maybe only HEAD?) to check if it's invidious. \ No newline at end of file
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index d5fe251..1744ce0 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -28,6 +28,7 @@ namespace QuickMedia {
std::string formatted_text_to_qm_text(Matrix *matrix, const char *str, size_t size, bool allow_formatted_text, mgl::vec2i image_max_size = mgl::vec2i(0, 0));
// |image_max_size| 0, 0 means no max size
std::string message_to_qm_text(Matrix *matrix, const Message *message, bool allow_formatted_text = true, mgl::vec2i image_max_size = mgl::vec2i(0, 0));
+ std::string pantalaimon_url_to_homeserver_url(Matrix *matrix, const std::string &url);
struct TimestampedDisplayData {
std::string data;
@@ -736,7 +737,7 @@ namespace QuickMedia {
void remove_rooms(const rapidjson::Value &leave_json);
PluginResult get_pinned_events(RoomData *room, std::vector<std::string> &pinned_events);
std::shared_ptr<Message> parse_message_event(const rapidjson::Value &event_item_json, RoomData *room_data);
- PluginResult upload_file(const std::string &filepath, std::string filename, UploadInfo &file_info, UploadInfo &thumbnail_info, std::string &err_msg, bool upload_thumbnail = true);
+ PluginResult upload_file(const std::string &filepath, std::string filename, UploadInfo &file_info, UploadInfo &thumbnail_info, std::string &err_msg, bool upload_thumbnail = true, bool bypass_proxy = false);
void add_room(std::unique_ptr<RoomData> room);
void remove_room(const std::string &room_id);
// Returns false if an invite to the room already exists
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);