MCPcopy Create free account
hub / github.com/ScattrdBlade/bigFileUpload / channelAttachMenuPatch

Function channelAttachMenuPatch

index.tsx:312–365  ·  view source on GitHub ↗
(children, props)

Source from the content-addressed store, hash-verified

310const ExternalIcon = () => <OpenExternalIcon height={24} width={24} />;
311
312const channelAttachMenuPatch: NavContextMenuPatchCallback = (children, props) => {
313 const channel = props?.channel;
314 if (!channel) return;
315 if (channel.guild_id && !PermissionStore.can(PermissionsBits.SEND_MESSAGES, channel)) return;
316 if (children.some(child => child?.props?.id === "file-upload-manual" || child?.props?.id === "file-upload-uploads")) return;
317
318 const uploads = UploadAttachmentStore.getUploads(channel.id, DraftType.ChannelMessage);
319 const draftUploads = Array.isArray(uploads) ? uploads.filter((u: CloudUpload) => u.item?.file && isFileTypeAllowed(u.item.file)) : [];
320
321 if (draftUploads.length > 0) {
322 children.splice(1, 0,
323 <Menu.MenuItem
324 id="file-upload-uploads"
325 key="file-upload-uploads"
326 label="Upload to Host"
327 iconLeft={ExternalIcon}
328 leadingAccessory={{
329 type: "icon",
330 icon: ExternalIcon
331 }}
332 >
333 {draftUploads.map((upload: CloudUpload) => (
334 <Menu.MenuItem
335 id={`file-upload-draft-${upload.id}`}
336 key={upload.id}
337 label={upload.filename}
338 action={() => handleUploadFileFromDraft(upload)}
339 />
340 ))}
341 <Menu.MenuSeparator />
342 <Menu.MenuItem
343 id="file-upload-manual"
344 key="file-upload-manual"
345 label="Choose File..."
346 action={() => uploadPickedFile()}
347 />
348 </Menu.MenuItem>
349 );
350 } else {
351 children.splice(1, 0,
352 <Menu.MenuItem
353 id="file-upload-manual"
354 key="file-upload-manual"
355 label="Upload to Host"
356 iconLeft={ExternalIcon}
357 leadingAccessory={{
358 type: "icon",
359 icon: ExternalIcon
360 }}
361 action={() => uploadPickedFile()}
362 />
363 );
364 }
365};
366
367export default definePlugin({
368 name: "BigFileUpload",

Callers

nothing calls this directly

Calls 3

isFileTypeAllowedFunction · 0.90
uploadPickedFileFunction · 0.90

Tested by

no test coverage detected