♻️ Update unfollow
This commit is contained in:
@@ -239,25 +239,19 @@ public class ActivityPubActivityProcessor(
|
|||||||
|
|
||||||
if (objectValue is not Dictionary<string, object> objectDict) return false;
|
if (objectValue is not Dictionary<string, object> objectDict) return false;
|
||||||
var objectType = objectDict.GetValueOrDefault("type")?.ToString();
|
var objectType = objectDict.GetValueOrDefault("type")?.ToString();
|
||||||
switch (objectType)
|
return objectType switch
|
||||||
{
|
{
|
||||||
case "Follow":
|
"Follow" => await UndoFollowAsync(actorUri, objectDict.GetValueOrDefault("object")?.ToString()),
|
||||||
return await UndoFollowAsync(actorUri, objectDict.GetValueOrDefault("id")?.ToString());
|
"Like" => await UndoLikeAsync(actorUri, objectDict.GetValueOrDefault("id")?.ToString()),
|
||||||
case "Like":
|
"Announce" => await UndoAnnounceAsync(actorUri, objectDict.GetValueOrDefault("id")?.ToString()),
|
||||||
return await UndoLikeAsync(actorUri, objectDict.GetValueOrDefault("id")?.ToString());
|
_ => false
|
||||||
case "Announce":
|
};
|
||||||
return await UndoAnnounceAsync(actorUri, objectDict.GetValueOrDefault("id")?.ToString());
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> ProcessCreateAsync(string actorUri, Dictionary<string, object> activity)
|
private async Task<bool> ProcessCreateAsync(string actorUri, Dictionary<string, object> activity)
|
||||||
{
|
{
|
||||||
var objectValue = activity.GetValueOrDefault("object");
|
var objectValue = activity.GetValueOrDefault("object");
|
||||||
if (objectValue == null || !(objectValue is Dictionary<string, object> objectDict))
|
if (objectValue is not Dictionary<string, object> objectDict)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var objectType = objectDict.GetValueOrDefault("type")?.ToString();
|
var objectType = objectDict.GetValueOrDefault("type")?.ToString();
|
||||||
@@ -419,22 +413,24 @@ public class ActivityPubActivityProcessor(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> UndoFollowAsync(string actorUri, string? activityId)
|
private async Task<bool> UndoFollowAsync(string actorUri, string? targetActorUri)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(targetActorUri))
|
||||||
|
{
|
||||||
|
logger.LogInformation("Undid follow relationship failed, no target actor uri provided.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var actor = await GetOrCreateActorAsync(actorUri);
|
var actor = await GetOrCreateActorAsync(actorUri);
|
||||||
|
var targetActor = await GetOrCreateActorAsync(targetActorUri);
|
||||||
|
|
||||||
var relationship = await db.FediverseRelationships
|
var relationship = await db.FediverseRelationships
|
||||||
.FirstOrDefaultAsync(r =>
|
.FirstOrDefaultAsync(r => r.ActorId == actor.Id && r.TargetActorId == targetActor.Id);
|
||||||
r.ActorId == actor.Id ||
|
|
||||||
r.TargetActorId == actor.Id);
|
|
||||||
|
|
||||||
if (relationship != null)
|
if (relationship == null) return true;
|
||||||
{
|
db.Remove(relationship);
|
||||||
relationship.IsFollowing = false;
|
await db.SaveChangesAsync();
|
||||||
relationship.IsFollowedBy = false;
|
logger.LogInformation("Undid follow relationship");
|
||||||
await db.SaveChangesAsync();
|
|
||||||
logger.LogInformation("Undid follow relationship");
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user