Skip to content
Draft
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
49 changes: 49 additions & 0 deletions src/commands/conversation/add-admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Args } from "@oclif/core";
import { requireGroup } from "../../utils/xmtp.js";
import { ConvosBaseCommand } from "../../baseCommand.js";
import { createClientForIdentity } from "../../utils/client.js";
import { createIdentityStore } from "../../utils/identities.js";

export default class ConversationAddAdmin extends ConvosBaseCommand {
static description = `Promote members to admin by inbox ID. Requires super admin permissions.`;

static strict = false;

static args = {
id: Args.string({ description: "The conversation ID", required: true }),
};

static flags = { ...ConvosBaseCommand.baseFlags };

async run(): Promise<void> {
const { args, argv } = await this.parse(ConversationAddAdmin);
const inboxIds = (argv as string[]).slice(1);
if (inboxIds.length === 0) this.error("At least one inbox ID is required");

const config = this.getConvosConfig();
const store = createIdentityStore(this.getConvosHome());
const identity = store.getByConversationId(args.id);
if (!identity) this.error(`No identity found for conversation: ${args.id}`);

const client = await createClientForIdentity(identity, config, this.getConvosHome());
const conversation = await client.conversations.getConversationById(args.id);
if (!conversation) this.error(`Conversation not found: ${args.id}`);

const group = requireGroup(conversation);

const promoted: string[] = [];
for (const inboxId of inboxIds) {
await group.addAdmin(inboxId);
promoted.push(inboxId);
}

this.output({
success: true,
conversationId: args.id,
promotedInboxIds: promoted,
count: promoted.length,
admins: group.listAdmins(),
superAdmins: group.listSuperAdmins(),
});
}
}
53 changes: 53 additions & 0 deletions src/commands/conversation/add-super-admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Args } from "@oclif/core";
import { requireGroup } from "../../utils/xmtp.js";
import { ConvosBaseCommand } from "../../baseCommand.js";
import { createClientForIdentity } from "../../utils/client.js";
import { createIdentityStore } from "../../utils/identities.js";

export default class ConversationAddSuperAdmin extends ConvosBaseCommand {
static description = `Promote members to super admin by inbox ID. Requires super admin permissions.

Super admins can add and remove other admins, remove members, lock the
conversation, and explode it. Use this to transfer ownership of a
conversation to another member.`;

static strict = false;

static args = {
id: Args.string({ description: "The conversation ID", required: true }),
};

static flags = { ...ConvosBaseCommand.baseFlags };

async run(): Promise<void> {
const { args, argv } = await this.parse(ConversationAddSuperAdmin);
const inboxIds = (argv as string[]).slice(1);
if (inboxIds.length === 0) this.error("At least one inbox ID is required");

const config = this.getConvosConfig();
const store = createIdentityStore(this.getConvosHome());
const identity = store.getByConversationId(args.id);
if (!identity) this.error(`No identity found for conversation: ${args.id}`);

const client = await createClientForIdentity(identity, config, this.getConvosHome());
const conversation = await client.conversations.getConversationById(args.id);
if (!conversation) this.error(`Conversation not found: ${args.id}`);

const group = requireGroup(conversation);

const promoted: string[] = [];
for (const inboxId of inboxIds) {
await group.addSuperAdmin(inboxId);
promoted.push(inboxId);
}

this.output({
success: true,
conversationId: args.id,
promotedInboxIds: promoted,
count: promoted.length,
admins: group.listAdmins(),
superAdmins: group.listSuperAdmins(),
});
}
}
49 changes: 49 additions & 0 deletions src/commands/conversation/remove-admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Args } from "@oclif/core";
import { requireGroup } from "../../utils/xmtp.js";
import { ConvosBaseCommand } from "../../baseCommand.js";
import { createClientForIdentity } from "../../utils/client.js";
import { createIdentityStore } from "../../utils/identities.js";

export default class ConversationRemoveAdmin extends ConvosBaseCommand {
static description = `Demote admins to regular members by inbox ID. Requires super admin permissions.`;

static strict = false;

static args = {
id: Args.string({ description: "The conversation ID", required: true }),
};

static flags = { ...ConvosBaseCommand.baseFlags };

async run(): Promise<void> {
const { args, argv } = await this.parse(ConversationRemoveAdmin);
const inboxIds = (argv as string[]).slice(1);
if (inboxIds.length === 0) this.error("At least one inbox ID is required");

const config = this.getConvosConfig();
const store = createIdentityStore(this.getConvosHome());
const identity = store.getByConversationId(args.id);
if (!identity) this.error(`No identity found for conversation: ${args.id}`);

const client = await createClientForIdentity(identity, config, this.getConvosHome());
const conversation = await client.conversations.getConversationById(args.id);
if (!conversation) this.error(`Conversation not found: ${args.id}`);

const group = requireGroup(conversation);

const demoted: string[] = [];
for (const inboxId of inboxIds) {
await group.removeAdmin(inboxId);
demoted.push(inboxId);
}

this.output({
success: true,
conversationId: args.id,
demotedInboxIds: demoted,
count: demoted.length,
admins: group.listAdmins(),
superAdmins: group.listSuperAdmins(),
});
}
}
52 changes: 52 additions & 0 deletions src/commands/conversation/remove-super-admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Args } from "@oclif/core";
import { requireGroup } from "../../utils/xmtp.js";
import { ConvosBaseCommand } from "../../baseCommand.js";
import { createClientForIdentity } from "../../utils/client.js";
import { createIdentityStore } from "../../utils/identities.js";

export default class ConversationRemoveSuperAdmin extends ConvosBaseCommand {
static description = `Demote super admins by inbox ID. Requires super admin permissions.

A super admin can demote themselves with this command, provided at
least one other super admin remains in the conversation.`;

static strict = false;

static args = {
id: Args.string({ description: "The conversation ID", required: true }),
};

static flags = { ...ConvosBaseCommand.baseFlags };

async run(): Promise<void> {
const { args, argv } = await this.parse(ConversationRemoveSuperAdmin);
const inboxIds = (argv as string[]).slice(1);
if (inboxIds.length === 0) this.error("At least one inbox ID is required");

const config = this.getConvosConfig();
const store = createIdentityStore(this.getConvosHome());
const identity = store.getByConversationId(args.id);
if (!identity) this.error(`No identity found for conversation: ${args.id}`);

const client = await createClientForIdentity(identity, config, this.getConvosHome());
const conversation = await client.conversations.getConversationById(args.id);
if (!conversation) this.error(`Conversation not found: ${args.id}`);

const group = requireGroup(conversation);

const demoted: string[] = [];
for (const inboxId of inboxIds) {
await group.removeSuperAdmin(inboxId);
demoted.push(inboxId);
}

this.output({
success: true,
conversationId: args.id,
demotedInboxIds: demoted,
count: demoted.length,
admins: group.listAdmins(),
superAdmins: group.listSuperAdmins(),
});
}
}