@@ -27,6 +27,7 @@ import { RealtimeService } from '../../services/api/realtime.service';
2727import { BaseResponse } from '../../types/responses/BaseResponse' ;
2828import { GetUserChatsResponse } from '../../types/responses/GetUserChatsResponse' ;
2929import { DeleteMessageResponse } from '../../types/responses/DeleteMessageResponse' ;
30+ import { DefaultChatHelper } from './defaultChatHelper' ;
3031
3132@Component ( {
3233 selector : 'app-chats' ,
@@ -45,7 +46,8 @@ export class ChatsComponent implements OnInit {
4546 private _apiBaseService : ApiBaseService ,
4647 public _modalWindowStateService : ModalWindowStateService ,
4748 public _replyStateService : ReplyStateService ,
48- private _realtimeService : RealtimeService
49+ private _realtimeService : RealtimeService ,
50+ private _defaultChatHelper : DefaultChatHelper
4951 ) { }
5052
5153 private connectionBuilder : signalR . HubConnectionBuilder = new signalR . HubConnectionBuilder ( ) ;
@@ -58,21 +60,7 @@ export class ChatsComponent implements OnInit {
5860 public userId : string | undefined = '' ;
5961 public chats : Chat [ ] = [ ] ;
6062
61- public activeChat : Chat = {
62- lastMessageId : '' ,
63- lastMessageAuthor : '' ,
64- lastMessageText : '' ,
65- lastMessageTime : '' ,
66- roleId : 1 ,
67- communityType : CommunityType . PublicChannel ,
68- description : '' ,
69- chatId : '' ,
70- chatLogoImageUrl : '' ,
71- isArchived : false ,
72- isMember : false ,
73- membersCount : 0 ,
74- title : ''
75- } ;
63+ public activeChat : Chat = this . _defaultChatHelper . getEmptyChat ( ) ;
7664
7765 public activeChatId = '' ;
7866 public messages : Message [ ] = [ ] ;
@@ -167,6 +155,12 @@ export class ChatsComponent implements OnInit {
167155 this . connection . on ( 'PrivateChatDeletedAsync' , ( chatId : string ) => {
168156 console . log ( `Private chat deleted: ${ chatId } ` ) ;
169157 this . chats = this . chats . filter ( ( x ) => x . chatId !== chatId ) ;
158+
159+ if ( this . activeChatId === chatId ) {
160+ this . activeChat = this . _defaultChatHelper . getEmptyChat ( ) ;
161+ this . activeChatId = '' ;
162+ this . messages = [ ] ;
163+ }
170164 } ) ;
171165
172166 this . connection . on ( 'NotifyOnMessageDeleteAsync' , ( notification : DeleteMessageNotification ) => {
0 commit comments