aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp14
-rw-r--r--src/plugins/Matrix.cpp12
2 files changed, 18 insertions, 8 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 81b9296..2c40580 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -5302,11 +5302,15 @@ namespace QuickMedia {
homeserver = "https://" + homeserver;
std::string err_msg;
- std::string username = login_inputs->inputs[0]->get_text();
- size_t at_index = username.find('@');
- if(at_index != std::string::npos)
- username.erase(username.begin() + at_index, username.end());
- if(matrix->login(username, login_inputs->inputs[1]->get_text(), homeserver, err_msg) == PluginResult::OK) {
+ std::string username = strip(login_inputs->inputs[0]->get_text());
+ std::string username_matrix_id = extract_user_name_from_user_id(username);
+ if(username_matrix_id.empty()) {
+ username_matrix_id = extract_user_name_from_email(username);
+ if(username_matrix_id.empty())
+ username_matrix_id = username;
+ }
+
+ if(matrix->login(username_matrix_id, login_inputs->inputs[1]->get_text(), homeserver, err_msg) == PluginResult::OK) {
login_finish();
return PluginResult::OK;
} else {
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 688e16e..0d93bd0 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -3476,14 +3476,20 @@ namespace QuickMedia {
return message;
}
- // Returns empty string on error
- static std::string extract_user_name_from_user_id(const std::string &user_id) {
+ std::string extract_user_name_from_user_id(const std::string &user_id) {
size_t index = user_id.find(':');
- if(index == std::string::npos || index == 0 || user_id.empty() || user_id[0] != '@')
+ if(index == std::string::npos || index == 0 || user_id[0] != '@')
return "";
return user_id.substr(1, index - 1);
}
+ std::string extract_user_name_from_email(const std::string &email) {
+ size_t index = email.find('@');
+ if(index == std::string::npos || index == 0)
+ return "";
+ return email.substr(0, index);
+ }
+
static std::string combine_user_display_names_for_room_name(std::vector<std::shared_ptr<UserInfo>> &user_info, const std::string &fallback_user_id) {
std::string result;
if(user_info.size() == 0)