stream-chat 6.7.3 → 6.8.0
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/browser.es.js +90 -11
- package/dist/browser.es.js.map +1 -1
- package/dist/browser.full-bundle.min.js +1 -1
- package/dist/browser.full-bundle.min.js.map +1 -1
- package/dist/browser.js +90 -11
- package/dist/browser.js.map +1 -1
- package/dist/index.es.js +90 -11
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +90 -11
- package/dist/index.js.map +1 -1
- package/dist/types/channel.d.ts +5 -0
- package/dist/types/channel.d.ts.map +1 -1
- package/dist/types/channel_state.d.ts +11 -1
- package/dist/types/channel_state.d.ts.map +1 -1
- package/dist/types/client.d.ts +7 -8
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/connection.d.ts +1 -0
- package/dist/types/connection.d.ts.map +1 -1
- package/dist/types/types.d.ts +25 -0
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/channel.ts +23 -1
- package/src/channel_state.ts +27 -0
- package/src/client.ts +22 -14
- package/src/connection.ts +4 -0
- package/src/types.ts +33 -0
package/dist/index.es.js
CHANGED
|
@@ -131,6 +131,8 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
131
131
|
|
|
132
132
|
_defineProperty(this, "pinnedMessages", void 0);
|
|
133
133
|
|
|
134
|
+
_defineProperty(this, "pending_messages", void 0);
|
|
135
|
+
|
|
134
136
|
_defineProperty(this, "threads", void 0);
|
|
135
137
|
|
|
136
138
|
_defineProperty(this, "mutedUsers", void 0);
|
|
@@ -251,6 +253,7 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
251
253
|
this.read = {};
|
|
252
254
|
this.initMessages();
|
|
253
255
|
this.pinnedMessages = [];
|
|
256
|
+
this.pending_messages = [];
|
|
254
257
|
this.threads = {}; // a list of users to hide messages from
|
|
255
258
|
|
|
256
259
|
this.mutedUsers = [];
|
|
@@ -906,6 +909,42 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
906
909
|
|
|
907
910
|
return loadMessageIntoState;
|
|
908
911
|
}()
|
|
912
|
+
/**
|
|
913
|
+
* findMessage - Finds a message inside the state
|
|
914
|
+
*
|
|
915
|
+
* @param {string} messageId The id of the message
|
|
916
|
+
* @param {string} parentMessageId The id of the parent message, if we want load a thread reply
|
|
917
|
+
*
|
|
918
|
+
* @return {ReturnType<ChannelState<StreamChatGenerics>['formatMessage']>} Returns the message, or undefined if the message wasn't found
|
|
919
|
+
*/
|
|
920
|
+
|
|
921
|
+
}, {
|
|
922
|
+
key: "findMessage",
|
|
923
|
+
value: function findMessage(messageId, parentMessageId) {
|
|
924
|
+
if (parentMessageId) {
|
|
925
|
+
var messages = this.threads[parentMessageId];
|
|
926
|
+
|
|
927
|
+
if (!messages) {
|
|
928
|
+
return undefined;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
return messages.find(function (m) {
|
|
932
|
+
return m.id === messageId;
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
var messageSetIndex = this.findMessageSetIndex({
|
|
937
|
+
id: messageId
|
|
938
|
+
});
|
|
939
|
+
|
|
940
|
+
if (messageSetIndex === -1) {
|
|
941
|
+
return undefined;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
return this.messageSets[messageSetIndex].messages.find(function (m) {
|
|
945
|
+
return m.id === messageId;
|
|
946
|
+
});
|
|
947
|
+
}
|
|
909
948
|
}, {
|
|
910
949
|
key: "switchToMessageSet",
|
|
911
950
|
value: function switchToMessageSet(index) {
|
|
@@ -1494,6 +1533,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
1494
1533
|
* @param {Message<StreamChatGenerics>} message The Message object
|
|
1495
1534
|
* @param {boolean} [options.skip_enrich_url] Do not try to enrich the URLs within message
|
|
1496
1535
|
* @param {boolean} [options.skip_push] Skip sending push notifications
|
|
1536
|
+
* @param {boolean} [options.is_pending_message] Make this message pending
|
|
1537
|
+
* @param {Record<string,string>} [options.pending_message_metadata] Metadata for the pending message
|
|
1497
1538
|
*
|
|
1498
1539
|
* @return {Promise<SendMessageAPIResponse<StreamChatGenerics>>} The Server Response
|
|
1499
1540
|
*/
|
|
@@ -3599,6 +3640,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3599
3640
|
|
|
3600
3641
|
case 'message.deleted':
|
|
3601
3642
|
if (event.message) {
|
|
3643
|
+
this._extendEventWithOwnReactions(event);
|
|
3644
|
+
|
|
3602
3645
|
if (event.hard_delete) channelState.removeMessage(event.message);else channelState.addMessageSorted(event.message, false, false);
|
|
3603
3646
|
channelState.removeQuotedMessageReferences(event.message);
|
|
3604
3647
|
|
|
@@ -3641,6 +3684,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3641
3684
|
|
|
3642
3685
|
case 'message.updated':
|
|
3643
3686
|
if (event.message) {
|
|
3687
|
+
this._extendEventWithOwnReactions(event);
|
|
3688
|
+
|
|
3644
3689
|
channelState.addMessageSorted(event.message, false, false);
|
|
3645
3690
|
|
|
3646
3691
|
if (event.message.pinned) {
|
|
@@ -3802,6 +3847,11 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3802
3847
|
}
|
|
3803
3848
|
|
|
3804
3849
|
this.state.addPinnedMessages(state.pinned_messages || []);
|
|
3850
|
+
|
|
3851
|
+
if (state.pending_messages) {
|
|
3852
|
+
this.state.pending_messages = state.pending_messages;
|
|
3853
|
+
}
|
|
3854
|
+
|
|
3805
3855
|
this.state.watcher_count = state.watcher_count || 0; // convert the arrays into objects for easier syncing...
|
|
3806
3856
|
|
|
3807
3857
|
if (state.watchers) {
|
|
@@ -3885,6 +3935,19 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3885
3935
|
}
|
|
3886
3936
|
}
|
|
3887
3937
|
}
|
|
3938
|
+
}, {
|
|
3939
|
+
key: "_extendEventWithOwnReactions",
|
|
3940
|
+
value: function _extendEventWithOwnReactions(event) {
|
|
3941
|
+
if (!event.message) {
|
|
3942
|
+
return;
|
|
3943
|
+
}
|
|
3944
|
+
|
|
3945
|
+
var message = this.state.findMessage(event.message.id, event.message.parent_id);
|
|
3946
|
+
|
|
3947
|
+
if (message) {
|
|
3948
|
+
event.message.own_reactions = message.own_reactions;
|
|
3949
|
+
}
|
|
3950
|
+
}
|
|
3888
3951
|
}, {
|
|
3889
3952
|
key: "_disconnect",
|
|
3890
3953
|
value: function _disconnect() {
|
|
@@ -4460,6 +4523,11 @@ var StableWSConnection = /*#__PURE__*/function () {
|
|
|
4460
4523
|
tags: ['connection']
|
|
4461
4524
|
}, extra));
|
|
4462
4525
|
}
|
|
4526
|
+
}, {
|
|
4527
|
+
key: "setClient",
|
|
4528
|
+
value: function setClient(client) {
|
|
4529
|
+
this.client = client;
|
|
4530
|
+
}
|
|
4463
4531
|
/**
|
|
4464
4532
|
* connect - Connect to the WS URL
|
|
4465
4533
|
* the default 15s timeout allows between 2~3 tries
|
|
@@ -6124,7 +6192,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6124
6192
|
throw Error('User is not set on client, use client.connectUser or client.connectAnonymousUser instead');
|
|
6125
6193
|
|
|
6126
6194
|
case 2:
|
|
6127
|
-
if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting)) {
|
|
6195
|
+
if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting && _this.wsPromise)) {
|
|
6128
6196
|
_context3.next = 5;
|
|
6129
6197
|
break;
|
|
6130
6198
|
}
|
|
@@ -6133,7 +6201,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6133
6201
|
tags: ['connection', 'client']
|
|
6134
6202
|
});
|
|
6135
6203
|
|
|
6136
|
-
return _context3.abrupt("return",
|
|
6204
|
+
return _context3.abrupt("return", _this.wsPromise);
|
|
6137
6205
|
|
|
6138
6206
|
case 5:
|
|
6139
6207
|
if (!(((_this$wsConnection4 = _this.wsConnection) !== null && _this$wsConnection4 !== void 0 && _this$wsConnection4.isHealthy || (_this$wsFallback3 = _this.wsFallback) !== null && _this$wsFallback3 !== void 0 && _this$wsFallback3.isHealthy()) && _this._hasConnectionID())) {
|
|
@@ -7593,9 +7661,16 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7593
7661
|
} // The StableWSConnection handles all the reconnection logic.
|
|
7594
7662
|
|
|
7595
7663
|
|
|
7596
|
-
this.wsConnection
|
|
7597
|
-
|
|
7598
|
-
|
|
7664
|
+
if (this.options.wsConnection && this.node) {
|
|
7665
|
+
// Intentionally avoiding adding ts generics on wsConnection in options since its only useful for unit test purpose.
|
|
7666
|
+
this.options.wsConnection.setClient(this);
|
|
7667
|
+
this.wsConnection = this.options.wsConnection;
|
|
7668
|
+
} else {
|
|
7669
|
+
this.wsConnection = new StableWSConnection({
|
|
7670
|
+
client: this
|
|
7671
|
+
});
|
|
7672
|
+
}
|
|
7673
|
+
|
|
7599
7674
|
_context15.prev = 8;
|
|
7600
7675
|
|
|
7601
7676
|
if (!this.wsFallback) {
|
|
@@ -7721,7 +7796,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7721
7796
|
}; // Make sure we wait for the connect promise if there is a pending one
|
|
7722
7797
|
|
|
7723
7798
|
_context16.next = 5;
|
|
7724
|
-
return this.
|
|
7799
|
+
return this.wsPromise;
|
|
7725
7800
|
|
|
7726
7801
|
case 5:
|
|
7727
7802
|
if (!this._hasConnectionID()) {
|
|
@@ -7901,7 +7976,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7901
7976
|
}; // Make sure we wait for the connect promise if there is a pending one
|
|
7902
7977
|
|
|
7903
7978
|
_context19.next = 7;
|
|
7904
|
-
return this.
|
|
7979
|
+
return this.wsPromise;
|
|
7905
7980
|
|
|
7906
7981
|
case 7:
|
|
7907
7982
|
if (!this._hasConnectionID()) {
|
|
@@ -8036,7 +8111,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
8036
8111
|
|
|
8037
8112
|
case 13:
|
|
8038
8113
|
_context20.next = 15;
|
|
8039
|
-
return this.
|
|
8114
|
+
return this.wsPromise;
|
|
8040
8115
|
|
|
8041
8116
|
case 15:
|
|
8042
8117
|
_context20.next = 17;
|
|
@@ -9725,7 +9800,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
9725
9800
|
}, {
|
|
9726
9801
|
key: "getUserAgent",
|
|
9727
9802
|
value: function getUserAgent() {
|
|
9728
|
-
return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.
|
|
9803
|
+
return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.8.0");
|
|
9729
9804
|
}
|
|
9730
9805
|
}, {
|
|
9731
9806
|
key: "setUserAgent",
|
|
@@ -9898,15 +9973,19 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
9898
9973
|
/** sync - returns all events that happened for a list of channels since last sync
|
|
9899
9974
|
* @param {string[]} channel_cids list of channel CIDs
|
|
9900
9975
|
* @param {string} last_sync_at last time the user was online and in sync. RFC3339 ie. "2020-05-06T15:05:01.207Z"
|
|
9976
|
+
* @param {SyncOptions} options See JSDoc in the type fields for more info
|
|
9977
|
+
*
|
|
9978
|
+
* @returns {Promise<SyncResponse>}
|
|
9901
9979
|
*/
|
|
9902
9980
|
|
|
9903
9981
|
}, {
|
|
9904
9982
|
key: "sync",
|
|
9905
9983
|
value: function sync(channel_cids, last_sync_at) {
|
|
9906
|
-
|
|
9984
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
9985
|
+
return this.post("".concat(this.baseURL, "/sync"), _objectSpread({
|
|
9907
9986
|
channel_cids: channel_cids,
|
|
9908
9987
|
last_sync_at: last_sync_at
|
|
9909
|
-
});
|
|
9988
|
+
}, options));
|
|
9910
9989
|
}
|
|
9911
9990
|
/**
|
|
9912
9991
|
* sendUserCustomEvent - Send a custom event to a user
|