2018-07-06 18:15:15 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const Vue = require("vue").default;
|
2019-10-17 16:56:44 +00:00
|
|
|
|
2019-02-26 20:23:41 +00:00
|
|
|
const store = require("./store").default;
|
2018-07-06 18:15:15 +00:00
|
|
|
const App = require("../components/App.vue").default;
|
2019-11-05 10:36:44 +00:00
|
|
|
const localetime = require("./helpers/localetime");
|
2019-04-13 20:44:04 +00:00
|
|
|
const storage = require("./localStorage");
|
2019-11-03 15:56:41 +00:00
|
|
|
const {router} = require("./router");
|
2019-10-17 16:56:44 +00:00
|
|
|
const constants = require("./constants");
|
2018-07-06 18:15:15 +00:00
|
|
|
|
2018-07-08 10:50:11 +00:00
|
|
|
Vue.filter("localetime", localetime);
|
2018-07-06 18:15:15 +00:00
|
|
|
|
2019-11-08 00:03:41 +00:00
|
|
|
const favicon = document.getElementById("favicon");
|
|
|
|
const faviconNormal = favicon.getAttribute("href");
|
|
|
|
const faviconAlerted = favicon.dataset.other;
|
|
|
|
|
2018-07-06 18:15:15 +00:00
|
|
|
const vueApp = new Vue({
|
|
|
|
el: "#viewport",
|
2019-10-17 16:56:44 +00:00
|
|
|
router,
|
2018-07-10 09:40:55 +00:00
|
|
|
mounted() {
|
2019-11-02 19:40:59 +00:00
|
|
|
// TODO: Hackfix because socket-events require vueApp somewhere
|
|
|
|
// and that breaks due to cyclical depenency as by this point vue.js
|
|
|
|
// does not export anything yet.
|
|
|
|
setTimeout(() => {
|
|
|
|
const socket = require("./socket");
|
|
|
|
|
|
|
|
require("./socket-events");
|
|
|
|
require("./contextMenuFactory");
|
|
|
|
require("./webpush");
|
|
|
|
require("./keybinds");
|
|
|
|
|
|
|
|
socket.open();
|
|
|
|
}, 1);
|
2018-07-10 09:40:55 +00:00
|
|
|
},
|
2019-04-13 20:44:04 +00:00
|
|
|
methods: {
|
2019-10-25 21:37:40 +00:00
|
|
|
switchToChannel(channel) {
|
2019-11-02 19:40:59 +00:00
|
|
|
if (
|
|
|
|
this.$store.state.activeChannel &&
|
|
|
|
this.$store.state.activeChannel.channel.id === channel.id
|
|
|
|
) {
|
2019-10-25 21:37:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-28 13:48:13 +00:00
|
|
|
this.$router.push("/chan-" + channel.id);
|
2019-10-25 21:37:40 +00:00
|
|
|
},
|
2019-10-17 16:56:44 +00:00
|
|
|
switchOutOfChannel(channel) {
|
|
|
|
// When switching out of a channel, mark everything as read
|
|
|
|
if (channel.messages.length > 0) {
|
|
|
|
channel.firstUnread = channel.messages[channel.messages.length - 1].id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channel.messages.length > 100) {
|
|
|
|
channel.messages.splice(0, channel.messages.length - 100);
|
|
|
|
channel.moreHistoryAvailable = true;
|
|
|
|
}
|
|
|
|
},
|
2019-04-13 20:44:04 +00:00
|
|
|
},
|
2018-07-06 18:15:15 +00:00
|
|
|
render(createElement) {
|
|
|
|
return createElement(App, {
|
2019-02-18 09:18:32 +00:00
|
|
|
ref: "app",
|
2018-07-06 18:15:15 +00:00
|
|
|
props: this,
|
|
|
|
});
|
|
|
|
},
|
2019-02-26 20:23:41 +00:00
|
|
|
store,
|
2018-07-06 18:15:15 +00:00
|
|
|
});
|
|
|
|
|
2019-11-07 23:47:45 +00:00
|
|
|
store.watch(
|
|
|
|
(state) => state.sidebarOpen,
|
|
|
|
(sidebarOpen) => {
|
|
|
|
if (window.outerWidth > constants.mobileViewportPixels) {
|
|
|
|
storage.set("thelounge.state.sidebar", sidebarOpen);
|
|
|
|
}
|
|
|
|
|
|
|
|
vueApp.$emit("resize");
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-11-07 23:50:51 +00:00
|
|
|
store.watch(
|
|
|
|
(state) => state.userlistOpen,
|
|
|
|
(userlistOpen) => {
|
|
|
|
storage.set("thelounge.state.userlist", userlistOpen);
|
|
|
|
vueApp.$emit("resize");
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-11-07 23:53:04 +00:00
|
|
|
store.watch(
|
|
|
|
(_, getters) => getters.title,
|
|
|
|
(title) => {
|
|
|
|
document.title = title;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-11-08 00:03:41 +00:00
|
|
|
// Toggles the favicon to red when there are unread notifications
|
|
|
|
store.watch(
|
|
|
|
(_, getters) => getters.highlightCount,
|
|
|
|
(highlightCount) => {
|
|
|
|
favicon.setAttribute("href", highlightCount > 0 ? faviconAlerted : faviconNormal);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2018-09-14 15:44:26 +00:00
|
|
|
Vue.config.errorHandler = function(e) {
|
2019-11-02 19:40:59 +00:00
|
|
|
store.commit("currentUserVisibleError", `Vue error: ${e.message}`);
|
2018-09-14 15:44:26 +00:00
|
|
|
console.error(e); // eslint-disable-line
|
|
|
|
};
|
|
|
|
|
2018-07-18 18:40:09 +00:00
|
|
|
function initChannel(channel) {
|
2018-09-09 12:23:12 +00:00
|
|
|
channel.pendingMessage = "";
|
|
|
|
channel.inputHistoryPosition = 0;
|
|
|
|
channel.inputHistory = [""];
|
2018-07-18 18:40:09 +00:00
|
|
|
channel.historyLoading = false;
|
|
|
|
channel.scrolledToBottom = true;
|
2019-08-03 10:09:55 +00:00
|
|
|
channel.editTopic = false;
|
2018-07-18 18:40:09 +00:00
|
|
|
|
2019-10-17 10:27:15 +00:00
|
|
|
channel.moreHistoryAvailable = channel.totalMessages > channel.messages.length;
|
|
|
|
delete channel.totalMessages;
|
|
|
|
|
2018-07-18 18:40:09 +00:00
|
|
|
if (channel.type === "channel") {
|
|
|
|
channel.usersOutdated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 09:18:32 +00:00
|
|
|
function getActiveWindowComponent() {
|
|
|
|
return vueApp.$refs.app.$refs.window;
|
|
|
|
}
|
|
|
|
|
2018-07-06 18:15:15 +00:00
|
|
|
module.exports = {
|
|
|
|
vueApp,
|
2018-07-18 18:40:09 +00:00
|
|
|
initChannel,
|
2019-02-18 09:18:32 +00:00
|
|
|
getActiveWindowComponent,
|
2018-07-06 18:15:15 +00:00
|
|
|
};
|