Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/commands/rooms/messages/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,16 @@ export default class MessagesHistory extends ChatBaseCommand {
}

// Get historical messages
const messagesResult = await room.messages.history({ limit: flags.limit });
const messagesResult = await room.messages.history({
limit: flags.limit,
});
const { items } = messagesResult;

if (this.shouldOutputJson(flags)) {
this.log(
this.formatJsonOutput(
{
messages: items.map((message) => ({
clientId: message.clientId,
text: message.text,
timestamp: message.timestamp,
...(flags["show-metadata"] && message.metadata
? { metadata: message.metadata }
: {}),
})),
messages: items,
roomId: args.roomId,
success: true,
},
Expand Down
14 changes: 7 additions & 7 deletions src/commands/rooms/messages/send.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Args, Flags } from "@oclif/core";
import * as Ably from "ably"; // Import Ably
import { ChatClient } from "@ably/chat";
import { ChatClient, Message } from "@ably/chat";

import { ChatBaseCommand } from "../../../chat-base-command.js";

Expand All @@ -13,7 +13,7 @@ interface MessageToSend {

interface MessageResult {
index?: number;
message?: MessageToSend;
message?: Message;
roomId: string;
success: boolean;
error?: string;
Expand Down Expand Up @@ -289,11 +289,11 @@ export default class MessagesSend extends ChatBaseCommand {
// Send the message without awaiting
room.messages
.send(messageToSend)
.then(() => {
.then((sent: Message) => {
sentCount++;
const result: MessageResult = {
index: i + 1,
message: messageToSend,
message: sent,
roomId: args.roomId,
success: true,
};
Expand Down Expand Up @@ -414,9 +414,9 @@ export default class MessagesSend extends ChatBaseCommand {
);

// Send the message
await room.messages.send(messageToSend);
const sent = await room.messages.send(messageToSend);
const result: MessageResult = {
message: messageToSend,
message: sent,
roomId: args.roomId,
success: true,
};
Expand All @@ -432,7 +432,7 @@ export default class MessagesSend extends ChatBaseCommand {
if (this.shouldOutputJson(flags)) {
this.log(this.formatJsonOutput(result, flags));
} else {
this.log("Message sent successfully.");
this.log(`Message sent successfully. Serial: ${sent.serial}`);
}
}
} catch (error) {
Expand Down
Loading
Loading