Skip to content

Commit afec9af

Browse files
committed
fixes 431
1 parent 25a1fae commit afec9af

2 files changed

Lines changed: 38 additions & 16 deletions

File tree

MangoAPI.Client/src/app/components/chats/chats.component.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { RealtimeService } from '../../services/api/realtime.service';
2727
import { BaseResponse } from '../../types/responses/BaseResponse';
2828
import { GetUserChatsResponse } from '../../types/responses/GetUserChatsResponse';
2929
import { 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) => {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Chat } from '../../types/models/Chat';
2+
import { CommunityType } from '../../types/enums/CommunityType';
3+
import { Injectable } from '@angular/core';
4+
5+
@Injectable({
6+
providedIn: 'root'
7+
})
8+
export class DefaultChatHelper {
9+
public getEmptyChat(): Chat {
10+
const emptyChat: Chat = {
11+
lastMessageId: '',
12+
lastMessageAuthor: '',
13+
lastMessageText: '',
14+
lastMessageTime: '',
15+
roleId: 1,
16+
communityType: CommunityType.PublicChannel,
17+
description: '',
18+
chatId: '',
19+
chatLogoImageUrl: '',
20+
isArchived: false,
21+
isMember: false,
22+
membersCount: 0,
23+
title: ''
24+
};
25+
26+
return emptyChat;
27+
}
28+
}

0 commit comments

Comments
 (0)