Skip to content
Closed
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
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ $ ably-interactive
* [`ably channels occupancy subscribe CHANNEL`](#ably-channels-occupancy-subscribe-channel)
* [`ably channels presence`](#ably-channels-presence)
* [`ably channels presence enter CHANNEL`](#ably-channels-presence-enter-channel)
* [`ably channels presence get-all CHANNEL`](#ably-channels-presence-get-all-channel)
* [`ably channels presence get CHANNEL`](#ably-channels-presence-get-channel)
* [`ably channels presence subscribe CHANNEL`](#ably-channels-presence-subscribe-channel)
* [`ably channels presence update CHANNEL`](#ably-channels-presence-update-channel)
* [`ably channels publish CHANNEL MESSAGE`](#ably-channels-publish-channel-message)
Expand Down Expand Up @@ -193,7 +193,7 @@ $ ably-interactive
* [`ably rooms occupancy subscribe ROOM`](#ably-rooms-occupancy-subscribe-room)
* [`ably rooms presence`](#ably-rooms-presence)
* [`ably rooms presence enter ROOM`](#ably-rooms-presence-enter-room)
* [`ably rooms presence get-all ROOM`](#ably-rooms-presence-get-all-room)
* [`ably rooms presence get ROOM`](#ably-rooms-presence-get-room)
* [`ably rooms presence subscribe ROOM`](#ably-rooms-presence-subscribe-room)
* [`ably rooms presence update ROOM`](#ably-rooms-presence-update-room)
* [`ably rooms reactions`](#ably-rooms-reactions)
Expand Down Expand Up @@ -1940,13 +1940,13 @@ EXAMPLES

_See code: [src/commands/channels/presence/enter.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/channels/presence/enter.ts)_

## `ably channels presence get-all CHANNEL`
## `ably channels presence get CHANNEL`

Get all current presence members on a channel

```
USAGE
$ ably channels presence get-all CHANNEL [-v] [--json | --pretty-json] [--limit <value>]
$ ably channels presence get CHANNEL [-v] [--json | --pretty-json] [--limit <value>]

ARGUMENTS
CHANNEL Channel name to get presence members for
Expand All @@ -1961,16 +1961,16 @@ DESCRIPTION
Get all current presence members on a channel

EXAMPLES
$ ably channels presence get-all my-channel
$ ably channels presence get my-channel

$ ably channels presence get-all my-channel --limit 50
$ ably channels presence get my-channel --limit 50

$ ably channels presence get-all my-channel --json
$ ably channels presence get my-channel --json

$ ably channels presence get-all my-channel --pretty-json
$ ably channels presence get my-channel --pretty-json
```

_See code: [src/commands/channels/presence/get-all.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/channels/presence/get-all.ts)_
_See code: [src/commands/channels/presence/get.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/channels/presence/get.ts)_

## `ably channels presence subscribe CHANNEL`

Expand Down Expand Up @@ -4251,13 +4251,13 @@ EXAMPLES

_See code: [src/commands/rooms/presence/enter.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/rooms/presence/enter.ts)_

## `ably rooms presence get-all ROOM`
## `ably rooms presence get ROOM`

Get all current presence members in a chat room

```
USAGE
$ ably rooms presence get-all ROOM [-v] [--json | --pretty-json] [--limit <value>]
$ ably rooms presence get ROOM [-v] [--json | --pretty-json] [--limit <value>]

ARGUMENTS
ROOM Room to get presence members for
Expand All @@ -4272,16 +4272,16 @@ DESCRIPTION
Get all current presence members in a chat room

EXAMPLES
$ ably rooms presence get-all my-room
$ ably rooms presence get my-room

$ ably rooms presence get-all my-room --limit 50
$ ably rooms presence get my-room --limit 50

$ ably rooms presence get-all my-room --json
$ ably rooms presence get my-room --json

$ ably rooms presence get-all my-room --pretty-json
$ ably rooms presence get my-room --pretty-json
```

_See code: [src/commands/rooms/presence/get-all.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/rooms/presence/get-all.ts)_
_See code: [src/commands/rooms/presence/get.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/rooms/presence/get.ts)_

## `ably rooms presence subscribe ROOM`

Expand Down Expand Up @@ -4321,17 +4321,17 @@ Update presence data in a chat room

```
USAGE
$ ably rooms presence update ROOM --data <value> [-v] [--json | --pretty-json] [--client-id <value>] [-D <value>]
$ ably rooms presence update ROOM --client-id <value> [-v] [--json | --pretty-json] [--data <value>] [-D <value>]

ARGUMENTS
ROOM Room to update presence in

FLAGS
-D, --duration=<value> Automatically exit after N seconds
-v, --verbose Output verbose logs
--client-id=<value> Overrides any default client ID when using API authentication. Use "none" to explicitly set
no client ID. Not applicable when using token authentication.
--data=<value> (required) JSON data to associate with the presence update
--client-id=<value> (required) Overrides any default client ID when using API authentication. Use "none" to
explicitly set no client ID. Not applicable when using token authentication.
--data=<value> JSON data to associate with the presence update
--json Output in JSON format
--pretty-json Output in colorized JSON format

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
formatPaginationLog,
} from "../../../utils/pagination.js";

export default class ChannelsPresenceGetAll extends AblyBaseCommand {
export default class ChannelsPresenceGet extends AblyBaseCommand {
static override args = {
channel: Args.string({
description: "Channel name to get presence members for",
Expand All @@ -31,10 +31,10 @@ export default class ChannelsPresenceGetAll extends AblyBaseCommand {
static override description = "Get all current presence members on a channel";

static override examples = [
"$ ably channels presence get-all my-channel",
"$ ably channels presence get-all my-channel --limit 50",
"$ ably channels presence get-all my-channel --json",
"$ ably channels presence get-all my-channel --pretty-json",
"$ ably channels presence get my-channel",
"$ ably channels presence get my-channel --limit 50",
"$ ably channels presence get my-channel --json",
"$ ably channels presence get my-channel --pretty-json",
];

static override flags = {
Expand All @@ -47,7 +47,7 @@ export default class ChannelsPresenceGetAll extends AblyBaseCommand {
};

async run(): Promise<void> {
const { args, flags } = await this.parse(ChannelsPresenceGetAll);
const { args, flags } = await this.parse(ChannelsPresenceGet);

try {
const client = await this.createAblyRestClient(flags);
Expand Down Expand Up @@ -154,7 +154,7 @@ export default class ChannelsPresenceGetAll extends AblyBaseCommand {
}
}
} catch (error) {
this.fail(error, flags, "presenceGetAll", {
this.fail(error, flags, "presenceGet", {
channel: args.channel,
});
}
Expand Down
8 changes: 5 additions & 3 deletions src/commands/channels/presence/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ export default class ChannelsPresenceUpdate extends AblyBaseCommand {

static override flags = {
...productApiFlags,
...clientIdFlag,
"client-id": Flags.string({
description: 'ClientId of a channels presence member.',
required: true,
}),
data: Flags.string({
description: "JSON data to associate with the presence update",
required: true,
}),
...durationFlag,
};
Expand All @@ -51,7 +53,7 @@ export default class ChannelsPresenceUpdate extends AblyBaseCommand {
const client = this.client;
const { channel: channelName } = args;

const data = this.parseJsonFlag(flags.data, "data", flags);
const data = this.parseJsonFlag(flags.data ?? "{}", "data", flags);

this.channel = client.channels.get(channelName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
// Chat SDK maps room presence to the underlying channel: roomName::$chat
const chatChannelName = (roomName: string) => `${roomName}::$chat`;

export default class RoomsPresenceGetAll extends AblyBaseCommand {
export default class RoomsPresenceGet extends AblyBaseCommand {
static override args = {
room: Args.string({
description: "Room to get presence members for",
Expand All @@ -36,10 +36,10 @@ export default class RoomsPresenceGetAll extends AblyBaseCommand {
"Get all current presence members in a chat room";

static override examples = [
"$ ably rooms presence get-all my-room",
"$ ably rooms presence get-all my-room --limit 50",
"$ ably rooms presence get-all my-room --json",
"$ ably rooms presence get-all my-room --pretty-json",
"$ ably rooms presence get my-room",
"$ ably rooms presence get my-room --limit 50",
"$ ably rooms presence get my-room --json",
"$ ably rooms presence get my-room --pretty-json",
];

static override flags = {
Expand All @@ -52,7 +52,7 @@ export default class RoomsPresenceGetAll extends AblyBaseCommand {
};

async run(): Promise<void> {
const { args, flags } = await this.parse(RoomsPresenceGetAll);
const { args, flags } = await this.parse(RoomsPresenceGet);

try {
const client = await this.createAblyRestClient(flags);
Expand Down Expand Up @@ -158,7 +158,7 @@ export default class RoomsPresenceGetAll extends AblyBaseCommand {
}
}
} catch (error) {
this.fail(error, flags, "roomPresenceGetAll", {
this.fail(error, flags, "roomPresenceGet", {
room: args.room,
});
}
Expand Down
19 changes: 15 additions & 4 deletions src/commands/rooms/presence/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
formatProgress,
formatResource,
formatSuccess,
formatWarning,
} from "../../../utils/output.js";

export default class RoomsPresenceUpdate extends ChatBaseCommand {
Expand All @@ -31,10 +32,12 @@ export default class RoomsPresenceUpdate extends ChatBaseCommand {

static override flags = {
...productApiFlags,
...clientIdFlag,
"client-id": Flags.string({
description: "ClientId of a rooms presence member.",
required: true,
}),
data: Flags.string({
description: "JSON data to associate with the presence update",
required: true,
}),
...durationFlag,
};
Expand All @@ -58,11 +61,19 @@ export default class RoomsPresenceUpdate extends ChatBaseCommand {

const { room: roomName } = args;
const data = this.parseJsonFlag(
flags.data,
flags.data ?? "{}",
"data",
flags,
) as PresenceData;

const wildcardWarning = `Updating a clientId on behalf of another user using a wildcard (*) is not supported, since chat rooms only recognize explicitly identified clients. So, a member with provided clientId but a new connectionId will be entered and updated.`;

if (this.shouldOutputJson(flags)) {
this.logJsonStatus("warning", wildcardWarning, flags);
} else {
this.log(formatWarning(wildcardWarning));
}

this.setupConnectionStateLogging(this.chatClient.realtime, flags, {
includeUserFriendlyMessages: true,
});
Expand Down Expand Up @@ -91,7 +102,7 @@ export default class RoomsPresenceUpdate extends ChatBaseCommand {
`Entering presence in room ${roomName}`,
{ room: roomName, clientId: this.chatClient.clientId },
);
await this.room.presence.enter(data);
await this.room.presence.enter();
this.logCliEvent(
flags,
"presence",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const mockPresenceMembers = [
},
];

describe("channels:presence:get-all command", () => {
describe("channels:presence:get command", () => {
beforeEach(() => {
const mock = getMockAblyRest();
const channel = mock.channels._getChannel("test-channel");
Expand All @@ -41,11 +41,11 @@ describe("channels:presence:get-all command", () => {
);
});

standardHelpTests("channels:presence:get-all", import.meta.url);
standardArgValidationTests("channels:presence:get-all", import.meta.url, {
standardHelpTests("channels:presence:get", import.meta.url);
standardArgValidationTests("channels:presence:get", import.meta.url, {
requiredArgs: ["test-channel"],
});
standardFlagTests("channels:presence:get-all", import.meta.url, [
standardFlagTests("channels:presence:get", import.meta.url, [
"--limit",
"--json",
"--pretty-json",
Expand All @@ -57,7 +57,7 @@ describe("channels:presence:get-all command", () => {
const channel = mock.channels._getChannel("test-channel");

const { stdout } = await runCommand(
["channels:presence:get-all", "test-channel"],
["channels:presence:get", "test-channel"],
import.meta.url,
);

Expand All @@ -75,7 +75,7 @@ describe("channels:presence:get-all command", () => {
channel.presence.get.mockResolvedValue(createMockPaginatedResult([]));

const { stderr } = await runCommand(
["channels:presence:get-all", "test-channel"],
["channels:presence:get", "test-channel"],
import.meta.url,
);

Expand All @@ -84,7 +84,7 @@ describe("channels:presence:get-all command", () => {

it("should output JSON with presenceMembers array", async () => {
const { stdout } = await runCommand(
["channels:presence:get-all", "test-channel", "--json"],
["channels:presence:get", "test-channel", "--json"],
import.meta.url,
);

Expand All @@ -104,7 +104,7 @@ describe("channels:presence:get-all command", () => {

it("should display member data when present", async () => {
const { stdout } = await runCommand(
["channels:presence:get-all", "test-channel"],
["channels:presence:get", "test-channel"],
import.meta.url,
);

Expand All @@ -118,7 +118,7 @@ describe("channels:presence:get-all command", () => {
const channel = mock.channels._getChannel("test-channel");

await runCommand(
["channels:presence:get-all", "test-channel", "--limit", "50"],
["channels:presence:get", "test-channel", "--limit", "50"],
import.meta.url,
);

Expand All @@ -144,7 +144,7 @@ describe("channels:presence:get-all command", () => {
);

const { stdout } = await runCommand(
["channels:presence:get-all", "test-channel", "--limit", "1", "--json"],
["channels:presence:get", "test-channel", "--limit", "1", "--json"],
import.meta.url,
);

Expand All @@ -162,7 +162,7 @@ describe("channels:presence:get-all command", () => {
channel.presence.get.mockRejectedValue(new Error("API error"));

const { error } = await runCommand(
["channels:presence:get-all", "test-channel"],
["channels:presence:get", "test-channel"],
import.meta.url,
);

Expand All @@ -180,7 +180,7 @@ describe("channels:presence:get-all command", () => {
);

const { error } = await runCommand(
["channels:presence:get-all", "nonexistent-channel"],
["channels:presence:get", "nonexistent-channel"],
import.meta.url,
);

Expand Down
Loading