Added in Quick Switcher team switch patch #120

Merged
merged 1 commit into from Aug 4, 2015
Jump to file or symbol
Failed to load files and symbols.
+43 −4
Diff settings

Always

Just for now

@@ -45,13 +45,13 @@
// If the target isn't a link, skip it
// DEV: This is a lo-fi event delegation. If we ever use it elsewhere, please use something more formal
var targetEl = evt.target;
- while (targetEl !== bodyEl) {
+ while (targetEl && targetEl !== bodyEl) {
if (targetEl.tagName.toLowerCase() === 'a') {
break;
}
targetEl = targetEl.parentNode;
}
- if (targetEl === bodyEl) {
+ if (!targetEl || targetEl === bodyEl) {
return;
}
@@ -111,6 +111,29 @@
});
},
+ // Override the team select action of the Slack quick switcher
+ addOmniboxOverrides: function () {
+ // If this is a page with TS on it, then install our overrides
+ var win = this.getWindow();
+ var TS = this.getTS();
+ // http://viewsource.in/https://slack.global.ssl.fastly.net/7eab/js/rollup-client.js#L10432
+ if (TS && TS.ui && TS.ui.omnibox && TS.ui.omnibox.selectTeamResult && !win._plaidchatBoundOmniboxOverrides) {
+ TS.ui.omnibox.selectTeamResult = function (teamUrl, teamName, userId) {
+ // ['https://plaidchat-test.slack.com/', 'plaidchat test', 'U039G6820' /* User id on selected team */]
+ // Hide the window and cancel the box as done in Slack
+ TS.ui.omnibox.div.find('#omnibox_ui').addClass('hidden');
+ TS.ui.omnibox.cancel();
+
+ // Dispatch our team activation
+ AppDispatcher.dispatch({
+ type: AppDispatcher.ActionTypes.ACTIVATE_TEAM,
+ userId: userId
+ });
+ };
+ win._plaidchatBoundOmniboxOverrides = true;
+ }
+ },
+
// When React adds/removes our `iframe` to the DOM
componentDidMount: function () {
// Whenever the iframe loads (e.g. we change pages for logging into a team)
@@ -191,6 +214,7 @@
// When our page loads, hook up listeners
this.addNotificationListeners();
this.addClickListeners();
+ this.addOmniboxOverrides();
this.resetTeamsLoaded();
this.watchTeamsLoaded();
},
View
@@ -117,6 +117,13 @@
// Lookup and return our team by its id
return _state.teamsById[id];
},
+ getTeamByUserId: function (userId) {
+ // DEV: This isn't performant as we loop over rather than doing an index lookup
+ // Maybe we should use a dictionary for tracking user ids as well?
+ var teams = _.values(_state.teamsById);
+ var team = _.findWhere(teams, {id: userId});
+ return team || null;
+ },
getTeamsById: function () {
return _state.teamsById;
},
@@ -138,6 +145,10 @@
}
}
},
+ setActiveTeamByUserId: function (id) {
+ var team = this.getTeamByUserId(id);
+ return this.setActiveTeamId(team.team_id);
+ },
setTeamIcon: function (id, teamIcon) {
_state.teamIconsById[id] = _.clone(teamIcon);
},
@@ -208,8 +219,12 @@
// Define our handler for various updates
TeamStore.dispatchToken = AppDispatcher.register(function handleAction (action) {
if (action.type === ActionTypes.ACTIVATE_TEAM) {
- console.debug('Setting active team id', {teamId: action.teamId});
- TeamStore.setActiveTeamId(action.teamId);
+ console.debug('Setting active team', {teamId: action.teamId, userId: action.userId});
+ if (action.teamId !== undefined) {
+ TeamStore.setActiveTeamId(action.teamId);
+ } else {
+ TeamStore.setActiveTeamByUserId(action.userId);
+ }
TeamStore.emitChange();
} else if (action.type === ActionTypes.ADD_TEAM_REQUESTED) {
console.debug('Adding placeholder team');