Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for server presets. #296

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 36 additions & 2 deletions assets/js/client.js
Expand Up @@ -14,7 +14,8 @@ window.irc = {
socket: io.connect(null, {port: document.location.port}),
chatWindows: new WindowList(),
connected: false,
loggedIn: false
loggedIn: false,
presets: false
};

window.unity = {
Expand Down Expand Up @@ -51,6 +52,11 @@ $(function() {
}
});

irc.socket.on('initialized', function(data) {
irc.presets = data.presets;
irc.appView.render();
});

// Registration (server joined)
irc.socket.on('registered', function(data) {
var window = irc.chatWindows.getByName('status');
Expand All @@ -65,11 +71,19 @@ $(function() {

// Will reflect modified nick, if chosen nick was taken already
irc.me.set('nick', data.message.args[0]);

// Join preset channels
$.each(irc.presets.channels, function(key, value){
irc.socket.emit('join', value);
});
});

irc.socket.on('login_success', function(data) {
window.irc.loggedIn = true;

if(data.exists){
irc.me = new User(data);
irc.me.on('change:nick', irc.appView.renderUserBox);
irc.socket.emit('connect', {});
} else {
irc.appView.overview.render({currentTarget: {id: "connection"}});
Expand All @@ -85,11 +99,31 @@ $(function() {

irc.socket.on('register_success', function(data) {
window.irc.loggedIn = true;
irc.appView.overview.render({currentTarget: {id: "connection"}});

if(irc.presets){
var connectInfo = {
nick: data.username,
server: irc.presets.server,
port: irc.presets.port,
secure: irc.presets.secure,
selfSigned: irc.presets.selfSigned,
away: irc.presets.away,
encoding: irc.presets.encoding,
stripColors: irc.presets.stripColors,
keepAlive: irc.presets.keepAlive
};

irc.me = new User(connectInfo);
irc.me.on('change:nick', irc.appView.renderUserBox);
irc.socket.emit('connect', connectInfo);
} else {
irc.appView.overview.render({currentTarget: {id: "connection"}});
}
});

irc.socket.on('restore_connection', function(data) {
irc.me = new User({nick: data.nick, server: data.server});
irc.me.on('change:nick', irc.appView.renderUserBox);
irc.connected = true;
irc.appView.render();
irc.appView.renderUserBox();
Expand Down
2 changes: 0 additions & 2 deletions assets/js/views/chat_application.js
Expand Up @@ -37,8 +37,6 @@ var ChatApplicationView = Backbone.View.extend({
clearTimeout(blurTimer);
if(activeChat && activeChat.set) { activeChat.set('active', true); }
});

this.render();
},

overview: null,
Expand Down
7 changes: 5 additions & 2 deletions assets/js/views/overview.js
Expand Up @@ -19,10 +19,13 @@ var OverviewView = Backbone.View.extend({

// Navigation to different overview panes
if (event === undefined) {
$('#overview').html(ich.overview_home());
$('#overview').html(ich.overview_home({'presets': irc.presets}));
} else {
var func = ich['overview_' + event.currentTarget.id];
$('#overview').html(func({'loggedIn': irc.loggedIn}));
$('#overview').html(func({
'presets': irc.presets,
'loggedIn': irc.loggedIn
}));
}

$('.overview_button').bind('click', $.proxy(this.render, this));
Expand Down
17 changes: 17 additions & 0 deletions config.js
Expand Up @@ -15,6 +15,23 @@ module.exports = {
// server_whitelist: ["irc.freenode.net"],
server_whitelist: false,

// If enabled, prevent creation of new accounts or editing settings. These presets
// are used for all new user accounts.
presets: false,
/*
presets: {
server: "chat.freenode.net",
port: 6667,
secure: false,
selfSigned: false,
away: "AKF",
encoding: null,
stripColors: false,
keepAlive: true,
channels: ["#subway"],
},
*/

/* not implemented yet */
user_access: {
users_enabled: true, // show and allow logins
Expand Down
10 changes: 9 additions & 1 deletion lib/socket.js
Expand Up @@ -32,6 +32,10 @@ module.exports = function(socket, app) {
app.ircbridge.emit(connection, event, dict);
}

socket.emit('initialized', {
presets: app.config.presets
});

/* auth/setup commands */

// user registration
Expand Down Expand Up @@ -87,7 +91,11 @@ module.exports = function(socket, app) {
socket.connID = connections[0].id;
socket.conn = connections[0];
}
socket.emit('login_success', {username: data.username, exists: exists});
socket.emit('login_success', {
username: data.username,
nick: data.username,
exists: exists
});
});
} else {
socket.emit('login_error', {message: 'Wrong password'});
Expand Down
2 changes: 2 additions & 0 deletions views/templates.jade
Expand Up @@ -16,12 +16,14 @@ script(id="load_image", type="text/html")

script(id="overview_home", type="text/html")
ul
{{^presets}}
li.overview_button#connection
img(src="/assets/images/connection.svg")
span New Connection
li.overview_button#settings
img(src="/assets/images/settings.svg")
span Settings
{{/presets}}
li.overview_button#login
img(src="/assets/images/login.svg")
span Login
Expand Down