Unverified Commit d0e8ef82 authored by Hong Minhee's avatar Hong Minhee
Browse files

Context.parseUri() method

parent 870042b1
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -29,6 +29,13 @@ To be released.
     -  Added `SendActivityOptions.excludeBaseUris` property.
     -  Added `ExtractInboxesParameters.excludeBaseUris` property.

 -  The `Context` now can parse URIs of objects, inboxes, and collections as
    well as actors.

     -  Added `Context.parseUri()` method.
     -  Added `ParseUriResult` type.
     -  Deprecated `Context.getHandleFromActorUri()` method.

 -  The time window for signature verification is now configurable.  [[#52]]

     -  The default time window for signature verification is now a minute (was
+3 −2
Original line number Diff line number Diff line
@@ -169,8 +169,9 @@ federation
      if (acceptFollows.length < 1) return;
      const objectId = activity.objectId;
      if (objectId == null) return;
      const handle = ctx.getHandleFromActorUri(objectId);
      if (handle !== "i") return;
      const parsed = ctx.parseUri(objectId);
      if (parsed?.type !== "actor" || parsed.handle !== "i") return;
      const { handle } = parsed;
      const follower = await activity.getActor();
      if (!isActor(follower)) return;
      const accepts = await acceptsFollowFrom(follower);
+6 −5
Original line number Diff line number Diff line
@@ -89,8 +89,9 @@ federation.setActorDispatcher("/users/{handle}", async (ctx, handle, key) => {
});
~~~~

On the other way around, you can use the `~Context.getHandleFromActorUri()`
method to get the bare handle from the actor URI.
On the other way around, you can use the `~Context.parseUri()` method to
determine the type of the URI and extract the handle or other values from
the URI. 


Enqueuing an outgoing activity
@@ -107,11 +108,11 @@ federation
  .setInboxListeners("/users/{handle}/inbox", "/inbox")
  .on(Follow, async (ctx, follow) => {
    // In order to send an activity, we need the bare handle of the sender:
    const handle = ctx.getHandleFromActorUri(follow.objectId);
    if (handle == null) return;
    const parsed = ctx.parseUri(follow.objectId);
    if (parsed?.type !== "actor") return;
    const recipient = await follow.getActor(ctx);
    await ctx.sendActivity(
      { handle }, // sender
      { handle: parsed.handle }, // sender
      recipient,
      new Accept({ actor: follow.objectId, object: follow }),
    );
+3 −3
Original line number Diff line number Diff line
@@ -43,11 +43,11 @@ const federation = new Federation({
federation
  .setInboxListeners("/users/{handle}/inbox", "/inbox")
  .on(Follow, async (ctx, follow) => {
    const handle = ctx.getHandleFromActorUri(follow.objectId);
    if (handle == null) return;
    const parsed = ctx.parseUri(follow.objectId);
    if (parsed?.type !== "actor") return;
    const recipient = await follow.getActor(ctx);
    await ctx.sendActivity(
      { handle },
      { handle: parsed.handle },
      recipient,
      new Accept({ actor: follow.objectId, object: follow }),
    );
+8 −8
Original line number Diff line number Diff line
@@ -619,8 +619,8 @@ federation
    if (follow.id == null || follow.actorId == null || follow.objectId == null) {
      return;
    }
    const handle = ctx.getHandleFromActorUri(follow.objectId);
    if (handle !== "me") return;
    const parsed = ctx.parseUri(follow.objectId);
    if (parsed?.type !== "actor" || parsed.handle !== "me") return;
    const follower = await follow.getActor(ctx);
    console.debug(follower);
  });
@@ -908,14 +908,14 @@ federation
    if (follow.id == null || follow.actorId == null || follow.objectId == null) {
      return;
    }
    const handle = ctx.getHandleFromActorUri(follow.objectId);
    if (handle !== "me") return;
    const parsed = ctx.parseUri(follow.objectId);
    if (parsed?.type !== "actor" || parsed.handle !== "me") return;
    const follower = await follow.getActor(ctx);
    // Note that if a server receives a `Follow` activity, it should reply
    // with either an `Accept` or a `Reject` activity.  In this case, the
    // server automatically accepts the follow request:
    await ctx.sendActivity(
      { handle },
      { handle: parsed.handle },
      follower,
      new Accept({ actor: follow.objectId, object: follow }),
    );
@@ -941,11 +941,11 @@ federation
    if (follow.id == null || follow.actorId == null || follow.objectId == null) {
      return;
    }
    const handle = ctx.getHandleFromActorUri(follow.objectId);
    if (handle !== "me") return;
    const parsed = ctx.parseUri(follow.objectId);
    if (parsed?.type !== "actor" || parsed.handle !== "me") return;
    const follower = await follow.getActor(ctx);
    await ctx.sendActivity(
      { handle },
      { handle: parsed.handle },
      follower,
      new Accept({ actor: follow.objectId, object: follow }),
    );
Loading