♻️ Refactored fediverse relationships
This commit is contained in:
@@ -16,10 +16,7 @@ public class SnFediverseRelationship : ModelBase
|
|||||||
public SnFediverseActor TargetActor { get; set; } = null!;
|
public SnFediverseActor TargetActor { get; set; } = null!;
|
||||||
|
|
||||||
public RelationshipState State { get; set; } = RelationshipState.Pending;
|
public RelationshipState State { get; set; } = RelationshipState.Pending;
|
||||||
|
|
||||||
public bool IsFollowing { get; set; } = false;
|
|
||||||
public bool IsFollowedBy { get; set; } = false;
|
|
||||||
|
|
||||||
public bool IsMuting { get; set; } = false;
|
public bool IsMuting { get; set; } = false;
|
||||||
public bool IsBlocking { get; set; } = false;
|
public bool IsBlocking { get; set; } = false;
|
||||||
|
|
||||||
|
|||||||
@@ -129,13 +129,11 @@ public class ActivityPubActivityProcessor(
|
|||||||
{
|
{
|
||||||
ActorId = actor.Id,
|
ActorId = actor.Id,
|
||||||
TargetActorId = localActor.Id,
|
TargetActorId = localActor.Id,
|
||||||
State = RelationshipState.Pending,
|
State = RelationshipState.Pending
|
||||||
IsFollowing = false,
|
|
||||||
IsFollowedBy = true
|
|
||||||
};
|
};
|
||||||
db.FediverseRelationships.Add(existingRelationship);
|
db.FediverseRelationships.Add(existingRelationship);
|
||||||
logger.LogInformation("Created new follow relationship. ActorId: {ActorId}, TargetActorId: {TargetActorId}",
|
logger.LogInformation("Created new follow relationship. ActorId: {ActorId}, TargetActorId: {TargetActorId}",
|
||||||
actor.Id, actor.Id);
|
actor.Id, localActor.Id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -184,8 +182,6 @@ public class ActivityPubActivityProcessor(
|
|||||||
ActorId = localActor.Id,
|
ActorId = localActor.Id,
|
||||||
TargetActorId = actor.Id,
|
TargetActorId = actor.Id,
|
||||||
State = RelationshipState.Accepted,
|
State = RelationshipState.Accepted,
|
||||||
IsFollowing = true,
|
|
||||||
IsFollowedBy = false,
|
|
||||||
FollowedAt = SystemClock.Instance.GetCurrentInstant()
|
FollowedAt = SystemClock.Instance.GetCurrentInstant()
|
||||||
};
|
};
|
||||||
db.FediverseRelationships.Add(relationship);
|
db.FediverseRelationships.Add(relationship);
|
||||||
@@ -193,7 +189,6 @@ public class ActivityPubActivityProcessor(
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
relationship.State = RelationshipState.Accepted;
|
relationship.State = RelationshipState.Accepted;
|
||||||
relationship.IsFollowing = true;
|
|
||||||
relationship.FollowedAt = SystemClock.Instance.GetCurrentInstant();
|
relationship.FollowedAt = SystemClock.Instance.GetCurrentInstant();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +217,6 @@ public class ActivityPubActivityProcessor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
relationship.State = RelationshipState.Rejected;
|
relationship.State = RelationshipState.Rejected;
|
||||||
relationship.IsFollowing = false;
|
|
||||||
relationship.RejectReason = "Remote rejected follow";
|
relationship.RejectReason = "Remote rejected follow";
|
||||||
|
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ public class ActivityPubController(
|
|||||||
|
|
||||||
var relationshipsQuery = db.FediverseRelationships
|
var relationshipsQuery = db.FediverseRelationships
|
||||||
.Include(r => r.Actor)
|
.Include(r => r.Actor)
|
||||||
.Where(r => r.Actor.PublisherId == publisher.Id && r.IsFollowedBy);
|
.Where(r => r.TargetActor.PublisherId == publisher.Id && r.State == RelationshipState.Accepted);
|
||||||
|
|
||||||
var totalItems = await relationshipsQuery.CountAsync();
|
var totalItems = await relationshipsQuery.CountAsync();
|
||||||
|
|
||||||
@@ -257,7 +257,7 @@ public class ActivityPubController(
|
|||||||
|
|
||||||
var relationshipsQuery = db.FediverseRelationships
|
var relationshipsQuery = db.FediverseRelationships
|
||||||
.Include(r => r.TargetActor)
|
.Include(r => r.TargetActor)
|
||||||
.Where(r => r.Actor.PublisherId == publisher.Id && r.IsFollowing);
|
.Where(r => r.Actor.PublisherId == publisher.Id && r.State == RelationshipState.Accepted);
|
||||||
|
|
||||||
var totalItems = await relationshipsQuery.CountAsync();
|
var totalItems = await relationshipsQuery.CountAsync();
|
||||||
|
|
||||||
|
|||||||
@@ -99,15 +99,12 @@ public class ActivityPubDeliveryService(
|
|||||||
{
|
{
|
||||||
ActorId = localActor.Id,
|
ActorId = localActor.Id,
|
||||||
TargetActorId = targetActor.Id,
|
TargetActorId = targetActor.Id,
|
||||||
State = RelationshipState.Pending,
|
State = RelationshipState.Pending
|
||||||
IsFollowing = true,
|
|
||||||
IsFollowedBy = false
|
|
||||||
};
|
};
|
||||||
db.FediverseRelationships.Add(existingRelationship);
|
db.FediverseRelationships.Add(existingRelationship);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
existingRelationship.IsFollowing = true;
|
|
||||||
existingRelationship.State = RelationshipState.Pending;
|
existingRelationship.State = RelationshipState.Pending;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -645,18 +642,23 @@ public class ActivityPubDeliveryService(
|
|||||||
|
|
||||||
private async Task<List<SnFediverseActor>> GetRemoteFollowersAsync()
|
private async Task<List<SnFediverseActor>> GetRemoteFollowersAsync()
|
||||||
{
|
{
|
||||||
|
var localActorIds = await db.FediverseActors
|
||||||
|
.Where(a => a.PublisherId != null)
|
||||||
|
.Select(a => a.Id)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
return await db.FediverseRelationships
|
return await db.FediverseRelationships
|
||||||
.Include(r => r.Actor)
|
.Include(r => r.Actor)
|
||||||
.Where(r => r.IsFollowedBy)
|
.Where(r => r.State == RelationshipState.Accepted && localActorIds.Contains(r.TargetActorId))
|
||||||
.Select(r => r.Actor)
|
.Select(r => r.Actor)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<List<SnFediverseActor>> GetRemoteFollowersAsync(Guid actorId)
|
private async Task<List<SnFediverseActor>> GetRemoteFollowersAsync(Guid actorId)
|
||||||
{
|
{
|
||||||
return await db.FediverseRelationships
|
return await db.FediverseRelationships
|
||||||
.Include(r => r.Actor)
|
.Include(r => r.Actor)
|
||||||
.Where(r => r.TargetActorId == actorId && r.IsFollowedBy)
|
.Where(r => r.TargetActorId == actorId && r.State == RelationshipState.Accepted)
|
||||||
.Select(r => r.Actor)
|
.Select(r => r.Actor)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,7 +149,6 @@ public class ActivityPubFollowController(
|
|||||||
var totalCount = await db.FediverseRelationships
|
var totalCount = await db.FediverseRelationships
|
||||||
.CountAsync(r =>
|
.CountAsync(r =>
|
||||||
r.Actor.PublisherId == publisher.Id &&
|
r.Actor.PublisherId == publisher.Id &&
|
||||||
r.IsFollowing &&
|
|
||||||
r.State == RelationshipState.Accepted);
|
r.State == RelationshipState.Accepted);
|
||||||
|
|
||||||
var actors = await db.FediverseRelationships
|
var actors = await db.FediverseRelationships
|
||||||
@@ -157,7 +156,6 @@ public class ActivityPubFollowController(
|
|||||||
.ThenInclude(a => a.Instance)
|
.ThenInclude(a => a.Instance)
|
||||||
.Where(r =>
|
.Where(r =>
|
||||||
r.Actor.PublisherId == publisher.Id &&
|
r.Actor.PublisherId == publisher.Id &&
|
||||||
r.IsFollowing &&
|
|
||||||
r.State == RelationshipState.Accepted)
|
r.State == RelationshipState.Accepted)
|
||||||
.OrderByDescending(r => r.FollowedAt)
|
.OrderByDescending(r => r.FollowedAt)
|
||||||
.Skip(offset)
|
.Skip(offset)
|
||||||
@@ -194,16 +192,14 @@ public class ActivityPubFollowController(
|
|||||||
|
|
||||||
var totalCount = await db.FediverseRelationships
|
var totalCount = await db.FediverseRelationships
|
||||||
.CountAsync(r =>
|
.CountAsync(r =>
|
||||||
r.Actor.PublisherId == publisher.Id &&
|
r.TargetActor.PublisherId == publisher.Id &&
|
||||||
r.IsFollowedBy &&
|
|
||||||
r.State == RelationshipState.Accepted);
|
r.State == RelationshipState.Accepted);
|
||||||
|
|
||||||
var actors = await db.FediverseRelationships
|
var actors = await db.FediverseRelationships
|
||||||
.Include(r => r.Actor)
|
.Include(r => r.Actor)
|
||||||
.ThenInclude(a => a.Instance)
|
.ThenInclude(a => a.Instance)
|
||||||
.Where(r =>
|
.Where(r =>
|
||||||
r.Actor.PublisherId == publisher.Id &&
|
r.TargetActor.PublisherId == publisher.Id &&
|
||||||
r.IsFollowedBy &&
|
|
||||||
r.State == RelationshipState.Accepted)
|
r.State == RelationshipState.Accepted)
|
||||||
.OrderByDescending(r => r.FollowedAt ?? r.CreatedAt)
|
.OrderByDescending(r => r.FollowedAt ?? r.CreatedAt)
|
||||||
.Skip(offset)
|
.Skip(offset)
|
||||||
@@ -265,13 +261,11 @@ public class ActivityPubFollowController(
|
|||||||
var followingCount = await db.FediverseRelationships
|
var followingCount = await db.FediverseRelationships
|
||||||
.CountAsync(r =>
|
.CountAsync(r =>
|
||||||
r.Actor.PublisherId == publisher.Id &&
|
r.Actor.PublisherId == publisher.Id &&
|
||||||
r.IsFollowing &&
|
|
||||||
r.State == RelationshipState.Accepted);
|
r.State == RelationshipState.Accepted);
|
||||||
|
|
||||||
var followersCount = await db.FediverseRelationships
|
var followersCount = await db.FediverseRelationships
|
||||||
.CountAsync(r =>
|
.CountAsync(r =>
|
||||||
r.Actor.PublisherId == publisher.Id &&
|
r.TargetActor.PublisherId == publisher.Id &&
|
||||||
r.IsFollowedBy &&
|
|
||||||
r.State == RelationshipState.Accepted);
|
r.State == RelationshipState.Accepted);
|
||||||
|
|
||||||
var pendingCount = await db.FediverseRelationships
|
var pendingCount = await db.FediverseRelationships
|
||||||
@@ -296,7 +290,7 @@ public class ActivityPubFollowController(
|
|||||||
{
|
{
|
||||||
Actor = r.TargetActor,
|
Actor = r.TargetActor,
|
||||||
State = r.State,
|
State = r.State,
|
||||||
IsFollowing = r.IsFollowing,
|
IsFollowing = true,
|
||||||
FollowedAt = r.FollowedAt,
|
FollowedAt = r.FollowedAt,
|
||||||
TargetActorUri = r.TargetActor.Uri,
|
TargetActorUri = r.TargetActor.Uri,
|
||||||
Username = r.TargetActor.Username,
|
Username = r.TargetActor.Username,
|
||||||
@@ -443,7 +437,6 @@ public class ActivityPubFollowController(
|
|||||||
.Where(r =>
|
.Where(r =>
|
||||||
r.ActorId == userActor.Id &&
|
r.ActorId == userActor.Id &&
|
||||||
actorIds.Contains(r.TargetActorId) &&
|
actorIds.Contains(r.TargetActorId) &&
|
||||||
r.IsFollowing &&
|
|
||||||
r.State == RelationshipState.Accepted)
|
r.State == RelationshipState.Accepted)
|
||||||
.Select(r => r.TargetActorId)
|
.Select(r => r.TargetActorId)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|||||||
2377
DysonNetwork.Sphere/Migrations/20251231102829_RemoveFollowingBooleanInFediverse.Designer.cs
generated
Normal file
2377
DysonNetwork.Sphere/Migrations/20251231102829_RemoveFollowingBooleanInFediverse.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,40 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DysonNetwork.Sphere.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class RemoveFollowingBooleanInFediverse : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "is_followed_by",
|
||||||
|
table: "fediverse_relationships");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "is_following",
|
||||||
|
table: "fediverse_relationships");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<bool>(
|
||||||
|
name: "is_followed_by",
|
||||||
|
table: "fediverse_relationships",
|
||||||
|
type: "boolean",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: false);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<bool>(
|
||||||
|
name: "is_following",
|
||||||
|
table: "fediverse_relationships",
|
||||||
|
type: "boolean",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -578,14 +578,6 @@ namespace DysonNetwork.Sphere.Migrations
|
|||||||
.HasColumnType("boolean")
|
.HasColumnType("boolean")
|
||||||
.HasColumnName("is_blocking");
|
.HasColumnName("is_blocking");
|
||||||
|
|
||||||
b.Property<bool>("IsFollowedBy")
|
|
||||||
.HasColumnType("boolean")
|
|
||||||
.HasColumnName("is_followed_by");
|
|
||||||
|
|
||||||
b.Property<bool>("IsFollowing")
|
|
||||||
.HasColumnType("boolean")
|
|
||||||
.HasColumnName("is_following");
|
|
||||||
|
|
||||||
b.Property<bool>("IsMuting")
|
b.Property<bool>("IsMuting")
|
||||||
.HasColumnType("boolean")
|
.HasColumnType("boolean")
|
||||||
.HasColumnName("is_muting");
|
.HasColumnName("is_muting");
|
||||||
|
|||||||
@@ -789,7 +789,7 @@ public class PublisherService(
|
|||||||
.FirstOrDefaultAsync(a => a.PublisherId == publisherId);
|
.FirstOrDefaultAsync(a => a.PublisherId == publisherId);
|
||||||
|
|
||||||
var followerCount = await db.FediverseRelationships
|
var followerCount = await db.FediverseRelationships
|
||||||
.Where(r => r.Actor.PublisherId == publisherId && r.IsFollowedBy)
|
.Where(r => r.TargetActor.PublisherId == publisherId && r.State == RelationshipState.Accepted)
|
||||||
.CountAsync();
|
.CountAsync();
|
||||||
|
|
||||||
var publisher = await db.Publishers
|
var publisher = await db.Publishers
|
||||||
|
|||||||
Reference in New Issue
Block a user