Skip to content

Commit 841b169

Browse files
committed
fixed chat scrolling, and particpants being removed
1 parent 6b84d6b commit 841b169

File tree

6 files changed

+5583
-22
lines changed

6 files changed

+5583
-22
lines changed

bower.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"underscore": "1.4.4",
2626
"socket.io-client": "0.9.11",
2727
"jquery": "1.9.0",
28-
"howler": "~1.1.26"
28+
"howler": "~1.1.26",
29+
"Autolinker.js": "~0.17.1"
2930
}
3031
}

grunt/concat.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
'bower_components/underscore/underscore.js',
1010
'bower_components/backbone/backbone.js',
1111
'bower_components/howler/howler.js',
12+
'bower_components/Autolinker.js/dist/Autolinker.js',
1213
'bower_components/socket.io-client/dist/socket.io.js',
1314
'bower_components/SimpleWebRTC/simplewebrtc.bundle.js',
1415
'lib/libraries/require.js',

lib/room.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ C("Room", ["require", "exports", "module", "RoomTopicView", "ChatView", "VideoVi
4545
};
4646

4747
room.prototype.join = function(cb) {
48-
this.isActiveRoom = true;
4948
this.isActiveRoom = true;
5049
this.webrtc.joinRoom(this.room, cb);
5150
}
@@ -56,6 +55,7 @@ C("Room", ["require", "exports", "module", "RoomTopicView", "ChatView", "VideoVi
5655
}
5756
this.isActiveRoom = false;
5857
this.webrtc.leaveRoom();
58+
this.chat.removeParticipants();
5959
}
6060

6161
room.prototype.setPeopleCount = function(count) {

lib/views/chatView.js

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
C("ChatView", ["require", "exports", "module"], function (require, exports, module) {
2-
var chatView;
2+
var
3+
chatView,
4+
linker = new Autolinker({ newWindow: true, truncate: 50, email: false, phone: false, twitter: false });
35

46
var Private = {
57
messageHTML: "<div class='chat-message'>" +
@@ -53,6 +55,10 @@ C("ChatView", ["require", "exports", "module"], function (require, exports, modu
5355
Private.addParticipant.call(self, participant);
5456
});
5557

58+
this.participants.on('remove', function (participant) {
59+
Private.removeParticipant.call(self, participant);
60+
});
61+
5662
// add the event listener so that when
5763
// the realtime module adds messages to the collection
5864
// from other mappers, it will update the UI
@@ -117,11 +123,10 @@ C("ChatView", ["require", "exports", "module"], function (require, exports, modu
117123
}
118124
m.timestamp = date;
119125
m.image = m.image || 'http://www.hotpepper.ca/wp-content/uploads/2014/11/default_profile_1_200x200.png';
126+
m.message = linker.link(m.message);
120127
var $html = $(this.messageTemplate(m));
121128
this.$messages.append($html);
122-
this.$messages.animate({
123-
scrollTop: $html.offset().top
124-
}, 200);
129+
this.scrollMessages(200);
125130

126131
if (this.alertSound) this.sound.play('laser');
127132
},
@@ -145,6 +150,9 @@ C("ChatView", ["require", "exports", "module"], function (require, exports, modu
145150
var p = _.clone(participant.attributes);
146151
var html = this.participantTemplate(p);
147152
this.$participants.append(html);
153+
},
154+
removeParticipant: function(participant) {
155+
this.$container.find('.participant-' + participant.get('username')).remove();
148156
}
149157
};
150158

@@ -206,9 +214,11 @@ C("ChatView", ["require", "exports", "module"], function (require, exports, modu
206214
var p = this.participants.find(function (p) { return p.get('username') === username; });
207215
if (p) {
208216
this.participants.remove(p);
209-
this.$container.find('.participant-' + username).remove();
210217
}
218+
}
211219

220+
chatView.prototype.removeParticipants = function () {
221+
this.participants.remove(this.participants.models);
212222
}
213223

214224
chatView.prototype.open = function () {
@@ -219,14 +229,19 @@ C("ChatView", ["require", "exports", "module"], function (require, exports, modu
219229
this.isOpen = true;
220230
this.unreadMessages = 0;
221231
this.$unread.hide();
232+
this.scrollMessages(0);
233+
}
234+
235+
chatView.prototype.scrollMessages = function(duration) {
236+
duration = duration || 0;
222237

223238
var
224239
numMessages = this.$messages.find('.chat-message').length,
225240
messageHeight = 52;
226241

227242
this.$messages.animate({
228243
scrollTop: numMessages * messageHeight
229-
}, 0);
244+
}, duration);
230245
}
231246

232247
chatView.prototype.close = function () {

0 commit comments

Comments
 (0)