diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-06-26 08:16:57 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-26 08:16:57 -0400 |
commit | 23ccfc845ca2350075f6027e16c6206fc7b71716 (patch) | |
tree | 3fd1f896a5a24b43913be03b21c85638dd7c356e /webapp/actions/integration_actions.jsx | |
parent | fe7e9d95b30ae2195fcba68db960866db91ce045 (diff) | |
download | chat-23ccfc845ca2350075f6027e16c6206fc7b71716.tar.gz chat-23ccfc845ca2350075f6027e16c6206fc7b71716.tar.bz2 chat-23ccfc845ca2350075f6027e16c6206fc7b71716.zip |
Move remaining actions over to use redux and v4 endpoints (#6720)
Diffstat (limited to 'webapp/actions/integration_actions.jsx')
-rw-r--r-- | webapp/actions/integration_actions.jsx | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/webapp/actions/integration_actions.jsx b/webapp/actions/integration_actions.jsx index 39dbbb2a8..6afaa5789 100644 --- a/webapp/actions/integration_actions.jsx +++ b/webapp/actions/integration_actions.jsx @@ -4,13 +4,21 @@ import UserStore from 'stores/user_store.jsx'; import TeamStore from 'stores/team_store.jsx'; -// Redux actions +import * as UserAgent from 'utils/user_agent.jsx'; +import {ActionTypes} from 'utils/constants.jsx'; +import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; + import store from 'stores/redux_store.jsx'; const dispatch = store.dispatch; const getState = store.getState; + +import {Client4} from 'mattermost-redux/client'; + import {getProfilesByIds} from 'mattermost-redux/actions/users'; import * as IntegrationActions from 'mattermost-redux/actions/integrations'; +import request from 'superagent'; + export function loadIncomingHooks(complete) { IntegrationActions.getIncomingHooks('', 0, 10000)(dispatch, getState).then( (data) => { @@ -201,3 +209,61 @@ export function deleteCommand(id) { export function regenCommandToken(id) { IntegrationActions.regenCommandToken(id)(dispatch, getState); } + +export function getSuggestedCommands(command, suggestionId, component) { + Client4.getCommandsList(TeamStore.getCurrentId()).then( + (data) => { + var matches = []; + data.forEach((cmd) => { + if (cmd.trigger !== 'shortcuts' || !UserAgent.isMobile()) { + if (('/' + cmd.trigger).indexOf(command) === 0) { + const s = '/' + cmd.trigger; + let hint = ''; + if (cmd.auto_complete_hint && cmd.auto_complete_hint.length !== 0) { + hint = cmd.auto_complete_hint; + } + matches.push({ + suggestion: s, + hint, + description: cmd.auto_complete_desc + }); + } + } + }); + + matches = matches.sort((a, b) => a.suggestion.localeCompare(b.suggestion)); + + // pull out the suggested commands from the returned data + const terms = matches.map((suggestion) => suggestion.suggestion); + + if (terms.length > 0) { + AppDispatcher.handleServerAction({ + type: ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS, + id: suggestionId, + matchedPretext: command, + terms, + items: matches, + component + }); + } + } + ).catch( + () => {} //eslint-disable-line no-empty-function + ); +} + +export function getYoutubeVideoInfo(googleKey, videoId, success, error) { + request.get('https://www.googleapis.com/youtube/v3/videos'). + query({part: 'snippet', id: videoId, key: googleKey}). + end((err, res) => { + if (err) { + return error(err); + } + + if (!res.body) { + console.error('Missing response body for getYoutubeVideoInfo'); // eslint-disable-line no-console + } + + return success(res.body); + }); +} |