diff --git a/ActivityStore.cs b/ActivityStore.cs
index df400da..b7df2d3 100644
--- a/ActivityStore.cs
+++ b/ActivityStore.cs
@@ -6,11 +6,23 @@ using Object = KristofferStrube.ActivityStreams.Object;
namespace ActivityPub;
+///
+/// An enum to differentiate inbox and outbox data stores
+///
public enum ActivityStoreType {
+ ///
+ /// For indicating an Inbox activity store
+ ///
Inbox,
+ ///
+ /// For indicating an Outbox activity store
+ ///
Outbox
}
+///
+/// A class representing the data store for activities
+///
public class ActivityStore {
private static Dictionary _outbox = new();
private static Dictionary _inbox = new();
@@ -96,7 +108,7 @@ public class ActivityStore {
public Activity InsertActivity(Activity newActivity, bool runSideEffects = true, bool runDelivery = true) {
string id = NewId;
- string uriId = this.Url.AbsoluteRouteUrl(ActivityStoreType == ActivityStoreType.Inbox ? "GetInboxById" : "GetOutboxById", new { id }).ToLower();
+ string? uriId = Url.AbsoluteRouteUrl(ActivityStoreType == ActivityStoreType.Inbox ? "GetInboxById" : "GetOutboxById", new { id })?.ToLower();
List recipients = runDelivery ? ExtractRecipients(newActivity) : new List();
newActivity.Id = uriId;
newActivity.Bto = newActivity.Bcc = null;
@@ -156,7 +168,7 @@ public class ActivityStore {
IntransitiveActivity activity = (IntransitiveActivity)newActivity;
if (activity is Arrive) return Arrive((Arrive)activity);
else if (activity is Travel) return Travel((Travel)activity);
- // else if (activity is Question) return Question((Question)activity); // TODO: Temporary until question is intransitory again
+ else if (activity is Question) return Question((Question)activity);
else throw new InvalidOperationException($"Activity type '{activity.Type?.FirstOrDefault()}' is unrecognized");
}
@@ -188,7 +200,6 @@ public class ActivityStore {
else if (activity is TentativeReject) return TentativeReject((TentativeReject)activity);
else if (activity is TentativeAccept) return TentativeAccept((TentativeAccept)activity);
else if (activity is View) return View((View)activity);
- else if (activity is Question) return Question((Question)activity); // TODO: Temporary until question is intransitory again
else throw new InvalidOperationException($"Activity type '{activity.Type?.FirstOrDefault()}' is unrecognized");
}
}
diff --git a/Constants.cs b/Constants.cs
index 5189a86..55e9216 100644
--- a/Constants.cs
+++ b/Constants.cs
@@ -1,9 +1,18 @@
namespace ActivityPub;
+///
+/// The context urls for JSON-LD
+///
public class Context {
+ ///
+ /// The ActivityStreams context
+ ///
public static readonly Uri ActivityStreams = new("https://www.w3.org/ns/activitystreams");
}
+///
+/// Known collection urls
+///
public class Collections {
///
/// The public address for delivery.
diff --git a/Controllers/OutboxController.cs b/Controllers/OutboxController.cs
index eae282d..c03c903 100644
--- a/Controllers/OutboxController.cs
+++ b/Controllers/OutboxController.cs
@@ -26,7 +26,7 @@ public class OutboxController : ControllerBase {
/// Method to create and process a new object.
/// See https://www.w3.org/TR/activitypub/#client-to-server-interactions
///
- /// The data for the Activity or Object to create
+ /// The data for the Activity or Object to create
///
/// 201 (Created) on success with the new id in the Location header
/// TODO: Also currently returns the newly created Action to assist in debugging.
@@ -44,7 +44,7 @@ public class OutboxController : ControllerBase {
return this.BadRequest($"No valid Activity or Object found in the request body");
Activity newActivity = (newObjectOrLink is Activity) ? (Activity)newObjectOrLink
- : Outbox.WrapObjectInCreate(newObjectOrLink as Object);
+ : Outbox.WrapObjectInCreate((Object)newObjectOrLink);
//// Validate the activity
//try {
diff --git a/ObjectStore.cs b/ObjectStore.cs
index a6859d8..c3a8ae0 100644
--- a/ObjectStore.cs
+++ b/ObjectStore.cs
@@ -7,6 +7,9 @@ using Object = KristofferStrube.ActivityStreams.Object;
namespace ActivityPub;
+///
+/// A Data layer to store objects
+///
public class ObjectStore {
private static Dictionary> _objects = new();
private IUrlHelper Url { get; set; }
diff --git a/Repositories/ActivityPubContext.cs b/Repositories/ActivityPubContext.cs
index 3a23096..d08373c 100644
--- a/Repositories/ActivityPubContext.cs
+++ b/Repositories/ActivityPubContext.cs
@@ -43,6 +43,10 @@ public class ActivityPubContext : DbContext {
options.UseSqlite($"Data Source={DbPath}");
}
+ ///
+ /// configuration for these models
+ ///
+ /// the model builder to configure
protected override void OnModelCreating(ModelBuilder modelBuilder) {
modelBuilder.Entity().HasMany(_ => _.Actor as IEnumerable);
modelBuilder.Entity().HasMany(_ => _.Object as IEnumerable);
diff --git a/Types.cs b/Types.cs
index a5da21b..60ce9c1 100644
--- a/Types.cs
+++ b/Types.cs
@@ -185,14 +185,43 @@ public static class Types {
"Mention"
];
+ ///
+ /// Checks if the object type is an activity type
+ ///
+ /// The type of the object
+ /// A boolean indicating whether the object is an activity type
public static bool IsActivity(string type) => Activity.Contains(type);
//public static bool IsActivity(this Object obj) => obj.Type == null ? false : IsActivity(obj.Type);
+
+ ///
+ /// Checks if the object type is an actor type
+ ///
+ /// The type of the object
+ /// A boolean indicating whether the object is an actor type
public static bool IsActor(string type) => Actor.Contains(type);
//public static bool IsActor(this Object obj) => obj.Type == null ? false : IsActor(obj.Type);
+
+ ///
+ /// Checks if the object type is an object type
+ ///
+ /// The type of the object
+ /// A boolean indicating whether the object is an object type
public static bool IsObject(string type) => Object.Contains(type);
//public static bool IsObject(this Object obj) => obj.Type == null ? false : IsObject(obj.Type);
+
+ ///
+ /// Checks if the object type is a link type
+ ///
+ /// The type of the object
+ /// A boolean indicating whether the object is a link type
public static bool IsLink(string type) => Link.Contains(type);
//public static bool IsLink(this Object obj) => obj.Type == null ? false : IsLink(obj.Type);
+
+ ///
+ /// Checks if the object type is an object or link type
+ ///
+ /// The type of the object
+ /// A boolean indicating whether the object is an object or link type
public static bool IsObjectOrLink(string type) => Object.Concat(Link).Contains(type);
//public static bool IsObjectOrLink(this Object obj) => obj.Type == null ? false : IsObjectOrLink(obj.Type);
diff --git a/Utils/Base36.cs b/Utils/Base36.cs
index cbac40f..0607bb2 100644
--- a/Utils/Base36.cs
+++ b/Utils/Base36.cs
@@ -1,6 +1,9 @@
namespace ActivityPub.Utils;
-// https://stackoverflow.com/a/35004409
+///
+/// Helper class for converting numbers to and from Base36 strings
+/// https://stackoverflow.com/a/35004409
+///
public class Base36
{
private static readonly char[] BaseChars =
@@ -9,6 +12,11 @@ public class Base36
.Select((c, i) => new { Char = c, Index = i })
.ToDictionary(c => c.Char, c => c.Index);
+ ///
+ /// Convert a long to a Base36 string
+ ///
+ /// The number to convert
+ /// A string representing the number in Base36
public static string ToString(long value)
{
long targetBase = BaseChars.Length;
@@ -27,6 +35,11 @@ public class Base36
return new string(buffer, i, buffer.Length - i);
}
+ ///
+ /// Converts a Base64 string back into a number
+ ///
+ /// The string to convert
+ /// The number resulting from converting the string
public static long FromString(string number)
{
char[] chrs = number.ToLower().ToCharArray();
diff --git a/Utils/UrlHelperExtensions.cs b/Utils/UrlHelperExtensions.cs
index 8143a65..2b36a92 100644
--- a/Utils/UrlHelperExtensions.cs
+++ b/Utils/UrlHelperExtensions.cs
@@ -16,11 +16,11 @@ public static class UrlHelperExtensions
/// The name of the controller.
/// The route values.
/// The absolute URL.
- public static string AbsoluteAction(
+ public static string? AbsoluteAction(
this IUrlHelper url,
string actionName,
string controllerName,
- object routeValues = null)
+ object? routeValues = null)
{
return url.Action(actionName, controllerName, routeValues, url.ActionContext.HttpContext.Request.Scheme);
}
@@ -47,10 +47,10 @@ public static class UrlHelperExtensions
/// Name of the route.
/// The route values.
/// The absolute URL.
- public static string AbsoluteRouteUrl(
+ public static string? AbsoluteRouteUrl(
this IUrlHelper url,
string routeName,
- object routeValues = null)
+ object? routeValues = null)
{
return url.RouteUrl(routeName, routeValues, url.ActionContext.HttpContext.Request.Scheme);
}
diff --git a/ap.net.csproj b/ap.net.csproj
index c7e5343..0f69b23 100644
--- a/ap.net.csproj
+++ b/ap.net.csproj
@@ -15,7 +15,7 @@
-
+