This repository has been archived on 2024-11-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
mattermost-plugin-attachmen.../webapp/src/index.tsx
Felipe Martin 2d962d18d2
Some checks failed
ci / plugin-ci (push) Has been cancelled
added command with interactive dialog
2024-08-08 18:06:32 +02:00

38 lines
1.4 KiB
TypeScript

import {Store, Action} from 'redux';
import {GlobalState} from 'mattermost-redux/types/store';
import {getPost} from 'mattermost-redux/selectors/entities/posts';
import manifest from '@/manifest';
import {PluginRegistry} from '@/types/mattermost-webapp';
import {triggerRemoveAttachmentsCommand} from './actions';
export default class Plugin {
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
public async initialize(registry: PluginRegistry, store: Store<GlobalState, Action<Record<string, unknown>>>) {
// @see https://developers.mattermost.com/extend/plugins/webapp/reference/
registry.registerPostDropdownMenuAction(
'Remove attachments',
async (postID) => {
store.dispatch(triggerRemoveAttachmentsCommand(postID) as any);
},
(postID) => {
const state = store.getState();
const post = getPost(state, postID);
// Don't show up if the post has no attachments. Permissions are checked server-side.
return typeof post.file_ids?.length !== 'undefined' && post.file_ids?.length > 0;
},
);
}
}
declare global {
interface Window {
registerPlugin(pluginId: string, plugin: Plugin): void
}
}
window.registerPlugin(manifest.id, new Plugin());