@@ -264,30 +264,48 @@ converse.plugins.add('converse-muc', {
264
264
} ,
265
265
266
266
onOccupantRemoved ( occupant ) {
267
+ this . stopListening ( this . occupant ) ;
267
268
delete this . occupant ;
268
269
const chatbox = _ . get ( this , 'collection.chatbox' ) ;
269
- chatbox . occupants . on ( 'add' , this . onOccupantAdded , this ) ;
270
+ if ( ! chatbox ) {
271
+ return _converse . log (
272
+ `Could not get collection.chatbox for message: ${ this . get ( 'id' ) } ` ,
273
+ Strophe . LogLevel . ERROR
274
+ ) ;
275
+ }
276
+ this . listenTo ( chatbox . occupants , 'add' , this . onOccupantAdded ) ;
270
277
} ,
271
278
272
279
onOccupantAdded ( occupant ) {
273
280
if ( occupant . get ( 'nick' ) === Strophe . getResourceFromJid ( this . get ( 'from' ) ) ) {
274
281
this . occupant = occupant ;
275
- this . occupant . on ( 'destroy' , this . onOccupantRemoved , this ) ;
282
+ this . listenTo ( this . occupant , 'destroy' , this . onOccupantRemoved ) ;
276
283
const chatbox = _ . get ( this , 'collection.chatbox' ) ;
277
- chatbox . occupants . off ( 'add' , this . onOccupantAdded , this ) ;
284
+ if ( ! chatbox ) {
285
+ return _converse . log (
286
+ `Could not get collection.chatbox for message: ${ this . get ( 'id' ) } ` ,
287
+ Strophe . LogLevel . ERROR
288
+ ) ;
289
+ }
290
+ this . stopListening ( chatbox . occupants , 'add' , this . onOccupantAdded ) ;
278
291
}
279
292
} ,
280
293
281
294
setOccupant ( ) {
282
295
if ( this . get ( 'type' ) !== 'groupchat' ) { return ; }
283
296
const chatbox = _ . get ( this , 'collection.chatbox' ) ;
284
- if ( ! chatbox ) { return ; }
297
+ if ( ! chatbox ) {
298
+ return _converse . log (
299
+ `Could not get collection.chatbox for message: ${ this . get ( 'id' ) } ` ,
300
+ Strophe . LogLevel . ERROR
301
+ ) ;
302
+ }
285
303
const nick = Strophe . getResourceFromJid ( this . get ( 'from' ) ) ;
286
304
this . occupant = chatbox . occupants . findWhere ( { 'nick' : nick } ) ;
287
305
if ( this . occupant ) {
288
- this . occupant . on ( 'destroy' , this . onOccupantRemoved , this ) ;
306
+ this . listenTo ( this . occupant , 'destroy' , this . onOccupantRemoved ) ;
289
307
} else {
290
- chatbox . occupants . on ( 'add' , this . onOccupantAdded , this ) ;
308
+ this . listenTo ( chatbox . occupants , 'add' , this . onOccupantAdded ) ;
291
309
}
292
310
293
311
} ,
0 commit comments