@fedify/botkit 0.3.0-dev.111 → 0.3.0-dev.112

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  import { Temporal, toTemporalInstant } from "@js-temporal/polyfill";
2
2
  Date.prototype.toTemporalInstant = toTemporalInstant;
3
3
  import { Text } from "./text.js";
4
- import { AuthorizedMessage, Message, MessageClass } from "./message.js";
5
- import { Session, SessionGetOutboxOptions, SessionPublishOptions, SessionPublishOptionsWithClass } from "./session.js";
4
+ import { AuthorizedMessage, Message, MessageClass, Question } from "./message.js";
5
+ import { Session, SessionGetOutboxOptions, SessionPublishOptions, SessionPublishOptionsWithClass, SessionPublishOptionsWithQuestion } from "./session.js";
6
6
  import { BotImpl } from "./bot-impl.js";
7
7
  import { Actor, Context, Note } from "@fedify/fedify";
8
8
 
@@ -11,6 +11,7 @@ interface SessionImplPublishOptions<TContextData> extends SessionPublishOptions<
11
11
  replyTarget?: Message<MessageClass, TContextData>;
12
12
  }
13
13
  interface SessionImplPublishOptionsWithClass<T extends MessageClass, TContextData> extends SessionPublishOptionsWithClass<T, TContextData>, SessionImplPublishOptions<TContextData> {}
14
+ interface SessionImplPublishOptionsWithQuestion<TContextData> extends SessionPublishOptionsWithQuestion<TContextData>, SessionImplPublishOptionsWithClass<Question, TContextData> {}
14
15
  declare class SessionImpl<TContextData> implements Session<TContextData> {
15
16
  readonly bot: BotImpl<TContextData>;
16
17
  readonly context: Context<TContextData>;
@@ -23,10 +24,11 @@ declare class SessionImpl<TContextData> implements Session<TContextData> {
23
24
  follows(actor: Actor | URL | string): Promise<boolean>;
24
25
  publish(content: Text<"block", TContextData>, options?: SessionImplPublishOptions<TContextData>): Promise<AuthorizedMessage<Note, TContextData>>;
25
26
  publish<T extends MessageClass>(content: Text<"block", TContextData>, options: SessionImplPublishOptionsWithClass<T, TContextData>): Promise<AuthorizedMessage<T, TContextData>>;
27
+ publish(content: Text<"block", TContextData>, options: SessionImplPublishOptionsWithQuestion<TContextData>): Promise<AuthorizedMessage<Question, TContextData>>;
26
28
  getOutbox(options?: SessionGetOutboxOptions): AsyncIterable<AuthorizedMessage<MessageClass, TContextData>>;
27
29
  }
28
30
  //# sourceMappingURL=session-impl.d.ts.map
29
31
 
30
32
  //#endregion
31
- export { SessionImpl, SessionImplPublishOptions, SessionImplPublishOptionsWithClass };
33
+ export { SessionImpl, SessionImplPublishOptions, SessionImplPublishOptionsWithClass, SessionImplPublishOptionsWithQuestion };
32
34
  //# sourceMappingURL=session-impl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session-impl.d.ts","names":[],"sources":["../src/session-impl.ts"],"sourcesContent":[],"mappings":";;;;;;;;;UA4CiB,gDACP,sBAAsB;gBAChB,QAAQ,cAAc;;UAGrB,6CACL,oCAGV,+BAA+B,GAAG,eAClC,0BAA0B;cAGf,qCAAqC,QAAQ;EAbzC,SAAA,GAAA,EAcD,OAdC,CAcO,YAdkB,CAAA;EAAA,SAAA,OAAA,EAetB,OAfsB,CAed,YAfc,CAAA;EAAA,WACV,CAAA,GAAA,EAgBb,OAhBa,CAgBL,YAhBK,CAAA,EAAA,OAAA,EAgBmB,OAhBnB,CAgB2B,YAhB3B,CAAA;EAAY,IACpB,OAAA,CAAA,CAAA,EAoBX,GApBW;EAAY,IAAE,WAAA,CAAA,CAAA,EAAA,IAAA,MAAA,IAAA,MAAA,EAAA;EAAY,QAAlC,CAAA,CAAA,EA4BI,OA5BJ,CA4BY,KA5BZ,CAAA;EAAO,MADb,CAAA,KAAA,EAiCY,KAjCZ,GAiCoB,GAjCpB,GAAA,MAAA,CAAA,EAiCmC,OAjCnC,CAAA,IAAA,CAAA;EAAqB,QAAA,CAAA,KAAA,EA8EP,KA9EO,GA8EC,GA9ED,GAAA,MAAA,CAAA,EA8EgB,OA9EhB,CAAA,IAAA,CAAA;EAId,OAAA,CAAA,KAAA,EAuHM,KAvHN,GAuHc,GAvHd,GAAA,MAAA,CA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+3,8 @@
3
3
  Date.prototype.toTemporalInstant = toTemporalInstant;
4
4
 
5
5
  import { createMessage, isMessageObject } from "./message-impl.js";
6
- import { Follow, Link, Undo } from "@fedify/fedify/vocab";
6
+ import { Question } from "./message.js";
7
+ import { Collection, Follow, Link, Undo } from "@fedify/fedify/vocab";
7
8
  import { Create as Create$1, LanguageString, Mention as Mention$1, Note as Note$1, PUBLIC_COLLECTION as PUBLIC_COLLECTION$1, isActor as isActor$1 } from "@fedify/fedify";
8
9
  import { getLogger } from "@logtape/logtape";
9
10
  import { encode } from "html-entities";
@@ -115,6 +116,20 @@ var SessionImpl = class {
115
116
  name: `RE: ${url.href}`
116
117
  }));
117
118
  }
119
+ let inclusiveOptions = [];
120
+ let exclusiveOptions = [];
121
+ let voters = null;
122
+ let endTime = null;
123
+ if ("class" in options && options.class === Question && "poll" in options) {
124
+ const pollOptions = options.poll.options.map((option) => new Note$1({
125
+ name: option,
126
+ replies: new Collection({ totalItems: 0 })
127
+ }));
128
+ if (options.poll.multiple) inclusiveOptions = pollOptions;
129
+ else exclusiveOptions = pollOptions;
130
+ voters = 0;
131
+ endTime = options.poll.endTime;
132
+ }
118
133
  const msg = new cls({
119
134
  id: this.context.getObjectUri(cls, { id }),
120
135
  contents: options.language == null ? [contentHtml] : [new LanguageString(contentHtml, options.language), contentHtml],
@@ -123,6 +138,10 @@ var SessionImpl = class {
123
138
  tags,
124
139
  attribution: this.context.getActorUri(this.bot.identifier),
125
140
  attachments: options.attachments ?? [],
141
+ inclusiveOptions,
142
+ exclusiveOptions,
143
+ voters,
144
+ endTime,
126
145
  tos: visibility === "public" ? [PUBLIC_COLLECTION$1, ...mentionedActorIds] : visibility === "unlisted" || visibility === "followers" ? [this.context.getFollowersUri(this.bot.identifier), ...mentionedActorIds] : mentionedActorIds,
127
146
  ccs: visibility === "public" ? [this.context.getFollowersUri(this.bot.identifier)] : visibility === "unlisted" ? [PUBLIC_COLLECTION$1] : [],
128
147
  published: published.toTemporalInstant(),
@@ -1 +1 @@
1
- {"version":3,"file":"session-impl.js","names":["bot: BotImpl<TContextData>","context: Context<TContextData>","actor: Actor | URL | string","actorId: URL","content: Text<\"block\", TContextData>","options:\n | SessionImplPublishOptions<TContextData>\n | SessionImplPublishOptionsWithClass<MessageClass, TContextData>","Note","mentionedActorIds: URL[]","Mention","PUBLIC_COLLECTION","Create","cachedObjects: Record<string, Object>","promises: Promise<Object | null>[]","isActor","options: SessionGetOutboxOptions","object: Object | null"],"sources":["../src/session-impl.ts"],"sourcesContent":["// BotKit by Fedify: A framework for creating ActivityPub bots\n// Copyright (C) 2025 Hong Minhee <https://hongminhee.org/>\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as\n// published by the Free Software Foundation, either version 3 of the\n// License, or (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\nimport {\n type Actor,\n type Context,\n Create,\n isActor,\n LanguageString,\n Mention,\n Note,\n type Object,\n PUBLIC_COLLECTION,\n} from \"@fedify/fedify\";\nimport { Follow, Link, Undo } from \"@fedify/fedify/vocab\";\nimport { getLogger } from \"@logtape/logtape\";\nimport { encode } from \"html-entities\";\nimport { v7 as uuidv7 } from \"uuid\";\nimport type { BotImpl } from \"./bot-impl.ts\";\nimport { createMessage, isMessageObject } from \"./message-impl.ts\";\nimport type { AuthorizedMessage, Message, MessageClass } from \"./message.ts\";\nimport type { Uuid } from \"./repository.ts\";\nimport type {\n Session,\n SessionGetOutboxOptions,\n SessionPublishOptions,\n SessionPublishOptionsWithClass,\n} from \"./session.ts\";\nimport type { Text } from \"./text.ts\";\n\nconst logger = getLogger([\"botkit\", \"session\"]);\n\nexport interface SessionImplPublishOptions<TContextData>\n extends SessionPublishOptions<TContextData> {\n replyTarget?: Message<MessageClass, TContextData>;\n}\n\nexport interface SessionImplPublishOptionsWithClass<\n T extends MessageClass,\n TContextData,\n> extends\n SessionPublishOptionsWithClass<T, TContextData>,\n SessionImplPublishOptions<TContextData> {\n}\n\nexport class SessionImpl<TContextData> implements Session<TContextData> {\n readonly bot: BotImpl<TContextData>;\n readonly context: Context<TContextData>;\n\n constructor(bot: BotImpl<TContextData>, context: Context<TContextData>) {\n this.bot = bot;\n this.context = context;\n }\n\n get actorId() {\n return this.context.getActorUri(this.bot.identifier);\n }\n\n get actorHandle() {\n return `@${this.bot.username}@${this.context.host}` as const;\n }\n\n async getActor(): Promise<Actor> {\n return (await this.bot.dispatchActor(this.context, this.bot.identifier))!;\n }\n\n async follow(actor: Actor | URL | string): Promise<void> {\n if (actor instanceof URL || typeof actor === \"string\") {\n if (\n actor instanceof URL && actor.href === this.actorId.href ||\n typeof actor === \"string\" &&\n (actor === this.actorId.href || actor === this.actorHandle)\n ) {\n throw new TypeError(\"The bot cannot follow itself.\");\n }\n const documentLoader = await this.context.getDocumentLoader(this.bot);\n const object = await this.context.lookupObject(actor, { documentLoader });\n if (!isActor(object)) {\n throw new TypeError(\"The resolved object is not an Actor.\");\n }\n actor = object;\n }\n if (actor.id == null) {\n throw new TypeError(\"The actor does not have an ID.\");\n } else if (actor.id.href === this.actorId.href) {\n throw new TypeError(\"The bot cannot follow itself.\");\n }\n const followee = await this.bot.repository.getFollowee(actor.id);\n if (followee != null) {\n logger.warn(\n \"The bot is already following the actor {actor}.\",\n { actor: actor.id.href },\n );\n return;\n }\n const id = uuidv7() as Uuid;\n const follow = new Follow({\n id: this.context.getObjectUri(Follow, { id }),\n actor: this.context.getActorUri(this.bot.identifier),\n object: actor.id,\n to: actor.id,\n });\n await this.bot.repository.addSentFollow(id, follow);\n await this.context.sendActivity(\n this.bot,\n actor,\n follow,\n { excludeBaseUris: [new URL(this.context.origin)] },\n );\n }\n\n async unfollow(actor: Actor | URL | string): Promise<void> {\n const documentLoader = await this.context.getDocumentLoader(this.bot);\n if (actor instanceof URL || typeof actor === \"string\") {\n if (\n actor instanceof URL && actor.href === this.actorId.href ||\n typeof actor === \"string\" &&\n (actor === this.actorId.href || actor === this.actorHandle)\n ) {\n throw new TypeError(\"The bot cannot unfollow itself.\");\n }\n const object = await this.context.lookupObject(actor, { documentLoader });\n if (!isActor(object)) {\n throw new TypeError(\"The resolved object is not an Actor.\");\n }\n actor = object;\n }\n if (actor.id == null) {\n throw new TypeError(\"The actor does not have an ID.\");\n } else if (actor.id.href === this.actorId.href) {\n throw new TypeError(\"The bot cannot unfollow itself.\");\n }\n const follow = await this.bot.repository.getFollowee(actor.id);\n if (follow == null) {\n logger.warn(\n \"The bot is not following the actor {actor}.\",\n { actor: actor.id.href },\n );\n return;\n }\n await this.bot.repository.removeFollowee(actor.id);\n if (follow.id != null && follow.objectId?.href === actor.id.href) {\n await this.context.sendActivity(\n this.bot,\n actor,\n new Undo({\n id: new URL(\"#undo\", follow.id),\n actor: this.context.getActorUri(this.bot.identifier),\n object: follow,\n to: actor.id,\n }),\n { excludeBaseUris: [new URL(this.context.origin)] },\n );\n }\n }\n\n async follows(actor: Actor | URL | string): Promise<boolean> {\n let actorId: URL;\n if (isActor(actor)) {\n if (actor.id == null) {\n throw new TypeError(\"The actor does not have an ID.\");\n }\n actorId = actor.id;\n } else if (actor instanceof URL) {\n actorId = actor;\n } else {\n if (actor.startsWith(\"http://\") || actor.startsWith(\"https://\")) {\n actorId = new URL(actor);\n } else {\n if (actor === this.actorHandle) return false;\n const documentLoader = await this.context.getDocumentLoader(this.bot);\n const object = await this.context.lookupObject(actor, {\n documentLoader,\n });\n if (!isActor(object)) {\n throw new TypeError(\"The resolved object is not an Actor.\");\n }\n if (object.id == null) {\n throw new TypeError(\"The actor does not have an ID.\");\n }\n actorId = object.id;\n }\n }\n if (actorId.href === this.actorId.href) return false;\n const follow = await this.bot.repository.getFollowee(actorId);\n return follow != null;\n }\n\n async publish(\n content: Text<\"block\", TContextData>,\n options?: SessionImplPublishOptions<TContextData>,\n ): Promise<AuthorizedMessage<Note, TContextData>>;\n async publish<T extends MessageClass>(\n content: Text<\"block\", TContextData>,\n options: SessionImplPublishOptionsWithClass<T, TContextData>,\n ): Promise<AuthorizedMessage<T, TContextData>>;\n async publish(\n content: Text<\"block\", TContextData>,\n options:\n | SessionImplPublishOptions<TContextData>\n | SessionImplPublishOptionsWithClass<MessageClass, TContextData> = {},\n ): Promise<AuthorizedMessage<MessageClass, TContextData>> {\n const published = new Date();\n const id = uuidv7({ msecs: +published }) as Uuid;\n const cls = \"class\" in options ? options.class : Note;\n const visibility = options.visibility ?? \"public\";\n let contentHtml = \"\";\n for await (const chunk of content.getHtml(this)) {\n contentHtml += chunk;\n }\n const tags = await Array.fromAsync(content.getTags(this));\n const mentionedActorIds: URL[] = [];\n for (const tag of tags) {\n if (tag instanceof Mention && tag.href != null) {\n mentionedActorIds.push(tag.href);\n }\n }\n if (options.quoteTarget != null) {\n let url = options.quoteTarget.raw.url ?? options.quoteTarget.id;\n if (url instanceof Link) url = url.href ?? options.quoteTarget.id;\n contentHtml += `\\n\\n<p class=\"quote-inline\"><br>RE: <a href=\"${\n encode(url.href)\n }\">${encode(url.href)}</a></p>`;\n tags.push(\n new Link({\n mediaType:\n 'application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"',\n rel: \"https://misskey-hub.net/ns#_misskey_quote\",\n href: options.quoteTarget.id,\n name: `RE: ${url.href}`,\n }),\n );\n }\n const msg = new cls({\n id: this.context.getObjectUri<MessageClass>(cls, { id }),\n contents: options.language == null\n ? [contentHtml]\n : [new LanguageString(contentHtml, options.language), contentHtml],\n replyTarget: options.replyTarget?.id,\n quoteUrl: options.quoteTarget?.id,\n tags,\n attribution: this.context.getActorUri(this.bot.identifier),\n attachments: options.attachments ?? [],\n tos: visibility === \"public\"\n ? [PUBLIC_COLLECTION, ...mentionedActorIds]\n : visibility === \"unlisted\" || visibility === \"followers\"\n ? [\n this.context.getFollowersUri(this.bot.identifier),\n ...mentionedActorIds,\n ]\n : mentionedActorIds,\n ccs: visibility === \"public\"\n ? [this.context.getFollowersUri(this.bot.identifier)]\n : visibility === \"unlisted\"\n ? [PUBLIC_COLLECTION]\n : [],\n published: published.toTemporalInstant(),\n url: new URL(`/message/${id}`, this.context.origin),\n });\n const activity = new Create({\n id: this.context.getObjectUri(Create, { id }),\n actors: msg.attributionIds,\n tos: msg.toIds,\n ccs: msg.ccIds,\n object: msg,\n published: published.toTemporalInstant(),\n });\n await this.bot.repository.addMessage(id, activity);\n const preferSharedInbox = visibility === \"public\" ||\n visibility === \"unlisted\" || visibility === \"followers\";\n const excludeBaseUris = [new URL(this.context.origin)];\n if (preferSharedInbox) {\n await this.context.sendActivity(\n this.bot,\n \"followers\",\n activity,\n { preferSharedInbox, excludeBaseUris },\n );\n }\n const cachedObjects: Record<string, Object> = {};\n for (const cachedObject of content.getCachedObjects()) {\n if (cachedObject.id == null) continue;\n cachedObjects[cachedObject.id.href] = cachedObject;\n }\n if (mentionedActorIds.length > 0) {\n const documentLoader = await this.context.getDocumentLoader(this.bot);\n const promises: Promise<Object | null>[] = [];\n for (const mentionedActorId of mentionedActorIds) {\n const cachedObject = cachedObjects[mentionedActorId.href];\n const promise = cachedObject == null\n ? this.context.lookupObject(\n mentionedActorId,\n { documentLoader },\n )\n : Promise.resolve(cachedObject);\n promises.push(promise);\n }\n const objects = await Promise.all(promises);\n const mentionedActors = objects.filter(isActor);\n await this.context.sendActivity(\n this.bot,\n mentionedActors,\n activity,\n { preferSharedInbox, excludeBaseUris },\n );\n }\n if (options.replyTarget != null) {\n await this.context.sendActivity(\n this.bot,\n options.replyTarget.actor,\n activity,\n { preferSharedInbox, excludeBaseUris, fanout: \"skip\" },\n );\n }\n if (options.quoteTarget != null) {\n await this.context.sendActivity(\n this.bot,\n options.quoteTarget.actor,\n activity,\n { preferSharedInbox, excludeBaseUris, fanout: \"skip\" },\n );\n }\n return await createMessage(\n msg,\n this,\n cachedObjects,\n options.replyTarget,\n options.quoteTarget,\n true,\n );\n }\n\n async *getOutbox(\n options: SessionGetOutboxOptions = {},\n ): AsyncIterable<AuthorizedMessage<MessageClass, TContextData>> {\n for await (const activity of this.bot.repository.getMessages(options)) {\n let object: Object | null;\n try {\n object = await activity.getObject(this.context);\n } catch {\n continue;\n }\n if (object == null || !isMessageObject(object)) continue;\n const message = await createMessage(object, this, {});\n yield message;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AA0CA,MAAM,SAAS,UAAU,CAAC,UAAU,SAAU,EAAC;AAe/C,IAAa,cAAb,MAAwE;CACtE,AAAS;CACT,AAAS;CAET,YAAYA,KAA4BC,SAAgC;AACtE,OAAK,MAAM;AACX,OAAK,UAAU;CAChB;CAED,IAAI,UAAU;AACZ,SAAO,KAAK,QAAQ,YAAY,KAAK,IAAI,WAAW;CACrD;CAED,IAAI,cAAc;AAChB,UAAQ,GAAG,KAAK,IAAI,SAAS,GAAG,KAAK,QAAQ,KAAK;CACnD;CAED,MAAM,WAA2B;AAC/B,SAAQ,MAAM,KAAK,IAAI,cAAc,KAAK,SAAS,KAAK,IAAI,WAAW;CACxE;CAED,MAAM,OAAOC,OAA4C;AACvD,MAAI,iBAAiB,cAAc,UAAU,UAAU;AACrD,OACE,iBAAiB,OAAO,MAAM,SAAS,KAAK,QAAQ,eAC7C,UAAU,aACd,UAAU,KAAK,QAAQ,QAAQ,UAAU,KAAK,aAEjD,OAAM,IAAI,UAAU;GAEtB,MAAM,iBAAiB,MAAM,KAAK,QAAQ,kBAAkB,KAAK,IAAI;GACrE,MAAM,SAAS,MAAM,KAAK,QAAQ,aAAa,OAAO,EAAE,eAAgB,EAAC;AACzE,QAAK,UAAQ,OAAO,CAClB,OAAM,IAAI,UAAU;AAEtB,WAAQ;EACT;AACD,MAAI,MAAM,MAAM,KACd,OAAM,IAAI,UAAU;WACX,MAAM,GAAG,SAAS,KAAK,QAAQ,KACxC,OAAM,IAAI,UAAU;EAEtB,MAAM,WAAW,MAAM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ACL,QAAQ,YAAY,OACpB,UACA;GAAE;GAAmB;GAAiB,QAAQ;EAAQ,EACvD;AAEH,SAAO,MAAM,cACX,KACA,MACA,eACA,QAAQ,aACR,QAAQ,aACR,KACD;CACF;CAED,OAAO,UACLC,UAAmC,CAAE,GACyB;AAC9D,aAAW,MAAM,YAAY,KAAK,IAAI,WAAW,YAAY,QAAQ,EAAE;GACrE,IAAIC;AACJ,OAAI;AACF,aAAS,MAAM,SAAS,UAAU,KAAK,QAAQ;GAChD,QAAO;AACN;GACD;AACD,OAAI,UAAU,SAAS,gBAAgB,OAAO,CAAE;GAChD,MAAM,UAAU,MAAM,cAAc,QAAQ,MAAM,CAAE,EAAC;AACrD,SAAM;EACP;CACF;AACF"}
1
+ {"version":3,"file":"session-impl.js","names":["bot: BotImpl<TContextData>","context: Context<TContextData>","actor: Actor | URL | string","actorId: URL","content: Text<\"block\", TContextData>","options:\n | SessionImplPublishOptions<TContextData>\n | SessionImplPublishOptionsWithClass<MessageClass, TContextData>\n | SessionImplPublishOptionsWithQuestion<TContextData>","Note","mentionedActorIds: URL[]","Mention","inclusiveOptions: Note[]","exclusiveOptions: Note[]","voters: number | null","endTime: Temporal.Instant | null","PUBLIC_COLLECTION","Create","cachedObjects: Record<string, Object>","promises: Promise<Object | null>[]","isActor","options: SessionGetOutboxOptions","object: Object | null"],"sources":["../src/session-impl.ts"],"sourcesContent":["// BotKit by Fedify: A framework for creating ActivityPub bots\n// Copyright (C) 2025 Hong Minhee <https://hongminhee.org/>\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as\n// published by the Free Software Foundation, either version 3 of the\n// License, or (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\nimport {\n type Actor,\n type Context,\n Create,\n isActor,\n LanguageString,\n Mention,\n Note,\n type Object,\n PUBLIC_COLLECTION,\n} from \"@fedify/fedify\";\nimport { Collection, Follow, Link, Undo } from \"@fedify/fedify/vocab\";\nimport { getLogger } from \"@logtape/logtape\";\nimport { encode } from \"html-entities\";\nimport { v7 as uuidv7 } from \"uuid\";\nimport type { BotImpl } from \"./bot-impl.ts\";\nimport { createMessage, isMessageObject } from \"./message-impl.ts\";\nimport {\n type AuthorizedMessage,\n type Message,\n type MessageClass,\n Question,\n} from \"./message.ts\";\nimport type { Uuid } from \"./repository.ts\";\nimport type {\n Session,\n SessionGetOutboxOptions,\n SessionPublishOptions,\n SessionPublishOptionsWithClass,\n SessionPublishOptionsWithQuestion,\n} from \"./session.ts\";\nimport type { Text } from \"./text.ts\";\n\nconst logger = getLogger([\"botkit\", \"session\"]);\n\nexport interface SessionImplPublishOptions<TContextData>\n extends SessionPublishOptions<TContextData> {\n replyTarget?: Message<MessageClass, TContextData>;\n}\n\nexport interface SessionImplPublishOptionsWithClass<\n T extends MessageClass,\n TContextData,\n> extends\n SessionPublishOptionsWithClass<T, TContextData>,\n SessionImplPublishOptions<TContextData> {\n}\n\nexport interface SessionImplPublishOptionsWithQuestion<TContextData>\n extends\n SessionPublishOptionsWithQuestion<TContextData>,\n SessionImplPublishOptionsWithClass<Question, TContextData> {\n}\n\nexport class SessionImpl<TContextData> implements Session<TContextData> {\n readonly bot: BotImpl<TContextData>;\n readonly context: Context<TContextData>;\n\n constructor(bot: BotImpl<TContextData>, context: Context<TContextData>) {\n this.bot = bot;\n this.context = context;\n }\n\n get actorId() {\n return this.context.getActorUri(this.bot.identifier);\n }\n\n get actorHandle() {\n return `@${this.bot.username}@${this.context.host}` as const;\n }\n\n async getActor(): Promise<Actor> {\n return (await this.bot.dispatchActor(this.context, this.bot.identifier))!;\n }\n\n async follow(actor: Actor | URL | string): Promise<void> {\n if (actor instanceof URL || typeof actor === \"string\") {\n if (\n actor instanceof URL && actor.href === this.actorId.href ||\n typeof actor === \"string\" &&\n (actor === this.actorId.href || actor === this.actorHandle)\n ) {\n throw new TypeError(\"The bot cannot follow itself.\");\n }\n const documentLoader = await this.context.getDocumentLoader(this.bot);\n const object = await this.context.lookupObject(actor, { documentLoader });\n if (!isActor(object)) {\n throw new TypeError(\"The resolved object is not an Actor.\");\n }\n actor = object;\n }\n if (actor.id == null) {\n throw new TypeError(\"The actor does not have an ID.\");\n } else if (actor.id.href === this.actorId.href) {\n throw new TypeError(\"The bot cannot follow itself.\");\n }\n const followee = await this.bot.repository.getFollowee(actor.id);\n if (followee != null) {\n logger.warn(\n \"The bot is already following the actor {actor}.\",\n { actor: actor.id.href },\n );\n return;\n }\n const id = uuidv7() as Uuid;\n const follow = new Follow({\n id: this.context.getObjectUri(Follow, { id }),\n actor: this.context.getActorUri(this.bot.identifier),\n object: actor.id,\n to: actor.id,\n });\n await this.bot.repository.addSentFollow(id, follow);\n await this.context.sendActivity(\n this.bot,\n actor,\n follow,\n { excludeBaseUris: [new URL(this.context.origin)] },\n );\n }\n\n async unfollow(actor: Actor | URL | string): Promise<void> {\n const documentLoader = await this.context.getDocumentLoader(this.bot);\n if (actor instanceof URL || typeof actor === \"string\") {\n if (\n actor instanceof URL && actor.href === this.actorId.href ||\n typeof actor === \"string\" &&\n (actor === this.actorId.href || actor === this.actorHandle)\n ) {\n throw new TypeError(\"The bot cannot unfollow itself.\");\n }\n const object = await this.context.lookupObject(actor, { documentLoader });\n if (!isActor(object)) {\n throw new TypeError(\"The resolved object is not an Actor.\");\n }\n actor = object;\n }\n if (actor.id == null) {\n throw new TypeError(\"The actor does not have an ID.\");\n } else if (actor.id.href === this.actorId.href) {\n throw new TypeError(\"The bot cannot unfollow itself.\");\n }\n const follow = await this.bot.repository.getFollowee(actor.id);\n if (follow == null) {\n logger.warn(\n \"The bot is not following the actor {actor}.\",\n { actor: actor.id.href },\n );\n return;\n }\n await this.bot.repository.removeFollowee(actor.id);\n if (follow.id != null && follow.objectId?.href === actor.id.href) {\n await this.context.sendActivity(\n this.bot,\n actor,\n new Undo({\n id: new URL(\"#undo\", follow.id),\n actor: this.context.getActorUri(this.bot.identifier),\n object: follow,\n to: actor.id,\n }),\n { excludeBaseUris: [new URL(this.context.origin)] },\n );\n }\n }\n\n async follows(actor: Actor | URL | string): Promise<boolean> {\n let actorId: URL;\n if (isActor(actor)) {\n if (actor.id == null) {\n throw new TypeError(\"The actor does not have an ID.\");\n }\n actorId = actor.id;\n } else if (actor instanceof URL) {\n actorId = actor;\n } else {\n if (actor.startsWith(\"http://\") || actor.startsWith(\"https://\")) {\n actorId = new URL(actor);\n } else {\n if (actor === this.actorHandle) return false;\n const documentLoader = await this.context.getDocumentLoader(this.bot);\n const object = await this.context.lookupObject(actor, {\n documentLoader,\n });\n if (!isActor(object)) {\n throw new TypeError(\"The resolved object is not an Actor.\");\n }\n if (object.id == null) {\n throw new TypeError(\"The actor does not have an ID.\");\n }\n actorId = object.id;\n }\n }\n if (actorId.href === this.actorId.href) return false;\n const follow = await this.bot.repository.getFollowee(actorId);\n return follow != null;\n }\n\n async publish(\n content: Text<\"block\", TContextData>,\n options?: SessionImplPublishOptions<TContextData>,\n ): Promise<AuthorizedMessage<Note, TContextData>>;\n async publish<T extends MessageClass>(\n content: Text<\"block\", TContextData>,\n options: SessionImplPublishOptionsWithClass<T, TContextData>,\n ): Promise<AuthorizedMessage<T, TContextData>>;\n async publish(\n content: Text<\"block\", TContextData>,\n options: SessionImplPublishOptionsWithQuestion<TContextData>,\n ): Promise<AuthorizedMessage<Question, TContextData>>;\n async publish(\n content: Text<\"block\", TContextData>,\n options:\n | SessionImplPublishOptions<TContextData>\n | SessionImplPublishOptionsWithClass<MessageClass, TContextData>\n | SessionImplPublishOptionsWithQuestion<TContextData> = {},\n ): Promise<AuthorizedMessage<MessageClass, TContextData>> {\n const published = new Date();\n const id = uuidv7({ msecs: +published }) as Uuid;\n const cls = \"class\" in options ? options.class : Note;\n const visibility = options.visibility ?? \"public\";\n let contentHtml = \"\";\n for await (const chunk of content.getHtml(this)) {\n contentHtml += chunk;\n }\n const tags = await Array.fromAsync(content.getTags(this));\n const mentionedActorIds: URL[] = [];\n for (const tag of tags) {\n if (tag instanceof Mention && tag.href != null) {\n mentionedActorIds.push(tag.href);\n }\n }\n if (options.quoteTarget != null) {\n let url = options.quoteTarget.raw.url ?? options.quoteTarget.id;\n if (url instanceof Link) url = url.href ?? options.quoteTarget.id;\n contentHtml += `\\n\\n<p class=\"quote-inline\"><br>RE: <a href=\"${\n encode(url.href)\n }\">${encode(url.href)}</a></p>`;\n tags.push(\n new Link({\n mediaType:\n 'application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"',\n rel: \"https://misskey-hub.net/ns#_misskey_quote\",\n href: options.quoteTarget.id,\n name: `RE: ${url.href}`,\n }),\n );\n }\n let inclusiveOptions: Note[] = [];\n let exclusiveOptions: Note[] = [];\n let voters: number | null = null;\n let endTime: Temporal.Instant | null = null;\n if (\"class\" in options && options.class === Question && \"poll\" in options) {\n const pollOptions = options.poll.options.map((option) =>\n new Note({\n name: option,\n replies: new Collection({ totalItems: 0 }),\n })\n );\n if (options.poll.multiple) inclusiveOptions = pollOptions;\n else exclusiveOptions = pollOptions;\n voters = 0;\n endTime = options.poll.endTime;\n }\n const msg = new cls({\n id: this.context.getObjectUri<MessageClass>(cls, { id }),\n contents: options.language == null\n ? [contentHtml]\n : [new LanguageString(contentHtml, options.language), contentHtml],\n replyTarget: options.replyTarget?.id,\n quoteUrl: options.quoteTarget?.id,\n tags,\n attribution: this.context.getActorUri(this.bot.identifier),\n attachments: options.attachments ?? [],\n inclusiveOptions,\n exclusiveOptions,\n voters,\n endTime,\n tos: visibility === \"public\"\n ? [PUBLIC_COLLECTION, ...mentionedActorIds]\n : visibility === \"unlisted\" || visibility === \"followers\"\n ? [\n this.context.getFollowersUri(this.bot.identifier),\n ...mentionedActorIds,\n ]\n : mentionedActorIds,\n ccs: visibility === \"public\"\n ? [this.context.getFollowersUri(this.bot.identifier)]\n : visibility === \"unlisted\"\n ? [PUBLIC_COLLECTION]\n : [],\n published: published.toTemporalInstant(),\n url: new URL(`/message/${id}`, this.context.origin),\n });\n const activity = new Create({\n id: this.context.getObjectUri(Create, { id }),\n actors: msg.attributionIds,\n tos: msg.toIds,\n ccs: msg.ccIds,\n object: msg,\n published: published.toTemporalInstant(),\n });\n await this.bot.repository.addMessage(id, activity);\n const preferSharedInbox = visibility === \"public\" ||\n visibility === \"unlisted\" || visibility === \"followers\";\n const excludeBaseUris = [new URL(this.context.origin)];\n if (preferSharedInbox) {\n await this.context.sendActivity(\n this.bot,\n \"followers\",\n activity,\n { preferSharedInbox, excludeBaseUris },\n );\n }\n const cachedObjects: Record<string, Object> = {};\n for (const cachedObject of content.getCachedObjects()) {\n if (cachedObject.id == null) continue;\n cachedObjects[cachedObject.id.href] = cachedObject;\n }\n if (mentionedActorIds.length > 0) {\n const documentLoader = await this.context.getDocumentLoader(this.bot);\n const promises: Promise<Object | null>[] = [];\n for (const mentionedActorId of mentionedActorIds) {\n const cachedObject = cachedObjects[mentionedActorId.href];\n const promise = cachedObject == null\n ? this.context.lookupObject(\n mentionedActorId,\n { documentLoader },\n )\n : Promise.resolve(cachedObject);\n promises.push(promise);\n }\n const objects = await Promise.all(promises);\n const mentionedActors = objects.filter(isActor);\n await this.context.sendActivity(\n this.bot,\n mentionedActors,\n activity,\n { preferSharedInbox, excludeBaseUris },\n );\n }\n if (options.replyTarget != null) {\n await this.context.sendActivity(\n this.bot,\n options.replyTarget.actor,\n activity,\n { preferSharedInbox, excludeBaseUris, fanout: \"skip\" },\n );\n }\n if (options.quoteTarget != null) {\n await this.context.sendActivity(\n this.bot,\n options.quoteTarget.actor,\n activity,\n { preferSharedInbox, excludeBaseUris, fanout: \"skip\" },\n );\n }\n return await createMessage(\n msg,\n this,\n cachedObjects,\n options.replyTarget,\n options.quoteTarget,\n true,\n );\n }\n\n async *getOutbox(\n options: SessionGetOutboxOptions = {},\n ): AsyncIterable<AuthorizedMessage<MessageClass, TContextData>> {\n for await (const activity of this.bot.repository.getMessages(options)) {\n let object: Object | null;\n try {\n object = await activity.getObject(this.context);\n } catch {\n continue;\n }\n if (object == null || !isMessageObject(object)) continue;\n const message = await createMessage(object, this, {});\n yield message;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAgDA,MAAM,SAAS,UAAU,CAAC,UAAU,SAAU,EAAC;AAqB/C,IAAa,cAAb,MAAwE;CACtE,AAAS;CACT,AAAS;CAET,YAAYA,KAA4BC,SAAgC;AACtE,OAAK,MAAM;AACX,OAAK,UAAU;CAChB;CAED,IAAI,UAAU;AACZ,SAAO,KAAK,QAAQ,YAAY,KAAK,IAAI,WAAW;CACrD;CAED,IAAI,cAAc;AAChB,UAAQ,GAAG,KAAK,IAAI,SAAS,GAAG,KAAK,QAAQ,KAAK;CACnD;CAED,MAAM,WAA2B;AAC/B,SAAQ,MAAM,KAAK,IAAI,cAAc,KAAK,SAAS,KAAK,IAAI,WAAW;CACxE;CAED,MAAM,OAAOC,OAA4C;AACvD,MAAI,iBAAiB,cAAc,UAAU,UAAU;AACrD,OACE,iBAAiB,OAAO,MAAM,SAAS,KAAK,QAAQ,eAC7C,UAAU,aACd,UAAU,KAAK,QAAQ,QAAQ,UAAU,KAAK,aAEjD,OAAM,IAAI,UAAU;GAEtB,MAAM,iBAAiB,MAAM,KAAK,QAAQ,kBAAkB,KAAK,IAAI;GACrE,MAAM,SAAS,MAAM,KAAK,QAAQ,aAAa,OAAO,EAAE,eAAgB,EAAC;AACzE,QAAK,UAAQ,OAAO,CAClB,OAAM,IAAI,UAAU;AAEtB,WAAQ;EACT;AACD,MAAI,MAAM,MAAM,KACd,OAAM,IAAI,UAAU;WACX,MAAM,GAAG,SAAS,KAAK,QAAQ,KACxC,OAAM,IAAI,UAAU;EAEtB,MAAM,WAAW,MAAM,KAAK,IAAI,WAAW,YAAY,MAAM,GAAG;AAChE,MAAI,YAAY,MAAM;AACpB,UAAO,KACL,mDACA,E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MAAM,kBAAkB,QAAQ,OAAOC,UAAQ;AAC/C,SAAM,KAAK,QAAQ,aACjB,KAAK,KACL,iBACA,UACA;IAAE;IAAmB;GAAiB,EACvC;EACF;AACD,MAAI,QAAQ,eAAe,KACzB,OAAM,KAAK,QAAQ,aACjB,KAAK,KACL,QAAQ,YAAY,OACpB,UACA;GAAE;GAAmB;GAAiB,QAAQ;EAAQ,EACvD;AAEH,MAAI,QAAQ,eAAe,KACzB,OAAM,KAAK,QAAQ,aACjB,KAAK,KACL,QAAQ,YAAY,OACpB,UACA;GAAE;GAAmB;GAAiB,QAAQ;EAAQ,EACvD;AAEH,SAAO,MAAM,cACX,KACA,MACA,eACA,QAAQ,aACR,QAAQ,aACR,KACD;CACF;CAED,OAAO,UACLC,UAAmC,CAAE,GACyB;AAC9D,aAAW,MAAM,YAAY,KAAK,IAAI,WAAW,YAAY,QAAQ,EAAE;GACrE,IAAIC;AACJ,OAAI;AACF,aAAS,MAAM,SAAS,UAAU,KAAK,QAAQ;GAChD,QAAO;AACN;GACD;AACD,OAAI,UAAU,SAAS,gBAAgB,OAAO,CAAE;GAChD,MAAM,UAAU,MAAM,cAAc,QAAQ,MAAM,CAAE,EAAC;AACrD,SAAM;EACP;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"session-impl.test.d.ts","names":[],"sources":["../src/session-impl.test.ts"],"sourcesContent":[],"mappings":";;;;;;;UAwqBiB,YAAA;4BACW;YAChB;;UAGK,WAAA,SAAoB;kBACnB;AANlB;AAA6B,iBASb,iBAAA,CATa,GAAA,EAUtB,OAVsB,CAAA,IAAA,CAAA,EAAA,MAAA,EAWnB,GAXmB,GAAA,MAAA,CAAA,EAY1B,WAZ0B"}
1
+ {"version":3,"file":"session-impl.test.d.ts","names":[],"sources":["../src/session-impl.test.ts"],"sourcesContent":[],"mappings":";;;;;;;UAw2BiB,YAAA;4BACW;YAChB;;UAGK,WAAA,SAAoB;kBACnB;AANlB;AAA6B,iBASb,iBAAA,CATa,GAAA,EAUtB,OAVsB,CAAA,IAAA,CAAA,EAAA,MAAA,EAWnB,GAXmB,GAAA,MAAA,CAAA,EAY1B,WAZ0B"}
@@ -8,7 +8,7 @@ import { SessionImpl } from "./session-impl.js";
8
8
  import { BotImpl } from "./bot-impl.js";
9
9
  import { mention, text } from "./text.js";
10
10
  import { MemoryKvStore } from "@fedify/fedify/federation";
11
- import { Create, Follow, Note, PUBLIC_COLLECTION, Person, Undo } from "@fedify/fedify/vocab";
11
+ import { Create, Follow, Note, PUBLIC_COLLECTION, Person, Question, Undo } from "@fedify/fedify/vocab";
12
12
  import assert from "node:assert";
13
13
  import { describe, test } from "node:test";
14
14
 
@@ -312,6 +312,165 @@ test("SessionImpl.publish()", async (t) => {
312
312
  assert.deepStrictEqual(quote.visibility, "public");
313
313
  assert.deepStrictEqual(quote.quoteTarget?.id, originalMsg.id);
314
314
  });
315
+ await t.test("poll single choice", async () => {
316
+ ctx.sentActivities = [];
317
+ const endTime = Temporal.Now.instant().add({ hours: 24 });
318
+ const poll = await session.publish(text`What's your favorite color?`, {
319
+ class: Question,
320
+ poll: {
321
+ multiple: false,
322
+ options: [
323
+ "Red",
324
+ "Blue",
325
+ "Green"
326
+ ],
327
+ endTime
328
+ }
329
+ });
330
+ assert.deepStrictEqual(ctx.sentActivities.length, 1);
331
+ const { recipients, activity } = ctx.sentActivities[0];
332
+ assert.deepStrictEqual(recipients, "followers");
333
+ assert.ok(activity instanceof Create);
334
+ assert.deepStrictEqual(activity.actorId, ctx.getActorUri(bot.identifier));
335
+ assert.deepStrictEqual(activity.toIds, [PUBLIC_COLLECTION]);
336
+ assert.deepStrictEqual(activity.ccIds, [ctx.getFollowersUri(bot.identifier)]);
337
+ const object = await activity.getObject(ctx);
338
+ assert.ok(object instanceof Question);
339
+ assert.deepStrictEqual(object.attributionId, ctx.getActorUri(bot.identifier));
340
+ assert.deepStrictEqual(object.toIds, [PUBLIC_COLLECTION]);
341
+ assert.deepStrictEqual(object.ccIds, [ctx.getFollowersUri(bot.identifier)]);
342
+ assert.deepStrictEqual(object.content, "<p>What&apos;s your favorite color?</p>");
343
+ assert.deepStrictEqual(object.endTime, endTime);
344
+ assert.deepStrictEqual(object.voters, 0);
345
+ assert.deepStrictEqual(object.inclusiveOptionIds, []);
346
+ const exclusiveOptions = await Array.fromAsync(object.getExclusiveOptions(ctx));
347
+ assert.deepStrictEqual(exclusiveOptions.length, 3);
348
+ assert.ok(exclusiveOptions[0] instanceof Note);
349
+ assert.deepStrictEqual(exclusiveOptions[0].name?.toString(), "Red");
350
+ assert.ok(exclusiveOptions[1] instanceof Note);
351
+ assert.deepStrictEqual(exclusiveOptions[1].name?.toString(), "Blue");
352
+ assert.ok(exclusiveOptions[2] instanceof Note);
353
+ assert.deepStrictEqual(exclusiveOptions[2].name?.toString(), "Green");
354
+ for (const option of exclusiveOptions) {
355
+ const replies = await option.getReplies(ctx);
356
+ assert.deepStrictEqual(replies?.totalItems, 0);
357
+ }
358
+ assert.deepStrictEqual(poll.id, object.id);
359
+ assert.deepStrictEqual(poll.text, "What's your favorite color?");
360
+ assert.deepStrictEqual(poll.html, "<p>What&apos;s your favorite color?</p>");
361
+ assert.deepStrictEqual(poll.visibility, "public");
362
+ });
363
+ await t.test("poll multiple choice", async () => {
364
+ ctx.sentActivities = [];
365
+ const endTime = Temporal.Now.instant().add({ hours: 24 * 7 });
366
+ const poll = await session.publish(text`Which programming languages do you know?`, {
367
+ class: Question,
368
+ poll: {
369
+ multiple: true,
370
+ options: [
371
+ "JavaScript",
372
+ "TypeScript",
373
+ "Python",
374
+ "Rust"
375
+ ],
376
+ endTime
377
+ },
378
+ visibility: "unlisted"
379
+ });
380
+ assert.deepStrictEqual(ctx.sentActivities.length, 1);
381
+ const { recipients, activity } = ctx.sentActivities[0];
382
+ assert.deepStrictEqual(recipients, "followers");
383
+ assert.ok(activity instanceof Create);
384
+ const object = await activity.getObject(ctx);
385
+ assert.ok(object instanceof Question);
386
+ assert.deepStrictEqual(object.endTime, endTime);
387
+ assert.deepStrictEqual(object.voters, 0);
388
+ assert.deepStrictEqual(object.exclusiveOptionIds, []);
389
+ const inclusiveOptions = await Array.fromAsync(object.getInclusiveOptions(ctx));
390
+ assert.deepStrictEqual(inclusiveOptions.length, 4);
391
+ assert.ok(inclusiveOptions[0] instanceof Note);
392
+ assert.deepStrictEqual(inclusiveOptions[0].name?.toString(), "JavaScript");
393
+ assert.ok(inclusiveOptions[1] instanceof Note);
394
+ assert.deepStrictEqual(inclusiveOptions[1].name?.toString(), "TypeScript");
395
+ assert.ok(inclusiveOptions[2] instanceof Note);
396
+ assert.deepStrictEqual(inclusiveOptions[2].name?.toString(), "Python");
397
+ assert.ok(inclusiveOptions[3] instanceof Note);
398
+ assert.deepStrictEqual(inclusiveOptions[3].name?.toString(), "Rust");
399
+ assert.deepStrictEqual(poll.visibility, "unlisted");
400
+ assert.deepStrictEqual(activity.toIds, [ctx.getFollowersUri(bot.identifier)]);
401
+ assert.deepStrictEqual(activity.ccIds, [PUBLIC_COLLECTION]);
402
+ });
403
+ await t.test("poll with direct visibility", async () => {
404
+ const mentioned = new Person({
405
+ id: new URL("https://example.com/ap/actor/alice"),
406
+ preferredUsername: "alice"
407
+ });
408
+ ctx.sentActivities = [];
409
+ const endTime = Temporal.Now.instant().add({ hours: 12 });
410
+ const poll = await session.publish(text`Hey ${mention(mentioned)}, what do you think?`, {
411
+ class: Question,
412
+ poll: {
413
+ multiple: false,
414
+ options: [
415
+ "Good",
416
+ "Bad",
417
+ "Neutral"
418
+ ],
419
+ endTime
420
+ },
421
+ visibility: "direct"
422
+ });
423
+ assert.deepStrictEqual(ctx.sentActivities.length, 1);
424
+ const { recipients, activity } = ctx.sentActivities[0];
425
+ assert.deepStrictEqual(recipients, [mentioned]);
426
+ assert.ok(activity instanceof Create);
427
+ const object = await activity.getObject(ctx);
428
+ assert.ok(object instanceof Question);
429
+ assert.deepStrictEqual(object.toIds, [mentioned.id]);
430
+ assert.deepStrictEqual(object.ccIds, []);
431
+ assert.deepStrictEqual(poll.visibility, "direct");
432
+ });
433
+ await t.test("poll end-to-end workflow", async () => {
434
+ const freshRepository = new MemoryRepository();
435
+ const freshBot = new BotImpl({
436
+ kv: new MemoryKvStore(),
437
+ repository: freshRepository,
438
+ username: "testbot"
439
+ });
440
+ const freshCtx = createMockContext(freshBot, "https://example.com");
441
+ const freshSession = new SessionImpl(freshBot, freshCtx);
442
+ const endTime = Temporal.Now.instant().add({ hours: 1 });
443
+ const poll = await freshSession.publish(text`What should we have for lunch?`, {
444
+ class: Question,
445
+ poll: {
446
+ multiple: false,
447
+ options: [
448
+ "Pizza",
449
+ "Burgers",
450
+ "Salad"
451
+ ],
452
+ endTime
453
+ }
454
+ });
455
+ assert.deepStrictEqual(freshCtx.sentActivities.length, 1);
456
+ const { activity: createActivity } = freshCtx.sentActivities[0];
457
+ assert.ok(createActivity instanceof Create);
458
+ const pollObject = await createActivity.getObject(freshCtx);
459
+ assert.ok(pollObject instanceof Question);
460
+ assert.deepStrictEqual(pollObject.endTime, endTime);
461
+ const options = await Array.fromAsync(pollObject.getExclusiveOptions(freshCtx));
462
+ assert.deepStrictEqual(options.length, 3);
463
+ assert.deepStrictEqual(options[0].name?.toString(), "Pizza");
464
+ assert.deepStrictEqual(options[1].name?.toString(), "Burgers");
465
+ assert.deepStrictEqual(options[2].name?.toString(), "Salad");
466
+ const outbox = freshSession.getOutbox({ order: "newest" });
467
+ const messages = await Array.fromAsync(outbox);
468
+ assert.deepStrictEqual(messages.length, 1);
469
+ assert.deepStrictEqual(messages[0].id, poll.id);
470
+ assert.deepStrictEqual(messages[0].text, "What should we have for lunch?");
471
+ assert.deepStrictEqual(poll.visibility, "public");
472
+ assert.deepStrictEqual(poll.mentions, []);
473
+ });
315
474
  });
316
475
  test("SessionImpl.getOutbox()", async (t) => {
317
476
  const repository = new MemoryRepository();
@@ -1 +1 @@
1
- {"version":3,"file":"session-impl.test.js","names":["bot: BotImpl<void>","origin: URL | string"],"sources":["../src/session-impl.test.ts"],"sourcesContent":["// BotKit by Fedify: A framework for creating ActivityPub bots\n// Copyright (C) 2025 Hong Minhee <https://hongminhee.org/>\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as\n// published by the Free Software Foundation, either version 3 of the\n// License, or (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\nimport { type Context, MemoryKvStore } from \"@fedify/fedify/federation\";\nimport {\n type Activity,\n Create,\n Follow,\n Note,\n Person,\n PUBLIC_COLLECTION,\n type Recipient,\n Undo,\n} from \"@fedify/fedify/vocab\";\nimport assert from \"node:assert\";\nimport { describe, test } from \"node:test\";\nimport { BotImpl } from \"./bot-impl.ts\";\nimport { createMessage } from \"./message-impl.ts\";\nimport { MemoryRepository, type Uuid } from \"./repository.ts\";\nimport { SessionImpl } from \"./session-impl.ts\";\nimport { mention, text } from \"./text.ts\";\n\ntest(\"SessionImpl.follow()\", async (t) => {\n const repository = new MemoryRepository();\n const bot = new BotImpl<void>({\n kv: new MemoryKvStore(),\n repository,\n username: \"bot\",\n });\n const ctx = createMockContext(bot, \"https://example.com\");\n const session = new SessionImpl(bot, ctx);\n\n await t.test(\"follow\", async () => {\n const actor = new Person({\n id: new URL(\"https://example.com/ap/actor/john\"),\n preferredUsername: \"john\",\n });\n await session.follow(actor);\n assert.deepStrictEqual(ctx.sentActivities.length, 1);\n const { recipients, activity } = ctx.sentActivities[0];\n assert.deepStrictEqual(recipients, [actor]);\n assert.ok(activity instanceof Follow);\n const parsed = ctx.parseUri(activity.id);\n assert.deepStrictEqual(parsed?.type, \"object\");\n assert.ok(parsed?.type === \"object\");\n assert.deepStrictEqual(parsed.class, Follow);\n assert.deepStrictEqual(activity.actorId, ctx.getActorUri(bot.identifier));\n assert.deepStrictEqual(activity.objectId, actor.id);\n assert.deepStrictEqual(activity.toIds, [actor.id]);\n const follow = await repository.getSentFollow(parsed.values.id as Uuid);\n assert.ok(follow != null);\n assert.deepStrictEqual(\n await follow.toJsonLd({ format: \"compact\" }),\n await activity.toJsonLd({ format: \"compact\" }),\n );\n });\n\n await t.test(\"follow again\", async () => {\n ctx.sentActivities = [];\n await repository.addFollowee(\n new URL(\"https://example.com/ap/actor/alice\"),\n new Follow({\n id: new URL(\n \"https://example.com/ap/follow/4114eadb-2596-408f-ad99-06f467c9ace0\",\n ),\n actor: new URL(\"https://example.com/ap/actor/bot\"),\n object: new URL(\"https://example.com/ap/actor/alice\"),\n }),\n );\n const actor = new Person({\n id: new URL(\"https://example.com/ap/actor/alice\"),\n preferredUsername: \"alice\",\n });\n await session.follow(actor);\n assert.deepStrictEqual(ctx.sentActivities, []);\n });\n\n await t.test(\"follow bot itself\", async () => {\n ctx.sentActivities = [];\n await assert.rejects(\n () => session.follow(session.actorId.href),\n TypeError,\n \"The bot cannot follow itself.\",\n );\n assert.deepStrictEqual(ctx.sentActivities, []);\n\n await assert.rejects(\n () => session.follow(session.actorId),\n TypeError,\n \"The bot cannot follow itself.\",\n );\n assert.deepStrictEqual(ctx.sentActivities, []);\n\n await assert.rejects(\n () => session.follow(session.actorHandle),\n TypeError,\n \"The bot cannot follow itself.\",\n );\n assert.deepStrictEqual(ctx.sentActivities, []);\n\n const actor = await session.getActor();\n await assert.rejects(\n () => session.follow(actor),\n TypeError,\n \"The bot cannot follow itself.\",\n );\n assert.deepStrictEqual(ctx.sentActivities, []);\n });\n});\n\ntest(\"SessionImpl.unfollow()\", async (t) => {\n const repository = new MemoryRepository();\n const bot = new BotImpl<void>({\n kv: new MemoryKvStore(),\n repository,\n username: \"bot\",\n });\n const ctx = createMockContext(bot, \"https://example.com\");\n const session = new SessionImpl(bot, ctx);\n\n await t.test(\"unfollow\", async () => {\n await repository.addFollowee(\n new URL(\"https://example.com/ap/actor/alice\"),\n new Follow({\n id: new URL(\n \"https://example.com/ap/follow/4114eadb-2596-408f-ad99-06f467c9ace0\",\n ),\n actor: new URL(\"https://example.com/ap/actor/bot\"),\n object: new URL(\"https://example.com/ap/actor/alice\"),\n }),\n );\n const actor = new Person({\n id: new URL(\"https://example.com/ap/actor/alice\"),\n preferredUsername: \"alice\",\n });\n await session.unfollow(actor);\n assert.deepStrictEqual(ctx.sentActivities.length, 1);\n const { recipients, activity } = ctx.sentActivities[0];\n assert.deepStrictEqual(recipients, [actor]);\n assert.ok(activity instanceof Undo);\n const object = await activity.getObject(ctx);\n assert.ok(object instanceof Follow);\n assert.deepStrictEqual(\n object.id,\n new URL(\n \"https://example.com/ap/follow/4114eadb-2596-408f-ad99-06f467c9ace0\",\n ),\n );\n assert.deepStrictEqual(object.actorId, ctx.getActorUri(bot.identifier));\n assert.deepStrictEqual(\n await repository.getFollowee(\n new URL(\"https://example.com/ap/actor/alice\"),\n ),\n undefined,\n );\n });\n\n await t.test(\"unfollow again\", async () => {\n ctx.sentActivities = [];\n const actor = new Person({\n id: new URL(\"https://example.com/ap/actor/alice\"),\n preferredUsername: \"alice\",\n });\n await session.unfollow(actor);\n assert.deepStrictEqual(ctx.sentActivities, []);\n });\n\n await t.test(\"unfollow bot itself\", async () => {\n ctx.sentActivities = [];\n await assert.rejects(\n () => session.unfollow(session.actorId.href),\n TypeError,\n \"The bot cannot unfollow itself.\",\n );\n assert.deepStrictEqual(ctx.sentActivities, []);\n\n await assert.rejects(\n () => session.unfollow(session.actorId),\n TypeError,\n \"The bot cannot unfollow itself.\",\n );\n assert.deepStrictEqual(ctx.sentActivities, []);\n\n await assert.rejects(\n () => session.unfollow(session.actorHandle),\n TypeError,\n \"The bot cannot unfollow itself.\",\n );\n assert.deepStrictEqual(ctx.sentActivities, []);\n\n const actor = await session.getActor();\n await assert.rejects(\n () => session.unfollow(actor),\n TypeError,\n \"The bot cannot unfollow itself.\",\n );\n assert.deepStrictEqual(ctx.sentActivities, []);\n });\n});\n\ndescribe(\"SessionImpl.follows()\", () => {\n const repository = new MemoryRepository();\n const bot = new BotImpl<void>({\n kv: new MemoryKvStore(),\n repository,\n username: \"bot\",\n });\n const ctx = createMockContext(bot, \"https://example.com\");\n const session = new SessionImpl(bot, ctx);\n\n test(\"when it follows\", async () => {\n const followeeId = new URL(\"https://example.com/ap/actor/alice\");\n const followee = new Person({\n id: followeeId,\n preferredUsername: \"alice\",\n });\n await repository.addFollowee(\n new URL(\"https://example.com/ap/actor/alice\"),\n new Follow({\n id: new URL(\n \"https://example.com/ap/follow/4114eadb-2596-408f-ad99-06f467c9ace0\",\n ),\n actor: new URL(\"https://example.com/ap/actor/bot\"),\n object: followee,\n }),\n );\n assert.ok(await session.follows(followeeId.href));\n assert.ok(await session.follows(followeeId));\n assert.ok(await session.follows(followee));\n });\n\n test(\"when it does not follow\", async () => {\n const actorId = new URL(\"https://example.com/ap/actor/john\");\n const actor = new Person({\n id: actorId,\n preferredUsername: \"john\",\n });\n assert.deepStrictEqual(await session.follows(actorId.href), false);\n assert.deepStrictEqual(await session.follows(actorId), false);\n assert.deepStrictEqual(await session.follows(actor), false);\n });\n\n test(\"bot itself\", async () => {\n assert.deepStrictEqual(await session.follows(session.actorId.href), false);\n assert.deepStrictEqual(await session.follows(session.actorId), false);\n assert.deepStrictEqual(\n await session.follows(await session.getActor()),\n false,\n );\n assert.deepStrictEqual(await session.follows(session.actorHandle), false);\n });\n});\n\ntest(\"SessionImpl.publish()\", async (t) => {\n const kv = new MemoryKvStore();\n const bot = new BotImpl<void>({ kv, username: \"bot\" });\n const ctx = createMockContext(bot, \"https://example.com\");\n const session = new SessionImpl(bot, ctx);\n\n await t.test(\"public\", async () => {\n ctx.sentActivities = [];\n const publicMsg = await session.publish(text`Hello, world!`);\n assert.deepStrictEqual(ctx.sentActivities.length, 1);\n const { recipients, activity } = ctx.sentActivities[0];\n assert.deepStrictEqual(recipients, \"followers\");\n assert.ok(activity instanceof Create);\n assert.deepStrictEqual(activity.actorId, ctx.getActorUri(bot.identifier));\n assert.deepStrictEqual(activity.toIds, [PUBLIC_COLLECTION]);\n assert.deepStrictEqual(activity.ccIds, [\n ctx.getFollowersUri(bot.identifier),\n ]);\n const object = await activity.getObject(ctx);\n assert.ok(object instanceof Note);\n assert.deepStrictEqual(\n object.attributionId,\n ctx.getActorUri(bot.identifier),\n );\n assert.deepStrictEqual(object.toIds, [PUBLIC_COLLECTION]);\n assert.deepStrictEqual(object.ccIds, [ctx.getFollowersUri(bot.identifier)]);\n assert.deepStrictEqual(object.content, \"<p>Hello, world!</p>\");\n assert.deepStrictEqual(object.tagIds, []);\n assert.deepStrictEqual(publicMsg.id, object.id);\n assert.deepStrictEqual(publicMsg.text, \"Hello, world!\");\n assert.deepStrictEqual(publicMsg.html, \"<p>Hello, world!</p>\");\n assert.deepStrictEqual(publicMsg.visibility, \"public\");\n assert.deepStrictEqual(publicMsg.mentions, []);\n });\n\n await t.test(\"unlisted\", async () => {\n ctx.sentActivities = [];\n const unlistedMsg = await session.publish(text`Hello!`, {\n visibility: \"unlisted\",\n });\n assert.deepStrictEqual(ctx.sentActivities.length, 1);\n const { recipients, activity } = ctx.sentActivities[0];\n assert.deepStrictEqual(recipients, \"followers\");\n assert.ok(activity instanceof Create);\n assert.deepStrictEqual(activity.actorId, ctx.getActorUri(bot.identifier));\n assert.deepStrictEqual(activity.toIds, [\n ctx.getFollowersUri(bot.identifier),\n ]);\n assert.deepStrictEqual(activity.ccIds, [PUBLIC_COLLECTION]);\n const object = await activity.getObject(ctx);\n assert.ok(object instanceof Note);\n assert.deepStrictEqual(\n object.attributionId,\n ctx.getActorUri(bot.identifier),\n );\n assert.deepStrictEqual(object.toIds, [ctx.getFollowersUri(bot.identifier)]);\n assert.deepStrictEqual(object.ccIds, [PUBLIC_COLLECTION]);\n assert.deepStrictEqual(object.content, \"<p>Hello!</p>\");\n assert.deepStrictEqual(object.tagIds, []);\n assert.deepStrictEqual(unlistedMsg.id, object.id);\n assert.deepStrictEqual(unlistedMsg.text, \"Hello!\");\n assert.deepStrictEqual(unlistedMsg.html, \"<p>Hello!</p>\");\n assert.deepStrictEqual(unlistedMsg.visibility, \"unlisted\");\n assert.deepStrictEqual(unlistedMsg.mentions, []);\n });\n\n await t.test(\"followers\", async () => {\n ctx.sentActivities = [];\n const followersMsg = await session.publish(text`Hi!`, {\n visibility: \"followers\",\n });\n assert.deepStrictEqual(ctx.sentActivities.length, 1);\n const { recipients, activity } = ctx.sentActivities[0];\n assert.deepStrictEqual(recipients, \"followers\");\n assert.ok(activity instanceof Create);\n assert.deepStrictEqual(activity.actorId, ctx.getActorUri(bot.identifier));\n assert.deepStrictEqual(activity.toIds, [\n ctx.getFollowersUri(bot.identifier),\n ]);\n assert.deepStrictEqual(activity.ccIds, []);\n const object = await activity.getObject(ctx);\n assert.ok(object instanceof Note);\n assert.deepStrictEqual(\n object.attributionId,\n ctx.getActorUri(bot.identifier),\n );\n assert.deepStrictEqual(object.toIds, [ctx.getFollowersUri(bot.identifier)]);\n assert.deepStrictEqual(object.ccIds, []);\n assert.deepStrictEqual(object.content, \"<p>Hi!</p>\");\n assert.deepStrictEqual(object.tagIds, []);\n assert.deepStrictEqual(followersMsg.id, object.id);\n assert.deepStrictEqual(followersMsg.text, \"Hi!\");\n assert.deepStrictEqual(followersMsg.html, \"<p>Hi!</p>\");\n assert.deepStrictEqual(followersMsg.visibility, \"followers\");\n assert.deepStrictEqual(followersMsg.mentions, []);\n });\n\n await t.test(\"direct\", async () => {\n const mentioned = new Person({\n id: new URL(\"https://example.com/ap/actor/john\"),\n preferredUsername: \"john\",\n });\n ctx.sentActivities = [];\n const directMsg = await session.publish(\n text`Hey ${mention(mentioned)}!`,\n { visibility: \"direct\" },\n );\n assert.deepStrictEqual(ctx.sentActivities.length, 1);\n const { recipients, activity } = ctx.sentActivities[0];\n assert.deepStrictEqual(recipients, [mentioned]);\n assert.ok(activity instanceof Create);\n assert.deepStrictEqual(activity.actorId, ctx.getActorUri(bot.identifier));\n assert.deepStrictEqual(activity.toIds, [mentioned.id]);\n assert.deepStrictEqual(activity.ccIds, []);\n const object = await activity.getObject(ctx);\n assert.ok(object instanceof Note);\n assert.deepStrictEqual(\n object.attributionId,\n ctx.getActorUri(bot.identifier),\n );\n assert.deepStrictEqual(object.toIds, [mentioned.id]);\n assert.deepStrictEqual(object.ccIds, []);\n assert.deepStrictEqual(\n object.content,\n '<p>Hey <a href=\"https://example.com/ap/actor/john\" translate=\"no\" ' +\n 'class=\"h-card u-url mention\" target=\"_blank\">@<span>john@example.com' +\n \"</span></a>!</p>\",\n );\n const tags = await Array.fromAsync(object.getTags());\n assert.deepStrictEqual(tags.length, 1);\n assert.deepStrictEqual(directMsg.id, object.id);\n assert.deepStrictEqual(directMsg.text, \"Hey @john@example.com!\");\n assert.deepStrictEqual(directMsg.html, object.content);\n assert.deepStrictEqual(directMsg.visibility, \"direct\");\n // assert.deepStrictEqual(directMsg.mentions, [mentioned]); // FIXME\n });\n\n await t.test(\"quote\", async () => {\n const originalAuthor = new Person({\n id: new URL(\"https://example.com/ap/actor/john\"),\n preferredUsername: \"john\",\n });\n const originalPost = new Note({\n id: new URL(\n \"https://example.com/ap/note/c1c792ce-a0be-4685-b396-e59e5ef8c788\",\n ),\n content: \"<p>Hello, world!</p>\",\n attribution: originalAuthor,\n to: new URL(\"https://example.com/ap/actor/john/followers\"),\n cc: PUBLIC_COLLECTION,\n });\n const originalMsg = await createMessage<Note, void>(\n originalPost,\n session,\n {},\n );\n ctx.sentActivities = [];\n const quote = await session.publish(text`Check this out!`, {\n quoteTarget: originalMsg,\n });\n assert.deepStrictEqual(ctx.sentActivities.length, 2);\n const { recipients, activity } = ctx.sentActivities[0];\n assert.deepStrictEqual(recipients, \"followers\");\n assert.ok(activity instanceof Create);\n assert.deepStrictEqual(activity.actorId, ctx.getActorUri(bot.identifier));\n assert.deepStrictEqual(activity.toIds, [PUBLIC_COLLECTION]);\n assert.deepStrictEqual(activity.ccIds, [\n ctx.getFollowersUri(bot.identifier),\n ]);\n const object = await activity.getObject(ctx);\n const { recipients: recipients2, activity: activity2 } =\n ctx.sentActivities[1];\n assert.deepStrictEqual(recipients2, [originalAuthor]);\n assert.ok(activity2 instanceof Create);\n assert.deepStrictEqual(activity2.actorId, ctx.getActorUri(bot.identifier));\n assert.deepStrictEqual(activity2.toIds, [PUBLIC_COLLECTION]);\n assert.deepStrictEqual(activity2.ccIds, [\n ctx.getFollowersUri(bot.identifier),\n ]);\n assert.ok(object instanceof Note);\n assert.deepStrictEqual(\n object.attributionId,\n ctx.getActorUri(bot.identifier),\n );\n assert.deepStrictEqual(object.toIds, [PUBLIC_COLLECTION]);\n assert.deepStrictEqual(object.ccIds, [ctx.getFollowersUri(bot.identifier)]);\n assert.deepStrictEqual(\n object.content,\n `<p>Check this out!</p>\n\n<p class=\"quote-inline\"><br>RE: <a href=\"${originalMsg.id.href}\">${originalMsg.id.href}</a></p>`,\n );\n assert.deepStrictEqual(object.quoteUrl, originalMsg.id);\n assert.deepStrictEqual(quote.id, object.id);\n assert.deepStrictEqual(\n quote.text,\n `Check this out!\\n\\nRE: ${originalMsg.id.href}`,\n );\n assert.deepStrictEqual(\n quote.html,\n `<p>Check this out!</p>\n\n<p><br>RE: <a href=\"${originalMsg.id.href}\">${originalMsg.id.href}</a></p>`,\n );\n assert.deepStrictEqual(quote.visibility, \"public\");\n assert.deepStrictEqual(quote.quoteTarget?.id, originalMsg.id);\n });\n});\n\ntest(\"SessionImpl.getOutbox()\", async (t) => {\n const repository = new MemoryRepository();\n const bot = new BotImpl<void>({\n kv: new MemoryKvStore(),\n repository,\n username: \"bot\",\n });\n const ctx = createMockContext(bot, \"https://example.com\");\n const session = new SessionImpl(bot, ctx);\n\n const messageA = new Create({\n id: new URL(\n \"https://example.com/ap/create/01941f29-7c00-7fe8-ab0a-7b593990a3c0\",\n ),\n actor: new URL(\"https://example.com/ap/actor/bot\"),\n to: new URL(\"https://example.com/ap/actor/bot/followers\"),\n cc: PUBLIC_COLLECTION,\n object: new Note({\n id: new URL(\n \"https://example.com/ap/note/01941f29-7c00-7fe8-ab0a-7b593990a3c0\",\n ),\n attribution: new URL(\"https://example.com/ap/actor/bot\"),\n to: new URL(\"https://example.com/ap/actor/bot/followers\"),\n cc: PUBLIC_COLLECTION,\n content: \"Hello, world!\",\n published: Temporal.Instant.from(\"2025-01-01T00:00:00Z\"),\n }),\n published: Temporal.Instant.from(\"2025-01-01T00:00:00Z\"),\n });\n const messageB = new Create({\n id: new URL(\n \"https://example.com/ap/create/0194244f-d800-7873-8993-ef71ccd47306\",\n ),\n actor: new URL(\"https://example.com/ap/actor/bot\"),\n to: new URL(\"https://example.com/ap/actor/bot/followers\"),\n cc: PUBLIC_COLLECTION,\n object: new Note({\n id: new URL(\n \"https://example.com/ap/note/0194244f-d800-7873-8993-ef71ccd47306\",\n ),\n attribution: new URL(\"https://example.com/ap/actor/bot\"),\n to: new URL(\"https://example.com/ap/actor/bot/followers\"),\n cc: PUBLIC_COLLECTION,\n content: \"Hello, world!\",\n published: Temporal.Instant.from(\"2025-01-02T00:00:00Z\"),\n }),\n published: Temporal.Instant.from(\"2025-01-02T00:00:00Z\"),\n });\n const messageC = new Create({\n id: new URL(\n \"https://example.com/ap/create/01942976-3400-7f34-872e-2cbf0f9eeac4\",\n ),\n actor: new URL(\"https://example.com/ap/actor/bot\"),\n to: new URL(\"https://example.com/ap/actor/bot/followers\"),\n cc: PUBLIC_COLLECTION,\n object: new Note({\n id: new URL(\n \"https://example.com/ap/note/01942976-3400-7f34-872e-2cbf0f9eeac4\",\n ),\n attribution: new URL(\"https://example.com/ap/actor/bot\"),\n to: new URL(\"https://example.com/ap/actor/bot/followers\"),\n cc: PUBLIC_COLLECTION,\n content: \"Hello, world!\",\n published: Temporal.Instant.from(\"2025-01-03T00:00:00Z\"),\n }),\n published: Temporal.Instant.from(\"2025-01-03T00:00:00Z\"),\n });\n const messageD = new Create({\n id: new URL(\n \"https://example.com/ap/create/01942e9c-9000-7480-a553-7a6ce737ce14\",\n ),\n actor: new URL(\"https://example.com/ap/actor/bot\"),\n to: new URL(\"https://example.com/ap/actor/bot/followers\"),\n cc: PUBLIC_COLLECTION,\n object: new Note({\n id: new URL(\n \"https://example.com/ap/note/01942e9c-9000-7480-a553-7a6ce737ce14\",\n ),\n attribution: new URL(\"https://example.com/ap/actor/bot\"),\n to: new URL(\"https://example.com/ap/actor/bot/followers\"),\n cc: PUBLIC_COLLECTION,\n content: \"Hello, world!\",\n published: Temporal.Instant.from(\"2025-01-04T00:00:00Z\"),\n }),\n published: Temporal.Instant.from(\"2025-01-04T00:00:00Z\"),\n });\n await repository.addMessage(\"01941f29-7c00-7fe8-ab0a-7b593990a3c0\", messageA);\n await repository.addMessage(\"0194244f-d800-7873-8993-ef71ccd47306\", messageB);\n await repository.addMessage(\"01942976-3400-7f34-872e-2cbf0f9eeac4\", messageC);\n await repository.addMessage(\"01942e9c-9000-7480-a553-7a6ce737ce14\", messageD);\n\n await t.test(\"default\", async () => {\n const outbox = session.getOutbox({ order: \"oldest\" });\n const messages = await Array.fromAsync(outbox);\n assert.deepStrictEqual(messages.length, 4);\n\n assert.deepStrictEqual(\n messages[0].id.href,\n \"https://example.com/ap/note/01941f29-7c00-7fe8-ab0a-7b593990a3c0\",\n );\n assert.deepStrictEqual(\n messages[0].actor.id?.href,\n \"https://example.com/ap/actor/bot\",\n );\n assert.deepStrictEqual(messages[0].visibility, \"unlisted\");\n assert.deepStrictEqual(messages[0].text, \"Hello, world!\");\n assert.deepStrictEqual(\n messages[0].published,\n Temporal.Instant.from(\"2025-01-01T00:00:00Z\"),\n );\n\n assert.deepStrictEqual(\n messages[1].id.href,\n \"https://example.com/ap/note/0194244f-d800-7873-8993-ef71ccd47306\",\n );\n assert.deepStrictEqual(\n messages[1].actor.id?.href,\n \"https://example.com/ap/actor/bot\",\n );\n assert.deepStrictEqual(messages[1].visibility, \"unlisted\");\n assert.deepStrictEqual(messages[1].text, \"Hello, world!\");\n assert.deepStrictEqual(\n messages[1].published,\n Temporal.Instant.from(\"2025-01-02T00:00:00Z\"),\n );\n\n assert.deepStrictEqual(\n messages[2].id.href,\n \"https://example.com/ap/note/01942976-3400-7f34-872e-2cbf0f9eeac4\",\n );\n assert.deepStrictEqual(\n messages[2].actor.id?.href,\n \"https://example.com/ap/actor/bot\",\n );\n assert.deepStrictEqual(messages[2].visibility, \"unlisted\");\n assert.deepStrictEqual(messages[2].text, \"Hello, world!\");\n assert.deepStrictEqual(\n messages[2].published,\n Temporal.Instant.from(\"2025-01-03T00:00:00Z\"),\n );\n\n assert.deepStrictEqual(\n messages[3].id.href,\n \"https://example.com/ap/note/01942e9c-9000-7480-a553-7a6ce737ce14\",\n );\n assert.deepStrictEqual(\n messages[3].actor.id?.href,\n \"https://example.com/ap/actor/bot\",\n );\n assert.deepStrictEqual(messages[3].visibility, \"unlisted\");\n assert.deepStrictEqual(messages[3].text, \"Hello, world!\");\n assert.deepStrictEqual(\n messages[3].published,\n Temporal.Instant.from(\"2025-01-04T00:00:00Z\"),\n );\n });\n\n await t.test(\"order: 'oldest'\", async () => {\n const outbox = session.getOutbox({ order: \"oldest\" });\n const messages = await Array.fromAsync(outbox);\n const messageIds = messages.map((msg) => msg.id.href);\n assert.deepStrictEqual(messageIds, [\n \"https://example.com/ap/note/01941f29-7c00-7fe8-ab0a-7b593990a3c0\",\n \"https://example.com/ap/note/0194244f-d800-7873-8993-ef71ccd47306\",\n \"https://example.com/ap/note/01942976-3400-7f34-872e-2cbf0f9eeac4\",\n \"https://example.com/ap/note/01942e9c-9000-7480-a553-7a6ce737ce14\",\n ]);\n });\n\n await t.test(\"order: 'newest'\", async () => {\n const outbox = session.getOutbox({ order: \"newest\" });\n const messages = await Array.fromAsync(outbox);\n const messageIds = messages.map((msg) => msg.id.href);\n assert.deepStrictEqual(messageIds, [\n \"https://example.com/ap/note/01942e9c-9000-7480-a553-7a6ce737ce14\",\n \"https://example.com/ap/note/01942976-3400-7f34-872e-2cbf0f9eeac4\",\n \"https://example.com/ap/note/0194244f-d800-7873-8993-ef71ccd47306\",\n \"https://example.com/ap/note/01941f29-7c00-7fe8-ab0a-7b593990a3c0\",\n ]);\n });\n\n await t.test(\"since\", async () => {\n const outbox = session.getOutbox({\n since: Temporal.Instant.from(\"2025-01-03T00:00:00Z\"),\n });\n const messages = await Array.fromAsync(outbox);\n const messageIds = messages.map((msg) => msg.id.href);\n assert.deepStrictEqual(messageIds, [\n \"https://example.com/ap/note/01942e9c-9000-7480-a553-7a6ce737ce14\",\n \"https://example.com/ap/note/01942976-3400-7f34-872e-2cbf0f9eeac4\",\n ]);\n });\n\n await t.test(\"until\", async () => {\n const outbox = session.getOutbox({\n until: Temporal.Instant.from(\"2025-01-02T00:00:00Z\"),\n });\n const messages = await Array.fromAsync(outbox);\n const messageIds = messages.map((msg) => msg.id.href);\n assert.deepStrictEqual(messageIds, [\n \"https://example.com/ap/note/0194244f-d800-7873-8993-ef71ccd47306\",\n \"https://example.com/ap/note/01941f29-7c00-7fe8-ab0a-7b593990a3c0\",\n ]);\n });\n});\n\nexport interface SentActivity {\n recipients: \"followers\" | Recipient[];\n activity: Activity;\n}\n\nexport interface MockContext extends Context<void> {\n sentActivities: SentActivity[];\n}\n\nexport function createMockContext(\n bot: BotImpl<void>,\n origin: URL | string,\n): MockContext {\n const ctx = bot.federation.createContext(\n new URL(origin),\n undefined,\n ) as MockContext;\n ctx.sentActivities = [];\n ctx.sendActivity = (_, recipients, activity) => {\n ctx.sentActivities.push({\n recipients: recipients === \"followers\"\n ? \"followers\"\n : Array.isArray(recipients)\n ? recipients\n : [recipients],\n activity,\n });\n return Promise.resolve();\n };\n return ctx;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAkCA,KAAK,wBAAwB,OAAO,MAAM;CACxC,MAAM,aAAa,IAAI;CACvB,MAAM,MAAM,IAAI,QAAc;EAC5B,IAAI,IAAI;EACR;EACA,UAAU;CACX;CACD,MAAM,MAAM,kBAAkB,KAAK,sBAAsB;CACzD,MAAM,UAAU,IAAI,YAAY,K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MAAM,SAAS,QAAQ,UAAU,EAC/B,OAAO,SAAS,QAAQ,KAAK,uBAAuB,CACrD,EAAC;EACF,MAAM,WAAW,MAAM,MAAM,UAAU,OAAO;EAC9C,MAAM,aAAa,SAAS,IAAI,CAAC,QAAQ,IAAI,GAAG,KAAK;AACrD,SAAO,gBAAgB,YAAY,CACjC,oEACA,kEACD,EAAC;CACH,EAAC;AACH,EAAC;AAWF,SAAgB,kBACdA,KACAC,QACa;CACb,MAAM,MAAM,IAAI,WAAW,cACzB,IAAI,IAAI,gBAET;AACD,KAAI,iBAAiB,CAAE;AACvB,KAAI,eAAe,CAAC,GAAG,YAAY,aAAa;AAC9C,MAAI,eAAe,KAAK;GACtB,YAAY,eAAe,cACvB,cACA,MAAM,QAAQ,WAAW,GACzB,aACA,CAAC,UAAW;GAChB;EACD,EAAC;AACF,SAAO,QAAQ,SAAS;CACzB;AACD,QAAO;AACR"}
1
+ {"version":3,"file":"session-impl.test.js","names":["bot: BotImpl<void>","origin: URL | string"],"sources":["../src/session-impl.test.ts"],"sourcesContent":["// BotKit by Fedify: A framework for creating ActivityPub bots\n// Copyright (C) 2025 Hong Minhee <https://hongminhee.org/>\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as\n// published by the Free Software Foundation, either version 3 of the\n// License, or (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\nimport { type Context, MemoryKvStore } from \"@fedify/fedify/federation\";\nimport {\n type Activity,\n Create,\n Follow,\n Note,\n Person,\n PUBLIC_COLLECTION,\n Question,\n type Recipient,\n Undo,\n} from \"@fedify/fedify/vocab\";\nimport assert from \"node:assert\";\nimport { describe, test } from \"node:test\";\nimport { BotImpl } from \"./bot-impl.ts\";\nimport { createMessage } from \"./message-impl.ts\";\nimport { MemoryRepository, type Uuid } from \"./repository.ts\";\nimport { SessionImpl } from \"./session-impl.ts\";\nimport { mention, text } from \"./text.ts\";\n\ntest(\"SessionImpl.follow()\", async (t) => {\n const repository = new MemoryRepository();\n const bot = new BotImpl<void>({\n kv: new MemoryKvStore(),\n repository,\n username: \"bot\",\n });\n const ctx = createMockContext(bot, \"https://example.com\");\n const session = new SessionImpl(bot, ctx);\n\n await t.test(\"follow\", async () => {\n const actor = new Person({\n id: new URL(\"https://example.com/ap/actor/john\"),\n preferredUsername: \"john\",\n });\n await session.follow(actor);\n assert.deepStrictEqual(ctx.sentActivities.length, 1);\n const { recipients, activity } = ctx.sentActivities[0];\n assert.deepStrictEqual(recipients, [actor]);\n assert.ok(activity instanceof Follow);\n const parsed = ctx.parseUri(activity.id);\n assert.deepStrictEqual(parsed?.type, \"object\");\n assert.ok(parsed?.type === \"object\");\n assert.deepStrictEqual(parsed.class, Follow);\n assert.deepStrictEqual(activity.actorId, ctx.getActorUri(bot.identifier));\n assert.deepStrictEqual(activity.objectId, actor.id);\n assert.deepStrictEqual(activity.toIds, [actor.id]);\n const follow = await repository.getSentFollow(parsed.values.id as Uuid);\n assert.ok(follow != null);\n assert.deepStrictEqual(\n await follow.toJsonLd({ format: \"compact\" }),\n await activity.toJsonLd({ format: \"compact\" }),\n );\n });\n\n await t.test(\"follow again\", async () => {\n ctx.sentActivities = [];\n await repository.addFollowee(\n new URL(\"https://example.com/ap/actor/alice\"),\n new Follow({\n id: new URL(\n \"https://example.com/ap/follow/4114eadb-2596-408f-ad99-06f467c9ace0\",\n ),\n actor: new URL(\"https://example.com/ap/actor/bot\"),\n object: new URL(\"https://example.com/ap/actor/alice\"),\n }),\n );\n const actor = new Person({\n id: new URL(\"https://example.com/ap/actor/alice\"),\n preferredUsername: \"alice\",\n });\n await session.follow(actor);\n assert.deepStrictEqual(ctx.sentActivities, []);\n });\n\n await t.test(\"follow bot itself\", async () => {\n ctx.sentActivities = [];\n await assert.rejects(\n () => session.follow(session.actorId.href),\n TypeError,\n \"The bot cannot follow itself.\",\n );\n assert.deepStrictEqual(ctx.sentActivities, []);\n\n await assert.rejects(\n () => session.follow(session.actorId),\n TypeError,\n \"The bot cannot follow itself.\",\n );\n assert.deepStrictEqual(ctx.sentActivities, []);\n\n await assert.rejects(\n () => session.follow(session.actorHandle),\n TypeError,\n \"The bot cannot follow itself.\",\n );\n assert.deepStrictEqual(ctx.sentActivities, []);\n\n const actor = await session.getActor();\n await assert.rejects(\n () => session.follow(actor),\n TypeError,\n \"The bot cannot follow itself.\",\n );\n assert.deepStrictEqual(ctx.sentActivities, []);\n });\n});\n\ntest(\"SessionImpl.unfollow()\", async (t) => {\n const repository = new MemoryRepository();\n const bot = new BotImpl<void>({\n kv: new MemoryKvStore(),\n repository,\n username: \"bot\",\n });\n const ctx = createMockContext(bot, \"https://example.com\");\n const session = new SessionImpl(bot, ctx);\n\n await t.test(\"unfollow\", async () => {\n await repository.addFollowee(\n new URL(\"https://example.com/ap/actor/alice\"),\n new Follow({\n id: new URL(\n \"https://example.com/ap/follow/4114eadb-2596-408f-ad99-06f467c9ace0\",\n ),\n actor: new URL(\"https://example.com/ap/actor/bot\"),\n object: new URL(\"https://example.com/ap/actor/alice\"),\n }),\n );\n const actor = new Person({\n id: new URL(\"https://example.com/ap/actor/alice\"),\n preferredUsername: \"alice\",\n });\n await session.unfollow(actor);\n assert.deepStrictEqual(ctx.sentActivities.length, 1);\n const { recipients, activity } = ctx.sentActivities[0];\n assert.deepStrictEqual(recipients, [actor]);\n assert.ok(activity instanceof Undo);\n const object = await activity.getObject(ctx);\n assert.ok(object instanceof Follow);\n assert.deepStrictEqual(\n object.id,\n new URL(\n \"https://example.com/ap/follow/4114eadb-2596-408f-ad99-06f467c9ace0\",\n ),\n );\n assert.deepStrictEqual(object.actorId, ctx.getActorUri(bot.identifier));\n assert.deepStrictEqual(\n await repository.getFollowee(\n new URL(\"https://example.com/ap/actor/alice\"),\n ),\n undefined,\n );\n });\n\n await t.test(\"unfollow again\", async () => {\n ctx.sentActivities = [];\n const actor = new Person({\n id: new URL(\"https://example.com/ap/actor/alice\"),\n preferredUsername: \"alice\",\n });\n await session.unfollow(actor);\n assert.deepStrictEqual(ctx.sentActivities, []);\n });\n\n await t.test(\"unfollow bot itself\", async () => {\n ctx.sentActivities = [];\n await assert.rejects(\n () => session.unfollow(session.actorId.href),\n TypeError,\n \"The bot cannot unfollow itself.\",\n );\n assert.deepStrictEqual(ctx.sentActivities, []);\n\n await assert.rejects(\n () => session.unfollow(session.actorId),\n TypeError,\n \"The bot cannot unfollow itself.\",\n );\n assert.deepStrictEqual(ctx.sentActivities, []);\n\n await assert.rejects(\n () => session.unfollow(session.actorHandle),\n TypeError,\n \"The bot cannot unfollow itself.\",\n );\n assert.deepStrictEqual(ctx.sentActivities, []);\n\n const actor = await session.getActor();\n await assert.rejects(\n () => session.unfollow(actor),\n TypeError,\n \"The bot cannot unfollow itself.\",\n );\n assert.deepStrictEqual(ctx.sentActivities, []);\n });\n});\n\ndescribe(\"SessionImpl.follows()\", () => {\n const repository = new MemoryRepository();\n const bot = new BotImpl<void>({\n kv: new MemoryKvStore(),\n repository,\n username: \"bot\",\n });\n const ctx = createMockContext(bot, \"https://example.com\");\n const session = new SessionImpl(bot, ctx);\n\n test(\"when it follows\", async () => {\n const followeeId = new URL(\"https://example.com/ap/actor/alice\");\n const followee = new Person({\n id: followeeId,\n preferredUsername: \"alice\",\n });\n await repository.addFollowee(\n new URL(\"https://example.com/ap/actor/alice\"),\n new Follow({\n id: new URL(\n \"https://example.com/ap/follow/4114eadb-2596-408f-ad99-06f467c9ace0\",\n ),\n actor: new URL(\"https://example.com/ap/actor/bot\"),\n object: followee,\n }),\n );\n assert.ok(await session.follows(followeeId.href));\n assert.ok(await session.follows(followeeId));\n assert.ok(await session.follows(followee));\n });\n\n test(\"when it does not follow\", async () => {\n const actorId = new URL(\"https://example.com/ap/actor/john\");\n const actor = new Person({\n id: actorId,\n preferredUsername: \"john\",\n });\n assert.deepStrictEqual(await session.follows(actorId.href), false);\n assert.deepStrictEqual(await session.follows(actorId), false);\n assert.deepStrictEqual(await session.follows(actor), false);\n });\n\n test(\"bot itself\", async () => {\n assert.deepStrictEqual(await session.follows(session.actorId.href), false);\n assert.deepStrictEqual(await session.follows(session.actorId), false);\n assert.deepStrictEqual(\n await session.follows(await session.getActor()),\n false,\n );\n assert.deepStrictEqual(await session.follows(session.actorHandle), false);\n });\n});\n\ntest(\"SessionImpl.publish()\", async (t) => {\n const kv = new MemoryKvStore();\n const bot = new BotImpl<void>({ kv, username: \"bot\" });\n const ctx = createMockContext(bot, \"https://example.com\");\n const session = new SessionImpl(bot, ctx);\n\n await t.test(\"public\", async () => {\n ctx.sentActivities = [];\n const publicMsg = await session.publish(text`Hello, world!`);\n assert.deepStrictEqual(ctx.sentActivities.length, 1);\n const { recipients, activity } = ctx.sentActivities[0];\n assert.deepStrictEqual(recipients, \"followers\");\n assert.ok(activity instanceof Create);\n assert.deepStrictEqual(activity.actorId, ctx.getActorUri(bot.identifier));\n assert.deepStrictEqual(activity.toIds, [PUBLIC_COLLECTION]);\n assert.deepStrictEqual(activity.ccIds, [\n ctx.getFollowersUri(bot.identifier),\n ]);\n const object = await activity.getObject(ctx);\n assert.ok(object instanceof Note);\n assert.deepStrictEqual(\n object.attributionId,\n ctx.getActorUri(bot.identifier),\n );\n assert.deepStrictEqual(object.toIds, [PUBLIC_COLLECTION]);\n assert.deepStrictEqual(object.ccIds, [ctx.getFollowersUri(bot.identifier)]);\n assert.deepStrictEqual(object.content, \"<p>Hello, world!</p>\");\n assert.deepStrictEqual(object.tagIds, []);\n assert.deepStrictEqual(publicMsg.id, object.id);\n assert.deepStrictEqual(publicMsg.text, \"Hello, world!\");\n assert.deepStrictEqual(publicMsg.html, \"<p>Hello, world!</p>\");\n assert.deepStrictEqual(publicMsg.visibility, \"public\");\n assert.deepStrictEqual(publicMsg.mentions, []);\n });\n\n await t.test(\"unlisted\", async () => {\n ctx.sentActivities = [];\n const unlistedMsg = await session.publish(text`Hello!`, {\n visibility: \"unlisted\",\n });\n assert.deepStrictEqual(ctx.sentActivities.length, 1);\n const { recipients, activity } = ctx.sentActivities[0];\n assert.deepStrictEqual(recipients, \"followers\");\n assert.ok(activity instanceof Create);\n assert.deepStrictEqual(activity.actorId, ctx.getActorUri(bot.identifier));\n assert.deepStrictEqual(activity.toIds, [\n ctx.getFollowersUri(bot.identifier),\n ]);\n assert.deepStrictEqual(activity.ccIds, [PUBLIC_COLLECTION]);\n const object = await activity.getObject(ctx);\n assert.ok(object instanceof Note);\n assert.deepStrictEqual(\n object.attributionId,\n ctx.getActorUri(bot.identifier),\n );\n assert.deepStrictEqual(object.toIds, [ctx.getFollowersUri(bot.identifier)]);\n assert.deepStrictEqual(object.ccIds, [PUBLIC_COLLECTION]);\n assert.deepStrictEqual(object.content, \"<p>Hello!</p>\");\n assert.deepStrictEqual(object.tagIds, []);\n assert.deepStrictEqual(unlistedMsg.id, object.id);\n assert.deepStrictEqual(unlistedMsg.text, \"Hello!\");\n assert.deepStrictEqual(unlistedMsg.html, \"<p>Hello!</p>\");\n assert.deepStrictEqual(unlistedMsg.visibility, \"unlisted\");\n assert.deepStrictEqual(unlistedMsg.mentions, []);\n });\n\n await t.test(\"followers\", async () => {\n ctx.sentActivities = [];\n const followersMsg = await session.publish(text`Hi!`, {\n visibility: \"followers\",\n });\n assert.deepStrictEqual(ctx.sentActivities.length, 1);\n const { recipients, activity } = ctx.sentActivities[0];\n assert.deepStrictEqual(recipients, \"followers\");\n assert.ok(activity instanceof Create);\n assert.deepStrictEqual(activity.actorId, ctx.getActorUri(bot.identifier));\n assert.deepStrictEqual(activity.toIds, [\n ctx.getFollowersUri(bot.identifier),\n ]);\n assert.deepStrictEqual(activity.ccIds, []);\n const object = await activity.getObject(ctx);\n assert.ok(object instanceof Note);\n assert.deepStrictEqual(\n object.attributionId,\n ctx.getActorUri(bot.identifier),\n );\n assert.deepStrictEqual(object.toIds, [ctx.getFollowersUri(bot.identifier)]);\n assert.deepStrictEqual(object.ccIds, []);\n assert.deepStrictEqual(object.content, \"<p>Hi!</p>\");\n assert.deepStrictEqual(object.tagIds, []);\n assert.deepStrictEqual(followersMsg.id, object.id);\n assert.deepStrictEqual(followersMsg.text, \"Hi!\");\n assert.deepStrictEqual(followersMsg.html, \"<p>Hi!</p>\");\n assert.deepStrictEqual(followersMsg.visibility, \"followers\");\n assert.deepStrictEqual(followersMsg.mentions, []);\n });\n\n await t.test(\"direct\", async () => {\n const mentioned = new Person({\n id: new URL(\"https://example.com/ap/actor/john\"),\n preferredUsername: \"john\",\n });\n ctx.sentActivities = [];\n const directMsg = await session.publish(\n text`Hey ${mention(mentioned)}!`,\n { visibility: \"direct\" },\n );\n assert.deepStrictEqual(ctx.sentActivities.length, 1);\n const { recipients, activity } = ctx.sentActivities[0];\n assert.deepStrictEqual(recipients, [mentioned]);\n assert.ok(activity instanceof Create);\n assert.deepStrictEqual(activity.actorId, ctx.getActorUri(bot.identifier));\n assert.deepStrictEqual(activity.toIds, [mentioned.id]);\n assert.deepStrictEqual(activity.ccIds, []);\n const object = await activity.getObject(ctx);\n assert.ok(object instanceof Note);\n assert.deepStrictEqual(\n object.attributionId,\n ctx.getActorUri(bot.identifier),\n );\n assert.deepStrictEqual(object.toIds, [mentioned.id]);\n assert.deepStrictEqual(object.ccIds, []);\n assert.deepStrictEqual(\n object.content,\n '<p>Hey <a href=\"https://example.com/ap/actor/john\" translate=\"no\" ' +\n 'class=\"h-card u-url mention\" target=\"_blank\">@<span>john@example.com' +\n \"</span></a>!</p>\",\n );\n const tags = await Array.fromAsync(object.getTags());\n assert.deepStrictEqual(tags.length, 1);\n assert.deepStrictEqual(directMsg.id, object.id);\n assert.deepStrictEqual(directMsg.text, \"Hey @john@example.com!\");\n assert.deepStrictEqual(directMsg.html, object.content);\n assert.deepStrictEqual(directMsg.visibility, \"direct\");\n // assert.deepStrictEqual(directMsg.mentions, [mentioned]); // FIXME\n });\n\n await t.test(\"quote\", async () => {\n const originalAuthor = new Person({\n id: new URL(\"https://example.com/ap/actor/john\"),\n preferredUsername: \"john\",\n });\n const originalPost = new Note({\n id: new URL(\n \"https://example.com/ap/note/c1c792ce-a0be-4685-b396-e59e5ef8c788\",\n ),\n content: \"<p>Hello, world!</p>\",\n attribution: originalAuthor,\n to: new URL(\"https://example.com/ap/actor/john/followers\"),\n cc: PUBLIC_COLLECTION,\n });\n const originalMsg = await createMessage<Note, void>(\n originalPost,\n session,\n {},\n );\n ctx.sentActivities = [];\n const quote = await session.publish(text`Check this out!`, {\n quoteTarget: originalMsg,\n });\n assert.deepStrictEqual(ctx.sentActivities.length, 2);\n const { recipients, activity } = ctx.sentActivities[0];\n assert.deepStrictEqual(recipients, \"followers\");\n assert.ok(activity instanceof Create);\n assert.deepStrictEqual(activity.actorId, ctx.getActorUri(bot.identifier));\n assert.deepStrictEqual(activity.toIds, [PUBLIC_COLLECTION]);\n assert.deepStrictEqual(activity.ccIds, [\n ctx.getFollowersUri(bot.identifier),\n ]);\n const object = await activity.getObject(ctx);\n const { recipients: recipients2, activity: activity2 } =\n ctx.sentActivities[1];\n assert.deepStrictEqual(recipients2, [originalAuthor]);\n assert.ok(activity2 instanceof Create);\n assert.deepStrictEqual(activity2.actorId, ctx.getActorUri(bot.identifier));\n assert.deepStrictEqual(activity2.toIds, [PUBLIC_COLLECTION]);\n assert.deepStrictEqual(activity2.ccIds, [\n ctx.getFollowersUri(bot.identifier),\n ]);\n assert.ok(object instanceof Note);\n assert.deepStrictEqual(\n object.attributionId,\n ctx.getActorUri(bot.identifier),\n );\n assert.deepStrictEqual(object.toIds, [PUBLIC_COLLECTION]);\n assert.deepStrictEqual(object.ccIds, [ctx.getFollowersUri(bot.identifier)]);\n assert.deepStrictEqual(\n object.content,\n `<p>Check this out!</p>\n\n<p class=\"quote-inline\"><br>RE: <a href=\"${originalMsg.id.href}\">${originalMsg.id.href}</a></p>`,\n );\n assert.deepStrictEqual(object.quoteUrl, originalMsg.id);\n assert.deepStrictEqual(quote.id, object.id);\n assert.deepStrictEqual(\n quote.text,\n `Check this out!\\n\\nRE: ${originalMsg.id.href}`,\n );\n assert.deepStrictEqual(\n quote.html,\n `<p>Check this out!</p>\n\n<p><br>RE: <a href=\"${originalMsg.id.href}\">${originalMsg.id.href}</a></p>`,\n );\n assert.deepStrictEqual(quote.visibility, \"public\");\n assert.deepStrictEqual(quote.quoteTarget?.id, originalMsg.id);\n });\n\n await t.test(\"poll single choice\", async () => {\n ctx.sentActivities = [];\n const endTime = Temporal.Now.instant().add({ hours: 24 });\n const poll = await session.publish(text`What's your favorite color?`, {\n class: Question,\n poll: {\n multiple: false,\n options: [\"Red\", \"Blue\", \"Green\"],\n endTime,\n },\n });\n assert.deepStrictEqual(ctx.sentActivities.length, 1);\n const { recipients, activity } = ctx.sentActivities[0];\n assert.deepStrictEqual(recipients, \"followers\");\n assert.ok(activity instanceof Create);\n assert.deepStrictEqual(activity.actorId, ctx.getActorUri(bot.identifier));\n assert.deepStrictEqual(activity.toIds, [PUBLIC_COLLECTION]);\n assert.deepStrictEqual(activity.ccIds, [\n ctx.getFollowersUri(bot.identifier),\n ]);\n const object = await activity.getObject(ctx);\n assert.ok(object instanceof Question);\n assert.deepStrictEqual(\n object.attributionId,\n ctx.getActorUri(bot.identifier),\n );\n assert.deepStrictEqual(object.toIds, [PUBLIC_COLLECTION]);\n assert.deepStrictEqual(object.ccIds, [ctx.getFollowersUri(bot.identifier)]);\n assert.deepStrictEqual(\n object.content,\n \"<p>What&apos;s your favorite color?</p>\",\n );\n assert.deepStrictEqual(object.endTime, endTime);\n assert.deepStrictEqual(object.voters, 0);\n assert.deepStrictEqual(object.inclusiveOptionIds, []);\n\n const exclusiveOptions = await Array.fromAsync(\n object.getExclusiveOptions(ctx),\n );\n assert.deepStrictEqual(exclusiveOptions.length, 3);\n assert.ok(exclusiveOptions[0] instanceof Note);\n assert.deepStrictEqual(exclusiveOptions[0].name?.toString(), \"Red\");\n assert.ok(exclusiveOptions[1] instanceof Note);\n assert.deepStrictEqual(exclusiveOptions[1].name?.toString(), \"Blue\");\n assert.ok(exclusiveOptions[2] instanceof Note);\n assert.deepStrictEqual(exclusiveOptions[2].name?.toString(), \"Green\");\n\n for (const option of exclusiveOptions) {\n const replies = await option.getReplies(ctx);\n assert.deepStrictEqual(replies?.totalItems, 0);\n }\n\n assert.deepStrictEqual(poll.id, object.id);\n assert.deepStrictEqual(poll.text, \"What's your favorite color?\");\n assert.deepStrictEqual(\n poll.html,\n \"<p>What&apos;s your favorite color?</p>\",\n );\n assert.deepStrictEqual(poll.visibility, \"public\");\n });\n\n await t.test(\"poll multiple choice\", async () => {\n ctx.sentActivities = [];\n const endTime = Temporal.Now.instant().add({ hours: 24 * 7 });\n const poll = await session.publish(\n text`Which programming languages do you know?`,\n {\n class: Question,\n poll: {\n multiple: true,\n options: [\"JavaScript\", \"TypeScript\", \"Python\", \"Rust\"],\n endTime,\n },\n visibility: \"unlisted\",\n },\n );\n assert.deepStrictEqual(ctx.sentActivities.length, 1);\n const { recipients, activity } = ctx.sentActivities[0];\n assert.deepStrictEqual(recipients, \"followers\");\n assert.ok(activity instanceof Create);\n const object = await activity.getObject(ctx);\n assert.ok(object instanceof Question);\n assert.deepStrictEqual(object.endTime, endTime);\n assert.deepStrictEqual(object.voters, 0);\n assert.deepStrictEqual(object.exclusiveOptionIds, []);\n\n const inclusiveOptions = await Array.fromAsync(\n object.getInclusiveOptions(ctx),\n );\n assert.deepStrictEqual(inclusiveOptions.length, 4);\n assert.ok(inclusiveOptions[0] instanceof Note);\n assert.deepStrictEqual(inclusiveOptions[0].name?.toString(), \"JavaScript\");\n assert.ok(inclusiveOptions[1] instanceof Note);\n assert.deepStrictEqual(inclusiveOptions[1].name?.toString(), \"TypeScript\");\n assert.ok(inclusiveOptions[2] instanceof Note);\n assert.deepStrictEqual(inclusiveOptions[2].name?.toString(), \"Python\");\n assert.ok(inclusiveOptions[3] instanceof Note);\n assert.deepStrictEqual(inclusiveOptions[3].name?.toString(), \"Rust\");\n\n assert.deepStrictEqual(poll.visibility, \"unlisted\");\n assert.deepStrictEqual(activity.toIds, [\n ctx.getFollowersUri(bot.identifier),\n ]);\n assert.deepStrictEqual(activity.ccIds, [PUBLIC_COLLECTION]);\n });\n\n await t.test(\"poll with direct visibility\", async () => {\n const mentioned = new Person({\n id: new URL(\"https://example.com/ap/actor/alice\"),\n preferredUsername: \"alice\",\n });\n ctx.sentActivities = [];\n const endTime = Temporal.Now.instant().add({ hours: 12 });\n const poll = await session.publish(\n text`Hey ${mention(mentioned)}, what do you think?`,\n {\n class: Question,\n poll: {\n multiple: false,\n options: [\"Good\", \"Bad\", \"Neutral\"],\n endTime,\n },\n visibility: \"direct\",\n },\n );\n assert.deepStrictEqual(ctx.sentActivities.length, 1);\n const { recipients, activity } = ctx.sentActivities[0];\n assert.deepStrictEqual(recipients, [mentioned]);\n assert.ok(activity instanceof Create);\n const object = await activity.getObject(ctx);\n assert.ok(object instanceof Question);\n assert.deepStrictEqual(object.toIds, [mentioned.id]);\n assert.deepStrictEqual(object.ccIds, []);\n assert.deepStrictEqual(poll.visibility, \"direct\");\n });\n\n await t.test(\"poll end-to-end workflow\", async () => {\n // Create fresh repository and session for isolation\n const freshRepository = new MemoryRepository();\n const freshBot = new BotImpl<void>({\n kv: new MemoryKvStore(),\n repository: freshRepository,\n username: \"testbot\",\n });\n const freshCtx = createMockContext(freshBot, \"https://example.com\");\n const freshSession = new SessionImpl(freshBot, freshCtx);\n\n const endTime = Temporal.Now.instant().add({ hours: 1 });\n\n // 1. Create a poll\n const poll = await freshSession.publish(\n text`What should we have for lunch?`,\n {\n class: Question,\n poll: {\n multiple: false,\n options: [\"Pizza\", \"Burgers\", \"Salad\"],\n endTime,\n },\n },\n );\n\n // Verify poll was created correctly\n assert.deepStrictEqual(freshCtx.sentActivities.length, 1);\n const { activity: createActivity } = freshCtx.sentActivities[0];\n assert.ok(createActivity instanceof Create);\n const pollObject = await createActivity.getObject(freshCtx);\n assert.ok(pollObject instanceof Question);\n assert.deepStrictEqual(pollObject.endTime, endTime);\n\n // Get poll options\n const options = await Array.fromAsync(\n pollObject.getExclusiveOptions(freshCtx),\n );\n assert.deepStrictEqual(options.length, 3);\n assert.deepStrictEqual(options[0].name?.toString(), \"Pizza\");\n assert.deepStrictEqual(options[1].name?.toString(), \"Burgers\");\n assert.deepStrictEqual(options[2].name?.toString(), \"Salad\");\n\n // 2. Verify poll is accessible via getOutbox\n const outbox = freshSession.getOutbox({ order: \"newest\" });\n const messages = await Array.fromAsync(outbox);\n assert.deepStrictEqual(messages.length, 1);\n assert.deepStrictEqual(messages[0].id, poll.id);\n assert.deepStrictEqual(messages[0].text, \"What should we have for lunch?\");\n\n // 3. Verify poll structure\n assert.deepStrictEqual(poll.visibility, \"public\");\n assert.deepStrictEqual(poll.mentions, []);\n });\n});\n\ntest(\"SessionImpl.getOutbox()\", async (t) => {\n const repository = new MemoryRepository();\n const bot = new BotImpl<void>({\n kv: new MemoryKvStore(),\n repository,\n username: \"bot\",\n });\n const ctx = createMockContext(bot, \"https://example.com\");\n const session = new SessionImpl(bot, ctx);\n\n const messageA = new Create({\n id: new URL(\n \"https://example.com/ap/create/01941f29-7c00-7fe8-ab0a-7b593990a3c0\",\n ),\n actor: new URL(\"https://example.com/ap/actor/bot\"),\n to: new URL(\"https://example.com/ap/actor/bot/followers\"),\n cc: PUBLIC_COLLECTION,\n object: new Note({\n id: new URL(\n \"https://example.com/ap/note/01941f29-7c00-7fe8-ab0a-7b593990a3c0\",\n ),\n attribution: new URL(\"https://example.com/ap/actor/bot\"),\n to: new URL(\"https://example.com/ap/actor/bot/followers\"),\n cc: PUBLIC_COLLECTION,\n content: \"Hello, world!\",\n published: Temporal.Instant.from(\"2025-01-01T00:00:00Z\"),\n }),\n published: Temporal.Instant.from(\"2025-01-01T00:00:00Z\"),\n });\n const messageB = new Create({\n id: new URL(\n \"https://example.com/ap/create/0194244f-d800-7873-8993-ef71ccd47306\",\n ),\n actor: new URL(\"https://example.com/ap/actor/bot\"),\n to: new URL(\"https://example.com/ap/actor/bot/followers\"),\n cc: PUBLIC_COLLECTION,\n object: new Note({\n id: new URL(\n \"https://example.com/ap/note/0194244f-d800-7873-8993-ef71ccd47306\",\n ),\n attribution: new URL(\"https://example.com/ap/actor/bot\"),\n to: new URL(\"https://example.com/ap/actor/bot/followers\"),\n cc: PUBLIC_COLLECTION,\n content: \"Hello, world!\",\n published: Temporal.Instant.from(\"2025-01-02T00:00:00Z\"),\n }),\n published: Temporal.Instant.from(\"2025-01-02T00:00:00Z\"),\n });\n const messageC = new Create({\n id: new URL(\n \"https://example.com/ap/create/01942976-3400-7f34-872e-2cbf0f9eeac4\",\n ),\n actor: new URL(\"https://example.com/ap/actor/bot\"),\n to: new URL(\"https://example.com/ap/actor/bot/followers\"),\n cc: PUBLIC_COLLECTION,\n object: new Note({\n id: new URL(\n \"https://example.com/ap/note/01942976-3400-7f34-872e-2cbf0f9eeac4\",\n ),\n attribution: new URL(\"https://example.com/ap/actor/bot\"),\n to: new URL(\"https://example.com/ap/actor/bot/followers\"),\n cc: PUBLIC_COLLECTION,\n content: \"Hello, world!\",\n published: Temporal.Instant.from(\"2025-01-03T00:00:00Z\"),\n }),\n published: Temporal.Instant.from(\"2025-01-03T00:00:00Z\"),\n });\n const messageD = new Create({\n id: new URL(\n \"https://example.com/ap/create/01942e9c-9000-7480-a553-7a6ce737ce14\",\n ),\n actor: new URL(\"https://example.com/ap/actor/bot\"),\n to: new URL(\"https://example.com/ap/actor/bot/followers\"),\n cc: PUBLIC_COLLECTION,\n object: new Note({\n id: new URL(\n \"https://example.com/ap/note/01942e9c-9000-7480-a553-7a6ce737ce14\",\n ),\n attribution: new URL(\"https://example.com/ap/actor/bot\"),\n to: new URL(\"https://example.com/ap/actor/bot/followers\"),\n cc: PUBLIC_COLLECTION,\n content: \"Hello, world!\",\n published: Temporal.Instant.from(\"2025-01-04T00:00:00Z\"),\n }),\n published: Temporal.Instant.from(\"2025-01-04T00:00:00Z\"),\n });\n await repository.addMessage(\"01941f29-7c00-7fe8-ab0a-7b593990a3c0\", messageA);\n await repository.addMessage(\"0194244f-d800-7873-8993-ef71ccd47306\", messageB);\n await repository.addMessage(\"01942976-3400-7f34-872e-2cbf0f9eeac4\", messageC);\n await repository.addMessage(\"01942e9c-9000-7480-a553-7a6ce737ce14\", messageD);\n\n await t.test(\"default\", async () => {\n const outbox = session.getOutbox({ order: \"oldest\" });\n const messages = await Array.fromAsync(outbox);\n assert.deepStrictEqual(messages.length, 4);\n\n assert.deepStrictEqual(\n messages[0].id.href,\n \"https://example.com/ap/note/01941f29-7c00-7fe8-ab0a-7b593990a3c0\",\n );\n assert.deepStrictEqual(\n messages[0].actor.id?.href,\n \"https://example.com/ap/actor/bot\",\n );\n assert.deepStrictEqual(messages[0].visibility, \"unlisted\");\n assert.deepStrictEqual(messages[0].text, \"Hello, world!\");\n assert.deepStrictEqual(\n messages[0].published,\n Temporal.Instant.from(\"2025-01-01T00:00:00Z\"),\n );\n\n assert.deepStrictEqual(\n messages[1].id.href,\n \"https://example.com/ap/note/0194244f-d800-7873-8993-ef71ccd47306\",\n );\n assert.deepStrictEqual(\n messages[1].actor.id?.href,\n \"https://example.com/ap/actor/bot\",\n );\n assert.deepStrictEqual(messages[1].visibility, \"unlisted\");\n assert.deepStrictEqual(messages[1].text, \"Hello, world!\");\n assert.deepStrictEqual(\n messages[1].published,\n Temporal.Instant.from(\"2025-01-02T00:00:00Z\"),\n );\n\n assert.deepStrictEqual(\n messages[2].id.href,\n \"https://example.com/ap/note/01942976-3400-7f34-872e-2cbf0f9eeac4\",\n );\n assert.deepStrictEqual(\n messages[2].actor.id?.href,\n \"https://example.com/ap/actor/bot\",\n );\n assert.deepStrictEqual(messages[2].visibility, \"unlisted\");\n assert.deepStrictEqual(messages[2].text, \"Hello, world!\");\n assert.deepStrictEqual(\n messages[2].published,\n Temporal.Instant.from(\"2025-01-03T00:00:00Z\"),\n );\n\n assert.deepStrictEqual(\n messages[3].id.href,\n \"https://example.com/ap/note/01942e9c-9000-7480-a553-7a6ce737ce14\",\n );\n assert.deepStrictEqual(\n messages[3].actor.id?.href,\n \"https://example.com/ap/actor/bot\",\n );\n assert.deepStrictEqual(messages[3].visibility, \"unlisted\");\n assert.deepStrictEqual(messages[3].text, \"Hello, world!\");\n assert.deepStrictEqual(\n messages[3].published,\n Temporal.Instant.from(\"2025-01-04T00:00:00Z\"),\n );\n });\n\n await t.test(\"order: 'oldest'\", async () => {\n const outbox = session.getOutbox({ order: \"oldest\" });\n const messages = await Array.fromAsync(outbox);\n const messageIds = messages.map((msg) => msg.id.href);\n assert.deepStrictEqual(messageIds, [\n \"https://example.com/ap/note/01941f29-7c00-7fe8-ab0a-7b593990a3c0\",\n \"https://example.com/ap/note/0194244f-d800-7873-8993-ef71ccd47306\",\n \"https://example.com/ap/note/01942976-3400-7f34-872e-2cbf0f9eeac4\",\n \"https://example.com/ap/note/01942e9c-9000-7480-a553-7a6ce737ce14\",\n ]);\n });\n\n await t.test(\"order: 'newest'\", async () => {\n const outbox = session.getOutbox({ order: \"newest\" });\n const messages = await Array.fromAsync(outbox);\n const messageIds = messages.map((msg) => msg.id.href);\n assert.deepStrictEqual(messageIds, [\n \"https://example.com/ap/note/01942e9c-9000-7480-a553-7a6ce737ce14\",\n \"https://example.com/ap/note/01942976-3400-7f34-872e-2cbf0f9eeac4\",\n \"https://example.com/ap/note/0194244f-d800-7873-8993-ef71ccd47306\",\n \"https://example.com/ap/note/01941f29-7c00-7fe8-ab0a-7b593990a3c0\",\n ]);\n });\n\n await t.test(\"since\", async () => {\n const outbox = session.getOutbox({\n since: Temporal.Instant.from(\"2025-01-03T00:00:00Z\"),\n });\n const messages = await Array.fromAsync(outbox);\n const messageIds = messages.map((msg) => msg.id.href);\n assert.deepStrictEqual(messageIds, [\n \"https://example.com/ap/note/01942e9c-9000-7480-a553-7a6ce737ce14\",\n \"https://example.com/ap/note/01942976-3400-7f34-872e-2cbf0f9eeac4\",\n ]);\n });\n\n await t.test(\"until\", async () => {\n const outbox = session.getOutbox({\n until: Temporal.Instant.from(\"2025-01-02T00:00:00Z\"),\n });\n const messages = await Array.fromAsync(outbox);\n const messageIds = messages.map((msg) => msg.id.href);\n assert.deepStrictEqual(messageIds, [\n \"https://example.com/ap/note/0194244f-d800-7873-8993-ef71ccd47306\",\n \"https://example.com/ap/note/01941f29-7c00-7fe8-ab0a-7b593990a3c0\",\n ]);\n });\n});\n\nexport interface SentActivity {\n recipients: \"followers\" | Recipient[];\n activity: Activity;\n}\n\nexport interface MockContext extends Context<void> {\n sentActivities: SentActivity[];\n}\n\nexport function createMockContext(\n bot: BotImpl<void>,\n origin: URL | string,\n): MockContext {\n const ctx = bot.federation.createContext(\n new URL(origin),\n undefined,\n ) as MockContext;\n ctx.sentActivities = [];\n ctx.sendActivity = (_, recipients, activity) => {\n ctx.sentActivities.push({\n recipients: recipients === \"followers\"\n ? \"followers\"\n : Array.isArray(recipients)\n ? recipients\n : [recipients],\n activity,\n });\n return Promise.resolve();\n };\n return ctx;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmCA,KAAK,wBAAwB,OAAO,MAAM;CACxC,MAAM,aAAa,IAAI;CACvB,MAAM,MAAM,IAAI,QAAc;EAC5B,IAAI,IAAI;EACR;EACA,UAAU;CACX;CACD,MAAM,MAAM,kBAAkB,KAAK,sBAAsB;CACzD,MAAM,UAAU,IAAI,YAAY,KAAK;AAErC,OAAM,EAAE,KAAK,UAAU,YAAY;EACjC,MAAM,QAAQ,IAAI,OAAO;GACvB,IAAI,IAAI,IAAI;GACZ,mBAAmB;EACpB;AACD,QAAM,QAAQ,OAAO,MAAM;AAC3B,SAAO,gBAAgB,IAAI,eAAe,QAAQ,EAAE;EACpD,MAAM,EAAE,YAAY,UAAU,GAAG,IAAI,eAAe;AACpD,SAAO,gBAAgB,YAAY,CAAC,KAAM,EAAC;AAC3C,SAAO,GAAG,oBAAoB,OAAO;EACrC,MAAM,SA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