2020-11-09 10:26:56 +01:00
|
|
|
import Vue from 'vue'
|
|
|
|
|
import VueRouter from 'vue-router'
|
2021-02-09 12:37:56 +01:00
|
|
|
import Home from '../components/Home.vue'
|
2020-11-09 10:26:56 +01:00
|
|
|
import Chat from '../components/Chat.vue'
|
2021-01-12 20:28:23 +01:00
|
|
|
import Join from '../components/Join.vue'
|
2020-11-09 10:26:56 +01:00
|
|
|
import Login from '../components/Login.vue'
|
2021-01-20 14:44:10 +01:00
|
|
|
import Profile from '../components/Profile.vue'
|
2021-03-23 16:20:01 +01:00
|
|
|
import CreateRoom from '../components/CreateRoom.vue'
|
2023-09-29 15:13:12 +00:00
|
|
|
import GetLink from '../components/GetLink.vue'
|
2024-04-03 09:34:24 +02:00
|
|
|
import CreateChannel from '../components/CreateChannel.vue'
|
2023-10-09 19:10:07 +02:00
|
|
|
import User from '../models/user'
|
2021-01-12 11:26:01 +01:00
|
|
|
import util from '../plugins/utils'
|
2020-11-09 10:26:56 +01:00
|
|
|
|
|
|
|
|
Vue.use(VueRouter)
|
|
|
|
|
|
|
|
|
|
const routes = [
|
|
|
|
|
{
|
|
|
|
|
path: '/',
|
2021-01-11 17:42:58 +01:00
|
|
|
name: 'Home',
|
2021-02-09 12:37:56 +01:00
|
|
|
component: Home
|
2021-01-11 17:42:58 +01:00
|
|
|
},
|
|
|
|
|
{
|
2021-01-12 20:51:31 +01:00
|
|
|
path: '/room/:roomId?',
|
2020-11-09 10:26:56 +01:00
|
|
|
name: 'Chat',
|
2021-01-29 21:41:43 +01:00
|
|
|
component: Chat,
|
|
|
|
|
meta: {
|
2021-11-12 19:29:28 +02:00
|
|
|
includeRoom: true,
|
|
|
|
|
includeFavicon: true
|
2021-01-29 21:41:43 +01:00
|
|
|
}
|
2020-11-09 10:26:56 +01:00
|
|
|
},
|
2020-12-04 17:15:18 +01:00
|
|
|
{
|
|
|
|
|
path: '/info',
|
|
|
|
|
name: 'RoomInfo',
|
|
|
|
|
component: () => import('../components/RoomInfo.vue'),
|
|
|
|
|
props: true,
|
2021-01-29 21:41:43 +01:00
|
|
|
meta: {
|
|
|
|
|
title: 'Info',
|
2021-11-12 19:29:28 +02:00
|
|
|
includeRoom: true,
|
|
|
|
|
includeFavicon: true
|
2021-01-29 21:41:43 +01:00
|
|
|
}
|
2020-12-04 17:15:18 +01:00
|
|
|
},
|
2021-01-20 14:44:10 +01:00
|
|
|
{
|
|
|
|
|
path: '/profile',
|
|
|
|
|
name: 'Profile',
|
2021-01-29 21:41:43 +01:00
|
|
|
component: Profile,
|
|
|
|
|
meta: {
|
2021-11-12 19:29:28 +02:00
|
|
|
title: 'Profile',
|
|
|
|
|
includeFavicon: true
|
2021-01-29 21:41:43 +01:00
|
|
|
}
|
2021-01-20 14:44:10 +01:00
|
|
|
},
|
2021-03-23 16:20:01 +01:00
|
|
|
{
|
|
|
|
|
path: '/createroom',
|
|
|
|
|
name: 'CreateRoom',
|
|
|
|
|
component: CreateRoom,
|
|
|
|
|
meta: {
|
2021-04-01 22:59:19 +02:00
|
|
|
title: 'Create room'
|
2021-03-23 16:20:01 +01:00
|
|
|
}
|
|
|
|
|
},
|
2023-09-29 15:13:12 +00:00
|
|
|
{
|
|
|
|
|
path: '/getlink',
|
|
|
|
|
name: 'GetLink',
|
|
|
|
|
component: GetLink,
|
|
|
|
|
},
|
2024-04-03 09:34:24 +02:00
|
|
|
{
|
|
|
|
|
path: '/createchannel',
|
|
|
|
|
name: 'CreateChannel',
|
|
|
|
|
component: CreateChannel,
|
|
|
|
|
},
|
2020-11-09 10:26:56 +01:00
|
|
|
{
|
|
|
|
|
path: '/login',
|
2021-01-08 11:07:02 +01:00
|
|
|
name: 'Login',
|
|
|
|
|
component: Login,
|
|
|
|
|
props: true
|
2020-11-09 10:26:56 +01:00
|
|
|
},
|
2020-11-19 22:48:08 +01:00
|
|
|
{
|
2021-01-12 20:28:23 +01:00
|
|
|
path: '/join/:roomId?',
|
2021-01-11 17:42:58 +01:00
|
|
|
name: 'Join',
|
2021-01-12 20:28:23 +01:00
|
|
|
component: Join
|
2020-11-19 22:48:08 +01:00
|
|
|
},
|
2022-12-12 16:10:53 +00:00
|
|
|
{
|
|
|
|
|
path: '/user/:userId?',
|
|
|
|
|
name: 'User',
|
|
|
|
|
component: Join
|
|
|
|
|
},
|
2021-04-01 22:59:19 +02:00
|
|
|
{
|
2021-04-02 09:28:51 +02:00
|
|
|
path: '/invite/:roomId?',
|
2021-04-01 22:59:19 +02:00
|
|
|
name: 'Invite',
|
|
|
|
|
component: () => import('../components/Invite.vue'),
|
|
|
|
|
meta: {
|
|
|
|
|
title: 'Add Friends'
|
|
|
|
|
}
|
2021-04-02 10:58:58 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/goodbye',
|
|
|
|
|
name: 'Goodbye',
|
|
|
|
|
component: () => import('../components/QuoteView.vue'),
|
2021-07-05 18:16:21 +02:00
|
|
|
props: true
|
2021-04-01 22:59:19 +02:00
|
|
|
}
|
2020-11-09 10:26:56 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
const router = new VueRouter({
|
|
|
|
|
routes
|
2021-01-11 17:42:58 +01:00
|
|
|
});
|
2020-11-09 10:26:56 +01:00
|
|
|
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
2024-04-03 09:34:24 +02:00
|
|
|
const publicPages = ['/login', '/createroom', '/getlink', '/createchannel'];
|
2021-01-12 20:28:23 +01:00
|
|
|
var authRequired = !publicPages.includes(to.path);
|
2021-05-10 11:13:22 +02:00
|
|
|
const loggedIn = router.app.$store.state.auth.user;
|
2020-11-09 10:26:56 +01:00
|
|
|
|
2021-09-25 15:08:26 +02:00
|
|
|
if (to.query && to.query.lang) {
|
|
|
|
|
// Set language via query param
|
|
|
|
|
const lang = to.query.lang;
|
|
|
|
|
// Check if valid translation
|
|
|
|
|
if (router.app.$i18n.messages[lang]) {
|
|
|
|
|
router.app.$store.commit('setLanguage', lang);
|
|
|
|
|
if (router.app.$i18n) {
|
|
|
|
|
router.app.$i18n.locale = to.query.lang;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-12 20:28:23 +01:00
|
|
|
if (to.name == 'Chat' || to.name == 'Join') {
|
2021-01-12 20:51:31 +01:00
|
|
|
if (!to.params.roomId && to.hash) {
|
|
|
|
|
// Public rooms start with '#', confuses the router. If hash but no roomId param, set it.
|
|
|
|
|
to.params.roomId = to.hash;
|
|
|
|
|
}
|
2021-01-12 11:26:01 +01:00
|
|
|
const roomId = util.sanitizeRoomId(to.params.roomId);
|
|
|
|
|
router.app.$matrix.setCurrentRoomId(roomId);
|
|
|
|
|
if (roomId && roomId.startsWith('#')) {
|
2021-01-11 17:42:58 +01:00
|
|
|
//Invite to public room
|
|
|
|
|
authRequired = false;
|
|
|
|
|
}
|
2022-12-12 16:10:53 +00:00
|
|
|
} else if (to.name == 'User') {
|
|
|
|
|
if (to.params.userId) {
|
2023-10-09 19:10:07 +02:00
|
|
|
let roomId = util.sanitizeUserId(to.params.userId);
|
|
|
|
|
if (roomId && !roomId.startsWith("@")) {
|
|
|
|
|
// Not a full username. Assume local name on this server.
|
2023-10-13 09:55:02 +02:00
|
|
|
return router.app.$config.promise.then((config) => {
|
2023-12-04 11:40:57 +01:00
|
|
|
const domain = config.defaultMatrixDomainPart;
|
2023-12-01 08:20:03 +00:00
|
|
|
if (!domain) throw new Error("No domain part for user invite!");
|
|
|
|
|
roomId = "@" + roomId + ":" + domain;
|
2023-10-13 09:55:02 +02:00
|
|
|
router.app.$matrix.setCurrentRoomId(roomId);
|
|
|
|
|
}).catch(err => console.error(err)).finally(() => next());
|
|
|
|
|
} else {
|
|
|
|
|
router.app.$matrix.setCurrentRoomId(roomId);
|
|
|
|
|
authRequired = false;
|
2023-10-09 19:10:07 +02:00
|
|
|
}
|
2022-12-12 16:10:53 +00:00
|
|
|
}
|
2021-04-02 09:28:51 +02:00
|
|
|
} else if (to.name == 'Invite') {
|
|
|
|
|
if (to.params.roomId) {
|
|
|
|
|
const roomId = util.sanitizeRoomId(to.params.roomId);
|
|
|
|
|
router.app.$matrix.setCurrentRoomId(roomId);
|
|
|
|
|
}
|
2023-10-31 09:51:57 +01:00
|
|
|
} else if (to.name == 'CreateRoom') {
|
|
|
|
|
return router.app.$config.promise.then((config) => {
|
|
|
|
|
if (config.hide_add_room_on_home) {
|
|
|
|
|
next('/');
|
|
|
|
|
} else {
|
|
|
|
|
next();
|
|
|
|
|
}
|
|
|
|
|
}).catch(err => { console.error(err); next('/'); });
|
2021-01-11 17:42:58 +01:00
|
|
|
}
|
|
|
|
|
|
2020-11-09 10:26:56 +01:00
|
|
|
// trying to access a restricted page + not logged in
|
|
|
|
|
// redirect to login page
|
|
|
|
|
if (authRequired && !loggedIn) {
|
|
|
|
|
next('/login');
|
|
|
|
|
} else {
|
|
|
|
|
next();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-06-28 12:14:44 +00:00
|
|
|
router.getRoomLink = function (alias, roomId, roomName, mode) {
|
|
|
|
|
let params = {};
|
2023-05-23 16:29:17 +02:00
|
|
|
if ((!alias || roomName.replace(/\s/g, "").toLowerCase() !== util.getRoomNameFromAlias(alias)) && roomName) {
|
|
|
|
|
// There is no longer a correlation between alias and room name, probably because room name has
|
|
|
|
|
// changed. Include the "?roomName" part
|
2023-06-28 12:14:44 +00:00
|
|
|
params["roomName"] = roomName;
|
|
|
|
|
}
|
|
|
|
|
if (mode) {
|
|
|
|
|
// Optional mode given, append as "m" query param
|
|
|
|
|
params["m"] = mode;
|
|
|
|
|
}
|
|
|
|
|
if (Object.entries(params).length > 0) {
|
|
|
|
|
const queryString = Object.entries(params)
|
|
|
|
|
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
|
|
|
|
.join('&')
|
|
|
|
|
return window.location.origin + window.location.pathname + "?" + queryString + "#/room/" + encodeURIComponent(util.sanitizeRoomId(alias || roomId));
|
2023-05-23 16:29:17 +02:00
|
|
|
}
|
|
|
|
|
return window.location.origin + window.location.pathname + "#/room/" + encodeURIComponent(util.sanitizeRoomId(alias || roomId));
|
2021-01-21 12:12:55 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:10:07 +02:00
|
|
|
router.getDMLink = function (user, config) {
|
|
|
|
|
let userId = user.user_id;
|
2023-12-04 11:40:57 +01:00
|
|
|
if (User.domainPart(userId) === config.defaultMatrixDomainPart && !config.useFullyQualifiedDMLinks) {
|
2023-10-09 19:10:07 +02:00
|
|
|
// 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)}`
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-09 10:26:56 +01:00
|
|
|
export default router
|