Commit aa1b7f51 authored by Lev's avatar Lev Committed by Christopher Speller

Added doPostActionWithCookie for MM-10516, actions in ephemeral messages (#769)

* Added doPostActionWithCookie for MM-10516, actions in ephemeral messages.

These functions (action, and client method) extend doPostAction to
include the "cookie" value. The old functions should no longer be used,
but I wasn't sure if it's safe to deprecate them, thus new additions.

* PR feedback
parent 7987bd8b
......@@ -1089,10 +1089,14 @@ export function getOpenGraphMetadata(url) {
}
export function doPostAction(postId, actionId, selectedOption = '') {
return doPostActionWithCookie(postId, actionId, '', selectedOption);
}
export function doPostActionWithCookie(postId, actionId, actionCookie, selectedOption = '') {
return async (dispatch, getState) => {
let data;
try {
data = await Client4.doPostAction(postId, actionId, selectedOption);
data = await Client4.doPostActionWithCookie(postId, actionId, actionCookie, selectedOption);
} catch (error) {
forceLogoutIfNecessary(error, dispatch, getState);
dispatch(logError(error));
......@@ -1105,6 +1109,7 @@ export function doPostAction(postId, actionId, selectedOption = '') {
data: data.trigger_id,
});
}
return {data};
};
}
......
......@@ -1598,6 +1598,15 @@ describe('Actions.Posts', () => {
assert.deepEqual(data, {});
});
it('doPostActionWithCookie', async () => {
nock(Client4.getBaseRoute()).
post('/posts/posth67ja7ntdkek6g13dp3wka/actions/action7ja7ntdkek6g13dp3wka').
reply(200, {});
const {data} = await Actions.doPostActionWithCookie('posth67ja7ntdkek6g13dp3wka', 'action7ja7ntdkek6g13dp3wka', '', 'option')(store.dispatch, store.getState);
assert.deepEqual(data, {});
});
it('addMessageIntoHistory', async () => {
const {dispatch, getState} = store;
......
......@@ -1577,15 +1577,25 @@ export default class Client4 {
};
doPostAction = async (postId, actionId, selectedOption = '') => {
return this.doPostActionWithCookie(postId, actionId, '', selectedOption);
};
doPostActionWithCookie = async (postId, actionId, actionCookie, selectedOption = '') => {
if (selectedOption) {
this.trackEvent('api', 'api_interactive_messages_menu_selected');
} else {
this.trackEvent('api', 'api_interactive_messages_button_clicked');
}
const msg = {
selected_option: selectedOption,
};
if (actionCookie !== '') {
msg.cookie = actionCookie;
}
return this.doFetch(
`${this.getPostRoute(postId)}/actions/${encodeURIComponent(actionId)}`,
{method: 'post', body: JSON.stringify({selected_option: selectedOption})}
{method: 'post', body: JSON.stringify(msg)}
);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment