Skip to content

Commit 44469c6

Browse files
authored
Merge pull request #455 from MangoInstantMessenger/develop
Develop
2 parents c1e1ffc + ce965f4 commit 44469c6

65 files changed

Lines changed: 799 additions & 654 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build-angular.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ on:
44
push:
55
branches:
66
- develop
7-
- master
7+
- main
88

99
pull_request:
10-
branches: [ develop ]
10+
branches:
11+
- develop
12+
- main
1113

1214
workflow_dispatch:
1315

.github/workflows/build-test-coverage-dotnet.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ on:
44
push:
55
branches:
66
- develop
7-
- master
7+
- main
88

99
pull_request:
10-
branches: [ develop ]
10+
branches:
11+
- develop
12+
- main
1113

1214
workflow_dispatch:
1315

.github/workflows/qoudana-scan.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ on:
44
push:
55
branches:
66
- develop
7-
- master
7+
- main
88

99
pull_request:
10-
branches: [ develop ]
10+
branches:
11+
- develop
12+
- main
1113

1214
workflow_dispatch:
1315

.github/workflows/resharper-scan.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ on:
44
push:
55
branches:
66
- develop
7-
- master
7+
- main
88

99
pull_request:
10-
branches: [ develop ]
10+
branches:
11+
- develop
12+
- main
1113

1214
workflow_dispatch:
1315

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning v2.0.0](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
- Semantic version is properly displayed on UI at settings
11+
12+
### Changed
13+
814
## [v0.2.0]
915

1016
### Changed

MangoAPI.BusinessLogic/ApiCommands/Communities/CreateChatCommandHandler.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66
using MangoAPI.BusinessLogic.HubConfig;
7-
using MangoAPI.BusinessLogic.Models;
7+
using MangoAPI.BusinessLogic.Notifications;
88
using MangoAPI.BusinessLogic.Responses;
99
using MangoAPI.Domain.Constants;
1010
using MangoAPI.Domain.Entities;
@@ -99,9 +99,17 @@ public async Task<Result<CreateCommunityResponse>> Handle(
9999

100100
var partnerImageUrl = $"{blobServiceSettings.MangoBlobAccess}/{senderData.ImageFileName}";
101101

102-
var chatDto = chat.ToChatDto(partnerImageUrl, partner.DisplayName);
103-
104-
await hubContext.Clients.Group(request.PartnerId.ToString()).PrivateChatCreatedAsync(chatDto);
102+
var chatCreatedNotification = new PrivateChatCreatedNotification(
103+
chat.Id,
104+
senderData.DisplayName,
105+
chat.CommunityType,
106+
chat.Description,
107+
chat.MembersCount,
108+
IsArchived: false,
109+
IsMember: true,
110+
partnerImageUrl);
111+
112+
await hubContext.Clients.Group(request.PartnerId.ToString()).PrivateChatCreatedAsync(chatCreatedNotification);
105113

106114
return responseFactory.SuccessResponse(CreateCommunityResponse.FromSuccess(chat));
107115
}

MangoAPI.BusinessLogic/ApiCommands/Communities/LeaveGroupCommandHandler.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using MangoAPI.BusinessLogic.HubConfig;
2+
using MangoAPI.BusinessLogic.Notifications;
23
using System.Linq;
34
using System.Threading;
45
using System.Threading.Tasks;
@@ -69,17 +70,19 @@ public async Task<Result<LeaveGroupResponse>> Handle(
6970

7071
await dbContext.SaveChangesAsync(cancellationToken);
7172

72-
await hubContext.Clients.Group(partnerId.ToString()).PrivateChatDeletedAsync(request.ChatId);
73+
var chatDeletedNotification = new PrivateChatDeletedNotification(request.ChatId);
74+
75+
await hubContext.Clients.Group(partnerId.ToString()).PrivateChatDeletedAsync(chatDeletedNotification);
7376

7477
return responseFactory.SuccessResponse(LeaveGroupResponse.FromSuccess(chat.Id));
7578
}
76-
79+
7780
var userChat = chat.ChatUsers.First(x => x.UserId == request.UserId);
7881
chat.IncrementMembersCount(-1);
7982

8083
dbContext.Update(chat);
8184
dbContext.UserChats.Remove(userChat);
82-
85+
8386
await dbContext.SaveChangesAsync(cancellationToken);
8487

8588
return responseFactory.SuccessResponse(LeaveGroupResponse.FromSuccess(chat.Id));

MangoAPI.BusinessLogic/ApiCommands/Messages/DeleteMessageCommandHandler.cs

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
using System.Threading;
33
using System.Threading.Tasks;
44
using MangoAPI.BusinessLogic.HubConfig;
5-
using MangoAPI.BusinessLogic.Models;
5+
using MangoAPI.BusinessLogic.Notifications;
66
using MangoAPI.BusinessLogic.Responses;
77
using MangoAPI.Domain.Constants;
8+
using MangoAPI.Domain.Entities;
89
using MangoAPI.Infrastructure.Database;
910
using MediatR;
1011
using Microsoft.AspNetCore.SignalR;
1112
using Microsoft.EntityFrameworkCore;
13+
using System;
1214

1315
namespace MangoAPI.BusinessLogic.ApiCommands.Messages;
1416

@@ -35,7 +37,8 @@ public async Task<Result<DeleteMessageResponse>> Handle(
3537
{
3638
var checkMessage = await dbContext.Messages
3739
.Include(x => x.User)
38-
.FirstOrDefaultAsync(t => t.Id == request.MessageId, cancellationToken);
40+
.Select(x => new { MessageId = x.Id, UserId = x.User.Id })
41+
.FirstOrDefaultAsync(t => t.MessageId == request.MessageId, cancellationToken);
3942

4043
if (checkMessage == null)
4144
{
@@ -45,7 +48,7 @@ public async Task<Result<DeleteMessageResponse>> Handle(
4548
return responseFactory.ConflictResponse(errorMessage, errorDescription);
4649
}
4750

48-
if (checkMessage.User.Id != request.UserId)
51+
if (checkMessage.UserId != request.UserId)
4952
{
5053
const string errorMessage = ResponseMessageCodes.Unauthorized;
5154
var errorDescription = ResponseMessageCodes.ErrorDictionary[errorMessage];
@@ -70,42 +73,67 @@ public async Task<Result<DeleteMessageResponse>> Handle(
7073
return responseFactory.ConflictResponse(errorMessage, errorDescription);
7174
}
7275

73-
var message = chat.Messages.First(x => x.Id == request.MessageId);
76+
var deletedMessage = chat.Messages.First(x => x.Id == request.MessageId);
7477

75-
dbContext.Entry(message.User).State = EntityState.Detached;
78+
dbContext.Entry(deletedMessage.User).State = EntityState.Detached;
7679

77-
var deleteNotification = new MessageDeleteNotification
78-
{
79-
ChatId = request.ChatId, DeletedMessageId = request.MessageId, IsLastMessage = false,
80-
};
80+
var isMessageLast = chat.LastMessageId.HasValue && chat.LastMessageId == request.MessageId;
8181

82-
var messageIsLast = chat.LastMessageId.HasValue && chat.LastMessageId == request.MessageId;
82+
var deleteNotification = isMessageLast
83+
? UpdateChatLastMessageAndReturnNotification(chat, deletedMessage)
84+
: CreateNotLastMessageNotification(chat.Id, deletedMessage.Id, deletedMessage.UserId);
8385

84-
if (messageIsLast)
85-
{
86-
var newLastMessage = chat.Messages
87-
.Where(x => x != message).MaxBy(x => x.CreatedAt);
88-
89-
deleteNotification.NewLastMessageAuthor = newLastMessage?.User?.DisplayName;
90-
deleteNotification.NewLastMessageId = newLastMessage?.Id;
91-
deleteNotification.NewLastMessageText = newLastMessage?.Text;
92-
deleteNotification.NewLastMessageTime = newLastMessage?.CreatedAt;
93-
deleteNotification.IsLastMessage = true;
94-
95-
chat.UpdateLastMessage(
96-
lastMessageAuthor: newLastMessage?.User?.DisplayName,
97-
lastMessageText: newLastMessage?.Text,
98-
newLastMessage?.CreatedAt,
99-
newLastMessage?.Id);
100-
}
101-
102-
dbContext.Messages.Remove(message);
86+
dbContext.Messages.Remove(deletedMessage);
10387
dbContext.Chats.Update(chat);
10488

10589
await dbContext.SaveChangesAsync(cancellationToken);
10690

107-
await hubContext.Clients.Group(message.ChatId.ToString()).NotifyOnMessageDeleteAsync(deleteNotification);
91+
await hubContext.Clients.Group(deletedMessage.ChatId.ToString()).MessageDeletedAsync(deleteNotification);
92+
93+
return responseFactory.SuccessResponse(DeleteMessageResponse.FromSuccess(deletedMessage));
94+
}
10895

109-
return responseFactory.SuccessResponse(DeleteMessageResponse.FromSuccess(message));
96+
private static DeleteMessageNotification UpdateChatLastMessageAndReturnNotification(
97+
ChatEntity chat,
98+
MessageEntity deletedMessage)
99+
{
100+
var newLastMessage = chat.Messages
101+
.Where(x => x.Id != deletedMessage.Id).MaxBy(x => x.CreatedAt);
102+
103+
chat.UpdateLastMessage(
104+
lastMessageAuthor: newLastMessage?.User?.DisplayName,
105+
lastMessageText: newLastMessage?.Text,
106+
newLastMessage?.CreatedAt,
107+
newLastMessage?.Id);
108+
109+
var deleteNotification = new DeleteMessageNotification(
110+
deletedMessage.UserId,
111+
chat.Id,
112+
deletedMessage.Id,
113+
newLastMessage?.Text,
114+
newLastMessage?.CreatedAt,
115+
newLastMessage?.Id,
116+
newLastMessage?.User?.DisplayName,
117+
IsLastMessage: true);
118+
119+
return deleteNotification;
120+
}
121+
122+
private static DeleteMessageNotification CreateNotLastMessageNotification(
123+
Guid chatId,
124+
Guid deletedMessageId,
125+
Guid userId)
126+
{
127+
var deleteNotification = new DeleteMessageNotification(
128+
userId,
129+
chatId,
130+
deletedMessageId,
131+
NewLastMessageText: string.Empty,
132+
NewLastMessageTime: null,
133+
NewLastMessageId: null,
134+
NewLastMessageDisplayName: null,
135+
IsLastMessage: false);
136+
137+
return deleteNotification;
110138
}
111139
}

MangoAPI.BusinessLogic/ApiCommands/Messages/EditMessageCommandHandler.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
using System.Linq;
33
using System.Threading;
44
using System.Threading.Tasks;
5-
using MangoAPI.BusinessLogic.HubConfig;
6-
using MangoAPI.BusinessLogic.Models;
75
using MangoAPI.BusinessLogic.Responses;
86
using MangoAPI.Domain.Constants;
97
using MangoAPI.Infrastructure.Database;
108
using MediatR;
11-
using Microsoft.AspNetCore.SignalR;
129
using Microsoft.EntityFrameworkCore;
1310

1411
namespace MangoAPI.BusinessLogic.ApiCommands.Messages;
@@ -17,16 +14,13 @@ public class EditMessageCommandHandler
1714
: IRequestHandler<EditMessageCommand, Result<ResponseBase>>
1815
{
1916
private readonly MangoDbContext dbContext;
20-
private readonly IHubContext<ChatHub, IHubClient> hubContext;
2117
private readonly ResponseFactory<ResponseBase> responseFactory;
2218

2319
public EditMessageCommandHandler(
2420
MangoDbContext dbContext,
25-
IHubContext<ChatHub, IHubClient> hubContext,
2621
ResponseFactory<ResponseBase> responseFactory)
2722
{
2823
this.dbContext = dbContext;
29-
this.hubContext = hubContext;
3024
this.responseFactory = responseFactory;
3125
}
3226

@@ -89,17 +83,6 @@ public async Task<Result<ResponseBase>> Handle(
8983

9084
await dbContext.SaveChangesAsync(cancellationToken);
9185

92-
var messageDeleteNotification = new MessageEditNotification
93-
{
94-
MessageId = request.MessageId,
95-
ModifiedText = request.ModifiedText,
96-
UpdatedAt = updatedAt,
97-
IsLastMessage = messageIsLast,
98-
};
99-
100-
await hubContext.Clients.Group(message.ChatId.ToString())
101-
.NotifyOnMessageEditAsync(messageDeleteNotification);
102-
10386
return responseFactory.SuccessResponse(DeleteMessageResponse.FromSuccess(message));
10487
}
10588
}

MangoAPI.BusinessLogic/ApiCommands/Messages/SendMessageCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace MangoAPI.BusinessLogic.ApiCommands.Messages;
77

88
public record SendMessageCommand(
9-
Guid MessageId,
109
Guid UserId,
1110
Guid ChatId,
1211
string Text,

0 commit comments

Comments
 (0)