Skip to content

Commit 77bb872

Browse files
dahliaclaude
andcommitted
Fix getOutbox() messages missing update and delete methods
Messages returned from Session.getOutbox() now properly have update() and delete() methods by ensuring they are created as AuthorizedMessage instances. This resolves issue #9 where these methods were undefined. Also added regression test to prevent this bug from reoccurring. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 17d16c3 commit 77bb872

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
.claude/
12
coverage/

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Version 0.2.1
66

77
To be released.
88

9+
- Fixed a bug where messages from `Session.getOutbox()` didn't have `update()`
10+
and `delete()` methods. [[#9]]
11+
12+
[[#9]]: https://github.com/fedify-dev/botkit/issues/9
13+
914

1015
Version 0.2.0
1116
-------------

src/message-impl.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,9 @@ export async function createMessage<T extends MessageClass, TContextData>(
599599
raw: T,
600600
session: SessionImpl<TContextData>,
601601
cachedObjects: Record<string, Object>,
602-
replyTarget?: Message<MessageClass, TContextData>,
603-
quote?: Message<MessageClass, TContextData>,
604-
authorized?: true,
602+
replyTarget: Message<MessageClass, TContextData> | undefined,
603+
quote: Message<MessageClass, TContextData> | undefined,
604+
authorized: true,
605605
): Promise<AuthorizedMessage<T, TContextData>>;
606606
export async function createMessage<T extends MessageClass, TContextData>(
607607
raw: T,

src/session-impl.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,17 @@ Deno.test("SessionImpl.getOutbox()", async (t) => {
658658
"https://example.com/ap/note/01941f29-7c00-7fe8-ab0a-7b593990a3c0",
659659
]);
660660
});
661+
662+
await t.step("messages should have update and delete methods", async () => {
663+
const outbox = session.getOutbox({ order: "oldest" });
664+
const messages = await Array.fromAsync(outbox);
665+
assertEquals(messages.length, 4);
666+
667+
for (const message of messages) {
668+
assertEquals(typeof message.update, "function");
669+
assertEquals(typeof message.delete, "function");
670+
}
671+
});
661672
});
662673

663674
export interface SentActivity {

src/session-impl.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,14 @@ export class SessionImpl<TContextData> implements Session<TContextData> {
353353
continue;
354354
}
355355
if (object == null || !isMessageObject(object)) continue;
356-
const message = await createMessage(object, this, {});
356+
const message = await createMessage(
357+
object,
358+
this,
359+
{},
360+
undefined,
361+
undefined,
362+
true,
363+
);
357364
yield message;
358365
}
359366
}

0 commit comments

Comments
 (0)