Skip to content

Commit 88483d2

Browse files
committed
message send realtime
1 parent 949c89c commit 88483d2

2 files changed

Lines changed: 43 additions & 19 deletions

File tree

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

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,13 @@ export class ChatsComponent implements OnInit {
298298
}
299299

300300
async deleteMessage(message: Message) {
301-
const deleteMessageCommand: DeleteMessageCommand = {
302-
chatId: message.chatId,
303-
messageId: message.messageId
304-
};
301+
const deleteMessageCommand = new DeleteMessageCommand(message.messageId, message.chatId);
302+
303+
const messageIndex = this.messages.findIndex((x) => x.messageId === message.messageId);
304+
305+
if (messageIndex === -1) return;
306+
307+
this.messages.splice(messageIndex, 1);
305308

306309
const deleteMessageSub$ = this._messagesService.deleteMessage(deleteMessageCommand);
307310
const deleteMessageResult = await firstValueFrom<DeleteMessageResponse>(deleteMessageSub$);
@@ -405,16 +408,28 @@ export class ChatsComponent implements OnInit {
405408
}
406409

407410
private onMessageSendHandler(message: Message) {
408-
console.log(JSON.stringify(message));
411+
// console.log(JSON.stringify(message));
409412

410413
message.self = message.userId == this.userId;
411-
const chat = this.chats.filter((x) => x.chatId === message.chatId)[0];
414+
415+
const chatIndex = this.chats.findIndex((x) => x.chatId === message.chatId);
416+
417+
if (chatIndex === -1) return;
418+
419+
console.log('chats: ' + JSON.stringify(this.chats));
420+
421+
const chat = this.chats[chatIndex];
422+
412423
chat.lastMessageAuthor = message.userDisplayName;
413424
chat.lastMessageText = message.text;
414425
chat.lastMessageTime = message.createdAt;
415426
chat.lastMessageId = message.messageId;
416-
this.chats = this.chats.filter((x) => x.chatId !== message.chatId);
417-
this.chats = [chat, ...this.chats];
427+
428+
this.chats.splice(chatIndex, 1);
429+
430+
console.log('chats excluded: ' + JSON.stringify(this.chats));
431+
432+
this.chats.splice(0, 0, chat);
418433

419434
const includesMessage = this.messages.some((x) => x.messageId === message.messageId);
420435

@@ -445,8 +460,11 @@ export class ChatsComponent implements OnInit {
445460
console.log(`deleted message id: ${notification.deletedMessageId}`);
446461
console.log(`last message id: ${this.activeChat.lastMessageId}`);
447462

448-
if (notification.isLastMessage) {
449-
const updatedChat = this.chats.filter((x) => x.chatId == notification.chatId)[0];
463+
const chatIndex = this.chats.findIndex((x) => x.chatId === notification.chatId);
464+
465+
if (notification.isLastMessage && chatIndex !== -1) {
466+
const updatedChat = this.chats[chatIndex];
467+
450468
updatedChat.lastMessageAuthor = notification.newLastMessageAuthor;
451469
updatedChat.lastMessageText = notification.newLastMessageText;
452470
updatedChat.lastMessageTime = notification.newLastMessageTime;
@@ -455,8 +473,14 @@ export class ChatsComponent implements OnInit {
455473
console.log(`updated chat: ${JSON.stringify(updatedChat)}`);
456474
}
457475

458-
if (this.activeChatId === notification.chatId) {
459-
this.messages = this.messages.filter((x) => x.messageId !== notification.deletedMessageId);
476+
if (this.activeChatId !== notification.chatId) return;
477+
478+
const messageIndex = this.messages.findIndex(
479+
(x) => x.messageId === notification.deletedMessageId
480+
);
481+
482+
if (messageIndex !== -1) {
483+
this.messages.splice(messageIndex, 1);
460484
}
461485
}
462486

build/azure-pipelines-cd.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ stages:
3737
- template: templates/dotnet-build-job-template.yml
3838
- template: templates/dotnet-integration-tests-job-template.yml
3939

40-
- stage: 'Security_checks'
41-
displayName: 'Run security checks'
42-
dependsOn: 'Build_Test_Pack'
43-
condition: succeeded('Build_Test_Pack')
44-
jobs:
45-
- template: templates/sonarcloud-job-template.yml
46-
- template: templates/mend-scan-job-template.yml
40+
# - stage: 'Security_checks'
41+
# displayName: 'Run security checks'
42+
# dependsOn: 'Build_Test_Pack'
43+
# condition: succeeded('Build_Test_Pack')
44+
# jobs:
45+
# - template: templates/sonarcloud-job-template.yml
46+
# - template: templates/mend-scan-job-template.yml
4747
# - template: templates/snyk-job-template.yml
4848

4949
- stage: 'dev'

0 commit comments

Comments
 (0)