🚨 Fix warnings in the codebase
This commit is contained in:
@@ -6,7 +6,7 @@ namespace DysonNetwork.Pass.Account;
|
|||||||
|
|
||||||
public class ActionLogService(GeoIpService geo, FlushBufferService fbs)
|
public class ActionLogService(GeoIpService geo, FlushBufferService fbs)
|
||||||
{
|
{
|
||||||
public void CreateActionLog(Guid accountId, string action, Dictionary<string, object?> meta)
|
public void CreateActionLog(Guid accountId, string action, Dictionary<string, object> meta)
|
||||||
{
|
{
|
||||||
var log = new SnActionLog
|
var log = new SnActionLog
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ public class ActionLogServiceGrpc : Shared.Proto.ActionLogService.ActionLogServi
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var meta = request.Meta
|
var meta = request.Meta
|
||||||
?.Select(x => new KeyValuePair<string, object?>(x.Key, GrpcTypeHelper.ConvertValueToObject(x.Value)))
|
?.Select(x => new KeyValuePair<string, object>(x.Key, GrpcTypeHelper.ConvertValueToObject(x.Value)))
|
||||||
.ToDictionary() ?? new Dictionary<string, object?>();
|
.ToDictionary() ?? new Dictionary<string, object>();
|
||||||
|
|
||||||
_actionLogService.CreateActionLog(
|
_actionLogService.CreateActionLog(
|
||||||
accountId,
|
accountId,
|
||||||
@@ -41,6 +41,7 @@ public class ActionLogServiceGrpc : Shared.Proto.ActionLogService.ActionLogServi
|
|||||||
meta
|
meta
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await Task.CompletedTask;
|
||||||
return new CreateActionLogResponse();
|
return new CreateActionLogResponse();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
|
|
||||||
namespace DysonNetwork.Pass.Leveling;
|
namespace DysonNetwork.Pass.Leveling;
|
||||||
|
|
||||||
public class ExperienceService(AppDatabase db, SubscriptionService subscriptions, ICacheService cache)
|
public class ExperienceService(AppDatabase db, SubscriptionService subscriptions)
|
||||||
{
|
{
|
||||||
public async Task<SnExperienceRecord> AddRecord(string reasonType, string reason, long delta, Guid accountId)
|
public async Task<SnExperienceRecord> AddRecord(string reasonType, string reason, long delta, Guid accountId)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ using Quartz;
|
|||||||
namespace DysonNetwork.Pass.Wallet;
|
namespace DysonNetwork.Pass.Wallet;
|
||||||
|
|
||||||
public class FundExpirationJob(
|
public class FundExpirationJob(
|
||||||
AppDatabase db,
|
|
||||||
PaymentService paymentService,
|
PaymentService paymentService,
|
||||||
ILogger<FundExpirationJob> logger
|
ILogger<FundExpirationJob> logger
|
||||||
) : IJob
|
) : IJob
|
||||||
|
|||||||
@@ -343,7 +343,7 @@ public class ActivityService(
|
|||||||
|
|
||||||
private static async Task LoadPostsRealmsAsync(List<SnPost> posts, RemoteRealmService rs)
|
private static async Task LoadPostsRealmsAsync(List<SnPost> posts, RemoteRealmService rs)
|
||||||
{
|
{
|
||||||
var postRealmIds = posts.Where(p => p.RealmId != null).Select(p => p.RealmId.Value).Distinct().ToList();
|
var postRealmIds = posts.Where(p => p.RealmId != null).Select(p => p.RealmId!.Value).Distinct().ToList();
|
||||||
if (!postRealmIds.Any()) return;
|
if (!postRealmIds.Any()) return;
|
||||||
|
|
||||||
var realms = await rs.GetRealmBatch(postRealmIds.Select(id => id.ToString()).ToList());
|
var realms = await rs.GetRealmBatch(postRealmIds.Select(id => id.ToString()).ToList());
|
||||||
@@ -351,7 +351,7 @@ public class ActivityService(
|
|||||||
|
|
||||||
foreach (var post in posts.Where(p => p.RealmId != null))
|
foreach (var post in posts.Where(p => p.RealmId != null))
|
||||||
{
|
{
|
||||||
if (post.RealmId != null && realmDict.TryGetValue(post.RealmId.Value, out var realm))
|
if (realmDict.TryGetValue(post.RealmId!.Value, out var realm))
|
||||||
{
|
{
|
||||||
post.Realm = realm;
|
post.Realm = realm;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ public class PostController(
|
|||||||
|
|
||||||
private static async Task LoadPostsRealmsAsync(List<SnPost> posts, RemoteRealmService rs)
|
private static async Task LoadPostsRealmsAsync(List<SnPost> posts, RemoteRealmService rs)
|
||||||
{
|
{
|
||||||
var postRealmIds = posts.Where(p => p.RealmId != null).Select(p => p.RealmId.Value).Distinct().ToList();
|
var postRealmIds = posts.Where(p => p.RealmId != null).Select(p => p.RealmId!.Value).Distinct().ToList();
|
||||||
if (!postRealmIds.Any()) return;
|
if (!postRealmIds.Any()) return;
|
||||||
|
|
||||||
var realms = await rs.GetRealmBatch(postRealmIds.Select(id => id.ToString()).ToList());
|
var realms = await rs.GetRealmBatch(postRealmIds.Select(id => id.ToString()).ToList());
|
||||||
@@ -205,7 +205,7 @@ public class PostController(
|
|||||||
|
|
||||||
foreach (var post in posts.Where(p => p.RealmId != null))
|
foreach (var post in posts.Where(p => p.RealmId != null))
|
||||||
{
|
{
|
||||||
if (post.RealmId != null && realmDict.TryGetValue(post.RealmId.Value, out var realm))
|
if (realmDict.TryGetValue(post.RealmId!.Value, out var realm))
|
||||||
{
|
{
|
||||||
post.Realm = realm;
|
post.Realm = realm;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using DysonNetwork.Shared.Proto;
|
|||||||
using DysonNetwork.Shared.Models;
|
using DysonNetwork.Shared.Models;
|
||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using NodaTime.Serialization.Protobuf;
|
||||||
|
|
||||||
namespace DysonNetwork.Sphere.Post;
|
namespace DysonNetwork.Sphere.Post;
|
||||||
|
|
||||||
@@ -29,7 +30,8 @@ public class PostServiceGrpc(AppDatabase db, PostService ps) : Shared.Proto.Post
|
|||||||
return post.ToProtoValue();
|
return post.ToProtoValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<GetPostBatchResponse> GetPostBatch(GetPostBatchRequest request, ServerCallContext context)
|
public override async Task<GetPostBatchResponse> GetPostBatch(GetPostBatchRequest request,
|
||||||
|
ServerCallContext context)
|
||||||
{
|
{
|
||||||
var ids = request.Ids
|
var ids = request.Ids
|
||||||
.Where(s => !string.IsNullOrWhiteSpace(s) && Guid.TryParse(s, out _))
|
.Where(s => !string.IsNullOrWhiteSpace(s) && Guid.TryParse(s, out _))
|
||||||
@@ -76,9 +78,9 @@ public class PostServiceGrpc(AppDatabase db, PostService ps) : Shared.Proto.Post
|
|||||||
{
|
{
|
||||||
// Simple search, assuming full-text search or title/content contains
|
// Simple search, assuming full-text search or title/content contains
|
||||||
query = query.Where(p =>
|
query = query.Where(p =>
|
||||||
EF.Functions.ILike(p.Title, $"%{request.Query}%") ||
|
(p.Title != null && EF.Functions.ILike(p.Title, $"%{request.Query}%")) ||
|
||||||
EF.Functions.ILike(p.Content, $"%{request.Query}%") ||
|
(p.Content != null && EF.Functions.ILike(p.Content, $"%{request.Query}%")) ||
|
||||||
EF.Functions.ILike(p.Description, $"%{request.Query}%"));
|
(p.Description != null && EF.Functions.ILike(p.Description, $"%{request.Query}%")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(request.PublisherId) && Guid.TryParse(request.PublisherId, out var pid))
|
if (!string.IsNullOrWhiteSpace(request.PublisherId) && Guid.TryParse(request.PublisherId, out var pid))
|
||||||
@@ -163,30 +165,16 @@ public class PostServiceGrpc(AppDatabase db, PostService ps) : Shared.Proto.Post
|
|||||||
query = query.Where(e => e.Attachments.Count > 0);
|
query = query.Where(e => e.Attachments.Count > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinned filtering
|
query = request.Pinned switch
|
||||||
switch (request.Pinned)
|
|
||||||
{
|
{
|
||||||
case Shared.Proto.PostPinMode.RealmPage when !string.IsNullOrWhiteSpace(request.RealmId):
|
// Pinned filtering
|
||||||
query = query.Where(p => p.PinMode == Shared.Models.PostPinMode.RealmPage);
|
Shared.Proto.PostPinMode.RealmPage when !string.IsNullOrWhiteSpace(request.RealmId) => query.Where(p =>
|
||||||
break;
|
p.PinMode == Shared.Models.PostPinMode.RealmPage),
|
||||||
case Shared.Proto.PostPinMode.PublisherPage when !string.IsNullOrWhiteSpace(request.PublisherId):
|
Shared.Proto.PostPinMode.PublisherPage when !string.IsNullOrWhiteSpace(request.PublisherId) =>
|
||||||
query = query.Where(p => p.PinMode == Shared.Models.PostPinMode.PublisherPage);
|
query.Where(p => p.PinMode == Shared.Models.PostPinMode.PublisherPage),
|
||||||
break;
|
Shared.Proto.PostPinMode.ReplyPage => query.Where(p => p.PinMode == Shared.Models.PostPinMode.ReplyPage),
|
||||||
case Shared.Proto.PostPinMode.ReplyPage:
|
_ => query.Where(p => p.PinMode == (Shared.Models.PostPinMode)request.Pinned)
|
||||||
query = query.Where(p => p.PinMode == Shared.Models.PostPinMode.ReplyPage);
|
};
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (request.Pinned != null)
|
|
||||||
{
|
|
||||||
// Specific pinned mode but conditions not met, or unknown mode
|
|
||||||
query = query.Where(p => p.PinMode == (Shared.Models.PostPinMode)request.Pinned);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
query = query.Where(p => p.PinMode == null);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Include/exclude replies
|
// Include/exclude replies
|
||||||
if (request.IncludeReplies)
|
if (request.IncludeReplies)
|
||||||
@@ -199,27 +187,25 @@ public class PostServiceGrpc(AppDatabase db, PostService ps) : Shared.Proto.Post
|
|||||||
query = query.Where(e => e.RepliedPostId == null);
|
query = query.Where(e => e.RepliedPostId == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Time range filtering when proto fields are available
|
if (request.After != null)
|
||||||
// if (request.After != null)
|
{
|
||||||
// {
|
var afterTime = request.After.ToInstant();
|
||||||
// var afterTime = request.After.ToDateTimeOffset();
|
query = query.Where(p => (p.CreatedAt >= afterTime) || (p.PublishedAt >= afterTime));
|
||||||
// query = query.Where(p => (p.CreatedAt >= afterTime) || (p.PublishedAt >= afterTime));
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// if (request.Before != null)
|
if (request.Before != null)
|
||||||
// {
|
{
|
||||||
// var beforeTime = request.Before.ToDateTimeOffset();
|
var beforeTime = request.Before.ToInstant();
|
||||||
// query = query.Where(p => (p.CreatedAt <= beforeTime) || (p.PublishedAt <= beforeTime));
|
query = query.Where(p => (p.CreatedAt <= beforeTime) || (p.PublishedAt <= beforeTime));
|
||||||
// }
|
}
|
||||||
|
|
||||||
// TODO: Query text search when proto field is available
|
if (!string.IsNullOrWhiteSpace(request.Query))
|
||||||
// if (!string.IsNullOrWhiteSpace(request.Query))
|
{
|
||||||
// {
|
query = query.Where(p =>
|
||||||
// query = query.Where(p =>
|
(p.Title != null && EF.Functions.ILike(p.Title, $"%{request.Query}%")) ||
|
||||||
// EF.Functions.ILike(p.Title, $"%{request.Query}%") ||
|
(p.Content != null && EF.Functions.ILike(p.Content, $"%{request.Query}%")) ||
|
||||||
// EF.Functions.ILike(p.Content, $"%{request.Query}%") ||
|
(p.Description != null && EF.Functions.ILike(p.Description, $"%{request.Query}%")));
|
||||||
// EF.Functions.ILike(p.Description, $"%{request.Query}%"));
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// Visibility filter (simplified for grpc - no user context)
|
// Visibility filter (simplified for grpc - no user context)
|
||||||
query = query.FilterWithVisibility(null, [], []);
|
query = query.FilterWithVisibility(null, [], []);
|
||||||
@@ -231,7 +217,9 @@ public class PostServiceGrpc(AppDatabase db, PostService ps) : Shared.Proto.Post
|
|||||||
var offset = string.IsNullOrEmpty(pageToken) ? 0 : int.Parse(pageToken);
|
var offset = string.IsNullOrEmpty(pageToken) ? 0 : int.Parse(pageToken);
|
||||||
|
|
||||||
// Ordering - TODO: Add shuffle when proto field is available
|
// Ordering - TODO: Add shuffle when proto field is available
|
||||||
var orderedQuery = query.OrderByDescending(e => e.PublishedAt ?? e.CreatedAt);
|
var orderedQuery = request.Shuffle
|
||||||
|
? query.OrderBy(e => EF.Functions.Random())
|
||||||
|
: query.OrderByDescending(e => e.PublishedAt ?? e.CreatedAt);
|
||||||
|
|
||||||
var posts = await orderedQuery
|
var posts = await orderedQuery
|
||||||
.Skip(offset)
|
.Skip(offset)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using DysonNetwork.Shared.Cache;
|
|||||||
using DysonNetwork.Shared.Models;
|
using DysonNetwork.Shared.Models;
|
||||||
using DysonNetwork.Shared.Proto;
|
using DysonNetwork.Shared.Proto;
|
||||||
using DysonNetwork.Sphere.Localization;
|
using DysonNetwork.Sphere.Localization;
|
||||||
using DysonNetwork.Sphere.Post;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Localization;
|
using Microsoft.Extensions.Localization;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user