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/browser.js
CHANGED
|
@@ -155,6 +155,8 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
155
155
|
|
|
156
156
|
_defineProperty__default['default'](this, "pinnedMessages", void 0);
|
|
157
157
|
|
|
158
|
+
_defineProperty__default['default'](this, "pending_messages", void 0);
|
|
159
|
+
|
|
158
160
|
_defineProperty__default['default'](this, "threads", void 0);
|
|
159
161
|
|
|
160
162
|
_defineProperty__default['default'](this, "mutedUsers", void 0);
|
|
@@ -275,6 +277,7 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
275
277
|
this.read = {};
|
|
276
278
|
this.initMessages();
|
|
277
279
|
this.pinnedMessages = [];
|
|
280
|
+
this.pending_messages = [];
|
|
278
281
|
this.threads = {}; // a list of users to hide messages from
|
|
279
282
|
|
|
280
283
|
this.mutedUsers = [];
|
|
@@ -930,6 +933,42 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
930
933
|
|
|
931
934
|
return loadMessageIntoState;
|
|
932
935
|
}()
|
|
936
|
+
/**
|
|
937
|
+
* findMessage - Finds a message inside the state
|
|
938
|
+
*
|
|
939
|
+
* @param {string} messageId The id of the message
|
|
940
|
+
* @param {string} parentMessageId The id of the parent message, if we want load a thread reply
|
|
941
|
+
*
|
|
942
|
+
* @return {ReturnType<ChannelState<StreamChatGenerics>['formatMessage']>} Returns the message, or undefined if the message wasn't found
|
|
943
|
+
*/
|
|
944
|
+
|
|
945
|
+
}, {
|
|
946
|
+
key: "findMessage",
|
|
947
|
+
value: function findMessage(messageId, parentMessageId) {
|
|
948
|
+
if (parentMessageId) {
|
|
949
|
+
var messages = this.threads[parentMessageId];
|
|
950
|
+
|
|
951
|
+
if (!messages) {
|
|
952
|
+
return undefined;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
return messages.find(function (m) {
|
|
956
|
+
return m.id === messageId;
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
var messageSetIndex = this.findMessageSetIndex({
|
|
961
|
+
id: messageId
|
|
962
|
+
});
|
|
963
|
+
|
|
964
|
+
if (messageSetIndex === -1) {
|
|
965
|
+
return undefined;
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
return this.messageSets[messageSetIndex].messages.find(function (m) {
|
|
969
|
+
return m.id === messageId;
|
|
970
|
+
});
|
|
971
|
+
}
|
|
933
972
|
}, {
|
|
934
973
|
key: "switchToMessageSet",
|
|
935
974
|
value: function switchToMessageSet(index) {
|
|
@@ -1518,6 +1557,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
1518
1557
|
* @param {Message<StreamChatGenerics>} message The Message object
|
|
1519
1558
|
* @param {boolean} [options.skip_enrich_url] Do not try to enrich the URLs within message
|
|
1520
1559
|
* @param {boolean} [options.skip_push] Skip sending push notifications
|
|
1560
|
+
* @param {boolean} [options.is_pending_message] Make this message pending
|
|
1561
|
+
* @param {Record<string,string>} [options.pending_message_metadata] Metadata for the pending message
|
|
1521
1562
|
*
|
|
1522
1563
|
* @return {Promise<SendMessageAPIResponse<StreamChatGenerics>>} The Server Response
|
|
1523
1564
|
*/
|
|
@@ -3623,6 +3664,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3623
3664
|
|
|
3624
3665
|
case 'message.deleted':
|
|
3625
3666
|
if (event.message) {
|
|
3667
|
+
this._extendEventWithOwnReactions(event);
|
|
3668
|
+
|
|
3626
3669
|
if (event.hard_delete) channelState.removeMessage(event.message);else channelState.addMessageSorted(event.message, false, false);
|
|
3627
3670
|
channelState.removeQuotedMessageReferences(event.message);
|
|
3628
3671
|
|
|
@@ -3665,6 +3708,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3665
3708
|
|
|
3666
3709
|
case 'message.updated':
|
|
3667
3710
|
if (event.message) {
|
|
3711
|
+
this._extendEventWithOwnReactions(event);
|
|
3712
|
+
|
|
3668
3713
|
channelState.addMessageSorted(event.message, false, false);
|
|
3669
3714
|
|
|
3670
3715
|
if (event.message.pinned) {
|
|
@@ -3826,6 +3871,11 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3826
3871
|
}
|
|
3827
3872
|
|
|
3828
3873
|
this.state.addPinnedMessages(state.pinned_messages || []);
|
|
3874
|
+
|
|
3875
|
+
if (state.pending_messages) {
|
|
3876
|
+
this.state.pending_messages = state.pending_messages;
|
|
3877
|
+
}
|
|
3878
|
+
|
|
3829
3879
|
this.state.watcher_count = state.watcher_count || 0; // convert the arrays into objects for easier syncing...
|
|
3830
3880
|
|
|
3831
3881
|
if (state.watchers) {
|
|
@@ -3909,6 +3959,19 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3909
3959
|
}
|
|
3910
3960
|
}
|
|
3911
3961
|
}
|
|
3962
|
+
}, {
|
|
3963
|
+
key: "_extendEventWithOwnReactions",
|
|
3964
|
+
value: function _extendEventWithOwnReactions(event) {
|
|
3965
|
+
if (!event.message) {
|
|
3966
|
+
return;
|
|
3967
|
+
}
|
|
3968
|
+
|
|
3969
|
+
var message = this.state.findMessage(event.message.id, event.message.parent_id);
|
|
3970
|
+
|
|
3971
|
+
if (message) {
|
|
3972
|
+
event.message.own_reactions = message.own_reactions;
|
|
3973
|
+
}
|
|
3974
|
+
}
|
|
3912
3975
|
}, {
|
|
3913
3976
|
key: "_disconnect",
|
|
3914
3977
|
value: function _disconnect() {
|
|
@@ -4484,6 +4547,11 @@ var StableWSConnection = /*#__PURE__*/function () {
|
|
|
4484
4547
|
tags: ['connection']
|
|
4485
4548
|
}, extra));
|
|
4486
4549
|
}
|
|
4550
|
+
}, {
|
|
4551
|
+
key: "setClient",
|
|
4552
|
+
value: function setClient(client) {
|
|
4553
|
+
this.client = client;
|
|
4554
|
+
}
|
|
4487
4555
|
/**
|
|
4488
4556
|
* connect - Connect to the WS URL
|
|
4489
4557
|
* the default 15s timeout allows between 2~3 tries
|
|
@@ -6146,7 +6214,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6146
6214
|
throw Error('User is not set on client, use client.connectUser or client.connectAnonymousUser instead');
|
|
6147
6215
|
|
|
6148
6216
|
case 2:
|
|
6149
|
-
if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting)) {
|
|
6217
|
+
if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting && _this.wsPromise)) {
|
|
6150
6218
|
_context3.next = 5;
|
|
6151
6219
|
break;
|
|
6152
6220
|
}
|
|
@@ -6155,7 +6223,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6155
6223
|
tags: ['connection', 'client']
|
|
6156
6224
|
});
|
|
6157
6225
|
|
|
6158
|
-
return _context3.abrupt("return",
|
|
6226
|
+
return _context3.abrupt("return", _this.wsPromise);
|
|
6159
6227
|
|
|
6160
6228
|
case 5:
|
|
6161
6229
|
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())) {
|
|
@@ -7615,9 +7683,16 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7615
7683
|
} // The StableWSConnection handles all the reconnection logic.
|
|
7616
7684
|
|
|
7617
7685
|
|
|
7618
|
-
this.wsConnection
|
|
7619
|
-
|
|
7620
|
-
|
|
7686
|
+
if (this.options.wsConnection && this.node) {
|
|
7687
|
+
// Intentionally avoiding adding ts generics on wsConnection in options since its only useful for unit test purpose.
|
|
7688
|
+
this.options.wsConnection.setClient(this);
|
|
7689
|
+
this.wsConnection = this.options.wsConnection;
|
|
7690
|
+
} else {
|
|
7691
|
+
this.wsConnection = new StableWSConnection({
|
|
7692
|
+
client: this
|
|
7693
|
+
});
|
|
7694
|
+
}
|
|
7695
|
+
|
|
7621
7696
|
_context15.prev = 8;
|
|
7622
7697
|
|
|
7623
7698
|
if (!this.wsFallback) {
|
|
@@ -7743,7 +7818,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7743
7818
|
}; // Make sure we wait for the connect promise if there is a pending one
|
|
7744
7819
|
|
|
7745
7820
|
_context16.next = 5;
|
|
7746
|
-
return this.
|
|
7821
|
+
return this.wsPromise;
|
|
7747
7822
|
|
|
7748
7823
|
case 5:
|
|
7749
7824
|
if (!this._hasConnectionID()) {
|
|
@@ -7923,7 +7998,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7923
7998
|
}; // Make sure we wait for the connect promise if there is a pending one
|
|
7924
7999
|
|
|
7925
8000
|
_context19.next = 7;
|
|
7926
|
-
return this.
|
|
8001
|
+
return this.wsPromise;
|
|
7927
8002
|
|
|
7928
8003
|
case 7:
|
|
7929
8004
|
if (!this._hasConnectionID()) {
|
|
@@ -8058,7 +8133,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
8058
8133
|
|
|
8059
8134
|
case 13:
|
|
8060
8135
|
_context20.next = 15;
|
|
8061
|
-
return this.
|
|
8136
|
+
return this.wsPromise;
|
|
8062
8137
|
|
|
8063
8138
|
case 15:
|
|
8064
8139
|
_context20.next = 17;
|
|
@@ -9747,7 +9822,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
9747
9822
|
}, {
|
|
9748
9823
|
key: "getUserAgent",
|
|
9749
9824
|
value: function getUserAgent() {
|
|
9750
|
-
return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.
|
|
9825
|
+
return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.8.0");
|
|
9751
9826
|
}
|
|
9752
9827
|
}, {
|
|
9753
9828
|
key: "setUserAgent",
|
|
@@ -9920,15 +9995,19 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
9920
9995
|
/** sync - returns all events that happened for a list of channels since last sync
|
|
9921
9996
|
* @param {string[]} channel_cids list of channel CIDs
|
|
9922
9997
|
* @param {string} last_sync_at last time the user was online and in sync. RFC3339 ie. "2020-05-06T15:05:01.207Z"
|
|
9998
|
+
* @param {SyncOptions} options See JSDoc in the type fields for more info
|
|
9999
|
+
*
|
|
10000
|
+
* @returns {Promise<SyncResponse>}
|
|
9923
10001
|
*/
|
|
9924
10002
|
|
|
9925
10003
|
}, {
|
|
9926
10004
|
key: "sync",
|
|
9927
10005
|
value: function sync(channel_cids, last_sync_at) {
|
|
9928
|
-
|
|
10006
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
10007
|
+
return this.post("".concat(this.baseURL, "/sync"), _objectSpread({
|
|
9929
10008
|
channel_cids: channel_cids,
|
|
9930
10009
|
last_sync_at: last_sync_at
|
|
9931
|
-
});
|
|
10010
|
+
}, options));
|
|
9932
10011
|
}
|
|
9933
10012
|
/**
|
|
9934
10013
|
* sendUserCustomEvent - Send a custom event to a user
|