@@ -153,7 +153,11 @@ export class ChatsComponent implements OnInit {
153153
154154 this . connection . on ( 'PrivateChatDeletedAsync' , ( chatId : string ) => {
155155 console . log ( `Private chat deleted: ${ chatId } ` ) ;
156- this . chats = this . chats . filter ( ( x ) => x . chatId !== chatId ) ;
156+ const chatIndex = this . chats . findIndex ( ( x ) => x . chatId === chatId ) ;
157+
158+ if ( chatIndex === - 1 ) return ;
159+
160+ this . chats . splice ( chatIndex , 1 ) ;
157161
158162 if ( this . activeChatId === chatId ) {
159163 this . activeChat = this . _defaultChatHelper . getEmptyChat ( ) ;
@@ -416,7 +420,7 @@ export class ChatsComponent implements OnInit {
416420
417421 if ( chatIndex === - 1 ) return ;
418422
419- console . log ( 'chats: ' + JSON . stringify ( this . chats ) ) ;
423+ // console.log('chats: ' + JSON.stringify(this.chats));
420424
421425 const chat = this . chats [ chatIndex ] ;
422426
@@ -427,13 +431,15 @@ export class ChatsComponent implements OnInit {
427431
428432 this . chats . splice ( chatIndex , 1 ) ;
429433
430- console . log ( 'chats excluded: ' + JSON . stringify ( this . chats ) ) ;
434+ // console.log('chats excluded: ' + JSON.stringify(this.chats));
431435
432436 this . chats . splice ( 0 , 0 , chat ) ;
433437
434- const includesMessage = this . messages . some ( ( x ) => x . messageId === message . messageId ) ;
438+ if ( this . activeChatId !== message . chatId ) return ;
439+
440+ const messageIndex = this . messages . findIndex ( ( x ) => x . messageId === message . messageId ) ;
435441
436- if ( message . chatId === this . activeChatId && ! includesMessage ) {
442+ if ( messageIndex === - 1 ) {
437443 this . messages . push ( message ) ;
438444 }
439445 }
0 commit comments