Implement switchToChannel method.

This commit is contained in:
Richard Lewis 2019-10-25 21:37:40 +00:00 committed by Pavel Djundik
parent e845e17a63
commit 2049a16d64
11 changed files with 20 additions and 13 deletions

View file

@ -82,8 +82,7 @@ export default {
return this.channel.name;
},
click() {
// TODO: Find out why this sometimes throws `uncaught exception: Object`
this.$router.push("chan-" + this.channel.id);
this.$root.switchToChannel(this.channel);
},
},
};

View file

@ -18,7 +18,7 @@ export default {
);
if (existingChannel) {
this.$router.push("chan-" + existingChannel.id);
this.$root.switchToChannel(existingChannel);
}
// TODO: Required here because it breaks tests

View file

@ -65,7 +65,7 @@ export default {
);
if (existingChannel) {
this.$router.push("chan-" + existingChannel.id);
this.$root.switchToChannel(existingChannel);
} else {
const chanTypes = this.network.serverOptions.CHANTYPES;
let channel = this.inputChannel;

View file

@ -25,7 +25,7 @@ exports.input = function(args) {
const chan = utils.findCurrentNetworkChan(channels);
if (chan) {
vueApp.$router.push("chan-" + chan.id);
vueApp.switchToChannel(chan);
} else {
socket.emit("input", {
text: `/join ${channels} ${args.length > 1 ? args[1] : ""}`,

View file

@ -50,7 +50,7 @@ function addWhoisItem() {
const chan = utils.findCurrentNetworkChan(itemData);
if (chan) {
vueApp.$router.push("chan-" + chan.id);
vueApp.switchToChannel(chan);
}
socket.emit("input", {
@ -85,7 +85,7 @@ function addQueryItem() {
const chan = utils.findCurrentNetworkChan(itemData);
if (chan) {
vueApp.$router.push("chan-" + chan.id);
vueApp.switchToChannel(chan);
}
socket.emit("input", {

View file

@ -90,7 +90,7 @@ Mousetrap.bind(["alt+a"], function() {
}
if (targetchan) {
vueApp.$router.push("chan-" + targetchan.id);
vueApp.switchToChannel(targetchan);
}
return false;

View file

@ -15,5 +15,5 @@ socket.on("join", function(data) {
return;
}
vueApp.$router.push("chan-" + data.chan.id);
vueApp.switchToChannel(vueApp.findChannel(data.chan.id));
});

View file

@ -4,6 +4,7 @@ const socket = require("../socket");
const {vueApp, findChannel} = require("../vue");
socket.on("msg:special", function(data) {
findChannel(data.chan).channel.data = data.data;
vueApp.$router.push("chan-" + data.chan);
const channel = findChannel(data.chan);
channel.channel.data = data.data;
vueApp.switchToChannel(channel.channel);
});

View file

@ -12,7 +12,7 @@ socket.on("network", function(data) {
network.channels.forEach(initChannel);
vueApp.networks.push(network);
vueApp.$router.push("chan-" + network.channels[0].id);
vueApp.switchToChannel(network.channels[0]);
$("#connect")
.find(".btn")

View file

@ -6,7 +6,7 @@ const {vueApp, findChannel} = require("../vue");
socket.on("part", function(data) {
// When parting from the active channel/query, jump to the network's lobby
if (vueApp.activeChannel && vueApp.activeChannel.channel.id === data.chan) {
vueApp.$router.push("chan-" + vueApp.activeChannel.network.id);
vueApp.switchToChannel(vueApp.activeChannel.network);
}
const channel = findChannel(data.chan);

View file

@ -102,6 +102,13 @@ const vueApp = new Vue({
return null;
},
switchToChannel(channel) {
if (this.activeChannel && this.activeChannel.channel.id === channel.id) {
return;
}
this.$router.push("chan-" + channel.id);
},
switchOutOfChannel(channel) {
// When switching out of a channel, mark everything as read
if (channel.messages.length > 0) {