Don't include server in DM links if not needed
This commit is contained in:
parent
e6eeb9ede8
commit
c04a0a2638
5 changed files with 28 additions and 5 deletions
|
|
@ -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