♻️ No idea, but errors all gone
This commit is contained in:
@@ -2,7 +2,7 @@ using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json;
|
||||
using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Services;
|
||||
using DysonNetwork.Sphere.Permission;
|
||||
using DysonNetwork.Shared.Permission;
|
||||
using DysonNetwork.Sphere.Publisher;
|
||||
using DysonNetwork.Sphere.Storage;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -33,7 +33,9 @@ public class PostController(
|
||||
{
|
||||
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
|
||||
var currentUser = currentUserValue as Shared.Models.Account;
|
||||
var userFriends = currentUser is null ? [] : await rels.ListAccountFriends(currentUser);
|
||||
var userFriends = currentUser is null
|
||||
? []
|
||||
: (await rels.ListAccountFriends(currentUser)).Select(e => e.Id).ToList();
|
||||
var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(currentUser.Id);
|
||||
|
||||
var publisher = pubName == null ? null : await db.Publishers.FirstOrDefaultAsync(p => p.Name == pubName);
|
||||
@@ -67,8 +69,10 @@ public class PostController(
|
||||
public async Task<ActionResult<Post>> GetPost(Guid id)
|
||||
{
|
||||
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
|
||||
var currentUser = currentUserValue as Shared.Models.Account;
|
||||
var userFriends = currentUser is null ? [] : await rels.ListAccountFriends(currentUser);
|
||||
var currentUser = currentUserValue as Account;
|
||||
var userFriends = currentUser is null
|
||||
? []
|
||||
: (await rels.ListAccountFriends(currentUser)).Select(e => e.Id).ToList();
|
||||
var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(currentUser.Id);
|
||||
|
||||
var post = await db.Posts
|
||||
@@ -99,8 +103,10 @@ public class PostController(
|
||||
return BadRequest("Search query cannot be empty");
|
||||
|
||||
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
|
||||
var currentUser = currentUserValue as Shared.Models.Account;
|
||||
var userFriends = currentUser is null ? [] : await rels.ListAccountFriends(currentUser);
|
||||
var currentUser = currentUserValue as Account;
|
||||
var userFriends = currentUser is null
|
||||
? []
|
||||
: (await rels.ListAccountFriends(currentUser)).Select(e => e.Id).ToList();
|
||||
var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(currentUser.Id);
|
||||
|
||||
var queryable = db.Posts
|
||||
@@ -136,8 +142,10 @@ public class PostController(
|
||||
[FromQuery] int take = 20)
|
||||
{
|
||||
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
|
||||
var currentUser = currentUserValue as Shared.Models.Account;
|
||||
var userFriends = currentUser is null ? [] : await rels.ListAccountFriends(currentUser);
|
||||
var currentUser = currentUserValue as Account;
|
||||
var userFriends = currentUser is null
|
||||
? []
|
||||
: (await rels.ListAccountFriends(currentUser)).Select(e => e.Id).ToList();
|
||||
var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(currentUser.Id);
|
||||
|
||||
var parent = await db.Posts
|
||||
@@ -264,9 +272,12 @@ public class PostController(
|
||||
return BadRequest(err.Message);
|
||||
}
|
||||
|
||||
als.CreateActionLogFromRequest(
|
||||
await als.CreateActionLogFromRequest(
|
||||
ActionLogType.PostCreate,
|
||||
new Dictionary<string, object> { { "post_id", post.Id } }, Request
|
||||
new Dictionary<string, object> { { "post_id", post.Id } },
|
||||
Request.HttpContext.Connection.RemoteIpAddress?.ToString(),
|
||||
Request.Headers.UserAgent.ToString(),
|
||||
currentUser
|
||||
);
|
||||
|
||||
return post;
|
||||
@@ -280,12 +291,12 @@ public class PostController(
|
||||
|
||||
[HttpPost("{id:guid}/reactions")]
|
||||
[Authorize]
|
||||
[RequiredPermissionAttribute("global", "posts.react")]
|
||||
[RequiredPermission("global", "posts.react")]
|
||||
public async Task<ActionResult<PostReaction>> ReactPost(Guid id, [FromBody] PostReactionRequest request)
|
||||
{
|
||||
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
|
||||
if (currentUserValue is not Shared.Models.Account currentUser) return Unauthorized();
|
||||
var userFriends = await rels.ListAccountFriends(currentUser);
|
||||
if (currentUserValue is not Account currentUser) return Unauthorized();
|
||||
var userFriends = (await rels.ListAccountFriends(currentUser)).Select(e => e.Id).ToList();
|
||||
var userPublishers = await pub.GetUserPublishers(currentUser.Id);
|
||||
|
||||
var post = await db.Posts
|
||||
@@ -319,9 +330,12 @@ public class PostController(
|
||||
|
||||
if (isRemoving) return NoContent();
|
||||
|
||||
als.CreateActionLogFromRequest(
|
||||
await als.CreateActionLogFromRequest(
|
||||
ActionLogType.PostReact,
|
||||
new Dictionary<string, object> { { "post_id", post.Id }, { "reaction", request.Symbol } }, Request
|
||||
new Dictionary<string, object> { { "post_id", post.Id }, { "reaction", request.Symbol } },
|
||||
Request.HttpContext.Connection.RemoteIpAddress?.ToString(),
|
||||
Request.Headers.UserAgent.ToString(),
|
||||
currentUser
|
||||
);
|
||||
|
||||
return Ok(reaction);
|
||||
@@ -368,9 +382,12 @@ public class PostController(
|
||||
return BadRequest(err.Message);
|
||||
}
|
||||
|
||||
als.CreateActionLogFromRequest(
|
||||
await als.CreateActionLogFromRequest(
|
||||
ActionLogType.PostUpdate,
|
||||
new Dictionary<string, object> { { "post_id", post.Id } }, Request
|
||||
new Dictionary<string, object> { { "post_id", post.Id } },
|
||||
Request.HttpContext.Connection.RemoteIpAddress?.ToString(),
|
||||
Request.Headers.UserAgent.ToString(),
|
||||
currentUser
|
||||
);
|
||||
|
||||
return Ok(post);
|
||||
@@ -392,9 +409,12 @@ public class PostController(
|
||||
|
||||
await ps.DeletePostAsync(post);
|
||||
|
||||
als.CreateActionLogFromRequest(
|
||||
await als.CreateActionLogFromRequest(
|
||||
ActionLogType.PostDelete,
|
||||
new Dictionary<string, object> { { "post_id", post.Id } }, Request
|
||||
new Dictionary<string, object> { { "post_id", post.Id } },
|
||||
Request.HttpContext.Connection.RemoteIpAddress?.ToString(),
|
||||
Request.Headers.UserAgent.ToString(),
|
||||
currentUser
|
||||
);
|
||||
|
||||
return NoContent();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using DysonNetwork.Shared.Cache;
|
||||
using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Localization;
|
||||
using DysonNetwork.Shared.Services;
|
||||
using DysonNetwork.Sphere.Connection.WebReader;
|
||||
using DysonNetwork.Sphere.Localization;
|
||||
using DysonNetwork.Sphere.Publisher;
|
||||
@@ -158,14 +159,13 @@ public partial class PostService(
|
||||
var sender = post.Publisher;
|
||||
using var scope = factory.CreateScope();
|
||||
var pub = scope.ServiceProvider.GetRequiredService<PublisherService>();
|
||||
var nty = scope.ServiceProvider.GetRequiredService<NotificationService>();
|
||||
var logger = scope.ServiceProvider.GetRequiredService<ILogger<PostService>>();
|
||||
var nty = scope.ServiceProvider.GetRequiredService<INotificationService>();
|
||||
try
|
||||
{
|
||||
var members = await pub.GetPublisherMembers(post.RepliedPost.PublisherId);
|
||||
foreach (var member in members)
|
||||
{
|
||||
AccountService.SetCultureInfo(member.Account);
|
||||
CultureInfoService.SetCultureInfo(member.Account);
|
||||
var (_, content) = ChopPostForNotification(post);
|
||||
await nty.SendNotification(
|
||||
member.Account,
|
||||
@@ -439,14 +439,14 @@ public partial class PostService(
|
||||
{
|
||||
using var scope = factory.CreateScope();
|
||||
var pub = scope.ServiceProvider.GetRequiredService<PublisherService>();
|
||||
var nty = scope.ServiceProvider.GetRequiredService<NotificationService>();
|
||||
var nty = scope.ServiceProvider.GetRequiredService<INotificationService>();
|
||||
var logger = scope.ServiceProvider.GetRequiredService<ILogger<PostService>>();
|
||||
try
|
||||
{
|
||||
var members = await pub.GetPublisherMembers(post.PublisherId);
|
||||
foreach (var member in members)
|
||||
{
|
||||
AccountService.SetCultureInfo(member.Account);
|
||||
CultureInfoService.SetCultureInfo(member.Account);
|
||||
await nty.SendNotification(
|
||||
member.Account,
|
||||
"posts.reactions.new",
|
||||
|
||||
Reference in New Issue
Block a user