Basic group chat impl
This commit is contained in:
		
							
								
								
									
										2
									
								
								MareAPI
									
									
									
									
									
								
							
							
								
								
								
								
								
							
						
						
									
										2
									
								
								MareAPI
									
									
									
									
									
								
							 Submodule MareAPI updated: b529a101ae...e007d99f02
									
								
							| @@ -0,0 +1,52 @@ | |||||||
|  | using MareSynchronos.API.Data; | ||||||
|  | using MareSynchronos.API.Data.Enum; | ||||||
|  | using MareSynchronos.API.Dto.Group; | ||||||
|  | using MareSynchronos.API.Dto.User; | ||||||
|  | using MareSynchronosServer.Utils; | ||||||
|  | using Microsoft.AspNetCore.Authorization; | ||||||
|  | using Microsoft.AspNetCore.SignalR; | ||||||
|  | using Microsoft.EntityFrameworkCore; | ||||||
|  |  | ||||||
|  | namespace MareSynchronosServer.Hubs; | ||||||
|  |  | ||||||
|  | public partial class MareHub | ||||||
|  | { | ||||||
|  |     [Authorize(Policy = "Identified")] | ||||||
|  |     public Task UserChatSendMsg(UserDto dto, ChatMessage message) | ||||||
|  |     { | ||||||
|  |         _logger.LogCallInfo(MareHubLogger.Args(dto)); | ||||||
|  |         // TODO | ||||||
|  |         return Task.CompletedTask; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     [Authorize(Policy = "Identified")] | ||||||
|  |     public async Task GroupChatSendMsg(GroupDto dto, ChatMessage message) | ||||||
|  |     { | ||||||
|  |         _logger.LogCallInfo(MareHubLogger.Args(dto)); | ||||||
|  |  | ||||||
|  |         var (userExists, groupPair) = await TryValidateUserInGroup(dto.GID, UserUID).ConfigureAwait(false); | ||||||
|  |         if (!userExists) return; | ||||||
|  |  | ||||||
|  |         var group = await _dbContext.Groups.AsNoTracking().SingleAsync(g => g.GID == dto.GID).ConfigureAwait(false); | ||||||
|  |         var sender = await _dbContext.Users.AsNoTracking().SingleAsync(u => u.UID == UserUID).ConfigureAwait(false); | ||||||
|  |         var groupPairs = await _dbContext.GroupPairs.AsNoTracking().Include(p => p.GroupUser).Where(p => p.GroupGID == dto.Group.GID).ToListAsync().ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |         if (group == null || sender == null) return; | ||||||
|  |  | ||||||
|  |         // TODO: Add and check chat permissions | ||||||
|  |         if (group.Alias?.Equals("Loporrit", StringComparison.Ordinal) ?? false) | ||||||
|  |         { | ||||||
|  |             await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Warning, $"Chat is disabled for syncshell '{dto.GroupAliasOrGID}'.").ConfigureAwait(false); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // TOOO: Sign the message | ||||||
|  |         var signedMessage = new SignedChatMessage(message, sender.ToUserData()) | ||||||
|  |         { | ||||||
|  |             Timestamp = 0, | ||||||
|  |             Signature = "", | ||||||
|  |         }; | ||||||
|  |  | ||||||
|  |         await Clients.Users(groupPairs.Select(p => p.GroupUserUID)).Client_GroupChatMsg(new(new(group.ToGroupData()), signedMessage)).ConfigureAwait(false); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -1,5 +1,6 @@ | |||||||
| using MareSynchronos.API.Data.Enum; | using MareSynchronos.API.Data.Enum; | ||||||
| using MareSynchronos.API.Dto; | using MareSynchronos.API.Dto; | ||||||
|  | using MareSynchronos.API.Dto.Chat; | ||||||
| using MareSynchronos.API.Dto.Group; | using MareSynchronos.API.Dto.Group; | ||||||
| using MareSynchronos.API.Dto.User; | using MareSynchronos.API.Dto.User; | ||||||
|  |  | ||||||
| @@ -11,6 +12,8 @@ namespace MareSynchronosServer.Hubs | |||||||
|  |  | ||||||
|         public Task Client_GroupChangePermissions(GroupPermissionDto groupPermission) => throw new PlatformNotSupportedException("Calling clientside method on server not supported"); |         public Task Client_GroupChangePermissions(GroupPermissionDto groupPermission) => throw new PlatformNotSupportedException("Calling clientside method on server not supported"); | ||||||
|  |  | ||||||
|  |         public Task Client_GroupChatMsg(GroupChatMsgDto groupChatMsgDto) => throw new PlatformNotSupportedException("Calling clientside method on server not supported"); | ||||||
|  |  | ||||||
|         public Task Client_GroupDelete(GroupDto groupDto) => throw new PlatformNotSupportedException("Calling clientside method on server not supported"); |         public Task Client_GroupDelete(GroupDto groupDto) => throw new PlatformNotSupportedException("Calling clientside method on server not supported"); | ||||||
|  |  | ||||||
|         public Task Client_GroupPairChangePermissions(GroupPairUserPermissionDto permissionDto) => throw new PlatformNotSupportedException("Calling clientside method on server not supported"); |         public Task Client_GroupPairChangePermissions(GroupPairUserPermissionDto permissionDto) => throw new PlatformNotSupportedException("Calling clientside method on server not supported"); | ||||||
| @@ -31,6 +34,8 @@ namespace MareSynchronosServer.Hubs | |||||||
|  |  | ||||||
|         public Task Client_UserAddClientPair(UserPairDto dto) => throw new PlatformNotSupportedException("Calling clientside method on server not supported"); |         public Task Client_UserAddClientPair(UserPairDto dto) => throw new PlatformNotSupportedException("Calling clientside method on server not supported"); | ||||||
|  |  | ||||||
|  |         public Task Client_UserChatMsg(UserChatMsgDto userChatMsgDto) => throw new PlatformNotSupportedException("Calling clientside method on server not supported"); | ||||||
|  |  | ||||||
|         public Task Client_UserReceiveCharacterData(OnlineUserCharaDataDto dataDto) => throw new PlatformNotSupportedException("Calling clientside method on server not supported"); |         public Task Client_UserReceiveCharacterData(OnlineUserCharaDataDto dataDto) => throw new PlatformNotSupportedException("Calling clientside method on server not supported"); | ||||||
|  |  | ||||||
|         public Task Client_UserReceiveUploadStatus(UserDto dto) => throw new PlatformNotSupportedException("Calling clientside method on server not supported"); |         public Task Client_UserReceiveUploadStatus(UserDto dto) => throw new PlatformNotSupportedException("Calling clientside method on server not supported"); | ||||||
|   | |||||||
| @@ -1,5 +1,7 @@ | |||||||
| using MareSynchronos.API.Data.Enum; | using MareSynchronos.API.Data; | ||||||
|  | using MareSynchronos.API.Data.Enum; | ||||||
| using MareSynchronos.API.Data.Extensions; | using MareSynchronos.API.Data.Extensions; | ||||||
|  | using MareSynchronos.API.Dto.Chat; | ||||||
| using MareSynchronos.API.Dto.Group; | using MareSynchronos.API.Dto.Group; | ||||||
| using MareSynchronosServer.Utils; | using MareSynchronosServer.Utils; | ||||||
| using MareSynchronosShared.Models; | using MareSynchronosShared.Models; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Loporrit
					Loporrit