-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add localization, call validation and use call type on subpath #5221
Changes from all commits
6229a23
f28b4dd
cde4f45
dcfddad
474763d
67ce2f3
9f7bf74
5bbf084
769e7eb
620c4f1
13c02d9
32798ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,15 @@ import {intlShape} from 'react-intl'; | |
import {IntegrationTypes} from '@mm-redux/action_types'; | ||
import {executeCommand as executeCommandService} from '@mm-redux/actions/integrations'; | ||
import {getCurrentTeamId} from '@mm-redux/selectors/entities/teams'; | ||
import {AppCallTypes} from '@mm-redux/constants/apps'; | ||
import {AppCallResponseTypes, AppCallTypes} from '@mm-redux/constants/apps'; | ||
import {DispatchFunc, GetStateFunc, ActionFunc} from '@mm-redux/types/actions'; | ||
|
||
import {AppCommandParser} from '@components/autocomplete/slash_suggestion/app_command_parser/app_command_parser'; | ||
|
||
import {doAppCall} from '@actions/apps'; | ||
import {appsEnabled} from '@utils/apps'; | ||
import {AppCallResponse} from '@mm-redux/types/apps'; | ||
import {sendEphemeralPost} from './post'; | ||
|
||
export function executeCommand(message: string, channelId: string, rootId: string, intl: typeof intlShape): ActionFunc { | ||
return async (dispatch: DispatchFunc, getState: GetStateFunc) => { | ||
|
@@ -39,15 +41,46 @@ export function executeCommand(message: string, channelId: string, rootId: strin | |
|
||
const appsAreEnabled = appsEnabled(state); | ||
if (appsAreEnabled) { | ||
const parser = new AppCommandParser({dispatch, getState}, args.channel_id, args.root_id); | ||
const parser = new AppCommandParser({dispatch, getState}, intl, args.channel_id, args.root_id); | ||
if (parser.isAppCommand(msg)) { | ||
const call = await parser.composeCallFromCommand(message); | ||
const createErrorMessage = (errMessage: string) => { | ||
return {error: {message: errMessage}}; | ||
}; | ||
|
||
if (!call) { | ||
return {error: {message: 'Error submitting command'}}; | ||
return createErrorMessage(intl.formatMessage({ | ||
id: 'mobile.commands.error_title', | ||
defaultMessage: 'Error Executing Command', | ||
})); | ||
} | ||
|
||
call.type = AppCallTypes.SUBMIT; | ||
return dispatch(doAppCall(call, intl)); | ||
const res = await dispatch(doAppCall(call, AppCallTypes.SUBMIT, intl)); | ||
if (res.error) { | ||
const errorResponse = res.error as AppCallResponse; | ||
return createErrorMessage(errorResponse.error || intl.formatMessage({ | ||
id: 'apps.error.unknown', | ||
defaultMessage: 'Unknown error.', | ||
})); | ||
} | ||
const callResp = res.data as AppCallResponse; | ||
switch (callResp.type) { | ||
case AppCallResponseTypes.OK: | ||
if (callResp.markdown) { | ||
dispatch(sendEphemeralPost(callResp.markdown, args.channel_id, args.parent_id)); | ||
} | ||
return {data: {}}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this returning an empty object in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The expected data to be returned from here is an Slash Command Response (https://developers.mattermost.com/integrate/slash-commands/). Right now is not being used, so {} and true would mean almost the same, but I preferred to keep the empty object. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As long as the empty object is being handled correctly I have no problem with it |
||
case AppCallResponseTypes.FORM: | ||
case AppCallResponseTypes.NAVIGATE: | ||
return {data: {}}; | ||
default: | ||
return createErrorMessage(intl.formatMessage({ | ||
id: 'apps.error.responses.unknown_type', | ||
defaultMessage: 'App response type not supported. Response type: {type}.', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we eventually (not now) add links to supported App response types. |
||
}, { | ||
type: callResp.type, | ||
})); | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering if this errors are shown to the user somehow, if they are.. do they make sense for an end user? they seem more relevant to the plugin developer / sysadmin, I doubt an end user will understand the meaning of this type of errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We feel the error should somehow be delivered specially for debugging. What do you think about a "default error" and a
console.log
statement here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console output is removed from the code base in production builds, see https://reactnative.dev/docs/next/performance#using-consolelog-statements