diff --git a/webapp/channels/src/components/edit_post/edit_post.tsx b/webapp/channels/src/components/edit_post/edit_post.tsx index 81e6e570b3..e37e2007e4 100644 --- a/webapp/channels/src/components/edit_post/edit_post.tsx +++ b/webapp/channels/src/components/edit_post/edit_post.tsx @@ -29,6 +29,7 @@ import {ModalData} from 'types/actions'; import {PostDraft} from '../../types/store/draft'; import EditPostFooter from './edit_post_footer'; +import {ActionResult} from 'mattermost-redux/types/actions'; type DialogProps = { post?: Post; @@ -42,6 +43,7 @@ export type Actions = { unsetEditingPost: () => void; openModal: (input: ModalData) => void; scrollPostListToBottom: () => void; + runMessageWillBeUpdatedHooks: (newPost: Partial, oldPost: Post) => Promise; } export type Props = { @@ -233,12 +235,20 @@ const EditPost = ({editingPost, actions, canEditPost, config, channelId, draft, return; } - const updatedPost = { + let updatedPost = { message: editText, id: editingPost.postId, channel_id: editingPost.post.channel_id, }; + const hookResult = await actions.runMessageWillBeUpdatedHooks(updatedPost, editingPost.post); + if (hookResult.error && hookResult.error.message) { + setPostError(<>{hookResult.error.message}); + return; + } + + updatedPost = hookResult.data; + if (postError) { setErrorClass('animation--highlight'); setTimeout(() => setErrorClass(''), Constants.ANIMATION_TIMEOUT); diff --git a/webapp/channels/src/components/edit_post/index.ts b/webapp/channels/src/components/edit_post/index.ts index 78e7a7aac3..8f226a5d06 100644 --- a/webapp/channels/src/components/edit_post/index.ts +++ b/webapp/channels/src/components/edit_post/index.ts @@ -22,6 +22,7 @@ import {GlobalState} from 'types/store'; import Constants, {RHSStates, StoragePrefixes} from 'utils/constants'; import {setGlobalItem} from '../../actions/storage'; import {getIsRhsOpen, getPostDraft, getRhsState} from '../../selectors/rhs'; +import {runMessageWillBeUpdatedHooks} from 'actions/hooks'; import EditPost, {Actions} from './edit_post'; @@ -67,6 +68,7 @@ function mapDispatchToProps(dispatch: Dispatch) { setDraft: setGlobalItem, unsetEditingPost, openModal, + runMessageWillBeUpdatedHooks, }, dispatch), }; }