Skip to content
This repository
Browse code

Merge pull request #141 from ericbarch/master

Memory bug fix, updated models, package.json dependencies updated, backlog scrolling works
  • Loading branch information...
commit 91c96632d07bda66ff7cbfcbb472f5ee130e2513 2 parents 0a752eb + e07b330
David Petersen authored
14 assets/js/client.js
@@ -98,9 +98,9 @@ $(function() {
98 98 $.each(value.users, function(user, role) {
99 99 channel.userList.add({nick: user, role: role, idle:0, user_status: 'idle', activity: ''});
100 100 });
101   - irc.socket.emit('getOldMessages',{channelName: chanName, skip:-50, amount: 50});
  101 + irc.socket.emit('getOldMessages',{channelName: chanName, skip:0, amount: 50});
102 102 } else {
103   - irc.socket.emit('getOldMessages',{channelName: chanName, skip:-50, amount: 50});
  103 + irc.socket.emit('getOldMessages',{channelName: chanName, skip:0, amount: 50});
104 104 channel.stream.add(new Message({sender:'', raw:''}));
105 105 }
106 106 });
@@ -143,7 +143,7 @@ $(function() {
143 143 if (typeof chatWindow === 'undefined') {
144 144 irc.chatWindows.add({name: data.nick, type: 'pm'})
145 145 .trigger('forMe', 'newPm');
146   - irc.socket.emit('getOldMessages',{channelName: data.nick, skip:-50, amount: 50});
  146 + irc.socket.emit('getOldMessages',{channelName: data.nick, skip:0, amount: 50});
147 147 chatWindow = irc.chatWindows.getByName(data.nick);
148 148 }
149 149 chatWindow.stream.add({sender: data.nick, raw: data.text, type: 'pm'});
@@ -154,7 +154,7 @@ $(function() {
154 154 console.log('Join event received for ' + chanName + ' - ' + data.nick);
155 155 if (data.nick === irc.me.get('nick')) {
156 156 irc.chatWindows.add({name: chanName});
157   - irc.socket.emit('getOldMessages',{channelName: chanName, skip:-50, amount: 50});
  157 + irc.socket.emit('getOldMessages',{channelName: chanName, skip:0, amount: 50});
158 158 } else {
159 159 var channel = irc.chatWindows.getByName(chanName);
160 160 if (typeof channel === 'undefined') {
@@ -252,11 +252,11 @@ $(function() {
252 252 var output = '';
253 253 channel = irc.chatWindows.getByName(data.name);
254 254
255   - $.each(data.messages, function(index, message){
  255 + $.each(data.messages.reverse(), function(index, message){
256 256 if($('#' + message._id).length) {
257 257 return true; //continue to next iteration
258 258 }
259   -
  259 +
260 260 var type = '';
261 261 var message_html;
262 262 if (message.message.substr(1, 6) === 'ACTION') {
@@ -337,7 +337,7 @@ $(function() {
337 337 if (typeof irc.chatWindows.getByName(target) === 'undefined') {
338 338 irc.chatWindows.add({name: target, type: 'pm'});
339 339 }
340   - irc.socket.emit('getOldMessages',{channelName: target, skip:-50, amount: 50});
  340 + irc.socket.emit('getOldMessages',{channelName: target, skip:0, amount: 50});
341 341 irc.socket.emit('say', {
342 342 target: target,
343 343 message: commandText.splice(2).join(" ")
4 assets/js/views/chat.js
@@ -182,7 +182,7 @@ var ChatView = Backbone.View.extend({
182 182 handleScroll: function() {
183 183 $('#chat-contents').scroll(function(){
184 184 if ($('#chat-contents').scrollTop() < 150) {
185   - var skip = (-50)-$('#chat-contents').children().length;
  185 + var skip = $('#chat-contents').children().length;
186 186 var windowName = irc.chatWindows.getActive().get('name');
187 187 var target;
188 188 if(windowName[0] == '#'){
@@ -191,7 +191,7 @@ var ChatView = Backbone.View.extend({
191 191 var userName = irc.me.get('nick');
192 192 target = (userName < windowName) ? userName + windowName : windowName + userName;
193 193 }
194   - irc.socket.emit('getOldMessages',{channelName: target, skip:skip, amount: 10});
  194 + irc.socket.emit('getOldMessages',{channelName: target, skip:skip, amount: 50});
195 195 }
196 196 });
197 197 },
15 lib/irclink.js
@@ -4,7 +4,6 @@ var irc = require('irc'),
@@ -89,7 +88,7 @@ var IRCLink = function(hostname, port, ssl, selfSigned, nick, realName, password
@@ -157,16 +156,10 @@ IRCLink.prototype = {
11 lib/models.js
@@ -24,20 +24,15 @@ module.exports = function() {
24 24 });
25 25
26 26 var Messages = new Schema({
  27 + linkedto: String,
  28 + channel: String,
  29 + server: String,
27 30 user: String,
28 31 message: String,
29 32 date: { type: Date, default: Date.now }
30 33 });
31 34
32   - var Channels = new Schema({
33   - user: String,
34   - name: String,
35   - server: String,
36   - messages: [Messages]
37   - });
38   -
39 35 mongoose.model('User', Users);
40 36 mongoose.model('Connection', Connections);
41   - mongoose.model('Channel', Channels);
42 37 mongoose.model('Message', Messages);
43 38 };
3  lib/restore.js
@@ -2,10 +2,7 @@ var mongoose = require('mongoose'),
2 2 IRCLink = require('./irclink');
3 3
4 4 // establish models
5   -var User = mongoose.model('User');
6 5 var Connection = mongoose.model('Connection');
7   -var Channel = mongoose.model('Channel');
8   -var Message = mongoose.model('Message');
9 6
10 7 module.exports = function (connections) {
11 8 // restore connections
25 lib/socket.js
@@ -5,7 +5,6 @@ var bcrypt = require('bcrypt'),
5 5 // establish models
6 6 var User = mongoose.model('User');
7 7 var Connection = mongoose.model('Connection');
8   -var Channel = mongoose.model('Channel');
9 8 var Message = mongoose.model('Message');
10 9
11 10 module.exports = function(socket, connections) {
@@ -117,7 +116,7 @@ module.exports = function(socket, connections) {
117 116 connection.client.say(data.target, data.message);
118 117 socket.emit('message', {to:data.target.toLowerCase(), from: connection.client.nick, text:data.message});
119 118 if(current_user){
120   - connection.logMessage(data.target, {user: connection.client.nick, message: data.message});
  119 + connection.logMessage(data.target, connection.client.nick, data.message);
121 120 }
122 121 });
123 122
@@ -157,15 +156,21 @@ module.exports = function(socket, connections) {
157 156
158 157 socket.on('getOldMessages', function(data){
159 158 if (current_user) {
160   - Channel.find({name: data.channelName.toLowerCase(), server: connection.client.opt.server.toLowerCase(), user: current_user.username},
161   - {messages: {$slice: [data.skip, data.amount]}},
162   - function(err, results) {
163   - if(results){
164   - if(results[0]){
165   - results[0]['name'] = data.channelName.toLowerCase();
166   - }
167   - socket.emit('oldMessages', results[0]);
  159 + var query = Message.find({channel: data.channelName.toLowerCase(), server: connection.server.toLowerCase(), linkedto: current_user.username});
  160 +
  161 + query.limit(data.amount);
  162 + query.sort('date', -1);
  163 + query.skip(data.skip);
  164 +
  165 + query.exec(function (err, results) {
  166 + if(results){
  167 + var returnData = {};
  168 + if(results && results.length > 0){
  169 + returnData['name'] = data.channelName.toLowerCase();
  170 + returnData['messages'] = results;
168 171 }
  172 + socket.emit('oldMessages', returnData);
  173 + }
169 174 });
170 175 }
171 176 });
12 package.json
@@ -14,13 +14,13 @@
14 14 "node": ">=0.6.1"
15 15 },
16 16 "dependencies": {
17   - "express": "=2.5.2",
18   - "jade": "=0.19.0",
19   - "connect-assets": "=2.1.6",
  17 + "express": ">=2.5.2",
  18 + "jade": ">=0.19.0",
  19 + "connect-assets": ">=2.1.6",
20 20 "irc": "git://github.com/martynsmith/node-irc.git",
21   - "socket.io": "0.9.x-1",
22   - "mongoose": "=2.5.7",
23   - "bcrypt": "=0.5.0"
  21 + "socket.io": ">=0.9.x",
  22 + "mongoose": ">=2.5.7",
  23 + "bcrypt": ">=0.5.0"
24 24 },
25 25 "noAnalyze": true,
26 26 "subdomain": "subway",

0 comments on commit 91c9663

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