Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Support disconnect from server

  • Loading branch information...
commit 3d9d0e9e076611036196daf7edc36daa944fbfd9 1 parent ac23ef4
HyeonJe Jun authored
View
31 assets/css/subway.css
@@ -115,8 +115,8 @@ html { overflow: hidden; }
}
-#user-box div{
- padding: 10px 25px;
+#user-box .user_box_element {
+ padding: 10px 15px 10px 25px;
background: #434950;
color: #EEEEEE;
font-weight: bold;
@@ -126,14 +126,37 @@ html { overflow: hidden; }
text-overflow: ellipsis;
}
-#user-box div:first-child{
+#user-box .user_box_element:first-child{
border-left: 5px solid #8A9B0F;
}
-#user-box div:last-child{
+#user-box .user_box_element:last-child{
border-left: 5px solid #FA6900;
}
+#user-box .user_box_element .close-button {
+ display: block;
+ color: white;
+ text-shadow: 0 1px 0 black;
+ font: bold 20px Arial;
+ line-height: 19px;
+ float: right;
+ opacity: 0.3;
+ width: 24px;
+ text-align: center;
+ cursor: pointer;
+ margin-left: 5px;
+ visibility: hidden;
+}
+
+#user-box .user_box_element:hover .close-button {
+ visibility: visible;
+}
+
+#user-box .user_box_element .close-button:hover {
+ opacity: 0.8;
+}
+
#channels {
overflow: auto;
width: 100%;
View
13 assets/js/client.js
@@ -270,6 +270,19 @@ $(function() {
irc.appView.showError(data.message);
});
+ irc.socket.on('reset', function(data) {
+ irc.chatWindows = new WindowList();
+ irc.connected = false;
+ irc.loggedIn = false;
+ irc.me = null;
+
+ // move to main view
+ irc.appView.render();
+
+ // remove login and register button if no database
+ irc.socket.emit('getDatabaseState', {});
+ });
+
irc.socket.on('oldMessages', function(data){
var output = '';
channel = irc.chatWindows.getByName(data.name);
View
5 assets/js/views/chat_application.js
@@ -58,6 +58,11 @@ var ChatApplicationView = Backbone.View.extend({
renderUserBox: function() {
$('#user-box').html(ich.user_box(irc.me.toJSON()));
+
+ // disconnect server handler
+ $('#user-box .close-button').click(function() {
+ irc.socket.emit('disconnectServer');
+ });
},
// Show number of unread mentions in title
View
25 lib/socket.js
@@ -89,6 +89,7 @@ module.exports = function(socket, connections) {
connection.addSocket(socket);
// Socket events sent FROM the front-end
+ socket.removeAllListeners('join');
socket.on('join', function(name) {
if (name[0] != '#')
name = '#' + name;
@@ -96,12 +97,14 @@ module.exports = function(socket, connections) {
connection.client.join(name);
});
+ socket.removeAllListeners('part_pm');
socket.on('part_pm', function(name){
if(connection.clients.chans[name.toLowerCase()] !== undefined){
delete connection.clients.chans[name.toLowerCase()];
}
});
+ socket.removeAllListeners('part');
socket.on('part', function(name) {
if (name[0] != '#')
name = '#' + name;
@@ -113,6 +116,7 @@ module.exports = function(socket, connections) {
}
});
+ socket.removeAllListeners('say');
socket.on('say', function(data) {
connection.client.say(data.target, data.message);
socket.emit('message', {to:data.target.toLowerCase(), from: connection.client.nick, text:data.message});
@@ -121,6 +125,7 @@ module.exports = function(socket, connections) {
}
});
+ socket.removeAllListeners('action');
socket.on('action', function(data) {
connection.client.action(data.target, data.message);
socket.emit('message', {
@@ -130,20 +135,24 @@ module.exports = function(socket, connections) {
);
});
+ socket.removeAllListeners('topic');
socket.on('topic', function(data){
connection.client.send('TOPIC ', data.name, data.topic);
});
+ socket.removeAllListeners('nick');
socket.on('nick', function(data){
connection.client.send('NICK', data.nick);
connection.client.nick = data.nick;
connection.client.opt.nick = data.nick;
});
+ socket.removeAllListeners('command');
socket.on('command', function(text) {
connection.client.send(text);
});
+ socket.removeAllListeners('disconnect');
socket.on('disconnect', function() {
if(!current_user){
// not logged in, drop this session
@@ -155,6 +164,22 @@ module.exports = function(socket, connections) {
}
});
+ socket.removeAllListeners('disconnectServer');
+ socket.on('disconnectServer', function() {
+ connection.disconnect();
+ connection = null;
+
+ // remove current user and connect
+ if(current_user) {
+ connections[current_user.username].disconnect();
+ connections[current_user.username] = undefined;
+ current_user = null;
+ }
+
+ socket.emit('reset');
+ });
+
+ socket.removeAllListeners('getOldMessages');
socket.on('getOldMessages', function(data){
if (current_user) {
var query = Message.find({channel: data.channelName.toLowerCase(), server: connection.server.toLowerCase(), linkedto: current_user.username});
View
5 views/templates.jade
@@ -148,10 +148,11 @@ script(id="channel", type="text/html")
{{/notStatus}}
script(id="user_box", type="text/html")
- div
+ div.user_box_element
i(class="icon-user icon-white spacing-right")
{{nick}}
- div
+ div.user_box_element
+ .close-button ×
i(class="icon-asterisk icon-white spacing-right")
{{server}}

0 comments on commit 3d9d0e9

Please sign in to comment.
Something went wrong with that request. Please try again.