🐛 Fixes for relationships

This commit is contained in:
LittleSheep 2025-05-17 00:09:35 +08:00
parent 88977ccda3
commit b489a79df2
2 changed files with 6 additions and 1 deletions

View File

@ -107,6 +107,11 @@ public class RelationshipController(AppDatabase db, RelationshipService rels) :
var relatedUser = await db.Accounts.FindAsync(userId);
if (relatedUser is null) return NotFound("Account was not found.");
var existing = await db.AccountRelationships.FirstOrDefaultAsync(r =>
(r.AccountId == currentUser.Id && r.RelatedId == userId) ||
(r.AccountId == userId && r.RelatedId == currentUser.Id));
if (existing != null) return BadRequest("Relationship already exists.");
try
{

View File

@ -263,7 +263,7 @@ public static class PostQueryExtensions
.Where(e => e.Visibility == PostVisibility.Public);
return source
.Where(e => e.PublishedAt != null && now >= e.PublishedAt && e.Publisher.AccountId == currentUser.Id)
.Where(e => (e.PublishedAt != null && now >= e.PublishedAt) || e.Publisher.AccountId == currentUser.Id)
.Where(e => e.Visibility != PostVisibility.Private || e.Publisher.AccountId == currentUser.Id)
.Where(e => e.Visibility != PostVisibility.Friends ||
(e.Publisher.AccountId != null && userFriends.Contains(e.Publisher.AccountId.Value)) ||