Make a single function to initialize channel variables

This commit is contained in:
Pavel Djundik 2018-07-18 21:40:09 +03:00 committed by Pavel Djundik
parent ad0f638487
commit a10ac4e7da
6 changed files with 20 additions and 18 deletions

View File

@ -240,7 +240,7 @@ export default {
let lastMessage = this.channel.messages[0]; let lastMessage = this.channel.messages[0];
lastMessage = lastMessage ? lastMessage.id : -1; lastMessage = lastMessage ? lastMessage.id : -1;
this.$set(this.channel, "historyLoading", true); this.channel.historyLoading = true;
socket.emit("more", { socket.emit("more", {
target: this.channel.id, target: this.channel.id,

View File

@ -1087,7 +1087,7 @@ background on hover (unless active) */
.scroll-down.fade-enter-active { .scroll-down.fade-enter-active {
opacity: 0; opacity: 0;
transform: translateY(16px); transform: translateY(16px);
transition: opacity .3s, transform .3s; transition: opacity 0.3s, transform 0.3s;
} }
.scroll-down.fade-enter-to { .scroll-down.fade-enter-to {
@ -1097,7 +1097,6 @@ background on hover (unless active) */
.scroll-down { .scroll-down {
position: absolute; position: absolute;
bottom: 16px; bottom: 16px;
right: 16px; right: 16px;
z-index: 2; z-index: 2;

View File

@ -8,7 +8,7 @@ const slideoutMenu = require("../slideout");
const sidebar = $("#sidebar"); const sidebar = $("#sidebar");
const storage = require("../localStorage"); const storage = require("../localStorage");
const utils = require("../utils"); const utils = require("../utils");
const {vueApp} = require("../vue"); const {vueApp, initChannel} = require("../vue");
socket.on("init", function(data) { socket.on("init", function(data) {
$("#loading-page-message, #connection-error").text("Rendering…"); $("#loading-page-message, #connection-error").text("Rendering…");
@ -46,13 +46,7 @@ socket.on("init", function(data) {
network.isCollapsed = networks.has(network.uuid); network.isCollapsed = networks.has(network.uuid);
} }
for (const channel of network.channels) { network.channels.forEach(initChannel);
channel.scrolledToBottom = true;
if (channel.type === "channel") {
channel.usersOutdated = true;
}
}
} }
vueApp.networks = data.networks; vueApp.networks = data.networks;

View File

@ -3,9 +3,11 @@
const $ = require("jquery"); const $ = require("jquery");
const socket = require("../socket"); const socket = require("../socket");
const sidebar = $("#sidebar"); const sidebar = $("#sidebar");
const {vueApp} = require("../vue"); const {vueApp, initChannel} = require("../vue");
socket.on("join", function(data) { socket.on("join", function(data) {
initChannel(data.chan);
vueApp.networks.find((n) => n.uuid === data.network) vueApp.networks.find((n) => n.uuid === data.network)
.channels.splice(data.index || -1, 0, data.chan); .channels.splice(data.index || -1, 0, data.chan);

View File

@ -5,20 +5,17 @@ const socket = require("../socket");
const templates = require("../../views"); const templates = require("../../views");
const sidebar = $("#sidebar"); const sidebar = $("#sidebar");
const utils = require("../utils"); const utils = require("../utils");
const {vueApp} = require("../vue"); const {vueApp, initChannel} = require("../vue");
socket.on("network", function(data) { socket.on("network", function(data) {
const network = data.networks[0]; const network = data.networks[0];
network.isJoinChannelShown = false; network.isJoinChannelShown = false;
network.isCollapsed = false; network.isCollapsed = false;
network.channels.forEach(initChannel);
for (const channel of network.channels) { for (const channel of network.channels) {
channel.scrolledToBottom = true; initChannel(channel);
if (channel.type === "channel") {
channel.usersOutdated = true;
}
} }
vueApp.networks.push(network); vueApp.networks.push(network);

View File

@ -67,7 +67,17 @@ function findChannel(id) {
return null; return null;
} }
function initChannel(channel) {
channel.historyLoading = false;
channel.scrolledToBottom = true;
if (channel.type === "channel") {
channel.usersOutdated = true;
}
}
module.exports = { module.exports = {
vueApp, vueApp,
findChannel, findChannel,
initChannel,
}; };