Improved BaseURL and DM link handling

This commit is contained in:
N Pex 2023-12-01 08:20:03 +00:00
parent b14749c28f
commit dd70e4a576
9 changed files with 373 additions and 322 deletions

View file

@ -463,7 +463,7 @@ export default {
.getUniqueAliasForRoomName(
this.$matrix.matrixClient,
this.roomName,
this.$matrix.currentUserHomeServer
this.$matrix.currentUserMXDomain
)
.then((alias) => {
createRoomOptions.room_alias_name = alias;

View file

@ -53,7 +53,7 @@ import * as sdk from "matrix-js-sdk";
import logoMixin from "./logoMixin";
import InteractiveAuth from './InteractiveAuth.vue';
import CopyLink from "./CopyLink.vue"
import utils from "../plugins/utils";
import util from "../plugins/utils";
export default {
name: "GetLink",
@ -91,7 +91,7 @@ export default {
methods: {
defaultData() {
return {
user: new User(this.$config.defaultServer, "", utils.randomPass()),
user: new User("", util.randomPass()),
isValid: false,
loading: false,
message: "",
@ -128,10 +128,10 @@ export default {
var user = Object.assign({}, this.user);
let prefix = userDisplayName.toLowerCase().replaceAll(" ", "-").replaceAll(utils.invalidUserIdChars(), "");
let prefix = userDisplayName.toLowerCase().replaceAll(" ", "-").replaceAll(util.invalidUserIdChars(), "");
if (prefix.length == 0) {
prefix = this.$config.userIdPrefix;
user.user_id = utils.randomUser(prefix);
user.user_id = util.randomUser(prefix);
} else {
// We first try with a username that is just a processed version of the display name.
// If it is already taken, try again with random characters appended.
@ -139,8 +139,6 @@ export default {
prefix = prefix + "-";
}
user.normalize();
this.loading = true;
this.loadLoginFlows().then(() => {
@ -160,7 +158,7 @@ export default {
this.hasError = true;
} else if (error.data && error.data.errcode === 'M_USER_IN_USE') {
// Try again with (other/new) random chars appended
user.user_id = utils.randomUser(prefix);
user.user_id = util.randomUser(prefix);
return this.$store.dispatch("createUser", { user, registrationFlowHandler: this.$refs.interactiveAuth.registrationFlowHandler }).then(
(ignoreduser) => {
this.$matrix.setUserDisplayName(userDisplayName);
@ -191,28 +189,29 @@ export default {
},
loadLoginFlows() {
var user = Object.assign({}, this.user);
user.normalize();
const server = user.home_server || this.$config.defaultServer;
if (server !== this.currentLoginServer) {
this.currentLoginServer = server;
this.loadingLoginFlows = true;
util.getMatrixBaseUrl(user, this.$config)
.then((baseUrl) => {
if (baseUrl !== this.currentLoginServer) {
this.currentLoginServer = baseUrl;
this.loadingLoginFlows = true;
const matrixClient = sdk.createClient({ baseUrl: server });
return matrixClient.loginFlows().then((response) => {
console.log("FLOWS", response.flows);
this.loginFlows = response.flows.filter(this.supportedLoginFlow);
this.loadingLoginFlows = false;
if (this.loginFlows.length == 0) {
this.message = this.$t('login.no_supported_flow')
this.hasError = true;
const matrixClient = sdk.createClient({ baseUrl: baseUrl });
return matrixClient.loginFlows().then((response) => {
console.log("FLOWS", response.flows);
this.loginFlows = response.flows.filter(this.supportedLoginFlow);
this.loadingLoginFlows = false;
if (this.loginFlows.length == 0) {
this.message = this.$t('login.no_supported_flow')
this.hasError = true;
} else {
this.message = "";
this.hasError = false;
}
});
} else {
this.message = "";
this.hasError = false;
return Promise.resolve();
}
});
} else {
return Promise.resolve();
}
})
},
supportedLoginFlow(flow) {
return ["m.login.password"].includes(flow.type);

View file

@ -128,7 +128,7 @@ export default {
},
data() {
return {
user: new User(this.$config.defaultServer, "", ""),
user: new User("", ""),
isValid: true,
loading: false,
message: "",
@ -184,7 +184,6 @@ export default {
// Is it a full matrix user id? Modify a copy, so that the UI will still show the full ID.
var user = Object.assign({}, this.user);
user.normalize();
this.loading = true;
this.$store.dispatch("login", { user }).then(
@ -231,35 +230,36 @@ export default {
},
onUsernameBlur() {
var user = Object.assign({}, this.user);
user.normalize();
const server = user.home_server || this.$config.defaultServer;
if (server !== this.currentLoginServer) {
this.showPasswordField = false;
util.getMatrixBaseUrl(user, this.$config)
.then((baseUrl) => {
if (baseUrl !== this.currentLoginServer) {
this.currentLoginServer = server;
this.loadingLoginFlows = true;
this.showPasswordField = false;
const matrixClient = sdk.createClient({baseUrl: server});
matrixClient.loginFlows().then((response) => {
console.log("FLOWS", response.flows);
this.loginFlows = response.flows.filter(this.supportedLoginFlow);
this.loadingLoginFlows = false;
if (this.loginFlows.length == 0) {
this.message = this.$t('login.no_supported_flow')
this.hasError = true;
} else {
this.message = "";
this.hasError = false;
this.showPasswordField = this.loginFlows.some(f => f.type == "m.login.password");
if (this.showPasswordField) {
this.$nextTick(() => {
this.$refs.password.focus();
});
}
this.currentLoginServer = baseUrl;
this.loadingLoginFlows = true;
const matrixClient = sdk.createClient({ baseUrl: baseUrl });
matrixClient.loginFlows().then((response) => {
console.log("FLOWS", response.flows);
this.loginFlows = response.flows.filter(this.supportedLoginFlow);
this.loadingLoginFlows = false;
if (this.loginFlows.length == 0) {
this.message = this.$t('login.no_supported_flow')
this.hasError = true;
} else {
this.message = "";
this.hasError = false;
this.showPasswordField = this.loginFlows.some(f => f.type == "m.login.password");
if (this.showPasswordField) {
this.$nextTick(() => {
this.$refs.password.focus();
});
}
}
});
}
});
}
},
supportedLoginFlow(flow) {
return ["m.login.password"].includes(flow.type);