From a10ac4e7da3709ede160b6fdb38bfdf69d980eec Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 18 Jul 2018 21:40:09 +0300 Subject: [PATCH] Make a single function to initialize channel variables --- client/components/MessageList.vue | 2 +- client/css/style.css | 3 +-- client/js/socket-events/init.js | 10 ++-------- client/js/socket-events/join.js | 4 +++- client/js/socket-events/network.js | 9 +++------ client/js/vue.js | 10 ++++++++++ 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/client/components/MessageList.vue b/client/components/MessageList.vue index 7ca57ed0..da23b1b0 100644 --- a/client/components/MessageList.vue +++ b/client/components/MessageList.vue @@ -240,7 +240,7 @@ export default { let lastMessage = this.channel.messages[0]; lastMessage = lastMessage ? lastMessage.id : -1; - this.$set(this.channel, "historyLoading", true); + this.channel.historyLoading = true; socket.emit("more", { target: this.channel.id, diff --git a/client/css/style.css b/client/css/style.css index 201d8f82..5b1788fc 100644 --- a/client/css/style.css +++ b/client/css/style.css @@ -1087,7 +1087,7 @@ background on hover (unless active) */ .scroll-down.fade-enter-active { opacity: 0; transform: translateY(16px); - transition: opacity .3s, transform .3s; + transition: opacity 0.3s, transform 0.3s; } .scroll-down.fade-enter-to { @@ -1097,7 +1097,6 @@ background on hover (unless active) */ .scroll-down { position: absolute; - bottom: 16px; right: 16px; z-index: 2; diff --git a/client/js/socket-events/init.js b/client/js/socket-events/init.js index 2e9347ee..1f153f88 100644 --- a/client/js/socket-events/init.js +++ b/client/js/socket-events/init.js @@ -8,7 +8,7 @@ const slideoutMenu = require("../slideout"); const sidebar = $("#sidebar"); const storage = require("../localStorage"); const utils = require("../utils"); -const {vueApp} = require("../vue"); +const {vueApp, initChannel} = require("../vue"); socket.on("init", function(data) { $("#loading-page-message, #connection-error").text("Rendering…"); @@ -46,13 +46,7 @@ socket.on("init", function(data) { network.isCollapsed = networks.has(network.uuid); } - for (const channel of network.channels) { - channel.scrolledToBottom = true; - - if (channel.type === "channel") { - channel.usersOutdated = true; - } - } + network.channels.forEach(initChannel); } vueApp.networks = data.networks; diff --git a/client/js/socket-events/join.js b/client/js/socket-events/join.js index 77b46283..c74d85f0 100644 --- a/client/js/socket-events/join.js +++ b/client/js/socket-events/join.js @@ -3,9 +3,11 @@ const $ = require("jquery"); const socket = require("../socket"); const sidebar = $("#sidebar"); -const {vueApp} = require("../vue"); +const {vueApp, initChannel} = require("../vue"); socket.on("join", function(data) { + initChannel(data.chan); + vueApp.networks.find((n) => n.uuid === data.network) .channels.splice(data.index || -1, 0, data.chan); diff --git a/client/js/socket-events/network.js b/client/js/socket-events/network.js index 67f19ba7..278f3b7c 100644 --- a/client/js/socket-events/network.js +++ b/client/js/socket-events/network.js @@ -5,20 +5,17 @@ const socket = require("../socket"); const templates = require("../../views"); const sidebar = $("#sidebar"); const utils = require("../utils"); -const {vueApp} = require("../vue"); +const {vueApp, initChannel} = require("../vue"); socket.on("network", function(data) { const network = data.networks[0]; network.isJoinChannelShown = false; network.isCollapsed = false; + network.channels.forEach(initChannel); for (const channel of network.channels) { - channel.scrolledToBottom = true; - - if (channel.type === "channel") { - channel.usersOutdated = true; - } + initChannel(channel); } vueApp.networks.push(network); diff --git a/client/js/vue.js b/client/js/vue.js index 8a693086..b70b7bf2 100644 --- a/client/js/vue.js +++ b/client/js/vue.js @@ -67,7 +67,17 @@ function findChannel(id) { return null; } +function initChannel(channel) { + channel.historyLoading = false; + channel.scrolledToBottom = true; + + if (channel.type === "channel") { + channel.usersOutdated = true; + } +} + module.exports = { vueApp, findChannel, + initChannel, };