Skip to content

Commit 0cb0ee2

Browse files
committed
Rename events: onAcceptFollow & onRejectFollow
1 parent 82e564f commit 0cb0ee2

File tree

6 files changed

+46
-43
lines changed

6 files changed

+46
-43
lines changed

docs/concepts/events.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,18 @@ bot.onUnfollow = async (session, follower) => {
6363
~~~~
6464

6565

66-
Accept
67-
------
66+
Accept follow
67+
-------------
6868

69-
The `~Bot.onAccept` event handler is called when someone accepts your bot's
70-
follow request. It receives an `Actor` object, who just accepted your bot's
71-
follow request, as the second argument.
69+
The `~Bot.onAcceptFollow` event handler is called when someone accepts your
70+
bot's follow request. It receives an `Actor` object, who just accepted your
71+
bot's follow request, as the second argument.
7272

7373
The following is an example of an accept event handler that sends a direct
7474
message when someone accepts your bot's follow request:
7575

7676
~~~~ typescript
77-
bot.onAccept = async (session, accepter) => {
77+
bot.onAcceptFollow = async (session, accepter) => {
7878
await session.publish(
7979
text`Thanks for accepting my follow request, ${accepter}!`,
8080
{ visibility: "direct" },
@@ -83,18 +83,18 @@ bot.onAccept = async (session, accepter) => {
8383
~~~~
8484

8585

86-
Reject
87-
------
86+
Reject follow
87+
-------------
8888

89-
The `~Bot.onReject` event handler is called when someone rejects your bot's
90-
follow request. It receives an `Actor` object, who just rejected your bot's
91-
follow request, as the second argument.
89+
The `~Bot.onRejectFollow` event handler is called when someone rejects your
90+
bot's follow request. It receives an `Actor` object, who just rejected your
91+
bot's follow request, as the second argument.
9292

9393
The following is an example of a reject event handler that sends a direct
9494
message when someone rejects your bot's follow request:
9595

9696
~~~~ typescript
97-
bot.onReject = async (session, rejecter) => {
97+
bot.onRejectFollow = async (session, rejecter) => {
9898
await session.publish(
9999
text`I'm sorry to hear that you rejected my follow request, ${rejecter}.`,
100100
{ visibility: "direct" },

docs/concepts/session.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ bot.onFollow = async (session, actor) => {
122122
> follow the actor.
123123
>
124124
> If you want to know whether the actor has accepted or rejected the follow
125-
> request, you need to register the [`Bot.onAccept`](./events.md#accept) and
126-
> [`Bot.onReject`](./events.md#reject) event handlers.
125+
> request, you need to register
126+
> the [`Bot.onAcceptFollow`](./events.md#accept-follow) and
127+
> [`Bot.onRejectFollow`](./events.md#reject-follow) event handlers.
127128
128129
> [!TIP]
129130
> It takes several kinds of objects as an argument, such as `Actor`, `string`,

src/bot-impl.test.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,15 +1297,16 @@ Deno.test("BotImpl.onUnfollowed()", async (t) => {
12971297
});
12981298
});
12991299

1300-
Deno.test("BotImpl.onAccepted()", async (t) => {
1300+
Deno.test("BotImpl.onFollowAccepted()", async (t) => {
13011301
const kv = new MemoryKvStore();
13021302
const bot = new BotImpl<void>({ kv, username: "bot" });
13031303
const accepted: [Session<void>, Actor][] = [];
1304-
bot.onAccept = (session, actor) => void (accepted.push([session, actor]));
1304+
bot.onAcceptFollow = (session, actor) =>
1305+
void (accepted.push([session, actor]));
13051306
const ctx = createMockInboxContext(bot, "https://example.com", "bot");
13061307

13071308
await t.step("without object", async () => {
1308-
await bot.onAccepted(
1309+
await bot.onFollowAccepted(
13091310
ctx,
13101311
new Accept({
13111312
actor: new URL("https://example.com/ap/actor/john"),
@@ -1315,7 +1316,7 @@ Deno.test("BotImpl.onAccepted()", async (t) => {
13151316
});
13161317

13171318
await t.step("with invalid object URI", async () => {
1318-
await bot.onAccepted(
1319+
await bot.onFollowAccepted(
13191320
ctx,
13201321
new Accept({
13211322
actor: new URL("https://example.com/ap/actor/john"),
@@ -1326,7 +1327,7 @@ Deno.test("BotImpl.onAccepted()", async (t) => {
13261327
});
13271328

13281329
await t.step("with non-existent object", async () => {
1329-
await bot.onAccepted(
1330+
await bot.onFollowAccepted(
13301331
ctx,
13311332
new Accept({
13321333
actor: new URL("https://example.com/ap/actor/john"),
@@ -1350,7 +1351,7 @@ Deno.test("BotImpl.onAccepted()", async (t) => {
13501351
},
13511352
},
13521353
);
1353-
await bot.onAccepted(
1354+
await bot.onFollowAccepted(
13541355
ctx,
13551356
new Accept({
13561357
actor: new URL("https://example.com/ap/actor/john"),
@@ -1377,7 +1378,7 @@ Deno.test("BotImpl.onAccepted()", async (t) => {
13771378
},
13781379
},
13791380
);
1380-
await bot.onAccepted(
1381+
await bot.onFollowAccepted(
13811382
ctx,
13821383
new Accept({
13831384
actor: new URL("https://example.com/ap/actor/john"),
@@ -1405,7 +1406,7 @@ Deno.test("BotImpl.onAccepted()", async (t) => {
14051406
},
14061407
},
14071408
);
1408-
await bot.onAccepted(
1409+
await bot.onFollowAccepted(
14091410
ctx,
14101411
new Accept({
14111412
actor: new URL("https://example.com/ap/actor/john"),
@@ -1437,15 +1438,16 @@ Deno.test("BotImpl.onAccepted()", async (t) => {
14371438
});
14381439
});
14391440

1440-
Deno.test("BotImpl.onRejected()", async (t) => {
1441+
Deno.test("BotImpl.onFollowRejected()", async (t) => {
14411442
const kv = new MemoryKvStore();
14421443
const bot = new BotImpl<void>({ kv, username: "bot" });
14431444
const rejected: [Session<void>, Actor][] = [];
1444-
bot.onReject = (session, actor) => void (rejected.push([session, actor]));
1445+
bot.onRejectFollow = (session, actor) =>
1446+
void (rejected.push([session, actor]));
14451447
const ctx = createMockInboxContext(bot, "https://example.com", "bot");
14461448

14471449
await t.step("without object", async () => {
1448-
await bot.onRejected(
1450+
await bot.onFollowRejected(
14491451
ctx,
14501452
new Reject({
14511453
actor: new URL("https://example.com/ap/actor/john"),
@@ -1455,7 +1457,7 @@ Deno.test("BotImpl.onRejected()", async (t) => {
14551457
});
14561458

14571459
await t.step("with invalid object URI", async () => {
1458-
await bot.onRejected(
1460+
await bot.onFollowRejected(
14591461
ctx,
14601462
new Reject({
14611463
actor: new URL("https://example.com/ap/actor/john"),
@@ -1466,7 +1468,7 @@ Deno.test("BotImpl.onRejected()", async (t) => {
14661468
});
14671469

14681470
await t.step("with non-existent object", async () => {
1469-
await bot.onRejected(
1471+
await bot.onFollowRejected(
14701472
ctx,
14711473
new Reject({
14721474
actor: new URL("https://example.com/ap/actor/john"),
@@ -1490,7 +1492,7 @@ Deno.test("BotImpl.onRejected()", async (t) => {
14901492
},
14911493
},
14921494
);
1493-
await bot.onRejected(
1495+
await bot.onFollowRejected(
14941496
ctx,
14951497
new Reject({
14961498
actor: new URL("https://example.com/ap/actor/john"),
@@ -1517,7 +1519,7 @@ Deno.test("BotImpl.onRejected()", async (t) => {
15171519
},
15181520
},
15191521
);
1520-
await bot.onRejected(
1522+
await bot.onFollowRejected(
15211523
ctx,
15221524
new Reject({
15231525
actor: new URL("https://example.com/ap/actor/john"),
@@ -1545,7 +1547,7 @@ Deno.test("BotImpl.onRejected()", async (t) => {
15451547
},
15461548
},
15471549
);
1548-
await bot.onRejected(
1550+
await bot.onFollowRejected(
15491551
ctx,
15501552
new Reject({
15511553
actor: new URL("https://example.com/ap/actor/john"),

src/bot-impl.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ export class BotImpl<TContextData> implements Bot<TContextData> {
9696

9797
onFollow?: FollowEventHandler<TContextData>;
9898
onUnfollow?: UnfollowEventHandler<TContextData>;
99-
onAccept?: AcceptEventHandler<TContextData>;
100-
onReject?: RejectEventHandler<TContextData>;
99+
onAcceptFollow?: AcceptEventHandler<TContextData>;
100+
onRejectFollow?: RejectEventHandler<TContextData>;
101101
onMention?: MentionEventHandler<TContextData>;
102102
onReply?: ReplyEventHandler<TContextData>;
103103

@@ -198,8 +198,8 @@ export class BotImpl<TContextData> implements Bot<TContextData> {
198198
.setInboxListeners("/ap/actor/{identifier}/inbox", "/ap/inbox")
199199
.on(Follow, this.onFollowed.bind(this))
200200
.on(Undo, this.onUnfollowed.bind(this))
201-
.on(Accept, this.onAccepted.bind(this))
202-
.on(Reject, this.onRejected.bind(this))
201+
.on(Accept, this.onFollowAccepted.bind(this))
202+
.on(Reject, this.onFollowRejected.bind(this))
203203
.on(Create, this.onCreated.bind(this))
204204
.setSharedKeyDispatcher(this.dispatchSharedKey.bind(this));
205205
if (this.software != null) {
@@ -631,7 +631,7 @@ export class BotImpl<TContextData> implements Bot<TContextData> {
631631
}
632632
}
633633

634-
async onAccepted(
634+
async onFollowAccepted(
635635
ctx: InboxContext<TContextData>,
636636
accept: Accept,
637637
): Promise<void> {
@@ -654,13 +654,13 @@ export class BotImpl<TContextData> implements Bot<TContextData> {
654654
[...this.kvPrefixes.followees, followee.id.href],
655655
followJson,
656656
);
657-
if (this.onAccept != null) {
657+
if (this.onAcceptFollow != null) {
658658
const session = this.getSession(ctx);
659-
await this.onAccept(session, followee);
659+
await this.onAcceptFollow(session, followee);
660660
}
661661
}
662662

663-
async onRejected(
663+
async onFollowRejected(
664664
ctx: InboxContext<TContextData>,
665665
reject: Reject,
666666
): Promise<void> {
@@ -683,9 +683,9 @@ export class BotImpl<TContextData> implements Bot<TContextData> {
683683
...this.kvPrefixes.follows,
684684
parsedObj.values.id,
685685
]);
686-
if (this.onReject != null) {
686+
if (this.onRejectFollow != null) {
687687
const session = this.getSession(ctx);
688-
await this.onReject(session, followee);
688+
await this.onRejectFollow(session, followee);
689689
}
690690
}
691691

src/bot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ export interface Bot<TContextData> {
9898
/**
9999
* An event handler invoked when a follow request the bot sent is accepted.
100100
*/
101-
onAccept?: AcceptEventHandler<TContextData>;
101+
onAcceptFollow?: AcceptEventHandler<TContextData>;
102102

103103
/**
104104
* An event handler invoked when a follow request the bot sent is rejected.
105105
*/
106-
onReject?: RejectEventHandler<TContextData>;
106+
onRejectFollow?: RejectEventHandler<TContextData>;
107107

108108
/**
109109
* An event handler for a message mentioned to the bot.

src/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export interface Session<TContextData> {
6161
* Send a follow request to the specified actor.
6262
*
6363
* Note that it does not guarantee that the follow request will be accepted.
64-
* You might need to handle {@link Bot.onAccept} and {@link Bot.onReject}
64+
* You might need to handle {@link Bot.onAcceptFollow} and {@link Bot.onRejectFollow}
6565
* events to know the result.
6666
*
6767
* If the bot is already following the actor, it does nothing.

0 commit comments

Comments
 (0)