Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

unified-list: enable rename channel (#509)

Caleb Taylor9367166982c6
diff --git a/js/app/packages/app/component/SoupContext.tsx b/js/app/packages/app/component/SoupContext.tsx
index 0a114a7604..094bca8dcf 100644
--- a/js/app/packages/app/component/SoupContext.tsx
+++ b/js/app/packages/app/component/SoupContext.tsx
@@ -1,4 +1,5 @@
import { globalSplitManager } from '@app/signal/splitLayout';
+import { useChannelsContext } from '@core/component/ChannelsProvider';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
import { HotkeyTags } from '@core/hotkey/constants';
import { activeScope, hotkeyScopeTree } from '@core/hotkey/state';
@@ -449,8 +450,42 @@ export function createNavigationEntityListShortcut({
},
{
testEnabled: (entity) => {
- // can't rename these bad boys yet.
- if (entity.type === 'channel' || entity.type === 'email') return false;
+ if (entity.type === 'channel') {
+ if (entity.channelType === 'direct_message') return false;
+
+ const currentUserId = userId();
+ if (!currentUserId) return false;
+
+ // Check if user is the owner
+ if (entity.ownerId === currentUserId) {
+ return true;
+ }
+
+ // Check if user is an admin by looking up channel participant data
+ try {
+ const channelsContext = useChannelsContext();
+ const channel = channelsContext
+ .channels()
+ .find((c) => c.id === entity.id);
+ if (channel) {
+ const participant = channel.participants.find(
+ (p) => p.user_id === currentUserId
+ );
+ if (
+ participant &&
+ ['admin', 'owner'].includes(participant.role)
+ ) {
+ return true;
+ }
+ }
+ } catch (_err) {
+ return false;
+ }
+
+ return false;
+ }
+ if (entity.type === 'email') return false;
+
// only rename what you own.
return entity.ownerId === userId();
},
diff --git a/js/app/packages/core/component/FileList/itemOperations.ts b/js/app/packages/core/component/FileList/itemOperations.ts
index 8d2d4b18bc..efa5fc8c1b 100644
--- a/js/app/packages/core/component/FileList/itemOperations.ts
+++ b/js/app/packages/core/component/FileList/itemOperations.ts
@@ -2,6 +2,7 @@ import { usePaywallState } from '@core/constant/PaywallState';
import { isPaymentError } from '@core/util/handlePaymentError';
import { isErr, isOk } from '@core/util/maybeResult';
import { cognitionApiServiceClient } from '@service-cognition/client';
+import { commsServiceClient } from '@service-comms/client';
import { type ItemType, storageServiceClient } from '@service-storage/client';
import {
optimisticallyRemoveDeletedItem,
@@ -92,6 +93,13 @@ export async function renameItem(args: {
});
break;
}
+ case 'channel': {
+ result = await commsServiceClient.patchChannel({
+ channel_id: id,
+ channel_name: newName,
+ });
+ break;
+ }
default: {
return false;
}
diff --git a/js/app/packages/macro-entity/src/queries/dss.ts b/js/app/packages/macro-entity/src/queries/dss.ts
index 5aaf731063..304c0f1fde 100644
--- a/js/app/packages/macro-entity/src/queries/dss.ts
+++ b/js/app/packages/macro-entity/src/queries/dss.ts
@@ -515,7 +515,10 @@ export function createRenameDssEntityMutation() {
export function createBulkRenameDssEntityMutation() {
const isUnsupportedEntity = (entity: EntityData) => {
const type = entity.type;
- return type === 'channel' || type === 'email';
+ if (entity.type === 'channel') {
+ return entity.channelType === 'direct_message';
+ }
+ return type === 'email';
};
return useMutation(() => ({