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

Already on GitHub? Sign in to your account

Memory bug fix, updated models, package.json dependencies updated, backlog scrolling works #141

Merged
merged 1 commit into from Jul 10, 2012
Jump to file or symbol
Failed to load files and symbols.
+37 −47
Split
View
@@ -98,9 +98,9 @@ $(function() {
$.each(value.users, function(user, role) {
channel.userList.add({nick: user, role: role, idle:0, user_status: 'idle', activity: ''});
});
- irc.socket.emit('getOldMessages',{channelName: chanName, skip:-50, amount: 50});
+ irc.socket.emit('getOldMessages',{channelName: chanName, skip:0, amount: 50});
} else {
- irc.socket.emit('getOldMessages',{channelName: chanName, skip:-50, amount: 50});
+ irc.socket.emit('getOldMessages',{channelName: chanName, skip:0, amount: 50});
channel.stream.add(new Message({sender:'', raw:''}));
}
});
@@ -143,7 +143,7 @@ $(function() {
if (typeof chatWindow === 'undefined') {
irc.chatWindows.add({name: data.nick, type: 'pm'})
.trigger('forMe', 'newPm');
- irc.socket.emit('getOldMessages',{channelName: data.nick, skip:-50, amount: 50});
+ irc.socket.emit('getOldMessages',{channelName: data.nick, skip:0, amount: 50});
chatWindow = irc.chatWindows.getByName(data.nick);
}
chatWindow.stream.add({sender: data.nick, raw: data.text, type: 'pm'});
@@ -154,7 +154,7 @@ $(function() {
console.log('Join event received for ' + chanName + ' - ' + data.nick);
if (data.nick === irc.me.get('nick')) {
irc.chatWindows.add({name: chanName});
- irc.socket.emit('getOldMessages',{channelName: chanName, skip:-50, amount: 50});
+ irc.socket.emit('getOldMessages',{channelName: chanName, skip:0, amount: 50});
} else {
var channel = irc.chatWindows.getByName(chanName);
if (typeof channel === 'undefined') {
@@ -252,11 +252,11 @@ $(function() {
var output = '';
channel = irc.chatWindows.getByName(data.name);
- $.each(data.messages, function(index, message){
+ $.each(data.messages.reverse(), function(index, message){
if($('#' + message._id).length) {
return true; //continue to next iteration
}
-
+
var type = '';
var message_html;
if (message.message.substr(1, 6) === 'ACTION') {
@@ -337,7 +337,7 @@ $(function() {
if (typeof irc.chatWindows.getByName(target) === 'undefined') {
irc.chatWindows.add({name: target, type: 'pm'});
}
- irc.socket.emit('getOldMessages',{channelName: target, skip:-50, amount: 50});
+ irc.socket.emit('getOldMessages',{channelName: target, skip:0, amount: 50});
irc.socket.emit('say', {
target: target,
message: commandText.splice(2).join(" ")
View
@@ -182,7 +182,7 @@ var ChatView = Backbone.View.extend({
handleScroll: function() {
$('#chat-contents').scroll(function(){
if ($('#chat-contents').scrollTop() < 150) {
- var skip = (-50)-$('#chat-contents').children().length;
+ var skip = $('#chat-contents').children().length;
var windowName = irc.chatWindows.getActive().get('name');
var target;
if(windowName[0] == '#'){
@@ -191,7 +191,7 @@ var ChatView = Backbone.View.extend({
var userName = irc.me.get('nick');
target = (userName < windowName) ? userName + windowName : windowName + userName;
}
- irc.socket.emit('getOldMessages',{channelName: target, skip:skip, amount: 10});
+ irc.socket.emit('getOldMessages',{channelName: target, skip:skip, amount: 50});
}
});
},
View
@@ -4,7 +4,6 @@ var irc = require('irc'),
// establish models
var User = mongoose.model('User');
var Connection = mongoose.model('Connection');
-var Channel = mongoose.model('Channel');
var Message = mongoose.model('Message');
// Constructor
@@ -89,7 +88,7 @@ var IRCLink = function(hostname, port, ssl, selfSigned, nick, realName, password
target = args.to.toLowerCase();
// log this message
- instance.logMessage(target, {user: args.from, message: args.text});
+ instance.logMessage(target, args.from, args.text);
if(instance.sockets.length == 0){
instance.client.chans[target].unread_messages++;
@@ -157,16 +156,10 @@ IRCLink.prototype = {
if (this.sockets.length == 0)
this.client.send('AWAY', this.away);
},
- logMessage: function(target, msg) {
+ logMessage: function(target, from, msg) {
if (this.username) {
- var instance = this;
- Channel.findOne({name: target.toLowerCase(), server: this.server, user: this.username}, function(err, channel) {
- if(!channel){
- var channel = new Channel({name: target.toLowerCase(), server: instance.server, user: instance.username});
- }
- channel.messages.push(msg);
- channel.save();
- });
+ var message = new Message({channel: target.toLowerCase(), server: this.server.toLowerCase(), linkedto: this.username, user: from, message: msg});
+ message.save();
}
}
};
View
@@ -24,20 +24,15 @@ module.exports = function() {
});
var Messages = new Schema({
+ linkedto: String,
+ channel: String,
+ server: String,
user: String,
message: String,
date: { type: Date, default: Date.now }
});
- var Channels = new Schema({
- user: String,
- name: String,
- server: String,
- messages: [Messages]
- });
-
mongoose.model('User', Users);
mongoose.model('Connection', Connections);
- mongoose.model('Channel', Channels);
mongoose.model('Message', Messages);
};
View
@@ -2,10 +2,7 @@ var mongoose = require('mongoose'),
IRCLink = require('./irclink');
// establish models
-var User = mongoose.model('User');
var Connection = mongoose.model('Connection');
-var Channel = mongoose.model('Channel');
-var Message = mongoose.model('Message');
module.exports = function (connections) {
// restore connections
View
@@ -5,7 +5,6 @@ var bcrypt = require('bcrypt'),
// establish models
var User = mongoose.model('User');
var Connection = mongoose.model('Connection');
-var Channel = mongoose.model('Channel');
var Message = mongoose.model('Message');
module.exports = function(socket, connections) {
@@ -117,7 +116,7 @@ module.exports = function(socket, connections) {
connection.client.say(data.target, data.message);
socket.emit('message', {to:data.target.toLowerCase(), from: connection.client.nick, text:data.message});
if(current_user){
- connection.logMessage(data.target, {user: connection.client.nick, message: data.message});
+ connection.logMessage(data.target, connection.client.nick, data.message);
}
});
@@ -157,15 +156,21 @@ module.exports = function(socket, connections) {
socket.on('getOldMessages', function(data){
if (current_user) {
- Channel.find({name: data.channelName.toLowerCase(), server: connection.client.opt.server.toLowerCase(), user: current_user.username},
- {messages: {$slice: [data.skip, data.amount]}},
- function(err, results) {
- if(results){
- if(results[0]){
- results[0]['name'] = data.channelName.toLowerCase();
- }
- socket.emit('oldMessages', results[0]);
+ var query = Message.find({channel: data.channelName.toLowerCase(), server: connection.server.toLowerCase(), linkedto: current_user.username});
+
+ query.limit(data.amount);
+ query.sort('date', -1);
+ query.skip(data.skip);
+
+ query.exec(function (err, results) {
+ if(results){
+ var returnData = {};
+ if(results && results.length > 0){
+ returnData['name'] = data.channelName.toLowerCase();
+ returnData['messages'] = results;
}
+ socket.emit('oldMessages', returnData);
+ }
});
}
});
View
@@ -14,13 +14,13 @@
"node": ">=0.6.1"
},
"dependencies": {
- "express": "=2.5.2",
- "jade": "=0.19.0",
- "connect-assets": "=2.1.6",
+ "express": ">=2.5.2",
+ "jade": ">=0.19.0",
+ "connect-assets": ">=2.1.6",
"irc": "git://github.com/martynsmith/node-irc.git",
- "socket.io": "0.9.x-1",
- "mongoose": "=2.5.7",
- "bcrypt": "=0.5.0"
+ "socket.io": ">=0.9.x",
+ "mongoose": ">=2.5.7",
+ "bcrypt": ">=0.5.0"
},
"noAnalyze": true,
"subdomain": "subway",