aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 144bbd8..5306349 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -3863,6 +3863,16 @@ namespace QuickMedia {
if(home_server_json.IsString())
this->homeserver_domain = home_server_json.GetString();
+ const rapidjson::Value &well_known_json = GetMember(json_root, "well_known");
+ if(well_known_json.IsObject()) {
+ const rapidjson::Value &homeserver_json = GetMember(well_known_json, "m.homeserver");
+ if(homeserver_json.IsObject()) {
+ const rapidjson::Value &base_url_json = GetMember(homeserver_json, "base_url");
+ if(base_url_json.IsString())
+ well_known_base_url = base_url_json.GetString();
+ }
+ }
+
// Use the user-provided homeserver instead of the one the server tells us about, otherwise this wont work with a proxy
// such as pantalaimon
json_root.AddMember("homeserver", rapidjson::StringRef(homeserver.c_str()), request_data.GetAllocator());
@@ -3906,6 +3916,7 @@ namespace QuickMedia {
access_token.clear();
homeserver.clear();
homeserver_domain.clear();
+ well_known_base_url.clear();
upload_limit.reset();
return PluginResult::OK;
@@ -4103,6 +4114,16 @@ namespace QuickMedia {
if(home_server_json.IsString())
this->homeserver_domain = home_server_json.GetString();
+ const rapidjson::Value &well_known_json = GetMember(json_root, "well_known");
+ if(well_known_json.IsObject()) {
+ const rapidjson::Value &homeserver_json = GetMember(well_known_json, "m.homeserver");
+ if(homeserver_json.IsObject()) {
+ const rapidjson::Value &base_url_json = GetMember(homeserver_json, "base_url");
+ if(base_url_json.IsString())
+ well_known_base_url = base_url_json.GetString();
+ }
+ }
+
this->my_user_id = user_id_json.GetString();
this->access_token = access_token_json.GetString();
this->homeserver = homeserver_json.GetString();
@@ -4527,6 +4548,21 @@ namespace QuickMedia {
return homeserver_domain;
}
+ std::string Matrix::get_remote_homeserver_url() const {
+ if(!well_known_base_url.empty())
+ return well_known_base_url;
+
+ if(!homeserver_domain.empty()) {
+ if(string_starts_with(homeserver_domain, "http://") || string_starts_with(homeserver_domain, "https://"))
+ return homeserver_domain;
+ return "https://" + homeserver_domain; // TODO: What if domain does not use https?
+ }
+
+ if(string_starts_with(homeserver, "http://") || string_starts_with(homeserver, "https://"))
+ return homeserver;
+ return "https://" + homeserver; // TODO: What if domain does not use https?
+ }
+
RoomData* Matrix::get_room_by_id(const std::string &id) {
std::lock_guard<std::recursive_mutex> lock(room_data_mutex);
auto room_it = room_data_by_id.find(id);