From 2f1e72876b889c0a31e7b2d173d24793755a8571 Mon Sep 17 00:00:00 2001 From: khlieng Date: Sun, 22 Feb 2015 09:51:06 +0100 Subject: [PATCH] Handle double hashtag channel names in URLs --- client/src/js/actions/tab.js | 5 ++++- client/src/js/components/Chat.jsx | 12 +++++++----- client/src/js/irc.js | 4 ++++ client/src/js/stores/selectedTab.js | 25 +++++++++++++++++++++++-- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/client/src/js/actions/tab.js b/client/src/js/actions/tab.js index 3a249794..3741d514 100644 --- a/client/src/js/actions/tab.js +++ b/client/src/js/actions/tab.js @@ -8,7 +8,10 @@ var tabActions = Reflux.createActions([ tabActions.select.preEmit = (server, channel) => { if (channel) { - routeActions.navigate('/' + server + '/' + channel.slice(1)) + while (channel[0] === '#') { + channel = channel.slice(1); + } + routeActions.navigate('/' + server + '/' + channel); } else { routeActions.navigate('/' + server); } diff --git a/client/src/js/components/Chat.jsx b/client/src/js/components/Chat.jsx index 8a453dae..66dbf15c 100644 --- a/client/src/js/components/Chat.jsx +++ b/client/src/js/components/Chat.jsx @@ -12,12 +12,14 @@ var Chat = React.createClass({ mixins: [Router.State], componentWillMount: function() { - var p = this.getParams(); + if (!window.loaded) { + var p = this.getParams(); - if (p.channel) { - tabActions.select(p.server, '#' + p.channel); - } else if (p.server) { - tabActions.select(p.server); + if (p.channel) { + tabActions.select(p.server, '#' + p.channel); + } else if (p.server) { + tabActions.select(p.server); + } } }, diff --git a/client/src/js/irc.js b/client/src/js/irc.js index 50e68c46..3c368d0b 100644 --- a/client/src/js/irc.js +++ b/client/src/js/irc.js @@ -6,6 +6,7 @@ var channelActions = require('./actions/channel'); var messageActions = require('./actions/message'); var serverActions = require('./actions/server'); var routeActions = require('./actions/route'); +var tabActions = require('./actions/tab'); socket.on('join', function(data) { channelActions.addUser(data.user, data.server, data.channels[0]); @@ -71,9 +72,12 @@ socket.on('whois', function(data) { }); socket.on('servers', function(data) { + window.loaded = true; + if (data === null) { routeActions.navigate('connect'); } + serverActions.load(data); }); diff --git a/client/src/js/stores/selectedTab.js b/client/src/js/stores/selectedTab.js index 7fda564c..21ecac90 100644 --- a/client/src/js/stores/selectedTab.js +++ b/client/src/js/stores/selectedTab.js @@ -5,6 +5,7 @@ var serverStore = require('./server'); var actions = require('../actions/tab'); var channelActions = require('../actions/channel'); var serverActions = require('../actions/server'); +var routeActions = require('../actions/route'); var selectedTab = {}; @@ -14,8 +15,9 @@ var selectedTabStore = Reflux.createStore({ this.listenTo(channelActions.part, 'part'); this.listenTo(serverActions.disconnect, 'disconnect'); this.listenTo(channelActions.addUser, 'userAdded'); - //this.listenTo(channelActions.load, 'loadChannels'); + this.listenTo(channelActions.load, 'loadChannels'); this.listenTo(serverActions.load, 'loadServers'); + this.listenTo(routeActions.navigate, 'navigate'); }, select: function(server, channel = null) { @@ -60,7 +62,18 @@ var selectedTabStore = Reflux.createStore({ }, loadChannels: function(channels) { - + // Handle double hashtag channel names, only a single hashtag + // gets added to the channel in the URL on page load + _.each(channels, (channel) => { + if (channel.server === selectedTab.server && + channel.name !== selectedTab.channel && + channel.name.indexOf(selectedTab.channel) !== -1) { + selectedTab.channel = channel.name; + selectedTab.name = channel.name; + + this.trigger(selectedTab); + } + }); }, loadServers: function(servers) { @@ -75,6 +88,14 @@ var selectedTabStore = Reflux.createStore({ } }, + navigate: function(route) { + if (route.indexOf('.') === -1) { + selectedTab.server = null; + selectedTab.channel = null; + this.trigger(selectedTab); + } + }, + getServer: function() { return selectedTab.server; },