🐛 Fix some issues in AP
This commit is contained in:
@@ -114,7 +114,7 @@ public class ActivityPubActivityProcessor(
|
||||
var existingRelationship = await db.FediverseRelationships
|
||||
.FirstOrDefaultAsync(r =>
|
||||
r.ActorId == actor.Id &&
|
||||
r.TargetActorId == actor.Id);
|
||||
r.TargetActorId == localActor.Id);
|
||||
|
||||
if (existingRelationship is { State: RelationshipState.Accepted })
|
||||
{
|
||||
@@ -168,18 +168,34 @@ public class ActivityPubActivityProcessor(
|
||||
.Include(r => r.Actor)
|
||||
.Include(r => r.TargetActor)
|
||||
.FirstOrDefaultAsync(r =>
|
||||
r.TargetActorId == actor.Id &&
|
||||
r.State == RelationshipState.Pending);
|
||||
r.TargetActorId == actor.Id);
|
||||
|
||||
if (relationship == null)
|
||||
{
|
||||
logger.LogWarning("No pending relationship found for accept");
|
||||
// Assume objectUri is the local actor URI that was followed
|
||||
var localActor = await db.FediverseActors.FirstOrDefaultAsync(a => a.Uri == objectUri);
|
||||
if (localActor == null)
|
||||
{
|
||||
logger.LogWarning("Local actor not found for accept object: {ObjectUri}", objectUri);
|
||||
return false;
|
||||
}
|
||||
|
||||
relationship = new SnFediverseRelationship
|
||||
{
|
||||
ActorId = localActor.Id,
|
||||
TargetActorId = actor.Id,
|
||||
State = RelationshipState.Accepted,
|
||||
IsFollowing = true,
|
||||
IsFollowedBy = false,
|
||||
FollowedAt = SystemClock.Instance.GetCurrentInstant()
|
||||
};
|
||||
db.FediverseRelationships.Add(relationship);
|
||||
}
|
||||
else
|
||||
{
|
||||
relationship.State = RelationshipState.Accepted;
|
||||
relationship.IsFollowing = true;
|
||||
relationship.FollowedAt = SystemClock.Instance.GetCurrentInstant();
|
||||
}
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
|
||||
@@ -148,8 +148,19 @@ public class ActivityPubDeliveryService(
|
||||
}
|
||||
};
|
||||
|
||||
var relationship = await db.FediverseRelationships
|
||||
.FirstOrDefaultAsync(r =>
|
||||
r.ActorId == localActor.Id &&
|
||||
r.TargetActorId == targetActor.Id);
|
||||
if (relationship == null) return false;
|
||||
|
||||
return await SendActivityToInboxAsync(activity, targetActor.InboxUri, actorUrl);
|
||||
var success = await SendActivityToInboxAsync(activity, targetActor.InboxUri, actorUrl);
|
||||
if (!success) return success;
|
||||
|
||||
db.Remove(relationship);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public async Task<bool> SendCreateActivityAsync(SnPost post)
|
||||
|
||||
Reference in New Issue
Block a user