Merge branch '524-don-t-display-homeserver-in-links-if-not-needed' into 'dev'
Don't include server in DM links if not needed See merge request keanuapp/keanuapp-weblite!240
This commit is contained in:
commit
c46d3a698f
5 changed files with 28 additions and 5 deletions
|
|
@ -109,7 +109,7 @@ export default {
|
|||
return this.$navigation && this.$navigation.canPop();
|
||||
},
|
||||
directMessageLink() {
|
||||
return `${window.location.origin + window.location.pathname}#/user/${encodeURIComponent(this.$matrix.currentUser.user_id)}`
|
||||
return this.$router.getDMLink(this.$matrix.currentUser, this.$config);
|
||||
},
|
||||
shareSupported() {
|
||||
return !!navigator.share;
|
||||
|
|
|
|||
|
|
@ -243,7 +243,7 @@ export default {
|
|||
return this.$matrix.currentUser.user_id
|
||||
},
|
||||
directMessageLink() {
|
||||
return `${window.location.origin + window.location.pathname}#/user/${this.currentUserId}`
|
||||
return this.$router.getDMLink(this.$matrix.currentUser, this.$config);
|
||||
},
|
||||
passwordsMatch() {
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -29,4 +29,12 @@ export default class User {
|
|||
}
|
||||
return user_id;
|
||||
}
|
||||
|
||||
// Get the domain out of the home_server, so if that one is e.g.
|
||||
// "https://yourdomain.com:8008" then we return "yourdomain.com"
|
||||
static serverDomain(home_server) {
|
||||
const parts = home_server.split("://");
|
||||
const serverAndPort = parts[parts.length - 1].split(/:|\//);
|
||||
return serverAndPort[0];
|
||||
}
|
||||
}
|
||||
|
|
@ -574,7 +574,7 @@ class Util {
|
|||
}
|
||||
|
||||
sanitizeUserId(userId) {
|
||||
if (userId && userId.match(/^@.+$/)) {
|
||||
if (userId && userId.match(/^([0-9a-z-.=_/]+|@[0-9a-z-.=_/]+:.+)$/)) {
|
||||
return userId;
|
||||
}
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import Login from '../components/Login.vue'
|
|||
import Profile from '../components/Profile.vue'
|
||||
import CreateRoom from '../components/CreateRoom.vue'
|
||||
import GetLink from '../components/GetLink.vue'
|
||||
|
||||
import User from '../models/user'
|
||||
import util from '../plugins/utils'
|
||||
|
||||
Vue.use(VueRouter)
|
||||
|
|
@ -126,7 +126,13 @@ router.beforeEach((to, from, next) => {
|
|||
}
|
||||
} else if (to.name == 'User') {
|
||||
if (to.params.userId) {
|
||||
const roomId = util.sanitizeUserId(to.params.userId);
|
||||
let roomId = util.sanitizeUserId(to.params.userId);
|
||||
if (roomId && !roomId.startsWith("@")) {
|
||||
// Not a full username. Assume local name on this server.
|
||||
const user = new User(router.app.$config.defaultServer, roomId, "");
|
||||
user.normalize();
|
||||
roomId = "@" + roomId + ":" + User.serverDomain(user.home_server);
|
||||
}
|
||||
router.app.$matrix.setCurrentRoomId(roomId);
|
||||
authRequired = false;
|
||||
}
|
||||
|
|
@ -166,4 +172,13 @@ router.getRoomLink = function (alias, roomId, roomName, mode) {
|
|||
return window.location.origin + window.location.pathname + "#/room/" + encodeURIComponent(util.sanitizeRoomId(alias || roomId));
|
||||
}
|
||||
|
||||
router.getDMLink = function (user, config) {
|
||||
let userId = user.user_id;
|
||||
if (user.home_server === config.defaultServer) {
|
||||
// Using default server, don't include it in the link
|
||||
userId = User.localPart(user.user_id);
|
||||
}
|
||||
return `${window.location.origin + window.location.pathname}#/user/${encodeURIComponent(userId)}`
|
||||
}
|
||||
|
||||
export default router
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue