@knocklabs/client 0.8.3 → 0.8.5
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.
- package/dist/cjs/clients/feed/feed.js +376 -92
- package/dist/cjs/clients/feed/feed.js.map +1 -1
- package/dist/cjs/clients/feed/store.js +23 -16
- package/dist/cjs/clients/feed/store.js.map +1 -1
- package/dist/esm/clients/feed/feed.js +247 -43
- package/dist/esm/clients/feed/feed.js.map +1 -1
- package/dist/esm/clients/feed/store.js +20 -15
- package/dist/esm/clients/feed/store.js.map +1 -1
- package/dist/types/clients/feed/feed.d.ts +5 -0
- package/dist/types/clients/feed/feed.d.ts.map +1 -1
- package/dist/types/clients/feed/interfaces.d.ts +1 -0
- package/dist/types/clients/feed/interfaces.d.ts.map +1 -1
- package/dist/types/clients/feed/store.d.ts.map +1 -1
- package/dist/types/clients/feed/types.d.ts +2 -1
- package/dist/types/clients/feed/types.d.ts.map +1 -1
- package/dist/types/clients/preferences/interfaces.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -59,10 +59,10 @@ var Feed = /*#__PURE__*/function () {
|
|
|
59
59
|
this.channel = this.apiClient.socket.channel("feeds:".concat(this.userFeedId), this.defaultOptions);
|
|
60
60
|
this.channel.on("new-message", function (resp) {
|
|
61
61
|
return _this.onNewMessageReceived(resp);
|
|
62
|
-
}); // Attempt to bind to listen to other events from this feed in different tabs
|
|
63
|
-
//
|
|
62
|
+
}); // Attempt to bind to listen to other events from this feed in different tabs
|
|
63
|
+
// Note: here we ensure `self` is available (it's not in server rendered envs)
|
|
64
64
|
|
|
65
|
-
this.broadcastChannel = "BroadcastChannel" in self ? new BroadcastChannel("knock:feed:".concat(this.userFeedId)) : null;
|
|
65
|
+
this.broadcastChannel = self && "BroadcastChannel" in self ? new BroadcastChannel("knock:feed:".concat(this.userFeedId)) : null;
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* Cleans up a feed instance by destroying the store and disconnecting
|
|
@@ -113,6 +113,9 @@ var Feed = /*#__PURE__*/function () {
|
|
|
113
113
|
case "items:unseen":
|
|
114
114
|
case "items:read":
|
|
115
115
|
case "items:unread":
|
|
116
|
+
case "items:all_read":
|
|
117
|
+
case "items:all_seen":
|
|
118
|
+
case "items:all_archived":
|
|
116
119
|
// When items are updated in any other tab, simply refetch to get the latest state
|
|
117
120
|
// to make sure that the state gets updated accordingly. In the future here we could
|
|
118
121
|
// maybe do this optimistically without the fetch.
|
|
@@ -172,24 +175,104 @@ var Feed = /*#__PURE__*/function () {
|
|
|
172
175
|
return markAsSeen;
|
|
173
176
|
}()
|
|
174
177
|
}, {
|
|
175
|
-
key: "
|
|
178
|
+
key: "markAllAsSeen",
|
|
176
179
|
value: function () {
|
|
177
|
-
var
|
|
180
|
+
var _markAllAsSeen = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
181
|
+
var _this$store, getState, setState, _getState, metadata, items, isViewingOnlyUnseen, attrs, itemIds, result;
|
|
182
|
+
|
|
178
183
|
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
179
184
|
while (1) {
|
|
180
185
|
switch (_context2.prev = _context2.next) {
|
|
186
|
+
case 0:
|
|
187
|
+
// To mark all of the messages as seen we:
|
|
188
|
+
// 1. Optimistically update *everything* we have in the store
|
|
189
|
+
// 2. We decrement the `unseen_count` to zero optimistically
|
|
190
|
+
// 3. We issue the API call to the endpoint
|
|
191
|
+
//
|
|
192
|
+
// Note: there is the potential for a race condition here because the bulk
|
|
193
|
+
// update is an async method, so if a new message comes in during this window before
|
|
194
|
+
// the update has been processed we'll effectively reset the `unseen_count` to be what it was.
|
|
195
|
+
//
|
|
196
|
+
// Note: here we optimistically handle the case whereby the feed is scoped to show only `unseen`
|
|
197
|
+
// items by removing everything from view.
|
|
198
|
+
_this$store = this.store, getState = _this$store.getState, setState = _this$store.setState;
|
|
199
|
+
_getState = getState(), metadata = _getState.metadata, items = _getState.items;
|
|
200
|
+
isViewingOnlyUnseen = this.defaultOptions.status === "unseen"; // If we're looking at the unseen view, then we want to remove all of the items optimistically
|
|
201
|
+
// from the store given that nothing should be visible. We do this by resetting the store state
|
|
202
|
+
// and setting the current metadata counts to 0
|
|
203
|
+
|
|
204
|
+
if (isViewingOnlyUnseen) {
|
|
205
|
+
setState(function (store) {
|
|
206
|
+
return store.resetStore(_objectSpread(_objectSpread({}, metadata), {}, {
|
|
207
|
+
total_count: 0,
|
|
208
|
+
unseen_count: 0
|
|
209
|
+
}));
|
|
210
|
+
});
|
|
211
|
+
} else {
|
|
212
|
+
// Otherwise we want to update the metadata and mark all of the items in the store as seen
|
|
213
|
+
setState(function (store) {
|
|
214
|
+
return store.setMetadata(_objectSpread(_objectSpread({}, metadata), {}, {
|
|
215
|
+
unseen_count: 0
|
|
216
|
+
}));
|
|
217
|
+
});
|
|
218
|
+
attrs = {
|
|
219
|
+
seen_at: new Date().toISOString()
|
|
220
|
+
};
|
|
221
|
+
itemIds = items.map(function (item) {
|
|
222
|
+
return item.id;
|
|
223
|
+
});
|
|
224
|
+
setState(function (store) {
|
|
225
|
+
return store.setItemAttrs(itemIds, attrs);
|
|
226
|
+
});
|
|
227
|
+
} // Issue the API request to the bulk status change API
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
_context2.next = 6;
|
|
231
|
+
return this.makeBulkStatusUpdate("seen");
|
|
232
|
+
|
|
233
|
+
case 6:
|
|
234
|
+
result = _context2.sent;
|
|
235
|
+
this.broadcaster.emit("items:all_seen", {
|
|
236
|
+
items: items
|
|
237
|
+
});
|
|
238
|
+
this.broadcastOverChannel("items:all_seen", {
|
|
239
|
+
items: items
|
|
240
|
+
});
|
|
241
|
+
return _context2.abrupt("return", result);
|
|
242
|
+
|
|
243
|
+
case 10:
|
|
244
|
+
case "end":
|
|
245
|
+
return _context2.stop();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}, _callee2, this);
|
|
249
|
+
}));
|
|
250
|
+
|
|
251
|
+
function markAllAsSeen() {
|
|
252
|
+
return _markAllAsSeen.apply(this, arguments);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return markAllAsSeen;
|
|
256
|
+
}()
|
|
257
|
+
}, {
|
|
258
|
+
key: "markAsUnseen",
|
|
259
|
+
value: function () {
|
|
260
|
+
var _markAsUnseen = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(itemOrItems) {
|
|
261
|
+
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
262
|
+
while (1) {
|
|
263
|
+
switch (_context3.prev = _context3.next) {
|
|
181
264
|
case 0:
|
|
182
265
|
this.optimisticallyPerformStatusUpdate(itemOrItems, "unseen", {
|
|
183
266
|
seen_at: null
|
|
184
267
|
}, "unseen_count");
|
|
185
|
-
return
|
|
268
|
+
return _context3.abrupt("return", this.makeStatusUpdate(itemOrItems, "unseen"));
|
|
186
269
|
|
|
187
270
|
case 2:
|
|
188
271
|
case "end":
|
|
189
|
-
return
|
|
272
|
+
return _context3.stop();
|
|
190
273
|
}
|
|
191
274
|
}
|
|
192
|
-
},
|
|
275
|
+
}, _callee3, this);
|
|
193
276
|
}));
|
|
194
277
|
|
|
195
278
|
function markAsUnseen(_x2) {
|
|
@@ -201,24 +284,24 @@ var Feed = /*#__PURE__*/function () {
|
|
|
201
284
|
}, {
|
|
202
285
|
key: "markAsRead",
|
|
203
286
|
value: function () {
|
|
204
|
-
var _markAsRead = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
287
|
+
var _markAsRead = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(itemOrItems) {
|
|
205
288
|
var now;
|
|
206
|
-
return _regenerator["default"].wrap(function
|
|
289
|
+
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
207
290
|
while (1) {
|
|
208
|
-
switch (
|
|
291
|
+
switch (_context4.prev = _context4.next) {
|
|
209
292
|
case 0:
|
|
210
293
|
now = new Date().toISOString();
|
|
211
294
|
this.optimisticallyPerformStatusUpdate(itemOrItems, "read", {
|
|
212
295
|
read_at: now
|
|
213
296
|
}, "unread_count");
|
|
214
|
-
return
|
|
297
|
+
return _context4.abrupt("return", this.makeStatusUpdate(itemOrItems, "read"));
|
|
215
298
|
|
|
216
299
|
case 3:
|
|
217
300
|
case "end":
|
|
218
|
-
return
|
|
301
|
+
return _context4.stop();
|
|
219
302
|
}
|
|
220
303
|
}
|
|
221
|
-
},
|
|
304
|
+
}, _callee4, this);
|
|
222
305
|
}));
|
|
223
306
|
|
|
224
307
|
function markAsRead(_x3) {
|
|
@@ -227,25 +310,105 @@ var Feed = /*#__PURE__*/function () {
|
|
|
227
310
|
|
|
228
311
|
return markAsRead;
|
|
229
312
|
}()
|
|
313
|
+
}, {
|
|
314
|
+
key: "markAllAsRead",
|
|
315
|
+
value: function () {
|
|
316
|
+
var _markAllAsRead = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5() {
|
|
317
|
+
var _this$store2, getState, setState, _getState2, metadata, items, isViewingOnlyUnread, attrs, itemIds, result;
|
|
318
|
+
|
|
319
|
+
return _regenerator["default"].wrap(function _callee5$(_context5) {
|
|
320
|
+
while (1) {
|
|
321
|
+
switch (_context5.prev = _context5.next) {
|
|
322
|
+
case 0:
|
|
323
|
+
// To mark all of the messages as read we:
|
|
324
|
+
// 1. Optimistically update *everything* we have in the store
|
|
325
|
+
// 2. We decrement the `unread_count` to zero optimistically
|
|
326
|
+
// 3. We issue the API call to the endpoint
|
|
327
|
+
//
|
|
328
|
+
// Note: there is the potential for a race condition here because the bulk
|
|
329
|
+
// update is an async method, so if a new message comes in during this window before
|
|
330
|
+
// the update has been processed we'll effectively reset the `unread_count` to be what it was.
|
|
331
|
+
//
|
|
332
|
+
// Note: here we optimistically handle the case whereby the feed is scoped to show only `unread`
|
|
333
|
+
// items by removing everything from view.
|
|
334
|
+
_this$store2 = this.store, getState = _this$store2.getState, setState = _this$store2.setState;
|
|
335
|
+
_getState2 = getState(), metadata = _getState2.metadata, items = _getState2.items;
|
|
336
|
+
isViewingOnlyUnread = this.defaultOptions.status === "unread"; // If we're looking at the unread view, then we want to remove all of the items optimistically
|
|
337
|
+
// from the store given that nothing should be visible. We do this by resetting the store state
|
|
338
|
+
// and setting the current metadata counts to 0
|
|
339
|
+
|
|
340
|
+
if (isViewingOnlyUnread) {
|
|
341
|
+
setState(function (store) {
|
|
342
|
+
return store.resetStore(_objectSpread(_objectSpread({}, metadata), {}, {
|
|
343
|
+
total_count: 0,
|
|
344
|
+
unread_count: 0
|
|
345
|
+
}));
|
|
346
|
+
});
|
|
347
|
+
} else {
|
|
348
|
+
// Otherwise we want to update the metadata and mark all of the items in the store as seen
|
|
349
|
+
setState(function (store) {
|
|
350
|
+
return store.setMetadata(_objectSpread(_objectSpread({}, metadata), {}, {
|
|
351
|
+
unread_count: 0
|
|
352
|
+
}));
|
|
353
|
+
});
|
|
354
|
+
attrs = {
|
|
355
|
+
read_at: new Date().toISOString()
|
|
356
|
+
};
|
|
357
|
+
itemIds = items.map(function (item) {
|
|
358
|
+
return item.id;
|
|
359
|
+
});
|
|
360
|
+
setState(function (store) {
|
|
361
|
+
return store.setItemAttrs(itemIds, attrs);
|
|
362
|
+
});
|
|
363
|
+
} // Issue the API request to the bulk status change API
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
_context5.next = 6;
|
|
367
|
+
return this.makeBulkStatusUpdate("read");
|
|
368
|
+
|
|
369
|
+
case 6:
|
|
370
|
+
result = _context5.sent;
|
|
371
|
+
this.broadcaster.emit("items:all_read", {
|
|
372
|
+
items: items
|
|
373
|
+
});
|
|
374
|
+
this.broadcastOverChannel("items:all_read", {
|
|
375
|
+
items: items
|
|
376
|
+
});
|
|
377
|
+
return _context5.abrupt("return", result);
|
|
378
|
+
|
|
379
|
+
case 10:
|
|
380
|
+
case "end":
|
|
381
|
+
return _context5.stop();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}, _callee5, this);
|
|
385
|
+
}));
|
|
386
|
+
|
|
387
|
+
function markAllAsRead() {
|
|
388
|
+
return _markAllAsRead.apply(this, arguments);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return markAllAsRead;
|
|
392
|
+
}()
|
|
230
393
|
}, {
|
|
231
394
|
key: "markAsUnread",
|
|
232
395
|
value: function () {
|
|
233
|
-
var _markAsUnread = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
234
|
-
return _regenerator["default"].wrap(function
|
|
396
|
+
var _markAsUnread = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(itemOrItems) {
|
|
397
|
+
return _regenerator["default"].wrap(function _callee6$(_context6) {
|
|
235
398
|
while (1) {
|
|
236
|
-
switch (
|
|
399
|
+
switch (_context6.prev = _context6.next) {
|
|
237
400
|
case 0:
|
|
238
401
|
this.optimisticallyPerformStatusUpdate(itemOrItems, "unread", {
|
|
239
402
|
read_at: null
|
|
240
403
|
}, "unread_count");
|
|
241
|
-
return
|
|
404
|
+
return _context6.abrupt("return", this.makeStatusUpdate(itemOrItems, "unread"));
|
|
242
405
|
|
|
243
406
|
case 2:
|
|
244
407
|
case "end":
|
|
245
|
-
return
|
|
408
|
+
return _context6.stop();
|
|
246
409
|
}
|
|
247
410
|
}
|
|
248
|
-
},
|
|
411
|
+
}, _callee6, this);
|
|
249
412
|
}));
|
|
250
413
|
|
|
251
414
|
function markAsUnread(_x4) {
|
|
@@ -264,14 +427,14 @@ var Feed = /*#__PURE__*/function () {
|
|
|
264
427
|
}, {
|
|
265
428
|
key: "markAsArchived",
|
|
266
429
|
value: function () {
|
|
267
|
-
var _markAsArchived = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
268
|
-
var _this$
|
|
430
|
+
var _markAsArchived = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(itemOrItems) {
|
|
431
|
+
var _this$store3, getState, setState, state, shouldOptimisticallyRemoveItems, normalizedItems, itemIds, unseenCount, unreadCount, updatedMetadata, entriesToSet;
|
|
269
432
|
|
|
270
|
-
return _regenerator["default"].wrap(function
|
|
433
|
+
return _regenerator["default"].wrap(function _callee7$(_context7) {
|
|
271
434
|
while (1) {
|
|
272
|
-
switch (
|
|
435
|
+
switch (_context7.prev = _context7.next) {
|
|
273
436
|
case 0:
|
|
274
|
-
_this$
|
|
437
|
+
_this$store3 = this.store, getState = _this$store3.getState, setState = _this$store3.setState;
|
|
275
438
|
state = getState();
|
|
276
439
|
shouldOptimisticallyRemoveItems = this.defaultOptions.archived === "exclude";
|
|
277
440
|
normalizedItems = Array.isArray(itemOrItems) ? itemOrItems : [itemOrItems];
|
|
@@ -330,14 +493,14 @@ var Feed = /*#__PURE__*/function () {
|
|
|
330
493
|
});
|
|
331
494
|
}
|
|
332
495
|
|
|
333
|
-
return
|
|
496
|
+
return _context7.abrupt("return", this.makeStatusUpdate(itemOrItems, "archived"));
|
|
334
497
|
|
|
335
498
|
case 7:
|
|
336
499
|
case "end":
|
|
337
|
-
return
|
|
500
|
+
return _context7.stop();
|
|
338
501
|
}
|
|
339
502
|
}
|
|
340
|
-
},
|
|
503
|
+
}, _callee7, this);
|
|
341
504
|
}));
|
|
342
505
|
|
|
343
506
|
function markAsArchived(_x5) {
|
|
@@ -346,25 +509,89 @@ var Feed = /*#__PURE__*/function () {
|
|
|
346
509
|
|
|
347
510
|
return markAsArchived;
|
|
348
511
|
}()
|
|
512
|
+
}, {
|
|
513
|
+
key: "markAllAsArchived",
|
|
514
|
+
value: function () {
|
|
515
|
+
var _markAllAsArchived = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8() {
|
|
516
|
+
var _this$store4, setState, getState, _getState3, items, shouldOptimisticallyRemoveItems, result;
|
|
517
|
+
|
|
518
|
+
return _regenerator["default"].wrap(function _callee8$(_context8) {
|
|
519
|
+
while (1) {
|
|
520
|
+
switch (_context8.prev = _context8.next) {
|
|
521
|
+
case 0:
|
|
522
|
+
// Note: there is the potential for a race condition here because the bulk
|
|
523
|
+
// update is an async method, so if a new message comes in during this window before
|
|
524
|
+
// the update has been processed we'll effectively reset the `unseen_count` to be what it was.
|
|
525
|
+
_this$store4 = this.store, setState = _this$store4.setState, getState = _this$store4.getState;
|
|
526
|
+
_getState3 = getState(), items = _getState3.items; // Here if we're looking at a feed that excludes all of the archived items by default then we
|
|
527
|
+
// will want to optimistically remove all of the items from the feed as they are now all excluded
|
|
528
|
+
|
|
529
|
+
shouldOptimisticallyRemoveItems = this.defaultOptions.archived === "exclude";
|
|
530
|
+
|
|
531
|
+
if (shouldOptimisticallyRemoveItems) {
|
|
532
|
+
// Reset the store to clear out all of items and reset the badge count
|
|
533
|
+
setState(function (store) {
|
|
534
|
+
return store.resetStore();
|
|
535
|
+
});
|
|
536
|
+
} else {
|
|
537
|
+
// Mark all the entries being updated as archived either way so the state is correct
|
|
538
|
+
setState(function (store) {
|
|
539
|
+
var itemIds = items.map(function (i) {
|
|
540
|
+
return i.id;
|
|
541
|
+
});
|
|
542
|
+
store.setItemAttrs(itemIds, {
|
|
543
|
+
archived_at: new Date().toISOString()
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
} // Issue the API request to the bulk status change API
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
_context8.next = 6;
|
|
550
|
+
return this.makeBulkStatusUpdate("archive");
|
|
551
|
+
|
|
552
|
+
case 6:
|
|
553
|
+
result = _context8.sent;
|
|
554
|
+
this.broadcaster.emit("items:all_archived", {
|
|
555
|
+
items: items
|
|
556
|
+
});
|
|
557
|
+
this.broadcastOverChannel("items:all_archived", {
|
|
558
|
+
items: items
|
|
559
|
+
});
|
|
560
|
+
return _context8.abrupt("return", result);
|
|
561
|
+
|
|
562
|
+
case 10:
|
|
563
|
+
case "end":
|
|
564
|
+
return _context8.stop();
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}, _callee8, this);
|
|
568
|
+
}));
|
|
569
|
+
|
|
570
|
+
function markAllAsArchived() {
|
|
571
|
+
return _markAllAsArchived.apply(this, arguments);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
return markAllAsArchived;
|
|
575
|
+
}()
|
|
349
576
|
}, {
|
|
350
577
|
key: "markAsUnarchived",
|
|
351
578
|
value: function () {
|
|
352
|
-
var _markAsUnarchived = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
353
|
-
return _regenerator["default"].wrap(function
|
|
579
|
+
var _markAsUnarchived = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(itemOrItems) {
|
|
580
|
+
return _regenerator["default"].wrap(function _callee9$(_context9) {
|
|
354
581
|
while (1) {
|
|
355
|
-
switch (
|
|
582
|
+
switch (_context9.prev = _context9.next) {
|
|
356
583
|
case 0:
|
|
357
584
|
this.optimisticallyPerformStatusUpdate(itemOrItems, "unarchived", {
|
|
358
585
|
archived_at: null
|
|
359
586
|
});
|
|
360
|
-
return
|
|
587
|
+
return _context9.abrupt("return", this.makeStatusUpdate(itemOrItems, "unarchived"));
|
|
361
588
|
|
|
362
589
|
case 2:
|
|
363
590
|
case "end":
|
|
364
|
-
return
|
|
591
|
+
return _context9.stop();
|
|
365
592
|
}
|
|
366
593
|
}
|
|
367
|
-
},
|
|
594
|
+
}, _callee9, this);
|
|
368
595
|
}));
|
|
369
596
|
|
|
370
597
|
function markAsUnarchived(_x6) {
|
|
@@ -378,12 +605,12 @@ var Feed = /*#__PURE__*/function () {
|
|
|
378
605
|
}, {
|
|
379
606
|
key: "fetch",
|
|
380
607
|
value: function () {
|
|
381
|
-
var _fetch = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
608
|
+
var _fetch = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10() {
|
|
382
609
|
var options,
|
|
383
|
-
_this$
|
|
610
|
+
_this$store5,
|
|
384
611
|
setState,
|
|
385
612
|
getState,
|
|
386
|
-
|
|
613
|
+
_getState4,
|
|
387
614
|
networkStatus,
|
|
388
615
|
queryParams,
|
|
389
616
|
result,
|
|
@@ -392,22 +619,22 @@ var Feed = /*#__PURE__*/function () {
|
|
|
392
619
|
_opts,
|
|
393
620
|
feedEventType,
|
|
394
621
|
eventPayload,
|
|
395
|
-
|
|
622
|
+
_args10 = arguments;
|
|
396
623
|
|
|
397
|
-
return _regenerator["default"].wrap(function
|
|
624
|
+
return _regenerator["default"].wrap(function _callee10$(_context10) {
|
|
398
625
|
while (1) {
|
|
399
|
-
switch (
|
|
626
|
+
switch (_context10.prev = _context10.next) {
|
|
400
627
|
case 0:
|
|
401
|
-
options =
|
|
402
|
-
_this$
|
|
403
|
-
|
|
628
|
+
options = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : {};
|
|
629
|
+
_this$store5 = this.store, setState = _this$store5.setState, getState = _this$store5.getState;
|
|
630
|
+
_getState4 = getState(), networkStatus = _getState4.networkStatus; // If there's an existing request in flight, then do nothing
|
|
404
631
|
|
|
405
632
|
if (!(0, _networkStatus.isRequestInFlight)(networkStatus)) {
|
|
406
|
-
|
|
633
|
+
_context10.next = 5;
|
|
407
634
|
break;
|
|
408
635
|
}
|
|
409
636
|
|
|
410
|
-
return
|
|
637
|
+
return _context10.abrupt("return");
|
|
411
638
|
|
|
412
639
|
case 5:
|
|
413
640
|
// Set the loading type based on the request type it is
|
|
@@ -423,7 +650,7 @@ var Feed = /*#__PURE__*/function () {
|
|
|
423
650
|
__fetchSource: undefined,
|
|
424
651
|
__experimentalCrossBrowserUpdates: undefined
|
|
425
652
|
});
|
|
426
|
-
|
|
653
|
+
_context10.next = 9;
|
|
427
654
|
return this.apiClient.makeRequest({
|
|
428
655
|
method: "GET",
|
|
429
656
|
url: "/v1/users/".concat(this.knock.userId, "/feeds/").concat(this.feedId),
|
|
@@ -431,17 +658,17 @@ var Feed = /*#__PURE__*/function () {
|
|
|
431
658
|
});
|
|
432
659
|
|
|
433
660
|
case 9:
|
|
434
|
-
result =
|
|
661
|
+
result = _context10.sent;
|
|
435
662
|
|
|
436
663
|
if (!(result.statusCode === "error" || !result.body)) {
|
|
437
|
-
|
|
664
|
+
_context10.next = 13;
|
|
438
665
|
break;
|
|
439
666
|
}
|
|
440
667
|
|
|
441
668
|
setState(function (store) {
|
|
442
669
|
return store.setNetworkStatus(_networkStatus.NetworkStatus.error);
|
|
443
670
|
});
|
|
444
|
-
return
|
|
671
|
+
return _context10.abrupt("return", {
|
|
445
672
|
status: result.statusCode,
|
|
446
673
|
data: result.error || result.body
|
|
447
674
|
});
|
|
@@ -485,17 +712,17 @@ var Feed = /*#__PURE__*/function () {
|
|
|
485
712
|
event: feedEventType
|
|
486
713
|
};
|
|
487
714
|
this.broadcast(eventPayload.event, eventPayload);
|
|
488
|
-
return
|
|
715
|
+
return _context10.abrupt("return", {
|
|
489
716
|
data: response,
|
|
490
717
|
status: result.statusCode
|
|
491
718
|
});
|
|
492
719
|
|
|
493
720
|
case 20:
|
|
494
721
|
case "end":
|
|
495
|
-
return
|
|
722
|
+
return _context10.stop();
|
|
496
723
|
}
|
|
497
724
|
}
|
|
498
|
-
},
|
|
725
|
+
}, _callee10, this);
|
|
499
726
|
}));
|
|
500
727
|
|
|
501
728
|
function fetch() {
|
|
@@ -507,23 +734,23 @@ var Feed = /*#__PURE__*/function () {
|
|
|
507
734
|
}, {
|
|
508
735
|
key: "fetchNextPage",
|
|
509
736
|
value: function () {
|
|
510
|
-
var _fetchNextPage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
511
|
-
var getState,
|
|
737
|
+
var _fetchNextPage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11() {
|
|
738
|
+
var getState, _getState5, pageInfo;
|
|
512
739
|
|
|
513
|
-
return _regenerator["default"].wrap(function
|
|
740
|
+
return _regenerator["default"].wrap(function _callee11$(_context11) {
|
|
514
741
|
while (1) {
|
|
515
|
-
switch (
|
|
742
|
+
switch (_context11.prev = _context11.next) {
|
|
516
743
|
case 0:
|
|
517
744
|
// Attempts to fetch the next page of results (if we have any)
|
|
518
745
|
getState = this.store.getState;
|
|
519
|
-
|
|
746
|
+
_getState5 = getState(), pageInfo = _getState5.pageInfo;
|
|
520
747
|
|
|
521
748
|
if (pageInfo.after) {
|
|
522
|
-
|
|
749
|
+
_context11.next = 4;
|
|
523
750
|
break;
|
|
524
751
|
}
|
|
525
752
|
|
|
526
|
-
return
|
|
753
|
+
return _context11.abrupt("return");
|
|
527
754
|
|
|
528
755
|
case 4:
|
|
529
756
|
this.fetch({
|
|
@@ -533,10 +760,10 @@ var Feed = /*#__PURE__*/function () {
|
|
|
533
760
|
|
|
534
761
|
case 5:
|
|
535
762
|
case "end":
|
|
536
|
-
return
|
|
763
|
+
return _context11.stop();
|
|
537
764
|
}
|
|
538
765
|
}
|
|
539
|
-
},
|
|
766
|
+
}, _callee11, this);
|
|
540
767
|
}));
|
|
541
768
|
|
|
542
769
|
function fetchNextPage() {
|
|
@@ -554,17 +781,17 @@ var Feed = /*#__PURE__*/function () {
|
|
|
554
781
|
}, {
|
|
555
782
|
key: "onNewMessageReceived",
|
|
556
783
|
value: function () {
|
|
557
|
-
var _onNewMessageReceived = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
558
|
-
var metadata, _this$
|
|
784
|
+
var _onNewMessageReceived = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12(_ref) {
|
|
785
|
+
var metadata, _this$store6, getState, setState, _getState6, items, currentHead;
|
|
559
786
|
|
|
560
|
-
return _regenerator["default"].wrap(function
|
|
787
|
+
return _regenerator["default"].wrap(function _callee12$(_context12) {
|
|
561
788
|
while (1) {
|
|
562
|
-
switch (
|
|
789
|
+
switch (_context12.prev = _context12.next) {
|
|
563
790
|
case 0:
|
|
564
791
|
metadata = _ref.metadata;
|
|
565
792
|
// Handle the new message coming in
|
|
566
|
-
_this$
|
|
567
|
-
|
|
793
|
+
_this$store6 = this.store, getState = _this$store6.getState, setState = _this$store6.setState;
|
|
794
|
+
_getState6 = getState(), items = _getState6.items;
|
|
568
795
|
currentHead = items[0]; // Optimistically set the badge counts
|
|
569
796
|
|
|
570
797
|
setState(function (state) {
|
|
@@ -578,10 +805,10 @@ var Feed = /*#__PURE__*/function () {
|
|
|
578
805
|
|
|
579
806
|
case 6:
|
|
580
807
|
case "end":
|
|
581
|
-
return
|
|
808
|
+
return _context12.stop();
|
|
582
809
|
}
|
|
583
810
|
}
|
|
584
|
-
},
|
|
811
|
+
}, _callee12, this);
|
|
585
812
|
}));
|
|
586
813
|
|
|
587
814
|
function onNewMessageReceived(_x7) {
|
|
@@ -598,16 +825,16 @@ var Feed = /*#__PURE__*/function () {
|
|
|
598
825
|
}, {
|
|
599
826
|
key: "optimisticallyPerformStatusUpdate",
|
|
600
827
|
value: function optimisticallyPerformStatusUpdate(itemOrItems, type, attrs, badgeCountAttr) {
|
|
601
|
-
var _this$
|
|
602
|
-
getState = _this$
|
|
603
|
-
setState = _this$
|
|
828
|
+
var _this$store7 = this.store,
|
|
829
|
+
getState = _this$store7.getState,
|
|
830
|
+
setState = _this$store7.setState;
|
|
604
831
|
var itemIds = Array.isArray(itemOrItems) ? itemOrItems.map(function (item) {
|
|
605
832
|
return item.id;
|
|
606
833
|
}) : [itemOrItems.id];
|
|
607
834
|
|
|
608
835
|
if (badgeCountAttr) {
|
|
609
|
-
var
|
|
610
|
-
metadata =
|
|
836
|
+
var _getState7 = getState(),
|
|
837
|
+
metadata = _getState7.metadata; // Tnis is a hack to determine the direction of whether we're
|
|
611
838
|
// adding or removing from the badge count
|
|
612
839
|
|
|
613
840
|
|
|
@@ -625,18 +852,18 @@ var Feed = /*#__PURE__*/function () {
|
|
|
625
852
|
}, {
|
|
626
853
|
key: "makeStatusUpdate",
|
|
627
854
|
value: function () {
|
|
628
|
-
var _makeStatusUpdate = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
855
|
+
var _makeStatusUpdate = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13(itemOrItems, type) {
|
|
629
856
|
var items, itemIds, result;
|
|
630
|
-
return _regenerator["default"].wrap(function
|
|
857
|
+
return _regenerator["default"].wrap(function _callee13$(_context13) {
|
|
631
858
|
while (1) {
|
|
632
|
-
switch (
|
|
859
|
+
switch (_context13.prev = _context13.next) {
|
|
633
860
|
case 0:
|
|
634
861
|
// Always treat items as a batch to use the corresponding batch endpoint
|
|
635
862
|
items = Array.isArray(itemOrItems) ? itemOrItems : [itemOrItems];
|
|
636
863
|
itemIds = items.map(function (item) {
|
|
637
864
|
return item.id;
|
|
638
865
|
});
|
|
639
|
-
|
|
866
|
+
_context13.next = 4;
|
|
640
867
|
return this.apiClient.makeRequest({
|
|
641
868
|
method: "POST",
|
|
642
869
|
url: "/v1/messages/batch/".concat(type),
|
|
@@ -646,30 +873,23 @@ var Feed = /*#__PURE__*/function () {
|
|
|
646
873
|
});
|
|
647
874
|
|
|
648
875
|
case 4:
|
|
649
|
-
result =
|
|
876
|
+
result = _context13.sent;
|
|
650
877
|
// Emit the event that these items had their statuses changed
|
|
651
878
|
// Note: we do this after the update to ensure that the server event actually completed
|
|
652
879
|
this.broadcaster.emit("items:".concat(type), {
|
|
653
880
|
items: items
|
|
654
881
|
});
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
payload: {
|
|
660
|
-
items: items
|
|
661
|
-
}
|
|
662
|
-
});
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
return _context10.abrupt("return", result);
|
|
882
|
+
this.broadcastOverChannel("items:".concat(type), {
|
|
883
|
+
items: items
|
|
884
|
+
});
|
|
885
|
+
return _context13.abrupt("return", result);
|
|
666
886
|
|
|
667
887
|
case 8:
|
|
668
888
|
case "end":
|
|
669
|
-
return
|
|
889
|
+
return _context13.stop();
|
|
670
890
|
}
|
|
671
891
|
}
|
|
672
|
-
},
|
|
892
|
+
}, _callee13, this);
|
|
673
893
|
}));
|
|
674
894
|
|
|
675
895
|
function makeStatusUpdate(_x8, _x9) {
|
|
@@ -678,6 +898,70 @@ var Feed = /*#__PURE__*/function () {
|
|
|
678
898
|
|
|
679
899
|
return makeStatusUpdate;
|
|
680
900
|
}()
|
|
901
|
+
}, {
|
|
902
|
+
key: "makeBulkStatusUpdate",
|
|
903
|
+
value: function () {
|
|
904
|
+
var _makeBulkStatusUpdate = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14(type) {
|
|
905
|
+
var options;
|
|
906
|
+
return _regenerator["default"].wrap(function _callee14$(_context14) {
|
|
907
|
+
while (1) {
|
|
908
|
+
switch (_context14.prev = _context14.next) {
|
|
909
|
+
case 0:
|
|
910
|
+
// The base scope for the call should take into account all of the options currently
|
|
911
|
+
// set on the feed, as well as being scoped for the current user. We do this so that
|
|
912
|
+
// we ONLY make changes to the messages that are currently in view on this feed, and not
|
|
913
|
+
// all messages that exist.
|
|
914
|
+
options = {
|
|
915
|
+
user_ids: [this.knock.userId],
|
|
916
|
+
engagement_status: this.defaultOptions.status !== "all" ? this.defaultOptions.status : undefined,
|
|
917
|
+
archived: this.defaultOptions.archived,
|
|
918
|
+
has_tenant: this.defaultOptions.has_tenant,
|
|
919
|
+
tenants: this.defaultOptions.tenant ? [this.defaultOptions.tenant] : undefined
|
|
920
|
+
};
|
|
921
|
+
_context14.next = 3;
|
|
922
|
+
return this.apiClient.makeRequest({
|
|
923
|
+
method: "POST",
|
|
924
|
+
url: "/v1/channels/".concat(this.feedId, "/messages/bulk/").concat(type),
|
|
925
|
+
data: options
|
|
926
|
+
});
|
|
927
|
+
|
|
928
|
+
case 3:
|
|
929
|
+
return _context14.abrupt("return", _context14.sent);
|
|
930
|
+
|
|
931
|
+
case 4:
|
|
932
|
+
case "end":
|
|
933
|
+
return _context14.stop();
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
}, _callee14, this);
|
|
937
|
+
}));
|
|
938
|
+
|
|
939
|
+
function makeBulkStatusUpdate(_x10) {
|
|
940
|
+
return _makeBulkStatusUpdate.apply(this, arguments);
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
return makeBulkStatusUpdate;
|
|
944
|
+
}()
|
|
945
|
+
}, {
|
|
946
|
+
key: "broadcastOverChannel",
|
|
947
|
+
value: function broadcastOverChannel(type, payload) {
|
|
948
|
+
// The broadcastChannel may not be available in non-browser environments
|
|
949
|
+
if (!this.broadcastChannel) {
|
|
950
|
+
return;
|
|
951
|
+
} // Here we stringify our payload and try and send as JSON such that we
|
|
952
|
+
// don't get any `An object could not be cloned` errors when trying to broadcast
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
try {
|
|
956
|
+
var stringifiedPayload = JSON.parse(JSON.stringify(payload));
|
|
957
|
+
this.broadcastChannel.postMessage({
|
|
958
|
+
type: type,
|
|
959
|
+
payload: stringifiedPayload
|
|
960
|
+
});
|
|
961
|
+
} catch (e) {
|
|
962
|
+
console.warn("Could not broadcast ".concat(type, ", got error: ").concat(e));
|
|
963
|
+
}
|
|
964
|
+
}
|
|
681
965
|
}]);
|
|
682
966
|
return Feed;
|
|
683
967
|
}();
|