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;
|
|
|
|
const roundBadgeNumber = require("./libs/handlebars/roundBadgeNumber");
|
2018-07-08 10:50:11 +00:00
|
|
|
const localetime = require("./libs/handlebars/localetime");
|
2018-07-10 11:57:11 +00:00
|
|
|
const friendlysize = require("./libs/handlebars/friendlysize");
|
2018-07-08 10:50:11 +00:00
|
|
|
const colorClass = require("./libs/handlebars/colorClass");
|
2019-04-13 20:44:04 +00:00
|
|
|
const storage = require("./localStorage");
|
2019-10-17 16:56:44 +00:00
|
|
|
const router = require("./router").default;
|
|
|
|
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-10 11:57:11 +00:00
|
|
|
Vue.filter("friendlysize", friendlysize);
|
2018-07-08 10:50:11 +00:00
|
|
|
Vue.filter("colorClass", colorClass);
|
2018-07-06 18:15:15 +00:00
|
|
|
Vue.filter("roundBadgeNumber", roundBadgeNumber);
|
|
|
|
|
|
|
|
const vueApp = new Vue({
|
|
|
|
el: "#viewport",
|
|
|
|
data: {
|
2018-09-09 13:09:19 +00:00
|
|
|
activeChannel: null,
|
|
|
|
appName: document.title,
|
|
|
|
currentUserVisibleError: null,
|
2018-07-15 20:23:49 +00:00
|
|
|
initialized: false,
|
2018-09-09 13:03:37 +00:00
|
|
|
isAutoCompleting: false,
|
2018-09-09 13:09:19 +00:00
|
|
|
isFileUploadEnabled: false,
|
2018-07-06 18:15:15 +00:00
|
|
|
networks: [],
|
2019-02-20 09:10:18 +00:00
|
|
|
pushNotificationState: "unsupported",
|
|
|
|
desktopNotificationState: "unsupported",
|
|
|
|
serverConfiguration: {},
|
2018-07-08 14:57:02 +00:00
|
|
|
settings: {
|
|
|
|
syncSettings: false,
|
|
|
|
advanced: false,
|
|
|
|
autocomplete: true,
|
|
|
|
nickPostfix: "",
|
|
|
|
coloredNicks: true,
|
|
|
|
desktopNotifications: false,
|
2019-01-16 09:23:12 +00:00
|
|
|
highlights: "",
|
2018-07-08 14:57:02 +00:00
|
|
|
links: true,
|
|
|
|
motd: true,
|
|
|
|
notification: true,
|
|
|
|
notifyAllMessages: false,
|
|
|
|
showSeconds: false,
|
|
|
|
statusMessages: "condensed",
|
|
|
|
theme: document.getElementById("theme").dataset.serverTheme,
|
|
|
|
media: true,
|
|
|
|
userStyles: "",
|
|
|
|
},
|
2018-07-06 18:15:15 +00:00
|
|
|
},
|
2019-10-17 16:56:44 +00:00
|
|
|
router,
|
2018-07-10 09:40:55 +00:00
|
|
|
mounted() {
|
|
|
|
Vue.nextTick(() => window.vueMounted());
|
2019-10-17 15:32:59 +00:00
|
|
|
|
|
|
|
if (navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i)) {
|
|
|
|
document.body.classList.add("is-apple");
|
|
|
|
}
|
2019-10-17 16:56:44 +00:00
|
|
|
|
|
|
|
document.addEventListener("visibilitychange", this.synchronizeNotifiedState());
|
|
|
|
document.addEventListener("focus", this.synchronizeNotifiedState());
|
|
|
|
document.addEventListener("click", this.synchronizeNotifiedState());
|
2018-07-10 09:40:55 +00:00
|
|
|
},
|
2019-04-13 20:44:04 +00:00
|
|
|
methods: {
|
|
|
|
onSocketInit() {
|
|
|
|
this.initialized = true;
|
|
|
|
this.$store.commit("isConnected", true);
|
|
|
|
},
|
|
|
|
setSidebar(state) {
|
|
|
|
this.$store.commit("sidebarOpen", state);
|
|
|
|
|
2019-10-17 16:56:44 +00:00
|
|
|
if (window.outerWidth > constants.mobileViewportPixels) {
|
2019-04-13 20:44:04 +00:00
|
|
|
storage.set("thelounge.state.sidebar", state);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit("resize");
|
|
|
|
},
|
|
|
|
toggleSidebar() {
|
|
|
|
this.setSidebar(!this.$store.state.sidebarOpen);
|
|
|
|
},
|
2019-10-17 16:56:44 +00:00
|
|
|
closeSidebarIfNeeded() {
|
|
|
|
if (window.innerWidth <= constants.mobileViewportPixels) {
|
|
|
|
this.setSidebar(false);
|
|
|
|
}
|
|
|
|
},
|
2019-04-13 20:44:04 +00:00
|
|
|
setUserlist(state) {
|
|
|
|
storage.set("thelounge.state.userlist", state);
|
|
|
|
this.$store.commit("userlistOpen", state);
|
|
|
|
this.$emit("resize");
|
|
|
|
},
|
|
|
|
toggleUserlist() {
|
|
|
|
this.setUserlist(!this.$store.state.userlistOpen);
|
|
|
|
},
|
2019-10-17 16:56:44 +00:00
|
|
|
findChannel(id) {
|
|
|
|
for (const network of this.networks) {
|
|
|
|
for (const channel of network.channels) {
|
|
|
|
if (channel.id === id) {
|
|
|
|
return {network, channel};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
2019-10-28 13:48:13 +00:00
|
|
|
findNetwork(uuid) {
|
|
|
|
for (const network of this.networks) {
|
|
|
|
if (network.uuid === uuid) {
|
|
|
|
return network;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
2019-10-25 21:37:40 +00:00
|
|
|
switchToChannel(channel) {
|
|
|
|
if (this.activeChannel && this.activeChannel.channel.id === channel.id) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
synchronizeNotifiedState() {
|
|
|
|
this.updateTitle();
|
|
|
|
|
|
|
|
let hasAnyHighlights = false;
|
|
|
|
|
|
|
|
for (const network of this.networks) {
|
|
|
|
for (const chan of network.channels) {
|
|
|
|
if (chan.highlight > 0) {
|
|
|
|
hasAnyHighlights = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.toggleNotificationMarkers(hasAnyHighlights);
|
|
|
|
},
|
|
|
|
updateTitle() {
|
|
|
|
let title = this.appName;
|
|
|
|
|
|
|
|
if (this.activeChannel) {
|
|
|
|
title = `${this.activeChannel.channel.name} — ${title}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add highlight count to title
|
|
|
|
let alertEventCount = 0;
|
|
|
|
|
|
|
|
for (const network of this.networks) {
|
|
|
|
for (const channel of network.channels) {
|
|
|
|
alertEventCount += channel.highlight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alertEventCount > 0) {
|
|
|
|
title = `(${alertEventCount}) ${title}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
document.title = title;
|
|
|
|
},
|
|
|
|
toggleNotificationMarkers(newState) {
|
|
|
|
if (this.$store.state.isNotified !== newState) {
|
|
|
|
// Toggles a dot on the menu icon when there are unread notifications
|
|
|
|
this.$store.commit("isNotified", newState);
|
|
|
|
|
|
|
|
// Toggles the favicon to red when there are unread notifications
|
|
|
|
const favicon = document.getElementById("favicon");
|
|
|
|
const old = favicon.getAttribute("href");
|
|
|
|
favicon.setAttribute("href", favicon.dataset.other);
|
|
|
|
favicon.dataset.other = old;
|
|
|
|
}
|
|
|
|
},
|
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
|
|
|
});
|
|
|
|
|
2018-09-14 15:44:26 +00:00
|
|
|
Vue.config.errorHandler = function(e) {
|
|
|
|
console.error(e); // eslint-disable-line
|
|
|
|
vueApp.currentUserVisibleError = `Vue error: ${e.message}. Please check devtools and report it in #thelounge`;
|
|
|
|
};
|
|
|
|
|
2018-07-06 18:15:15 +00:00
|
|
|
function findChannel(id) {
|
2019-10-17 16:56:44 +00:00
|
|
|
return vueApp.findChannel(id);
|
2018-07-06 18:15:15 +00:00
|
|
|
}
|
|
|
|
|
2019-11-02 18:45:00 +00:00
|
|
|
function findNetwork(uuid) {
|
|
|
|
return vueApp.findNetwork(uuid);
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
findChannel,
|
2019-11-02 18:45:00 +00:00
|
|
|
findNetwork,
|
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
|
|
|
};
|