🐛 Fix some issues in AP
This commit is contained in:
@@ -112,9 +112,9 @@ public class ActivityPubActivityProcessor(
|
|||||||
targetPublisher.Name, targetPublisher.Id);
|
targetPublisher.Name, targetPublisher.Id);
|
||||||
|
|
||||||
var existingRelationship = await db.FediverseRelationships
|
var existingRelationship = await db.FediverseRelationships
|
||||||
.FirstOrDefaultAsync(r =>
|
.FirstOrDefaultAsync(r =>
|
||||||
r.ActorId == actor.Id &&
|
r.ActorId == actor.Id &&
|
||||||
r.TargetActorId == actor.Id);
|
r.TargetActorId == localActor.Id);
|
||||||
|
|
||||||
if (existingRelationship is { State: RelationshipState.Accepted })
|
if (existingRelationship is { State: RelationshipState.Accepted })
|
||||||
{
|
{
|
||||||
@@ -167,20 +167,36 @@ public class ActivityPubActivityProcessor(
|
|||||||
var relationship = await db.FediverseRelationships
|
var relationship = await db.FediverseRelationships
|
||||||
.Include(r => r.Actor)
|
.Include(r => r.Actor)
|
||||||
.Include(r => r.TargetActor)
|
.Include(r => r.TargetActor)
|
||||||
.FirstOrDefaultAsync(r =>
|
.FirstOrDefaultAsync(r =>
|
||||||
r.TargetActorId == actor.Id &&
|
r.TargetActorId == actor.Id);
|
||||||
r.State == RelationshipState.Pending);
|
|
||||||
|
|
||||||
if (relationship == null)
|
if (relationship == null)
|
||||||
{
|
{
|
||||||
logger.LogWarning("No pending relationship found for accept");
|
// Assume objectUri is the local actor URI that was followed
|
||||||
return false;
|
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.State = RelationshipState.Accepted;
|
||||||
relationship.FollowedAt = SystemClock.Instance.GetCurrentInstant();
|
relationship.IsFollowing = true;
|
||||||
|
relationship.FollowedAt = SystemClock.Instance.GetCurrentInstant();
|
||||||
|
}
|
||||||
|
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
logger.LogInformation("Processed accept from {Actor}", actorUri);
|
logger.LogInformation("Processed accept from {Actor}", actorUri);
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ public class ActivityPubDeliveryService(
|
|||||||
|
|
||||||
return await SendActivityToInboxAsync(activity, targetActor.InboxUri, actorUrl);
|
return await SendActivityToInboxAsync(activity, targetActor.InboxUri, actorUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> SendUnfollowActivityAsync(
|
public async Task<bool> SendUnfollowActivityAsync(
|
||||||
Guid publisherId,
|
Guid publisherId,
|
||||||
string targetActorUri
|
string targetActorUri
|
||||||
@@ -124,11 +124,11 @@ public class ActivityPubDeliveryService(
|
|||||||
var publisher = await db.Publishers.FindAsync(publisherId);
|
var publisher = await db.Publishers.FindAsync(publisherId);
|
||||||
if (publisher == null)
|
if (publisher == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var actorUrl = $"https://{Domain}/activitypub/actors/{publisher.Name}";
|
var actorUrl = $"https://{Domain}/activitypub/actors/{publisher.Name}";
|
||||||
var targetActor = await GetOrFetchActorAsync(targetActorUri);
|
var targetActor = await GetOrFetchActorAsync(targetActorUri);
|
||||||
var localActor = await GetLocalActorAsync(publisher.Id);
|
var localActor = await GetLocalActorAsync(publisher.Id);
|
||||||
|
|
||||||
if (targetActor?.InboxUri == null || localActor == null)
|
if (targetActor?.InboxUri == null || localActor == null)
|
||||||
{
|
{
|
||||||
logger.LogWarning("Target actor or inbox not found: {Uri}", targetActorUri);
|
logger.LogWarning("Target actor or inbox not found: {Uri}", targetActorUri);
|
||||||
@@ -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;
|
||||||
|
|
||||||
|
var success = await SendActivityToInboxAsync(activity, targetActor.InboxUri, actorUrl);
|
||||||
|
if (!success) return success;
|
||||||
|
|
||||||
return await SendActivityToInboxAsync(activity, targetActor.InboxUri, actorUrl);
|
db.Remove(relationship);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> SendCreateActivityAsync(SnPost post)
|
public async Task<bool> SendCreateActivityAsync(SnPost post)
|
||||||
@@ -764,4 +775,4 @@ public class ActivityPubDeliveryService(
|
|||||||
{
|
{
|
||||||
return actorUri.Split('/').Last();
|
return actorUri.Split('/').Last();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user