From e384763faf799e371c7333b2e7752263b5231934 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 16 Aug 2025 01:12:38 +0800 Subject: [PATCH] :rotating_light: Fix complier warnings --- DysonNetwork.Develop/AppDatabase.cs | 10 ++-- DysonNetwork.Develop/Identity/CustomApp.cs | 9 ++-- DysonNetwork.Drive/Storage/CloudFile.cs | 8 +-- DysonNetwork.Drive/Storage/FileService.cs | 29 +++++++---- DysonNetwork.Pusher/AppDatabase.cs | 4 +- .../Notification/NotificationController.cs | 4 +- DysonNetwork.Sphere/AppDatabase.cs | 50 +++++++++---------- DysonNetwork.Sphere/Chat/ChatRoom.cs | 10 ++-- .../Chat/ChatRoomController.cs | 2 +- DysonNetwork.Sphere/Chat/ChatService.cs | 4 +- DysonNetwork.Sphere/PageData/PostPageData.cs | 5 +- DysonNetwork.Sphere/Post/PostController.cs | 7 +-- 12 files changed, 75 insertions(+), 67 deletions(-) diff --git a/DysonNetwork.Develop/AppDatabase.cs b/DysonNetwork.Develop/AppDatabase.cs index 07ce308..af17c2c 100644 --- a/DysonNetwork.Develop/AppDatabase.cs +++ b/DysonNetwork.Develop/AppDatabase.cs @@ -9,11 +9,11 @@ public class AppDatabase( IConfiguration configuration ) : DbContext(options) { - public DbSet Developers { get; set; } - - public DbSet CustomApps { get; set; } - public DbSet CustomAppSecrets { get; set; } - + public DbSet Developers { get; set; } = null!; + + public DbSet CustomApps { get; set; } = null!; + public DbSet CustomAppSecrets { get; set; } = null!; + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseNpgsql( diff --git a/DysonNetwork.Develop/Identity/CustomApp.cs b/DysonNetwork.Develop/Identity/CustomApp.cs index 59cab28..7f63632 100644 --- a/DysonNetwork.Develop/Identity/CustomApp.cs +++ b/DysonNetwork.Develop/Identity/CustomApp.cs @@ -8,9 +8,6 @@ using Google.Protobuf.WellKnownTypes; using NodaTime.Serialization.Protobuf; using NodaTime; -using DysonNetwork.Shared.Proto; -using Google.Protobuf.WellKnownTypes; -using NodaTime.Serialization.Protobuf; using VerificationMark = DysonNetwork.Shared.Data.VerificationMark; namespace DysonNetwork.Develop.Identity; @@ -134,8 +131,8 @@ public class CustomAppSecret : ModelBase public Guid AppId { get; set; } public CustomApp App { get; set; } = null!; - - + + public static CustomAppSecret FromProtoValue(DysonNetwork.Shared.Proto.CustomAppSecret p) { return new CustomAppSecret @@ -161,4 +158,4 @@ public class CustomAppSecret : ModelBase AppId = Id.ToString(), }; } -} \ No newline at end of file +} diff --git a/DysonNetwork.Drive/Storage/CloudFile.cs b/DysonNetwork.Drive/Storage/CloudFile.cs index d742547..9f198da 100644 --- a/DysonNetwork.Drive/Storage/CloudFile.cs +++ b/DysonNetwork.Drive/Storage/CloudFile.cs @@ -45,7 +45,7 @@ public class CloudFile : ModelBase, ICloudFile, IIdentifiedResource /// The object name which stored remotely, /// multiple cloud file may have same storage id to indicate they are the same file - /// + /// /// If the storage id was null and the uploaded at is not null, means it is an embedding file, /// The embedding file means the file is store on another site, /// or it is a webpage (based on mimetype) @@ -72,8 +72,8 @@ public class CloudFile : ModelBase, ICloudFile, IIdentifiedResource DeletedAt = DeletedAt, Id = Id, Name = Name, - FileMeta = FileMeta, - UserMeta = UserMeta, + FileMeta = FileMeta ?? [], + UserMeta = UserMeta ?? [], SensitiveMarks = SensitiveMarks, MimeType = MimeType, Hash = Hash, @@ -141,4 +141,4 @@ public class CloudFileReference : ModelBase ExpiredAt = ExpiredAt?.ToTimestamp() }; } -} \ No newline at end of file +} diff --git a/DysonNetwork.Drive/Storage/FileService.cs b/DysonNetwork.Drive/Storage/FileService.cs index 8844adc..15d1fe3 100644 --- a/DysonNetwork.Drive/Storage/FileService.cs +++ b/DysonNetwork.Drive/Storage/FileService.cs @@ -20,7 +20,6 @@ namespace DysonNetwork.Drive.Storage; public class FileService( AppDatabase db, IConfiguration configuration, - TusDiskStore store, ILogger logger, IServiceScopeFactory scopeFactory, ICacheService cache @@ -268,14 +267,26 @@ public class FileService( // Add detailed stream information ["video_streams"] = mediaInfo.VideoStreams.Select(s => new { - s.AvgFrameRate, s.BitRate, s.CodecName, s.Duration, s.Height, s.Width, s.Language, - s.PixelFormat, s.Rotation + s.AvgFrameRate, + s.BitRate, + s.CodecName, + s.Duration, + s.Height, + s.Width, + s.Language, + s.PixelFormat, + s.Rotation }).Where(s => double.IsNormal(s.AvgFrameRate)).ToList(), ["audio_streams"] = mediaInfo.AudioStreams.Select(s => new - { - s.BitRate, s.Channels, s.ChannelLayout, s.CodecName, s.Duration, s.Language, - s.SampleRateHz - }) + { + s.BitRate, + s.Channels, + s.ChannelLayout, + s.CodecName, + s.Duration, + s.Language, + s.SampleRateHz + }) .ToList(), }; if (mediaInfo.PrimaryVideoStream is not null) @@ -319,7 +330,7 @@ public class FileService( try { logger.LogInformation("Processing file {FileId} in background...", fileId); - + var fileExtension = Path.GetExtension(originalFilePath); if (!pool.PolicyConfig.NoOptimization) @@ -869,4 +880,4 @@ file class UpdatableCloudFile(CloudFile file) .SetProperty(f => f.UserMeta, userMeta!) .SetProperty(f => f.IsMarkedRecycle, IsMarkedRecycle); } -} \ No newline at end of file +} diff --git a/DysonNetwork.Pusher/AppDatabase.cs b/DysonNetwork.Pusher/AppDatabase.cs index 7f247d5..422c208 100644 --- a/DysonNetwork.Pusher/AppDatabase.cs +++ b/DysonNetwork.Pusher/AppDatabase.cs @@ -16,7 +16,7 @@ public class AppDatabase( ) : DbContext(options) { public DbSet Notifications { get; set; } = null!; - public DbSet PushSubscriptions { get; set; } + public DbSet PushSubscriptions { get; set; } = null!; protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { @@ -175,4 +175,4 @@ public static class OptionalQueryExtensions { return condition ? transform(source) : source; } -} \ No newline at end of file +} diff --git a/DysonNetwork.Pusher/Notification/NotificationController.cs b/DysonNetwork.Pusher/Notification/NotificationController.cs index 8aac56f..2df3465 100644 --- a/DysonNetwork.Pusher/Notification/NotificationController.cs +++ b/DysonNetwork.Pusher/Notification/NotificationController.cs @@ -127,7 +127,7 @@ public class NotificationController( [Required][MaxLength(1024)] public string Title { get; set; } = null!; [MaxLength(2048)] public string? Subtitle { get; set; } [Required][MaxLength(4096)] public string Content { get; set; } = null!; - public Dictionary? Meta { get; set; } + public Dictionary? Meta { get; set; } public int Priority { get; set; } = 10; } @@ -153,7 +153,7 @@ public class NotificationController( Title = request.Title, Subtitle = request.Subtitle, Content = request.Content, - Meta = request.Meta, + Meta = request.Meta ?? [], }, request.AccountId, save diff --git a/DysonNetwork.Sphere/AppDatabase.cs b/DysonNetwork.Sphere/AppDatabase.cs index 05842e9..241e43c 100644 --- a/DysonNetwork.Sphere/AppDatabase.cs +++ b/DysonNetwork.Sphere/AppDatabase.cs @@ -24,37 +24,37 @@ public class AppDatabase( IConfiguration configuration ) : DbContext(options) { - public DbSet Publishers { get; set; } - public DbSet PublisherMembers { get; set; } - public DbSet PublisherSubscriptions { get; set; } - public DbSet PublisherFeatures { get; set; } + public DbSet Publishers { get; set; } = null!; + public DbSet PublisherMembers { get; set; } = null!; + public DbSet PublisherSubscriptions { get; set; } = null!; + public DbSet PublisherFeatures { get; set; } = null!; - public DbSet Posts { get; set; } - public DbSet PostReactions { get; set; } - public DbSet PostTags { get; set; } - public DbSet PostCategories { get; set; } - public DbSet PostCollections { get; set; } - public DbSet PostFeaturedRecords { get; set; } + public DbSet Posts { get; set; } = null!; + public DbSet PostReactions { get; set; } = null!; + public DbSet PostTags { get; set; } = null!; + public DbSet PostCategories { get; set; } = null!; + public DbSet PostCollections { get; set; } = null!; + public DbSet PostFeaturedRecords { get; set; } = null!; - public DbSet Polls { get; set; } - public DbSet PollQuestions { get; set; } - public DbSet PollAnswers { get; set; } + public DbSet Polls { get; set; } = null!; + public DbSet PollQuestions { get; set; } = null!; + public DbSet PollAnswers { get; set; } = null!; - public DbSet Realms { get; set; } - public DbSet RealmMembers { get; set; } + public DbSet Realms { get; set; } = null!; + public DbSet RealmMembers { get; set; } = null!; - public DbSet ChatRooms { get; set; } - public DbSet ChatMembers { get; set; } - public DbSet ChatMessages { get; set; } - public DbSet ChatRealtimeCall { get; set; } - public DbSet ChatReactions { get; set; } + public DbSet ChatRooms { get; set; } = null!; + public DbSet ChatMembers { get; set; } = null!; + public DbSet ChatMessages { get; set; } = null!; + public DbSet ChatRealtimeCall { get; set; } = null!; + public DbSet ChatReactions { get; set; } = null!; - public DbSet Stickers { get; set; } - public DbSet StickerPacks { get; set; } - public DbSet StickerPackOwnerships { get; set; } + public DbSet Stickers { get; set; } = null!; + public DbSet StickerPacks { get; set; } = null!; + public DbSet StickerPackOwnerships { get; set; } = null!; - public DbSet WebArticles { get; set; } - public DbSet WebFeeds { get; set; } + public DbSet WebArticles { get; set; } = null!; + public DbSet WebFeeds { get; set; } = null!; protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { diff --git a/DysonNetwork.Sphere/Chat/ChatRoom.cs b/DysonNetwork.Sphere/Chat/ChatRoom.cs index 1d32ad6..d619cba 100644 --- a/DysonNetwork.Sphere/Chat/ChatRoom.cs +++ b/DysonNetwork.Sphere/Chat/ChatRoom.cs @@ -25,7 +25,7 @@ public class ChatRoom : ModelBase, IIdentifiedResource // Outdated fields, for backward compability [MaxLength(32)] public string? PictureId { get; set; } [MaxLength(32)] public string? BackgroundId { get; set; } - + [Column(TypeName = "jsonb")] public CloudFileReferenceObject? Picture { get; set; } [Column(TypeName = "jsonb")] public CloudFileReferenceObject? Background { get; set; } @@ -84,7 +84,7 @@ public class ChatMember : ModelBase public Instant? JoinedAt { get; set; } public Instant? LeaveAt { get; set; } public bool IsBot { get; set; } = false; - + /// /// The break time is the user doesn't receive any message from this member for a while. /// Expect mentioned him or her. @@ -115,7 +115,7 @@ public class ChatMemberTransmissionObject : ModelBase public Instant? JoinedAt { get; set; } public Instant? LeaveAt { get; set; } public bool IsBot { get; set; } = false; - + public Instant? BreakUntil { get; set; } public Instant? TimeoutUntil { get; set; } public ChatTimeoutCause? TimeoutCause { get; set; } @@ -127,7 +127,7 @@ public class ChatMemberTransmissionObject : ModelBase Id = member.Id, ChatRoomId = member.ChatRoomId, AccountId = member.AccountId, - Account = member.Account, + Account = member.Account!, Nick = member.Nick, Role = member.Role, Notify = member.Notify, @@ -142,4 +142,4 @@ public class ChatMemberTransmissionObject : ModelBase DeletedAt = member.DeletedAt }; } -} \ No newline at end of file +} diff --git a/DysonNetwork.Sphere/Chat/ChatRoomController.cs b/DysonNetwork.Sphere/Chat/ChatRoomController.cs index bc6191c..7f2a737 100644 --- a/DysonNetwork.Sphere/Chat/ChatRoomController.cs +++ b/DysonNetwork.Sphere/Chat/ChatRoomController.cs @@ -970,7 +970,7 @@ public class ChatRoomController( ? localizer["ChatInviteDirectBody", sender.Nick] : localizer["ChatInviteBody", member.ChatRoom.Name ?? "Unnamed"]; - CultureService.SetCultureInfo(member.Account.Language); + CultureService.SetCultureInfo(member.Account!.Language); await pusher.SendPushNotificationToUserAsync( new SendPushNotificationToUserRequest { diff --git a/DysonNetwork.Sphere/Chat/ChatService.cs b/DysonNetwork.Sphere/Chat/ChatService.cs index 87ac24a..a21d322 100644 --- a/DysonNetwork.Sphere/Chat/ChatService.cs +++ b/DysonNetwork.Sphere/Chat/ChatService.cs @@ -383,7 +383,7 @@ public partial class ChatService( // Get keys of messages to remove (where sender is not found) var messagesToRemove = messages - .Where(m => messageSenders.All(s => s.Id != m.Value.SenderId)) + .Where(m => messageSenders.All(s => s.Id != m.Value!.SenderId)) .Select(m => m.Key) .ToList(); @@ -647,4 +647,4 @@ public class SyncResponse { public List Changes { get; set; } = []; public Instant CurrentTimestamp { get; set; } -} \ No newline at end of file +} diff --git a/DysonNetwork.Sphere/PageData/PostPageData.cs b/DysonNetwork.Sphere/PageData/PostPageData.cs index 3592a32..ff8e513 100644 --- a/DysonNetwork.Sphere/PageData/PostPageData.cs +++ b/DysonNetwork.Sphere/PageData/PostPageData.cs @@ -2,7 +2,6 @@ using System.Net; using DysonNetwork.Shared.PageData; using DysonNetwork.Shared.Proto; using DysonNetwork.Sphere.Post; -using DysonNetwork.Sphere.Publisher; using Microsoft.EntityFrameworkCore; using OpenGraphNet; @@ -39,7 +38,7 @@ public class PostPageData( if (currentUser != null) { var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest - { AccountId = currentUser.Id }); + { AccountId = currentUser.Id }); userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList(); } @@ -72,4 +71,4 @@ public class PostPageData( ["OpenGraph"] = og }; } -} \ No newline at end of file +} diff --git a/DysonNetwork.Sphere/Post/PostController.cs b/DysonNetwork.Sphere/Post/PostController.cs index f28673c..6661807 100644 --- a/DysonNetwork.Sphere/Post/PostController.cs +++ b/DysonNetwork.Sphere/Post/PostController.cs @@ -216,9 +216,10 @@ public class PostController( if (useVector) queryable = queryable.Where(p => p.SearchVector.Matches(EF.Functions.ToTsQuery(query))); else - queryable = queryable.Where(p => EF.Functions.ILike(p.Title, $"%{query}%") || - EF.Functions.ILike(p.Description, $"%{query}%") || - EF.Functions.ILike(p.Content, $"%{query}%") + queryable = queryable.Where(p => + (p.Title != null && EF.Functions.ILike(p.Title, $"%{query}%")) || + (p.Description != null && EF.Functions.ILike(p.Description, $"%{query}%")) || + (p.Content != null && EF.Functions.ILike(p.Content, $"%{query}%")) ); var totalCount = await queryable.CountAsync();