@inboxsdk/core 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/inboxsdk.js +7 -34
  2. package/inboxsdk.js.map +1 -1
  3. package/package.json +1 -1
  4. package/pageWorld.js +1 -1
  5. package/pageWorld.js.map +1 -1
  6. package/src/common/version.d.ts.map +1 -1
  7. package/src/common/version.js +3 -1
  8. package/src/injected-js/main.js +0 -9
  9. package/src/platform-implementation-js/dom-driver/gmail/views/gmail-app-sidebar-view/index.test.js +6 -2
  10. package/src/platform-implementation-js/dom-driver/gmail/views/gmail-app-sidebar-view/primary/index.js +4 -2
  11. package/src/platform-implementation-js/dom-driver/gmail/views/gmail-thread-sidebar-view.js +4 -2
  12. package/src/platform-implementation-js/dom-driver/gmail/views/gmail-thread-sidebar-view.test.js +6 -2
  13. package/src/platform-implementation-js/driver-common/sidebar/ContentPanelViewDriver.js +2 -2
  14. package/src/platform-implementation-js/driver-common/sidebar/constants.d.ts +9 -0
  15. package/src/platform-implementation-js/driver-common/sidebar/constants.d.ts.map +1 -0
  16. package/src/platform-implementation-js/driver-common/sidebar/constants.js +26 -0
  17. package/src/platform-implementation-js/lib/idMap.d.ts +7 -0
  18. package/src/platform-implementation-js/lib/idMap.d.ts.map +1 -1
  19. package/src/platform-implementation-js/lib/idMap.js +35 -0
  20. package/src/platform-implementation-js/platform-implementation.d.ts +0 -3
  21. package/src/platform-implementation-js/platform-implementation.js +1 -9
  22. package/src/injected-js/inbox/setupAjaxInterceptor.js +0 -211
  23. package/src/injected-js/inbox/setupClickAndGetNewIframeSrc.js +0 -67
  24. package/src/injected-js/inbox/setupComposeViewDraftIDFinder.js +0 -35
  25. package/src/injected-js/inbox/setupInboxFakeWindowResizeListener.js +0 -29
  26. package/src/platform-implementation-js/dom-driver/inbox/__mocks__/getSidebarClassnames.js +0 -13
  27. package/src/platform-implementation-js/dom-driver/inbox/addNavItem.js +0 -38
  28. package/src/platform-implementation-js/dom-driver/inbox/addRecipientRow.js +0 -55
  29. package/src/platform-implementation-js/dom-driver/inbox/createLink.js +0 -19
  30. package/src/platform-implementation-js/dom-driver/inbox/createLink.test.js +0 -27
  31. package/src/platform-implementation-js/dom-driver/inbox/detection/appToolbarLocation/parser.js +0 -43
  32. package/src/platform-implementation-js/dom-driver/inbox/detection/attachmentCard/parser.js +0 -34
  33. package/src/platform-implementation-js/dom-driver/inbox/detection/attachmentOverlay/parser.js +0 -53
  34. package/src/platform-implementation-js/dom-driver/inbox/detection/chatSidebar/parser.js +0 -31
  35. package/src/platform-implementation-js/dom-driver/inbox/detection/compose/parser.js +0 -103
  36. package/src/platform-implementation-js/dom-driver/inbox/detection/message/parser.js +0 -69
  37. package/src/platform-implementation-js/dom-driver/inbox/detection/nativeDrawer/parser.js +0 -32
  38. package/src/platform-implementation-js/dom-driver/inbox/detection/searchBar/parser.js +0 -28
  39. package/src/platform-implementation-js/dom-driver/inbox/detection/thread/parser.js +0 -49
  40. package/src/platform-implementation-js/dom-driver/inbox/detection/thread-row/parser.js +0 -100
  41. package/src/platform-implementation-js/dom-driver/inbox/getComposeViewDriverLiveSet.js +0 -99
  42. package/src/platform-implementation-js/dom-driver/inbox/getInboxMessageIdForInboxThreadId.js +0 -36
  43. package/src/platform-implementation-js/dom-driver/inbox/getSidebarClassnames.js +0 -114
  44. package/src/platform-implementation-js/dom-driver/inbox/getSidebarClassnames.test.js +0 -73
  45. package/src/platform-implementation-js/dom-driver/inbox/gotoView.js +0 -39
  46. package/src/platform-implementation-js/dom-driver/inbox/gotoView.test.js +0 -28
  47. package/src/platform-implementation-js/dom-driver/inbox/inbox-butter-bar-driver.js +0 -148
  48. package/src/platform-implementation-js/dom-driver/inbox/inbox-driver.js +0 -863
  49. package/src/platform-implementation-js/dom-driver/inbox/inbox-page-communicator.js +0 -62
  50. package/src/platform-implementation-js/dom-driver/inbox/inboxResponseProcessor.js +0 -12
  51. package/src/platform-implementation-js/dom-driver/inbox/inboxResponseProcessor.test.js +0 -18
  52. package/src/platform-implementation-js/dom-driver/inbox/makePageParserTree.js +0 -33
  53. package/src/platform-implementation-js/dom-driver/inbox/pageParserOptions.js +0 -265
  54. package/src/platform-implementation-js/dom-driver/inbox/registerSearchSuggestionsProvider.js +0 -301
  55. package/src/platform-implementation-js/dom-driver/inbox/setupCustomAutocompleteSelectionHandling.js +0 -183
  56. package/src/platform-implementation-js/dom-driver/inbox/setupRouteViewDriverStream.js +0 -64
  57. package/src/platform-implementation-js/dom-driver/inbox/setupRouteViewDriverStream.test.js +0 -72
  58. package/src/platform-implementation-js/dom-driver/inbox/views/InboxLabelView.js +0 -78
  59. package/src/platform-implementation-js/dom-driver/inbox/views/InboxMoleViewDriver.js +0 -296
  60. package/src/platform-implementation-js/dom-driver/inbox/views/InboxToolbarButtonView.js +0 -91
  61. package/src/platform-implementation-js/dom-driver/inbox/views/InboxToolbarView.js +0 -53
  62. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-app-sidebar-view.js +0 -271
  63. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-app-toolbar-button-view.js +0 -160
  64. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-app-toolbar-tooltip-view.js +0 -57
  65. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-attachment-card-view.js +0 -197
  66. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-attachment-overlay-view.js +0 -83
  67. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-chat-sidebar-view.js +0 -45
  68. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-compose-button-view.js +0 -116
  69. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-compose-view.js +0 -842
  70. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-custom-route-view.js +0 -75
  71. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-dropdown-view.js +0 -25
  72. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-dummy-route-view.js +0 -63
  73. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-message-view.js +0 -274
  74. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-modal-view.js +0 -112
  75. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-route-view.js +0 -96
  76. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-thread-row-view.js +0 -315
  77. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-thread-view.js +0 -218
  78. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-thread-view.test.js +0 -171
  79. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-tooltip-view.js +0 -127
  80. package/src/platform-implementation-js/dom-driver/inbox/views/inboxNavItemView.js +0 -311
  81. package/src/platform-implementation-js/dom-driver/inbox/waitForAnimationClickBlockerGone.js +0 -26
@@ -1,315 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _ud = require("ud");
9
- var _updateIcon = _interopRequireDefault(require("../../../driver-common/update-icon"));
10
- var _autoHtml = _interopRequireDefault(require("auto-html"));
11
- var _kefir = _interopRequireDefault(require("kefir"));
12
- var _kefirBus = _interopRequireDefault(require("kefir-bus"));
13
- var _kefirStopper = _interopRequireDefault(require("kefir-stopper"));
14
- var _kefirCast = _interopRequireDefault(require("kefir-cast"));
15
- var _bignumber = _interopRequireDefault(require("bignumber.js"));
16
- var _InboxLabelView = _interopRequireDefault(require("./InboxLabelView"));
17
- var _InboxToolbarButtonView = _interopRequireDefault(require("./InboxToolbarButtonView"));
18
- class InboxThreadRowView {
19
- _eventStream = (0, _kefirBus.default)();
20
- _isDestroyed = false;
21
- constructor(element, driver, parsed) {
22
- this._element = element;
23
- this._driver = driver;
24
- this._p = parsed;
25
- this._stopper = this._eventStream.ignoreValues().beforeEnd(() => null).toProperty();
26
- }
27
- getEventStream() {
28
- return this._eventStream;
29
- }
30
- getStopper() {
31
- return this._stopper;
32
- }
33
-
34
- // keeping this here for now since the rest of the system expects it.
35
- // in Gmail it's used to pass a ThreadRowView interface to addButton()
36
- // onClick callbacks, but not sure if it will be needed in the end.
37
- setUserView(userView) {
38
- this._userView = userView;
39
- }
40
- isSelected() {
41
- if (!this._p.elements.checkbox) {
42
- throw new Error('Did not find checkbox element');
43
- }
44
- return this._p.elements.checkbox.getAttribute('aria-checked') === 'true';
45
- }
46
- addToolbarButton(options) {
47
- const {
48
- toolbar
49
- } = this._p.elements;
50
- if (!toolbar) {
51
- throw new Error('could not find toolbar element');
52
- }
53
- toolbar.classList.add('inboxsdk__list_toolbar');
54
- const button = new _InboxToolbarButtonView.default({
55
- ...options,
56
- onClick: event => {
57
- if (event.dropdown) {
58
- toolbar.classList.add('inboxsdk__thread_row_force_toolbar_visible');
59
- event.dropdown.once('destroy', () => {
60
- toolbar.classList.remove('inboxsdk__thread_row_force_toolbar_visible');
61
- });
62
- }
63
- if (options.onClick) options.onClick(event);
64
- }
65
- }, this._driver.getAppId(), toolbar);
66
- this._stopper.takeUntilBy(button.getStopper()).onValue(() => {
67
- button.destroy();
68
- });
69
- return button;
70
- }
71
- addAttachmentIcon(options) {
72
- throw new Error('Not supported in Inbox');
73
- }
74
- addButton(options) {
75
- throw new Error('Not supported in Inbox');
76
- }
77
- addActionButton(options) {
78
- throw new Error('not yet implemented');
79
- }
80
- addImage(icon) {
81
- if (this._isDestroyed) {
82
- console.warn('addImage called on destroyed thread row');
83
- return;
84
- }
85
- const {
86
- labelParent
87
- } = this._p.elements;
88
- if (!labelParent) throw new Error('Could not find label parent element');
89
- const prop = (0, _kefirCast.default)(_kefir.default, icon).takeUntilBy(this._stopper).toProperty();
90
- let imageMod = null;
91
- prop.onValue(iconDescriptor => {
92
- if (!iconDescriptor) {
93
- if (imageMod) {
94
- imageMod.remove();
95
- imageMod = null;
96
- }
97
- } else {
98
- if (!imageMod) {
99
- imageMod = {
100
- iconSettings: {},
101
- iconWrapper: document.createElement('div'),
102
- remove() {
103
- this.iconWrapper.remove();
104
- }
105
- };
106
- imageMod.iconWrapper.className = 'inboxsdk__thread_row_icon_wrapper';
107
- }
108
- const {
109
- iconSettings,
110
- iconWrapper
111
- } = imageMod;
112
- (0, _updateIcon.default)(iconSettings, iconWrapper, false, iconDescriptor.imageClass, iconDescriptor.imageUrl);
113
- if (iconDescriptor.tooltip) {
114
- iconWrapper.setAttribute('title', iconDescriptor.tooltip);
115
- }
116
- if (labelParent !== iconWrapper.parentElement) {
117
- const threadLabels = labelParent.querySelectorAll('.inboxsdk__inbox_thread_row_label');
118
- const insertionPoint = threadLabels.length > 0 ? threadLabels[threadLabels.length - 1].nextElementSibling : labelParent.firstChild;
119
- labelParent.insertBefore(iconWrapper, insertionPoint);
120
- }
121
- }
122
- });
123
- this._stopper.onEnd(() => {
124
- if (imageMod) {
125
- imageMod.remove();
126
- }
127
- });
128
- }
129
- addLabel(label) {
130
- if (this._isDestroyed) {
131
- console.warn('addLabel called on destroyed thread row');
132
- return;
133
- }
134
- const labelParentDiv = this._p.elements.labelParent;
135
- if (!labelParentDiv) throw new Error('Could not find label parent element');
136
- const prop = (0, _kefirCast.default)(_kefir.default, label).takeUntilBy(this._stopper).toProperty();
137
- let labelMod = null;
138
- prop.onValue(labelDescriptor => {
139
- if (!labelDescriptor) {
140
- if (labelMod) {
141
- labelMod.remove();
142
- labelMod = null;
143
- }
144
- } else {
145
- if (!labelMod) {
146
- const inboxLabelView = new _InboxLabelView.default();
147
- const el = inboxLabelView.getElement();
148
- labelMod = {
149
- inboxLabelView,
150
- remove: el.remove.bind(el)
151
- };
152
- }
153
- labelMod.inboxLabelView.updateLabelDescriptor(labelDescriptor);
154
- if (labelParentDiv !== labelMod.inboxLabelView.getElement().parentElement) {
155
- const threadLabels = labelParentDiv.querySelectorAll('.inboxsdk__inbox_thread_row_label');
156
- const insertionPoint = threadLabels.length > 0 ? threadLabels[threadLabels.length - 1].nextElementSibling : labelParentDiv.firstChild;
157
- labelParentDiv.insertBefore(labelMod.inboxLabelView.getElement(), insertionPoint);
158
- }
159
- }
160
- });
161
- this._stopper.onEnd(() => {
162
- if (labelMod) {
163
- labelMod.remove();
164
- }
165
- });
166
- }
167
- getDateString() {
168
- throw new Error('Not supported in Inbox');
169
- }
170
- getSubject() {
171
- if (!this._p.elements.subject) {
172
- throw new Error('Failed to find subject');
173
- }
174
- return this._p.elements.subject.textContent;
175
- }
176
- getThreadID() {
177
- throw new Error('Not supported in Inbox. Please use getThreadIDAsync() instead');
178
- }
179
- async getThreadIDAsync() {
180
- const {
181
- inboxThreadId
182
- } = this._p.attributes;
183
- if (!inboxThreadId) {
184
- throw new Error('Failed to find thread id');
185
- }
186
- if (/^thread-a:/.test(inboxThreadId)) {
187
- this._driver.trackThreadRowIdCall(false, inboxThreadId);
188
- // Get the inbox message id of any message in the thread, convert it to
189
- // a gmail message id, and then use that id in a request
190
- // to a gmail endpoint to get the id of the thread that message is in.
191
- const inboxMessageId = await this._driver.getInboxMessageIdForInboxThreadId(inboxThreadId);
192
- const gmailMessageId = await this._driver.getGmailMessageIdForSyncMessageId(inboxMessageId);
193
- return await this._driver.getThreadIdFromMessageId(gmailMessageId);
194
- } else {
195
- this._driver.trackThreadRowIdCall(true, inboxThreadId);
196
- const m = /\d+$/.exec(inboxThreadId);
197
- if (!m) throw new Error('Should not happen');
198
- return new _bignumber.default(m[0]).toString(16);
199
- }
200
- }
201
- async getDraftID() {
202
- const {
203
- isOnlyDraft,
204
- inboxThreadId
205
- } = this._p.attributes;
206
- if (isOnlyDraft && inboxThreadId) {
207
- const m = /\d+$/.exec(inboxThreadId);
208
- if (!m) throw new Error('Should not happen');
209
- return m[0];
210
- } else {
211
- return null;
212
- }
213
- }
214
- getVisibleDraftCount() {
215
- const {
216
- visibleDraftCount
217
- } = this._p.attributes;
218
- if (typeof visibleDraftCount !== 'number') throw new Error('Failed to find visible draft count');
219
- return visibleDraftCount;
220
- }
221
- getVisibleMessageCount() {
222
- const {
223
- visibleMessageCount
224
- } = this._p.attributes;
225
- if (typeof visibleMessageCount !== 'number') throw new Error('Failed to find visible message count');
226
- return visibleMessageCount;
227
- }
228
- getContacts() {
229
- const {
230
- contacts
231
- } = this._p.attributes;
232
- if (!Array.isArray(contacts)) throw new Error('Failed to find contacts');
233
- return contacts;
234
- }
235
- replaceDate(options) {
236
- throw new Error('Not supported in Inbox');
237
- }
238
- replaceDraftLabel(label) {
239
- if (this._isDestroyed) {
240
- console.warn('addLabel called on destroyed thread row');
241
- return;
242
- }
243
-
244
- // We don't want to replace draft labels on messages without drafts
245
- if (this._p.attributes.visibleDraftCount === 0) return;
246
- const {
247
- recipientParent,
248
- messageCountParent
249
- } = this._p.elements;
250
- if (!recipientParent || !messageCountParent) throw new Error('Could not find necessary parent elements');
251
- const prop = (0, _kefirCast.default)(_kefir.default, label).takeUntilBy(this._stopper).toProperty();
252
- let labelMod = null;
253
- prop.onValue(labelDescriptor => {
254
- if (!labelDescriptor) {
255
- if (labelMod) {
256
- labelMod.remove();
257
- labelMod = null;
258
- }
259
- } else {
260
- const {
261
- text,
262
- count
263
- } = labelDescriptor;
264
- if (!labelMod) {
265
- labelMod = {
266
- countEl: document.createElement('span'),
267
- draftEl: document.createElement('span'),
268
- remove() {
269
- this.countEl.remove();
270
- this.draftEl.remove();
271
- recipientParent.classList.remove('inboxsdk__thread_row_draft_label_replaced');
272
- messageCountParent.classList.remove('inboxsdk__thread_row_draft_count_replaced');
273
- if (!messageCountParent.querySelector('span:not(.inboxsdk__thread_row_custom_draft_count)')) {
274
- messageCountParent.style.display = 'none';
275
- }
276
- }
277
- };
278
- labelMod.draftEl.className = 'inboxsdk__thread_row_custom_draft_label';
279
- labelMod.countEl.className = 'inboxsdk__thread_row_custom_draft_count';
280
- recipientParent.classList.add('inboxsdk__thread_row_draft_label_replaced');
281
- }
282
- labelMod.draftEl.textContent = text;
283
- if (recipientParent !== labelMod.draftEl.parentElement) {
284
- recipientParent.appendChild(labelMod.draftEl);
285
- }
286
- const hasExistingCountEl = messageCountParent.querySelector('span:not(.inboxsdk__thread_row_custom_draft_count)');
287
- if (count && count > 1) {
288
- messageCountParent.classList.add('inboxsdk__thread_row_draft_count_replaced');
289
- messageCountParent.style.display = 'inline';
290
- labelMod.countEl.innerHTML = hasExistingCountEl ? (0, _autoHtml.default)`(${count})` : (0, _autoHtml.default)` (${count})`;
291
- if (messageCountParent !== labelMod.countEl.parentElement) {
292
- messageCountParent.appendChild(labelMod.countEl);
293
- }
294
- } else {
295
- messageCountParent.classList.remove('inboxsdk__thread_row_draft_count_replaced');
296
- if (!hasExistingCountEl) {
297
- messageCountParent.style.display = 'none';
298
- }
299
- labelMod.countEl.remove();
300
- }
301
- }
302
- this._stopper.onEnd(() => {
303
- if (labelMod) {
304
- labelMod.remove();
305
- }
306
- });
307
- });
308
- }
309
- destroy() {
310
- this._isDestroyed = true;
311
- this._eventStream.end();
312
- }
313
- }
314
- var _default = (0, _ud.defn)(module, InboxThreadRowView);
315
- exports.default = _default;
@@ -1,218 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _find = _interopRequireDefault(require("lodash/find"));
9
- var _ud = require("ud");
10
- var _autoHtml = _interopRequireDefault(require("auto-html"));
11
- var _kefir = _interopRequireDefault(require("kefir"));
12
- var _kefirBus = _interopRequireDefault(require("kefir-bus"));
13
- var _kefirStopper = _interopRequireDefault(require("kefir-stopper"));
14
- var _bignumber = _interopRequireDefault(require("bignumber.js"));
15
- var _delayAsap = _interopRequireDefault(require("../../../lib/delay-asap"));
16
- var _idMap = _interopRequireDefault(require("../../../lib/idMap"));
17
- var _querySelectorOrFail = _interopRequireDefault(require("../../../lib/dom/querySelectorOrFail"));
18
- var _makeMutationObserverChunkedStream = _interopRequireDefault(require("../../../lib/dom/make-mutation-observer-chunked-stream"));
19
- var _SimpleElementView = _interopRequireDefault(require("../../../views/SimpleElementView"));
20
- var _customMessageView = _interopRequireDefault(require("../../../views/conversations/custom-message-view"));
21
- var _parser = _interopRequireDefault(require("../detection/thread/parser"));
22
- class InboxThreadView {
23
- _eventStream = (0, _kefirBus.default)();
24
- _messageViews = [];
25
- _receivedMessageView = (0, _kefirStopper.default)();
26
- _sidebarPanels = new Set();
27
- constructor(element, driver, parsed) {
28
- this._element = element;
29
- this._driver = driver;
30
- this._p = parsed;
31
- this._stopper = this._eventStream.ignoreValues().beforeEnd(() => null).toProperty();
32
- this._driver.getThreadViewElementsMap().set(this._element, this);
33
- this._ready = this._receivedMessageView.flatMap(() => (0, _delayAsap.default)()).onValue(() => {
34
- this._p = (0, _parser.default)(this._element);
35
- }).toProperty();
36
- if (this.isLoadingStub()) {
37
- (0, _makeMutationObserverChunkedStream.default)(this._element, {
38
- attributes: true,
39
- attributeFilter: ['aria-busy']
40
- }).takeUntilBy(this._stopper).onValue(() => {
41
- if (!this.isLoadingStub()) {
42
- this.destroy();
43
- }
44
- });
45
- }
46
- }
47
- isLoadingStub() {
48
- return this._element.getAttribute('aria-busy') === 'true';
49
- }
50
- getEventStream() {
51
- return this._eventStream;
52
- }
53
- getStopper() {
54
- return this._stopper;
55
- }
56
- addMessageViewDriver(messageView) {
57
- this._messageViews.push(messageView);
58
- this._eventStream.plug(messageView.getEventStream().filter(event => event.eventName === 'contactHover'));
59
- messageView.getStopper().takeUntilBy(this._stopper).onValue(() => {
60
- this._messageViews = this._messageViews.filter(m => m !== messageView);
61
- });
62
- this._receivedMessageView.destroy();
63
- }
64
- getMessageViewDrivers() {
65
- return this._messageViews;
66
- }
67
- getToolbarElement() {
68
- if (!this._p.elements.toolbar) {
69
- throw new Error('Failed to find toolbar');
70
- }
71
- return this._p.elements.toolbar;
72
- }
73
- getSubject() {
74
- if (!this._p.elements.heading) {
75
- throw new Error('Failed to find subject');
76
- }
77
- return this._p.elements.heading.textContent;
78
- }
79
- getThreadID() {
80
- const {
81
- inboxThreadId
82
- } = this._p.attributes;
83
- if (!inboxThreadId) {
84
- throw new Error('Failed to find thread id');
85
- }
86
- if (/^msg-a:/.test(inboxThreadId)) {
87
- console.warn('ThreadView.getThreadID() returned an incorrect thread ID. This method will be deprecated soon. Use getThreadIDAsync() instead which does not have this problem.');
88
- }
89
- const m = /\d+$/.exec(inboxThreadId);
90
- if (!m) throw new Error('Should not happen');
91
- return new _bignumber.default(m[0]).toString(16);
92
- }
93
- async getThreadIDAsync() {
94
- const {
95
- inboxThreadId
96
- } = this._p.attributes;
97
- if (!inboxThreadId) {
98
- throw new Error('Failed to find message id');
99
- }
100
- if (/^thread-a:/.test(inboxThreadId)) {
101
- // Get the id of any message in the thread, and then use that id in a request
102
- // to a gmail endpoint to get the id of the thread that message is in.
103
- const firstMessage = this._messageViews[0];
104
- if (!firstMessage) throw new Error('Should not happen');
105
- const messageId = await firstMessage.getMessageIDAsync();
106
- return await this._driver.getThreadIdFromMessageId(messageId);
107
- } else {
108
- const m = /\d+$/.exec(inboxThreadId);
109
- if (!m) throw new Error('Should not happen');
110
- return new _bignumber.default(m[0]).toString(16);
111
- }
112
- }
113
- registerHiddenCustomMessageNoticeProvider(provider) {
114
- throw new Error('not supported');
115
- }
116
- addCustomMessage(descriptorStream) {
117
- throw new Error('not supported');
118
- }
119
- addSidebarContentPanel(descriptor) {
120
- const panel = this._driver.getAppSidebarView().addSidebarContentPanel(descriptor);
121
- this._sidebarPanels.add(panel);
122
- panel.getStopper().onValue(() => {
123
- this._sidebarPanels.delete(panel);
124
- });
125
- this._stopper.takeUntilBy(panel.getStopper()).onValue(() => {
126
- panel.remove();
127
- });
128
- descriptor.takeUntilBy(this._stopper).takeUntilBy(panel.getStopper()).take(1).onValue(descriptor => {
129
- const {
130
- stickyHeading
131
- } = this._p.elements;
132
- if (!stickyHeading) return;
133
- let iconArea = stickyHeading.querySelector('.' + (0, _idMap.default)('sidebar_iconArea'));
134
- if (!iconArea) {
135
- const _iconArea = iconArea = document.createElement('div');
136
- iconArea.className = (0, _idMap.default)('sidebar_iconArea');
137
- this._driver.getAppSidebarView().getOpenOrOpeningStream().takeUntilBy(this._stopper).onValue(open => {
138
- _iconArea.style.display = open ? 'none' : '';
139
- });
140
- stickyHeading.appendChild(iconArea);
141
- }
142
- const appName = descriptor.appName || this._driver.getOpts().appName || descriptor.title;
143
- const appIconUrl = descriptor.appIconUrl || this._driver.getOpts().appIconUrl || descriptor.iconUrl;
144
-
145
- // If there's an existing button for the app, then just increment its
146
- // data-count attribute instead of adding a new button.
147
- const existingButtonContainer = (0, _find.default)(iconArea.querySelectorAll('.' + (0, _idMap.default)('sidebar_button_container')), el => {
148
- const button = el.querySelector('button');
149
- if (!button || button.title !== appName) return false;
150
- const img = button.querySelector('img');
151
- if (!img || img.src !== appIconUrl) return false;
152
- return true;
153
- });
154
- let container;
155
- if (existingButtonContainer) {
156
- const currentCount = Number(existingButtonContainer.getAttribute('data-count')) || 1;
157
- existingButtonContainer.setAttribute('data-count', currentCount + 1);
158
- container = existingButtonContainer;
159
- } else {
160
- container = document.createElement('div');
161
- container.className = (0, _idMap.default)('sidebar_button_container');
162
- container.innerHTML = (0, _autoHtml.default)`
163
- <button class="inboxsdk__button_icon" type="button" title="${appName}">
164
- <img class="inboxsdk__button_iconImg" src="${appIconUrl}">
165
- </button>
166
- `;
167
- (0, _querySelectorOrFail.default)(container, 'button').addEventListener('click', event => {
168
- event.stopPropagation();
169
- this._driver.getAppSidebarView().open();
170
- panel.scrollIntoView();
171
- }, true);
172
- iconArea.appendChild(container);
173
- }
174
- panel.getStopper().onValue(() => {
175
- const currentCount = Number(container.getAttribute('data-count'));
176
- if (currentCount <= 1) {
177
- container.remove();
178
- } else if (currentCount === 2) {
179
- container.removeAttribute('data-count');
180
- } else {
181
- container.setAttribute('data-count', String(currentCount - 1));
182
- }
183
- });
184
- });
185
- return panel;
186
- }
187
- removePanels() {
188
- this._sidebarPanels.forEach(panel => {
189
- panel.remove();
190
- });
191
- }
192
- addNoticeBar() {
193
- const el = document.createElement('div');
194
- el.className = (0, _idMap.default)('thread_noticeBar');
195
- const {
196
- heading
197
- } = this._p.elements;
198
- if (!heading) {
199
- throw new Error('Failed to find subject');
200
- }
201
- heading.insertAdjacentElement('afterend', el);
202
- const view = new _SimpleElementView.default(el);
203
- this._stopper.takeUntilBy(_kefir.default.fromEvents(view, 'destroy')).onValue(() => view.destroy());
204
- return view;
205
- }
206
- addLabel() {
207
- throw new Error('not supported');
208
- }
209
- getReadyStream() {
210
- return this._ready;
211
- }
212
- destroy() {
213
- this._driver.getThreadViewElementsMap().delete(this._element);
214
- this._eventStream.end();
215
- }
216
- }
217
- var _default = (0, _ud.defn)(module, InboxThreadView);
218
- exports.default = _default;