Skip to content

Commit

Permalink
Use internal message dispatcher if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Jan 12, 2025
1 parent c4e3f4e commit 0faf0ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/bot-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export class BotImpl<TContextData> implements Bot<TContextData> {
async dispatchMessage<T extends MessageClass>(
// deno-lint-ignore no-explicit-any
cls: new (values: any) => T,
ctx: RequestContext<TContextData>,
ctx: Context<TContextData>,
id: string,
): Promise<T | null> {
const json = await this.kv.get([...this.kvPrefixes.messages, id]);
Expand Down
13 changes: 12 additions & 1 deletion src/message-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
Document,
Hashtag,
isActor,
type Link,
Mention,
Note,
type Object,
Expand Down Expand Up @@ -321,7 +322,17 @@ export async function createMessage<T extends MessageClass, TContextData>(
if (attachment instanceof Document) attachments.push(attachment);
}
if (replyTarget == null) {
const rt = await raw.getReplyTarget(options);
let rt: Link | Object | null;
const parsed = session.context.parseUri(raw.replyTargetId);
// @ts-ignore: The `class` property satisfies the `MessageClass` type.
if (parsed?.type === "object" && messageClasses.includes(parsed.class)) {
rt = await session.bot.dispatchMessage(
// @ts-ignore: The `class` property satisfies the `MessageClass` type.
parsed.class,
session.context,
parsed.values.id,
);
} else rt = await raw.getReplyTarget(options);
if (
rt instanceof Article || rt instanceof ChatMessage ||
rt instanceof Note || rt instanceof Question
Expand Down

0 comments on commit 0faf0ba

Please sign in to comment.