🐛 Use new isRelated to query relationship to avoid issues
This commit is contained in:
@@ -51,7 +51,7 @@ public class PostActionController(
|
|||||||
[MaxLength(16)] public List<string>? Tags { get; set; }
|
[MaxLength(16)] public List<string>? Tags { get; set; }
|
||||||
[MaxLength(8)] public List<string>? Categories { get; set; }
|
[MaxLength(8)] public List<string>? Categories { get; set; }
|
||||||
[MaxLength(32)] public List<string>? Attachments { get; set; }
|
[MaxLength(32)] public List<string>? Attachments { get; set; }
|
||||||
|
|
||||||
public Dictionary<string, object>? Meta { get; set; }
|
public Dictionary<string, object>? Meta { get; set; }
|
||||||
public Instant? PublishedAt { get; set; }
|
public Instant? PublishedAt { get; set; }
|
||||||
public Guid? RepliedPostId { get; set; }
|
public Guid? RepliedPostId { get; set; }
|
||||||
@@ -185,7 +185,7 @@ public class PostActionController(
|
|||||||
{
|
{
|
||||||
FundId = request.FundId.Value.ToString()
|
FundId = request.FundId.Value.ToString()
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if the fund was created by the current user
|
// Check if the fund was created by the current user
|
||||||
if (fundResponse.CreatorAccountId != currentUser.Id)
|
if (fundResponse.CreatorAccountId != currentUser.Id)
|
||||||
return BadRequest("You can only share funds that you created.");
|
return BadRequest("You can only share funds that you created.");
|
||||||
@@ -286,7 +286,7 @@ public class PostActionController(
|
|||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
|
|
||||||
var friendsResponse = await accounts.ListFriendsAsync(
|
var friendsResponse = await accounts.ListFriendsAsync(
|
||||||
new ListRelationshipSimpleRequest { AccountId = currentUser.Id.ToString() }
|
new ListRelationshipSimpleRequest { RelatedId = currentUser.Id }
|
||||||
);
|
);
|
||||||
var userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
var userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
||||||
var userPublishers = await pub.GetUserPublishers(Guid.Parse(currentUser.Id));
|
var userPublishers = await pub.GetUserPublishers(Guid.Parse(currentUser.Id));
|
||||||
@@ -305,7 +305,7 @@ public class PostActionController(
|
|||||||
|
|
||||||
var accountId = Guid.Parse(currentUser.Id);
|
var accountId = Guid.Parse(currentUser.Id);
|
||||||
var isSelfReact =
|
var isSelfReact =
|
||||||
post.Publisher.AccountId is not null && post.Publisher.AccountId == accountId;
|
post.Publisher?.AccountId is not null && post.Publisher.AccountId == accountId;
|
||||||
|
|
||||||
var isExistingReaction = await db.PostReactions.AnyAsync(r =>
|
var isExistingReaction = await db.PostReactions.AnyAsync(r =>
|
||||||
r.PostId == post.Id && r.Symbol == request.Symbol && r.AccountId == accountId
|
r.PostId == post.Id && r.Symbol == request.Symbol && r.AccountId == accountId
|
||||||
@@ -454,7 +454,8 @@ public class PostActionController(
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
var accountId = Guid.Parse(currentUser.Id);
|
var accountId = Guid.Parse(currentUser.Id);
|
||||||
if (post.PublisherId == null || !await pub.IsMemberWithRole(post.PublisherId.Value, accountId, PublisherMemberRole.Editor))
|
if (post.PublisherId == null ||
|
||||||
|
!await pub.IsMemberWithRole(post.PublisherId.Value, accountId, PublisherMemberRole.Editor))
|
||||||
return StatusCode(403, "You are not an editor of this publisher");
|
return StatusCode(403, "You are not an editor of this publisher");
|
||||||
|
|
||||||
if (request.Mode == Shared.Models.PostPinMode.RealmPage && post.RealmId != null)
|
if (request.Mode == Shared.Models.PostPinMode.RealmPage && post.RealmId != null)
|
||||||
@@ -518,7 +519,8 @@ public class PostActionController(
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
var accountId = Guid.Parse(currentUser.Id);
|
var accountId = Guid.Parse(currentUser.Id);
|
||||||
if (post.PublisherId == null || !await pub.IsMemberWithRole(post.PublisherId.Value, accountId, PublisherMemberRole.Editor))
|
if (post.PublisherId == null ||
|
||||||
|
!await pub.IsMemberWithRole(post.PublisherId.Value, accountId, PublisherMemberRole.Editor))
|
||||||
return StatusCode(403, "You are not an editor of this publisher");
|
return StatusCode(403, "You are not an editor of this publisher");
|
||||||
|
|
||||||
if (post is { PinMode: Shared.Models.PostPinMode.RealmPage, RealmId: not null })
|
if (post is { PinMode: Shared.Models.PostPinMode.RealmPage, RealmId: not null })
|
||||||
@@ -574,7 +576,7 @@ public class PostActionController(
|
|||||||
return BadRequest("Content is required.");
|
return BadRequest("Content is required.");
|
||||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(request.ThumbnailId) && request.Type != PostType.Article)
|
if (!string.IsNullOrWhiteSpace(request.ThumbnailId) && request.Type != PostType.Article)
|
||||||
return BadRequest("Thumbnail only supported in article.");
|
return BadRequest("Thumbnail only supported in article.");
|
||||||
if (!string.IsNullOrWhiteSpace(request.ThumbnailId) &&
|
if (!string.IsNullOrWhiteSpace(request.ThumbnailId) &&
|
||||||
@@ -675,7 +677,7 @@ public class PostActionController(
|
|||||||
{
|
{
|
||||||
FundId = request.FundId.Value.ToString()
|
FundId = request.FundId.Value.ToString()
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if the fund was created by the current user
|
// Check if the fund was created by the current user
|
||||||
if (fundResponse.CreatorAccountId != currentUser.Id)
|
if (fundResponse.CreatorAccountId != currentUser.Id)
|
||||||
return BadRequest("You can only share funds that you created.");
|
return BadRequest("You can only share funds that you created.");
|
||||||
@@ -746,7 +748,7 @@ public class PostActionController(
|
|||||||
{
|
{
|
||||||
post.RealmId = null;
|
post.RealmId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
post = await ps.UpdatePostAsync(
|
post = await ps.UpdatePostAsync(
|
||||||
@@ -828,4 +830,4 @@ public class PostActionController(
|
|||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,7 +80,7 @@ public class PostController(
|
|||||||
if (currentUser != null)
|
if (currentUser != null)
|
||||||
{
|
{
|
||||||
var friendsResponse = await accounts.ListFriendsAsync(
|
var friendsResponse = await accounts.ListFriendsAsync(
|
||||||
new ListRelationshipSimpleRequest { AccountId = currentUser.Id }
|
new ListRelationshipSimpleRequest { RelatedId = currentUser.Id }
|
||||||
);
|
);
|
||||||
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
||||||
}
|
}
|
||||||
@@ -239,7 +239,7 @@ public class PostController(
|
|||||||
if (currentUser != null)
|
if (currentUser != null)
|
||||||
{
|
{
|
||||||
var friendsResponse = await accounts.ListFriendsAsync(
|
var friendsResponse = await accounts.ListFriendsAsync(
|
||||||
new ListRelationshipSimpleRequest { AccountId = currentUser.Id }
|
new ListRelationshipSimpleRequest { RelatedId = currentUser.Id }
|
||||||
);
|
);
|
||||||
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
||||||
}
|
}
|
||||||
@@ -276,7 +276,7 @@ public class PostController(
|
|||||||
if (currentUser != null)
|
if (currentUser != null)
|
||||||
{
|
{
|
||||||
var friendsResponse = await accounts.ListFriendsAsync(
|
var friendsResponse = await accounts.ListFriendsAsync(
|
||||||
new ListRelationshipSimpleRequest { AccountId = currentUser.Id }
|
new ListRelationshipSimpleRequest { RelatedId = currentUser.Id }
|
||||||
);
|
);
|
||||||
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
||||||
}
|
}
|
||||||
@@ -354,7 +354,7 @@ public class PostController(
|
|||||||
if (currentUser != null)
|
if (currentUser != null)
|
||||||
{
|
{
|
||||||
var friendsResponse = await accounts.ListFriendsAsync(
|
var friendsResponse = await accounts.ListFriendsAsync(
|
||||||
new ListRelationshipSimpleRequest { AccountId = currentUser.Id }
|
new ListRelationshipSimpleRequest { RelatedId = currentUser.Id }
|
||||||
);
|
);
|
||||||
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
||||||
}
|
}
|
||||||
@@ -387,7 +387,7 @@ public class PostController(
|
|||||||
if (currentUser != null)
|
if (currentUser != null)
|
||||||
{
|
{
|
||||||
var friendsResponse = await accounts.ListFriendsAsync(
|
var friendsResponse = await accounts.ListFriendsAsync(
|
||||||
new ListRelationshipSimpleRequest { AccountId = currentUser.Id }
|
new ListRelationshipSimpleRequest { RelatedId = currentUser.Id }
|
||||||
);
|
);
|
||||||
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
||||||
}
|
}
|
||||||
@@ -396,9 +396,8 @@ public class PostController(
|
|||||||
? []
|
? []
|
||||||
: await pub.GetUserPublishers(Guid.Parse(currentUser.Id));
|
: await pub.GetUserPublishers(Guid.Parse(currentUser.Id));
|
||||||
|
|
||||||
var now = SystemClock.Instance.GetCurrentInstant();
|
var posts = await db.Posts
|
||||||
var posts = await db
|
.Where(e =>
|
||||||
.Posts.Where(e =>
|
|
||||||
e.RepliedPostId == id && e.PinMode == Shared.Models.PostPinMode.ReplyPage
|
e.RepliedPostId == id && e.PinMode == Shared.Models.PostPinMode.ReplyPage
|
||||||
)
|
)
|
||||||
.OrderByDescending(p => p.CreatedAt)
|
.OrderByDescending(p => p.CreatedAt)
|
||||||
@@ -423,7 +422,7 @@ public class PostController(
|
|||||||
if (currentUser != null)
|
if (currentUser != null)
|
||||||
{
|
{
|
||||||
var friendsResponse = await accounts.ListFriendsAsync(
|
var friendsResponse = await accounts.ListFriendsAsync(
|
||||||
new ListRelationshipSimpleRequest { AccountId = currentUser.Id }
|
new ListRelationshipSimpleRequest { RelatedId = currentUser.Id }
|
||||||
);
|
);
|
||||||
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public class TimelineService(
|
|||||||
|
|
||||||
// Get user's friends and publishers
|
// Get user's friends and publishers
|
||||||
var friendsResponse = await accounts.ListFriendsAsync(
|
var friendsResponse = await accounts.ListFriendsAsync(
|
||||||
new ListRelationshipSimpleRequest { AccountId = currentUser.Id }
|
new ListRelationshipSimpleRequest { RelatedId = currentUser.Id }
|
||||||
);
|
);
|
||||||
var userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
var userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
|
||||||
var userPublishers = await pub.GetUserPublishers(Guid.Parse(currentUser.Id));
|
var userPublishers = await pub.GetUserPublishers(Guid.Parse(currentUser.Id));
|
||||||
|
|||||||
Reference in New Issue
Block a user