1
1
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 } ) ;
3
5
4
6
var Private = {
5
7
messageHTML : "<div class='chat-message'>" +
@@ -53,6 +55,10 @@ C("ChatView", ["require", "exports", "module"], function (require, exports, modu
53
55
Private . addParticipant . call ( self , participant ) ;
54
56
} ) ;
55
57
58
+ this . participants . on ( 'remove' , function ( participant ) {
59
+ Private . removeParticipant . call ( self , participant ) ;
60
+ } ) ;
61
+
56
62
// add the event listener so that when
57
63
// the realtime module adds messages to the collection
58
64
// from other mappers, it will update the UI
@@ -117,11 +123,10 @@ C("ChatView", ["require", "exports", "module"], function (require, exports, modu
117
123
}
118
124
m . timestamp = date ;
119
125
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 ) ;
120
127
var $html = $ ( this . messageTemplate ( m ) ) ;
121
128
this . $messages . append ( $html ) ;
122
- this . $messages . animate ( {
123
- scrollTop : $html . offset ( ) . top
124
- } , 200 ) ;
129
+ this . scrollMessages ( 200 ) ;
125
130
126
131
if ( this . alertSound ) this . sound . play ( 'laser' ) ;
127
132
} ,
@@ -145,6 +150,9 @@ C("ChatView", ["require", "exports", "module"], function (require, exports, modu
145
150
var p = _ . clone ( participant . attributes ) ;
146
151
var html = this . participantTemplate ( p ) ;
147
152
this . $participants . append ( html ) ;
153
+ } ,
154
+ removeParticipant : function ( participant ) {
155
+ this . $container . find ( '.participant-' + participant . get ( 'username' ) ) . remove ( ) ;
148
156
}
149
157
} ;
150
158
@@ -206,9 +214,11 @@ C("ChatView", ["require", "exports", "module"], function (require, exports, modu
206
214
var p = this . participants . find ( function ( p ) { return p . get ( 'username' ) === username ; } ) ;
207
215
if ( p ) {
208
216
this . participants . remove ( p ) ;
209
- this . $container . find ( '.participant-' + username ) . remove ( ) ;
210
217
}
218
+ }
211
219
220
+ chatView . prototype . removeParticipants = function ( ) {
221
+ this . participants . remove ( this . participants . models ) ;
212
222
}
213
223
214
224
chatView . prototype . open = function ( ) {
@@ -219,14 +229,19 @@ C("ChatView", ["require", "exports", "module"], function (require, exports, modu
219
229
this . isOpen = true ;
220
230
this . unreadMessages = 0 ;
221
231
this . $unread . hide ( ) ;
232
+ this . scrollMessages ( 0 ) ;
233
+ }
234
+
235
+ chatView . prototype . scrollMessages = function ( duration ) {
236
+ duration = duration || 0 ;
222
237
223
238
var
224
239
numMessages = this . $messages . find ( '.chat-message' ) . length ,
225
240
messageHeight = 52 ;
226
241
227
242
this . $messages . animate ( {
228
243
scrollTop : numMessages * messageHeight
229
- } , 0 ) ;
244
+ } , duration ) ;
230
245
}
231
246
232
247
chatView . prototype . close = function ( ) {
0 commit comments