-
Notifications
You must be signed in to change notification settings - Fork 152
/
index.js
66 lines (55 loc) · 3.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import AttachCommentToIssuePostMenuAction from 'components/post_menu_actions/attach_comment_to_issue';
import AttachCommentToIssueModal from 'components/modals/attach_comment_to_issue';
import CreateIssueModal from './components/modals/create_issue';
import CreateIssuePostMenuAction from './components/post_menu_action/create_issue';
import SidebarHeader from './components/sidebar_header';
import TeamSidebar from './components/team_sidebar';
import UserAttribute from './components/user_attribute';
import SidebarRight from './components/sidebar_right';
import LinkTooltip from './components/link_tooltip';
import Reducer from './reducers';
import Client from './client';
import {getConnected, setShowRHSAction} from './actions';
import {handleConnect, handleDisconnect, handleConfigurationUpdate, handleOpenCreateIssueModal, handleReconnect, handleRefresh} from './websocket';
import {getServerRoute} from './selectors';
import {id as pluginId} from './manifest';
let activityFunc;
let lastActivityTime = Number.MAX_SAFE_INTEGER;
const activityTimeout = 60 * 60 * 1000; // 1 hour
class PluginClass {
async initialize(registry, store) {
registry.registerReducer(Reducer);
Client.setServerRoute(getServerRoute(store.getState()));
await getConnected(true)(store.dispatch, store.getState);
registry.registerLeftSidebarHeaderComponent(SidebarHeader);
registry.registerBottomTeamSidebarComponent(TeamSidebar);
registry.registerPopoverUserAttributesComponent(UserAttribute);
registry.registerRootComponent(CreateIssueModal);
registry.registerPostDropdownMenuComponent(CreateIssuePostMenuAction);
registry.registerRootComponent(AttachCommentToIssueModal);
registry.registerPostDropdownMenuComponent(AttachCommentToIssuePostMenuAction);
registry.registerLinkTooltipComponent(LinkTooltip);
const {showRHSPlugin} = registry.registerRightHandSidebarComponent(SidebarRight, 'GitHub');
store.dispatch(setShowRHSAction(() => store.dispatch(showRHSPlugin)));
registry.registerWebSocketEventHandler(`custom_${pluginId}_connect`, handleConnect(store));
registry.registerWebSocketEventHandler(`custom_${pluginId}_disconnect`, handleDisconnect(store));
registry.registerWebSocketEventHandler(`custom_${pluginId}_config_update`, handleConfigurationUpdate(store));
registry.registerWebSocketEventHandler(`custom_${pluginId}_refresh`, handleRefresh(store));
registry.registerWebSocketEventHandler(`custom_${pluginId}_createIssue`, handleOpenCreateIssueModal(store));
registry.registerReconnectHandler(handleReconnect(store));
activityFunc = () => {
const now = new Date().getTime();
if (now - lastActivityTime > activityTimeout) {
handleReconnect(store, true)();
}
lastActivityTime = now;
};
document.addEventListener('click', activityFunc);
}
deinitialize() {
document.removeEventListener('click', activityFunc);
}
}
global.window.registerPlugin(pluginId, new PluginClass());