Skip to content

Commit

Permalink
Real Name and Away message configuration. Automatically setting of yo…
Browse files Browse the repository at this point in the history
…ur away when you are disconnected.
  • Loading branch information
ericbarch committed Jul 3, 2012
1 parent 10a3cc5 commit 7cb7375
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion assets/js/views/chat.js
Expand Up @@ -120,7 +120,7 @@ var ChatView = Backbone.View.extend({
match = true;
//We decide whether or not to add colon
if (sentence.length === 1) {
$('#chat-input').val(sentence.join(' ') + ":");
$('#chat-input').val(sentence.join(' ') + ": ");
} else {
$('#chat-input').val(sentence.join(' '));
}
Expand Down
6 changes: 5 additions & 1 deletion assets/js/views/overview.js
Expand Up @@ -50,6 +50,8 @@ var OverviewView = Backbone.View.extend({
var server = $('#connect-server').val();
var nick = $('#connect-nick').val();
var port = $('#connect-port').val();
var away = $('#connect-away').val();
var realName = $('#connect-realName').val();
var secure = $('#connect-secure').is(':checked');
var selfSigned = $('#connect-selfSigned').is(':checked');
var rejoin = $('#connect-rejoin').is(':checked');
Expand All @@ -72,10 +74,12 @@ var OverviewView = Backbone.View.extend({
var connectInfo = {
nick: nick,
server: server,
port: port,
port: port,
secure: secure,
selfSigned: selfSigned,
rejoin: rejoin,
away: away,
realName: realName,
password: password
};

Expand Down
7 changes: 6 additions & 1 deletion lib/irclink.js
Expand Up @@ -8,10 +8,15 @@ var Channel = mongoose.model('Channel');
var Message = mongoose.model('Message');

// Constructor
var IRCLink = function(hostname, port, ssl, selfSigned, nick, realName, password, rejoin, channels) {
var IRCLink = function(hostname, port, ssl, selfSigned, nick, realName, password, rejoin, away, channels) {
this.sockets = new Array();
this.server = hostname;

if (away === undefined || away == '')
this.away = 'AFK';
else
this.away = away;

if (channels === undefined || !rejoin)
var channels = new Array();

Expand Down
2 changes: 2 additions & 0 deletions lib/models.js
Expand Up @@ -15,6 +15,8 @@ module.exports = function() {
port: Number,
ssl: Boolean,
rejoin: Boolean,
away: String,
realName: String,
selfSigned: Boolean,
channels: [String],
nick: String,
Expand Down
4 changes: 3 additions & 1 deletion lib/restore.js
Expand Up @@ -11,9 +11,11 @@ module.exports = function (connections) {
// restore connections
Connection.find({},function(err, docs){
docs.forEach(function(doc){
var connection = new IRCLink(doc.hostname, doc.port, doc.ssl, doc.selfSigned, doc.nick, doc.nick, doc.password, doc.rejoin, doc.channels);
var connection = new IRCLink(doc.hostname, doc.port, doc.ssl, doc.selfSigned, doc.nick, doc.realName, doc.password, doc.rejoin, doc.away, doc.channels);
connection.associateUser(doc.user);
connections[doc.user] = connection;
// set ourselves as away
connection.client.send('AWAY', doc.away);
});
});
}
12 changes: 11 additions & 1 deletion lib/socket.js
Expand Up @@ -57,7 +57,7 @@ module.exports = function(socket, connections) {
connection = connections[current_user.username];
}
if(connection === undefined) {
connection = new IRCLink(data.server, data.port, data.secure, data.selfSigned, data.nick, data.nick, data.password, data.rejoin);
connection = new IRCLink(data.server, data.port, data.secure, data.selfSigned, data.nick, data.realName, data.password, data.rejoin, data.away);

// save this connection
if(current_user){
Expand All @@ -69,6 +69,8 @@ module.exports = function(socket, connections) {
port: data.port || (data.secure ? 6697 : 6667),
ssl: data.secure,
rejoin: data.rejoin,
away: data.away,
realName: data.realName,
selfSigned: data.selfSigned,
channels: data.channels,
nick: data.nick,
Expand All @@ -81,6 +83,10 @@ module.exports = function(socket, connections) {
socket.emit('restore_connection', {nick: connection.client.nick,
server: connection.client.opt.server, channels: connection.client.chans});
connection.clearUnreads();

// set ourselves as not being away
if (connection.sockets.length == 0)
connection.client.send('AWAY');
}

// register this socket with our user's IRC connection
Expand Down Expand Up @@ -150,6 +156,10 @@ module.exports = function(socket, connections) {
// keep the session alive, remove this socket, and clear unreads
connection.removeSocket(socket);
connection.clearUnreads();

// set ourselves as away
if (connection.sockets.length == 0)
connection.client.send('AWAY', connection.away);
}
});

Expand Down
8 changes: 8 additions & 0 deletions views/templates.jade
Expand Up @@ -58,6 +58,14 @@ script(id="overview_connection", type="text/html")
label(for="connect-nick") Nick
.controls
input#connect-nick(type="text")
.control-group
label(for="connect-realName") Real Name
.controls
input#connect-realName(type="text")
.control-group
label(for="connect-away") Away Message
.controls
input#connect-away(type="text", placeholder="AFK")
.control-group
label(for="connect-password") Password
.controls
Expand Down

0 comments on commit 7cb7375

Please sign in to comment.