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.js
CHANGED
|
@@ -159,6 +159,8 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
159
159
|
|
|
160
160
|
_defineProperty__default['default'](this, "pinnedMessages", void 0);
|
|
161
161
|
|
|
162
|
+
_defineProperty__default['default'](this, "pending_messages", void 0);
|
|
163
|
+
|
|
162
164
|
_defineProperty__default['default'](this, "threads", void 0);
|
|
163
165
|
|
|
164
166
|
_defineProperty__default['default'](this, "mutedUsers", void 0);
|
|
@@ -279,6 +281,7 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
279
281
|
this.read = {};
|
|
280
282
|
this.initMessages();
|
|
281
283
|
this.pinnedMessages = [];
|
|
284
|
+
this.pending_messages = [];
|
|
282
285
|
this.threads = {}; // a list of users to hide messages from
|
|
283
286
|
|
|
284
287
|
this.mutedUsers = [];
|
|
@@ -934,6 +937,42 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
934
937
|
|
|
935
938
|
return loadMessageIntoState;
|
|
936
939
|
}()
|
|
940
|
+
/**
|
|
941
|
+
* findMessage - Finds a message inside the state
|
|
942
|
+
*
|
|
943
|
+
* @param {string} messageId The id of the message
|
|
944
|
+
* @param {string} parentMessageId The id of the parent message, if we want load a thread reply
|
|
945
|
+
*
|
|
946
|
+
* @return {ReturnType<ChannelState<StreamChatGenerics>['formatMessage']>} Returns the message, or undefined if the message wasn't found
|
|
947
|
+
*/
|
|
948
|
+
|
|
949
|
+
}, {
|
|
950
|
+
key: "findMessage",
|
|
951
|
+
value: function findMessage(messageId, parentMessageId) {
|
|
952
|
+
if (parentMessageId) {
|
|
953
|
+
var messages = this.threads[parentMessageId];
|
|
954
|
+
|
|
955
|
+
if (!messages) {
|
|
956
|
+
return undefined;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
return messages.find(function (m) {
|
|
960
|
+
return m.id === messageId;
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
var messageSetIndex = this.findMessageSetIndex({
|
|
965
|
+
id: messageId
|
|
966
|
+
});
|
|
967
|
+
|
|
968
|
+
if (messageSetIndex === -1) {
|
|
969
|
+
return undefined;
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
return this.messageSets[messageSetIndex].messages.find(function (m) {
|
|
973
|
+
return m.id === messageId;
|
|
974
|
+
});
|
|
975
|
+
}
|
|
937
976
|
}, {
|
|
938
977
|
key: "switchToMessageSet",
|
|
939
978
|
value: function switchToMessageSet(index) {
|
|
@@ -1522,6 +1561,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
1522
1561
|
* @param {Message<StreamChatGenerics>} message The Message object
|
|
1523
1562
|
* @param {boolean} [options.skip_enrich_url] Do not try to enrich the URLs within message
|
|
1524
1563
|
* @param {boolean} [options.skip_push] Skip sending push notifications
|
|
1564
|
+
* @param {boolean} [options.is_pending_message] Make this message pending
|
|
1565
|
+
* @param {Record<string,string>} [options.pending_message_metadata] Metadata for the pending message
|
|
1525
1566
|
*
|
|
1526
1567
|
* @return {Promise<SendMessageAPIResponse<StreamChatGenerics>>} The Server Response
|
|
1527
1568
|
*/
|
|
@@ -3627,6 +3668,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3627
3668
|
|
|
3628
3669
|
case 'message.deleted':
|
|
3629
3670
|
if (event.message) {
|
|
3671
|
+
this._extendEventWithOwnReactions(event);
|
|
3672
|
+
|
|
3630
3673
|
if (event.hard_delete) channelState.removeMessage(event.message);else channelState.addMessageSorted(event.message, false, false);
|
|
3631
3674
|
channelState.removeQuotedMessageReferences(event.message);
|
|
3632
3675
|
|
|
@@ -3669,6 +3712,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3669
3712
|
|
|
3670
3713
|
case 'message.updated':
|
|
3671
3714
|
if (event.message) {
|
|
3715
|
+
this._extendEventWithOwnReactions(event);
|
|
3716
|
+
|
|
3672
3717
|
channelState.addMessageSorted(event.message, false, false);
|
|
3673
3718
|
|
|
3674
3719
|
if (event.message.pinned) {
|
|
@@ -3830,6 +3875,11 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3830
3875
|
}
|
|
3831
3876
|
|
|
3832
3877
|
this.state.addPinnedMessages(state.pinned_messages || []);
|
|
3878
|
+
|
|
3879
|
+
if (state.pending_messages) {
|
|
3880
|
+
this.state.pending_messages = state.pending_messages;
|
|
3881
|
+
}
|
|
3882
|
+
|
|
3833
3883
|
this.state.watcher_count = state.watcher_count || 0; // convert the arrays into objects for easier syncing...
|
|
3834
3884
|
|
|
3835
3885
|
if (state.watchers) {
|
|
@@ -3913,6 +3963,19 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3913
3963
|
}
|
|
3914
3964
|
}
|
|
3915
3965
|
}
|
|
3966
|
+
}, {
|
|
3967
|
+
key: "_extendEventWithOwnReactions",
|
|
3968
|
+
value: function _extendEventWithOwnReactions(event) {
|
|
3969
|
+
if (!event.message) {
|
|
3970
|
+
return;
|
|
3971
|
+
}
|
|
3972
|
+
|
|
3973
|
+
var message = this.state.findMessage(event.message.id, event.message.parent_id);
|
|
3974
|
+
|
|
3975
|
+
if (message) {
|
|
3976
|
+
event.message.own_reactions = message.own_reactions;
|
|
3977
|
+
}
|
|
3978
|
+
}
|
|
3916
3979
|
}, {
|
|
3917
3980
|
key: "_disconnect",
|
|
3918
3981
|
value: function _disconnect() {
|
|
@@ -4488,6 +4551,11 @@ var StableWSConnection = /*#__PURE__*/function () {
|
|
|
4488
4551
|
tags: ['connection']
|
|
4489
4552
|
}, extra));
|
|
4490
4553
|
}
|
|
4554
|
+
}, {
|
|
4555
|
+
key: "setClient",
|
|
4556
|
+
value: function setClient(client) {
|
|
4557
|
+
this.client = client;
|
|
4558
|
+
}
|
|
4491
4559
|
/**
|
|
4492
4560
|
* connect - Connect to the WS URL
|
|
4493
4561
|
* the default 15s timeout allows between 2~3 tries
|
|
@@ -6152,7 +6220,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6152
6220
|
throw Error('User is not set on client, use client.connectUser or client.connectAnonymousUser instead');
|
|
6153
6221
|
|
|
6154
6222
|
case 2:
|
|
6155
|
-
if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting)) {
|
|
6223
|
+
if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting && _this.wsPromise)) {
|
|
6156
6224
|
_context3.next = 5;
|
|
6157
6225
|
break;
|
|
6158
6226
|
}
|
|
@@ -6161,7 +6229,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6161
6229
|
tags: ['connection', 'client']
|
|
6162
6230
|
});
|
|
6163
6231
|
|
|
6164
|
-
return _context3.abrupt("return",
|
|
6232
|
+
return _context3.abrupt("return", _this.wsPromise);
|
|
6165
6233
|
|
|
6166
6234
|
case 5:
|
|
6167
6235
|
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())) {
|
|
@@ -7621,9 +7689,16 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7621
7689
|
} // The StableWSConnection handles all the reconnection logic.
|
|
7622
7690
|
|
|
7623
7691
|
|
|
7624
|
-
this.wsConnection
|
|
7625
|
-
|
|
7626
|
-
|
|
7692
|
+
if (this.options.wsConnection && this.node) {
|
|
7693
|
+
// Intentionally avoiding adding ts generics on wsConnection in options since its only useful for unit test purpose.
|
|
7694
|
+
this.options.wsConnection.setClient(this);
|
|
7695
|
+
this.wsConnection = this.options.wsConnection;
|
|
7696
|
+
} else {
|
|
7697
|
+
this.wsConnection = new StableWSConnection({
|
|
7698
|
+
client: this
|
|
7699
|
+
});
|
|
7700
|
+
}
|
|
7701
|
+
|
|
7627
7702
|
_context15.prev = 8;
|
|
7628
7703
|
|
|
7629
7704
|
if (!this.wsFallback) {
|
|
@@ -7749,7 +7824,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7749
7824
|
}; // Make sure we wait for the connect promise if there is a pending one
|
|
7750
7825
|
|
|
7751
7826
|
_context16.next = 5;
|
|
7752
|
-
return this.
|
|
7827
|
+
return this.wsPromise;
|
|
7753
7828
|
|
|
7754
7829
|
case 5:
|
|
7755
7830
|
if (!this._hasConnectionID()) {
|
|
@@ -7929,7 +8004,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7929
8004
|
}; // Make sure we wait for the connect promise if there is a pending one
|
|
7930
8005
|
|
|
7931
8006
|
_context19.next = 7;
|
|
7932
|
-
return this.
|
|
8007
|
+
return this.wsPromise;
|
|
7933
8008
|
|
|
7934
8009
|
case 7:
|
|
7935
8010
|
if (!this._hasConnectionID()) {
|
|
@@ -8064,7 +8139,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
8064
8139
|
|
|
8065
8140
|
case 13:
|
|
8066
8141
|
_context20.next = 15;
|
|
8067
|
-
return this.
|
|
8142
|
+
return this.wsPromise;
|
|
8068
8143
|
|
|
8069
8144
|
case 15:
|
|
8070
8145
|
_context20.next = 17;
|
|
@@ -9753,7 +9828,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
9753
9828
|
}, {
|
|
9754
9829
|
key: "getUserAgent",
|
|
9755
9830
|
value: function getUserAgent() {
|
|
9756
|
-
return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.
|
|
9831
|
+
return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.8.0");
|
|
9757
9832
|
}
|
|
9758
9833
|
}, {
|
|
9759
9834
|
key: "setUserAgent",
|
|
@@ -9926,15 +10001,19 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
9926
10001
|
/** sync - returns all events that happened for a list of channels since last sync
|
|
9927
10002
|
* @param {string[]} channel_cids list of channel CIDs
|
|
9928
10003
|
* @param {string} last_sync_at last time the user was online and in sync. RFC3339 ie. "2020-05-06T15:05:01.207Z"
|
|
10004
|
+
* @param {SyncOptions} options See JSDoc in the type fields for more info
|
|
10005
|
+
*
|
|
10006
|
+
* @returns {Promise<SyncResponse>}
|
|
9929
10007
|
*/
|
|
9930
10008
|
|
|
9931
10009
|
}, {
|
|
9932
10010
|
key: "sync",
|
|
9933
10011
|
value: function sync(channel_cids, last_sync_at) {
|
|
9934
|
-
|
|
10012
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
10013
|
+
return this.post("".concat(this.baseURL, "/sync"), _objectSpread({
|
|
9935
10014
|
channel_cids: channel_cids,
|
|
9936
10015
|
last_sync_at: last_sync_at
|
|
9937
|
-
});
|
|
10016
|
+
}, options));
|
|
9938
10017
|
}
|
|
9939
10018
|
/**
|
|
9940
10019
|
* sendUserCustomEvent - Send a custom event to a user
|