Skip to content
This repository has been archived by the owner on May 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #60 from Phalanxia/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Phalanxia committed Feb 28, 2016
2 parents 1998cf8 + d19f3fc commit 9da1a0b
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 78 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"body-parser": "^1.15.0",
"commander": "^2.9.0",
"compression": "^1.6.1",
"errorhandler": "^1.4.3",
"express": "^4.13.4",
"express-minify": "^0.2.0",
"irc": "^0.4.1",
Expand Down
15 changes: 10 additions & 5 deletions src/client/js/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@
"selectAll": true,
"Maid": true,
"io": true,
"Handlebars": true,
"Autolinker": true,
"twemoji": true,
"uuid": true,
"UI": true,
"ui": true,
"Sources": true,
"sources": true,
"Outgoing": true,
"outgoing": true,
"Incoming": true,
"incoming": true,
"Connections": true,
"Message": true,
"Handlebars": true,
"Autolinker": true,
"twemoji": true,
"uuid": true,
"connections": true,
"Message": true
}
}
30 changes: 16 additions & 14 deletions src/client/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
const select = document.querySelector.bind(document);
const selectAll = selection => Array.prototype.slice.call(document.querySelectorAll(selection));

// Modules
const ui = new UI();
const sources = new Sources(ui);
const incoming = new Incoming(ui, sources);
const connections = new Connections(ui, sources, incoming);
const outgoing = new Outgoing(connections);

const Maid = {
settings: {
awayMessage: 'Away',
Expand All @@ -20,18 +27,13 @@ const Maid = {
focusedSource: '',
sessions: {},

version: select('#about .version').innerHTML.slice(16),

getFocused() {
return this.sessions[this.sessions.focusedServer];
},

init() {
// Modules
const ui = new UI();
const sources = new Sources(ui);
const incoming = new Incoming(ui, sources);
const connections = new Connections(ui, sources, incoming);
const outgoing = new Outgoing(connections);

init: () => {
// Do button magic here

// Handle connection information
Expand Down Expand Up @@ -96,19 +98,19 @@ const Maid = {
};

select('#channel-console footer button').onclick = () => enterMessage();

window.onbeforeunload = () => {
if (connections.status) {
return 'Leaving the page will disconnect you from IRC.';
}
};
},
};

window.onload = () => {
Maid.init();
};

window.onbeforeunload = () => {
if (Maid.connections.status) {
return 'Leaving the page will disconnect you from IRC.';
}
};

function hideModals() {
select('#pageCover').classList.remove('displayed');
selectAll('.modal').forEach(obj => obj.classList.remove('displayed'));
Expand Down
11 changes: 3 additions & 8 deletions src/client/js/modules/Connections.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
class Connections {
constructor(ui, sources, incoming) {
// Other modules
this.ui = ui;
this.sources = sources;
this.incoming = incoming;

constructor() {
// Technical
this.connected = false;
this.pastDisconnect = false;
Expand Down Expand Up @@ -33,7 +28,7 @@ class Connections {
const message = data[1];

if (['normal', 'reply', 'error'].indexOf(message.commandType) > -1) {
this.incoming.handler(connectionId, message);
incoming.handler(connectionId, message);
} else {
console.warn(`Error: Unknown message type "${message.commandType}"`);
}
Expand Down Expand Up @@ -66,7 +61,7 @@ class Connections {
this.socket.emit('connectToNetwork', [information, connectionId]);

// Display the server in the sources list
this.sources.addServer(connectionId);
sources.addServer(connectionId);

// If no server is focused, focus on this one
if (!Maid.focusedServer) {
Expand Down
86 changes: 56 additions & 30 deletions src/client/js/modules/Incoming.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
class Incoming {
constructor(ui, sources) {
this.ui = ui;
this.sources = sources;
}

addMessage(content) {
const _content = content;

Expand All @@ -14,15 +9,9 @@ class Incoming {
NewMessage.display();

const output = select('#channel-console output');
let scrollInfoView;

// If scrolled at the bottom set scrollIntoView as true
if (output.scrollHeight - output.scrollTop === output.clientHeight) {
scrollInfoView = true;
}

// Scroll to bottom unless the user is scrolled up
if (scrollInfoView) {
if (output.scrollHeight - output.scrollTop === output.clientHeight) {
output.scrollTop = output.scrollHeight;
}
}
Expand All @@ -33,6 +22,10 @@ class Incoming {
const network = Maid.sessions[connectionId];
this.connectionId = connectionId;

if (Maid.settings.debug) {
console.log(data);
}

const messageTable = {
default: () => {
if (Maid.settings.debug) {
Expand All @@ -47,13 +40,46 @@ class Incoming {
ping: () => {},

privmsg: () => {
this.addMessage({
type: 'privmsg',
channel: _data.args[0],
head: _data.nick,
message: _data.args[1],
isHighlightable: true,
});
// Detect if the message is a CTCP
if (_data.args[1].startsWith('\x01') && _data.args[1].endsWith('\x01')) {
// If its an ACTION message (/me)
if (_data.args[1].startsWith('\x01ACTION')) {
const slicedString = _data.args[1].slice(7, -1);

this.addMessage({
type: 'privmsg',
channel: _data.args[0],
icon: ['fa-angle-double-right', 'Action'],
message: `${_data.nick}${slicedString}`,
isHighlightable: true,
});
} else if (_data.args[1].startsWith('\x01VERSION')) {
// Display the CTCP VERSION request
this.addMessage({
type: 'privmsg',
channel: _data.nick,
icon: ['fa-angle-double-right', 'Action'],
message: `Recieved a CTCP VERSION from ${_data.nick}`,
isHighlightable: true,
});

// Respond
connections.send('send-raw', [
'NOTICE',
_data.nick,
`VERSION Maid-IRC ${Maid.version}`,
]);
}
} else {
// Normal message
this.addMessage({
type: 'privmsg',
channel: _data.args[0],
head: _data.nick,
message: _data.args[1],
isHighlightable: true,
});
}
},

notice: () => {
Expand All @@ -78,13 +104,13 @@ class Incoming {
console.log('Updating sources list');
}

this.sources.addToList(connectionId, _data.args[0]);
sources.addToList(connectionId, _data.args[0]);
}

// If its the focused channel update the userlist
if (network.sources[_data.args[0]].users !== undefined) {
if (_data.args[0] === Maid.focusedSource || Maid.focusedSource === '') {
this.ui.users(_data.args[0], connectionId);
ui.users(_data.args[0], connectionId);
}
}

Expand All @@ -93,7 +119,7 @@ class Incoming {
type: 'join',
channel: _data.args[0],
icon: ['fa-sign-in', 'Join'],
message: _data.nick + ' (' + _data.prefix + ') has Joined (' + _data.args[0] + ')',
message: `${_data.nick} (${_data.prefix}) has Joined (${_data.args[0]})`,
});
},

Expand All @@ -104,14 +130,14 @@ class Incoming {
channel,
type: 'quit',
icon: ['fa-angle-double-left', 'Warning'],
message: _data.nick + ' (' + _data.prefix + ') has Quit (' + _data.args[0] + ')',
message: `${_data.nick} (${_data.prefix}) has Quit (${_data.args[0]})`,
});
} else if (_data.nick in channel.users) {
this.addMessage({
channel,
type: 'quit',
icon: ['fa-angle-double-left', 'Warning'],
message: _data.nick + ' (' + _data.prefix + ') has Quit (' + _data.args[0] + ')',
message: `${_data.nick} (${_data.prefix}) has Quit (${_data.args[0]})`,
});
}
}
Expand All @@ -124,7 +150,7 @@ class Incoming {
channel,
type: 'error',
icon: ['fa-exclamation-circle', 'Alert'],
message: 'Error: ' + _data.args[0],
message: `Error: ${_data.args[0]}`,
});
}
}
Expand All @@ -134,7 +160,7 @@ class Incoming {
type: 'error',
channel: 'server',
icon: ['fa-exclamation-circle', 'Alert'],
message: 'Error: ' + _data.args[0],
message: `Error: ${_data.args[0]}`,
});
},

Expand Down Expand Up @@ -248,7 +274,7 @@ class Incoming {
}

if (network.sources[_channel] === Maid.focusedSource) {
this.ui.users(_channel, connectionId);
ui.users(_channel, connectionId);
}
},

Expand Down Expand Up @@ -279,7 +305,7 @@ class Incoming {
type: 'warning',
channel: 'server',
icon: ['fa-exclamation-triangle', 'Warning'],
message: _data.args[1] + ': ' + _data.args[2],
message: `${_data.args[1]}: ${_data.args[2]}`,
});
},

Expand All @@ -288,7 +314,7 @@ class Incoming {
type: 'warning',
channel: 'server',
icon: ['fa-exclamation-triangle', 'Warning'],
message: _data.args[1] + ': ' + _data.args[2],
message: `${_data.args[1]}: ${_data.args[2]}`,
});
},

Expand All @@ -297,7 +323,7 @@ class Incoming {
type: 'warning',
channel: 'server',
icon: ['fa-exclamation-triangle', 'Warning'],
message: _data.args[1] + ': ' + _data.args[2],
message: `${_data.args[1]}: ${_data.args[2]}`,
});
},
};
Expand Down
5 changes: 2 additions & 3 deletions src/client/js/modules/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ class Message {

// Time
this.rawTime = new Date();
this.timestamp = `${('0' + this.rawTime.getHours()).slice(-2)}:` +
`${('0' + this.rawTime.getMinutes()).slice(-2)}:` +
`${('0' + this.rawTime.getSeconds()).slice(-2)}`;

this.timestamp = `${(`0${this.rawTime.getHours()}`).slice(-2)}:${(`0${this.rawTime.getMinutes()}`).slice(-2)}:${(`0${this.rawTime.getSeconds()}`).slice(-2)}`;

// Icon
if (this.raw.icon) {
Expand Down
28 changes: 21 additions & 7 deletions src/client/js/modules/Outgoing.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
class Outgoing {
constructor(connections) {
this.connections = connections;
}

commands(command, args) {
const _args = args;

Expand All @@ -21,7 +17,25 @@ class Outgoing {
NewMessage.display();

// Send message data to the server
this.connections.send('send-action', [Maid.focusedSource, _args]);
connections.send('send-action', [Maid.focusedSource, _args]);
},

version: () => {
const message = {
type: 'privmsg',
icon: ['fa-angle-double-right', 'VERSION'],
head: `To ${_args.split(' ')[0]}`,
channel: Maid.focusedSource,
message: 'CTCP VERSION',
};

// Display the message
const NewMessage = new Message(message, Maid.focusedServer);
NewMessage.filter();
NewMessage.display();

// Send message data to the server
connections.send('send-raw', ['PRIVMSG', Maid.focusedSource, _args]);
},
};

Expand All @@ -45,7 +59,7 @@ class Outgoing {
this.commands(command, message);
} else {
// It's not one of our commands
this.connections.send('send-raw', message);
connections.send('send-raw', message);
}
}

Expand All @@ -65,7 +79,7 @@ class Outgoing {
this.command(_data);
} else {
// Normal message
this.connections.send('send-raw', ['PRIVMSG', Maid.focusedSource, _data]);
connections.send('send-raw', ['PRIVMSG', Maid.focusedSource, _data]);

// Display the message
const updateMessage = {
Expand Down
Loading

0 comments on commit 9da1a0b

Please sign in to comment.