stream-chat 6.7.1 → 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 +97 -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 +97 -11
- package/dist/browser.js.map +1 -1
- package/dist/index.es.js +97 -11
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +97 -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 +31 -0
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/channel.ts +27 -1
- package/src/channel_state.ts +27 -0
- package/src/client.ts +22 -14
- package/src/connection.ts +4 -0
- package/src/types.ts +39 -0
package/dist/browser.es.js
CHANGED
|
@@ -130,6 +130,8 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
130
130
|
|
|
131
131
|
_defineProperty(this, "pinnedMessages", void 0);
|
|
132
132
|
|
|
133
|
+
_defineProperty(this, "pending_messages", void 0);
|
|
134
|
+
|
|
133
135
|
_defineProperty(this, "threads", void 0);
|
|
134
136
|
|
|
135
137
|
_defineProperty(this, "mutedUsers", void 0);
|
|
@@ -250,6 +252,7 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
250
252
|
this.read = {};
|
|
251
253
|
this.initMessages();
|
|
252
254
|
this.pinnedMessages = [];
|
|
255
|
+
this.pending_messages = [];
|
|
253
256
|
this.threads = {}; // a list of users to hide messages from
|
|
254
257
|
|
|
255
258
|
this.mutedUsers = [];
|
|
@@ -905,6 +908,42 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
905
908
|
|
|
906
909
|
return loadMessageIntoState;
|
|
907
910
|
}()
|
|
911
|
+
/**
|
|
912
|
+
* findMessage - Finds a message inside the state
|
|
913
|
+
*
|
|
914
|
+
* @param {string} messageId The id of the message
|
|
915
|
+
* @param {string} parentMessageId The id of the parent message, if we want load a thread reply
|
|
916
|
+
*
|
|
917
|
+
* @return {ReturnType<ChannelState<StreamChatGenerics>['formatMessage']>} Returns the message, or undefined if the message wasn't found
|
|
918
|
+
*/
|
|
919
|
+
|
|
920
|
+
}, {
|
|
921
|
+
key: "findMessage",
|
|
922
|
+
value: function findMessage(messageId, parentMessageId) {
|
|
923
|
+
if (parentMessageId) {
|
|
924
|
+
var messages = this.threads[parentMessageId];
|
|
925
|
+
|
|
926
|
+
if (!messages) {
|
|
927
|
+
return undefined;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
return messages.find(function (m) {
|
|
931
|
+
return m.id === messageId;
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
var messageSetIndex = this.findMessageSetIndex({
|
|
936
|
+
id: messageId
|
|
937
|
+
});
|
|
938
|
+
|
|
939
|
+
if (messageSetIndex === -1) {
|
|
940
|
+
return undefined;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
return this.messageSets[messageSetIndex].messages.find(function (m) {
|
|
944
|
+
return m.id === messageId;
|
|
945
|
+
});
|
|
946
|
+
}
|
|
908
947
|
}, {
|
|
909
948
|
key: "switchToMessageSet",
|
|
910
949
|
value: function switchToMessageSet(index) {
|
|
@@ -1493,6 +1532,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
1493
1532
|
* @param {Message<StreamChatGenerics>} message The Message object
|
|
1494
1533
|
* @param {boolean} [options.skip_enrich_url] Do not try to enrich the URLs within message
|
|
1495
1534
|
* @param {boolean} [options.skip_push] Skip sending push notifications
|
|
1535
|
+
* @param {boolean} [options.is_pending_message] Make this message pending
|
|
1536
|
+
* @param {Record<string,string>} [options.pending_message_metadata] Metadata for the pending message
|
|
1496
1537
|
*
|
|
1497
1538
|
* @return {Promise<SendMessageAPIResponse<StreamChatGenerics>>} The Server Response
|
|
1498
1539
|
*/
|
|
@@ -3598,6 +3639,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3598
3639
|
|
|
3599
3640
|
case 'message.deleted':
|
|
3600
3641
|
if (event.message) {
|
|
3642
|
+
this._extendEventWithOwnReactions(event);
|
|
3643
|
+
|
|
3601
3644
|
if (event.hard_delete) channelState.removeMessage(event.message);else channelState.addMessageSorted(event.message, false, false);
|
|
3602
3645
|
channelState.removeQuotedMessageReferences(event.message);
|
|
3603
3646
|
|
|
@@ -3640,6 +3683,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3640
3683
|
|
|
3641
3684
|
case 'message.updated':
|
|
3642
3685
|
if (event.message) {
|
|
3686
|
+
this._extendEventWithOwnReactions(event);
|
|
3687
|
+
|
|
3643
3688
|
channelState.addMessageSorted(event.message, false, false);
|
|
3644
3689
|
|
|
3645
3690
|
if (event.message.pinned) {
|
|
@@ -3664,6 +3709,13 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3664
3709
|
});
|
|
3665
3710
|
});
|
|
3666
3711
|
});
|
|
3712
|
+
channelState.pinnedMessages.forEach(function (_ref3) {
|
|
3713
|
+
var id = _ref3.id,
|
|
3714
|
+
createdAt = _ref3.created_at;
|
|
3715
|
+
if (truncatedAt > +createdAt) channelState.removePinnedMessage({
|
|
3716
|
+
id: id
|
|
3717
|
+
});
|
|
3718
|
+
});
|
|
3667
3719
|
} else {
|
|
3668
3720
|
channelState.clearMessages();
|
|
3669
3721
|
}
|
|
@@ -3794,6 +3846,11 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3794
3846
|
}
|
|
3795
3847
|
|
|
3796
3848
|
this.state.addPinnedMessages(state.pinned_messages || []);
|
|
3849
|
+
|
|
3850
|
+
if (state.pending_messages) {
|
|
3851
|
+
this.state.pending_messages = state.pending_messages;
|
|
3852
|
+
}
|
|
3853
|
+
|
|
3797
3854
|
this.state.watcher_count = state.watcher_count || 0; // convert the arrays into objects for easier syncing...
|
|
3798
3855
|
|
|
3799
3856
|
if (state.watchers) {
|
|
@@ -3877,6 +3934,19 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3877
3934
|
}
|
|
3878
3935
|
}
|
|
3879
3936
|
}
|
|
3937
|
+
}, {
|
|
3938
|
+
key: "_extendEventWithOwnReactions",
|
|
3939
|
+
value: function _extendEventWithOwnReactions(event) {
|
|
3940
|
+
if (!event.message) {
|
|
3941
|
+
return;
|
|
3942
|
+
}
|
|
3943
|
+
|
|
3944
|
+
var message = this.state.findMessage(event.message.id, event.message.parent_id);
|
|
3945
|
+
|
|
3946
|
+
if (message) {
|
|
3947
|
+
event.message.own_reactions = message.own_reactions;
|
|
3948
|
+
}
|
|
3949
|
+
}
|
|
3880
3950
|
}, {
|
|
3881
3951
|
key: "_disconnect",
|
|
3882
3952
|
value: function _disconnect() {
|
|
@@ -4452,6 +4522,11 @@ var StableWSConnection = /*#__PURE__*/function () {
|
|
|
4452
4522
|
tags: ['connection']
|
|
4453
4523
|
}, extra));
|
|
4454
4524
|
}
|
|
4525
|
+
}, {
|
|
4526
|
+
key: "setClient",
|
|
4527
|
+
value: function setClient(client) {
|
|
4528
|
+
this.client = client;
|
|
4529
|
+
}
|
|
4455
4530
|
/**
|
|
4456
4531
|
* connect - Connect to the WS URL
|
|
4457
4532
|
* the default 15s timeout allows between 2~3 tries
|
|
@@ -6114,7 +6189,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6114
6189
|
throw Error('User is not set on client, use client.connectUser or client.connectAnonymousUser instead');
|
|
6115
6190
|
|
|
6116
6191
|
case 2:
|
|
6117
|
-
if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting)) {
|
|
6192
|
+
if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting && _this.wsPromise)) {
|
|
6118
6193
|
_context3.next = 5;
|
|
6119
6194
|
break;
|
|
6120
6195
|
}
|
|
@@ -6123,7 +6198,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6123
6198
|
tags: ['connection', 'client']
|
|
6124
6199
|
});
|
|
6125
6200
|
|
|
6126
|
-
return _context3.abrupt("return",
|
|
6201
|
+
return _context3.abrupt("return", _this.wsPromise);
|
|
6127
6202
|
|
|
6128
6203
|
case 5:
|
|
6129
6204
|
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())) {
|
|
@@ -7583,9 +7658,16 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7583
7658
|
} // The StableWSConnection handles all the reconnection logic.
|
|
7584
7659
|
|
|
7585
7660
|
|
|
7586
|
-
this.wsConnection
|
|
7587
|
-
|
|
7588
|
-
|
|
7661
|
+
if (this.options.wsConnection && this.node) {
|
|
7662
|
+
// Intentionally avoiding adding ts generics on wsConnection in options since its only useful for unit test purpose.
|
|
7663
|
+
this.options.wsConnection.setClient(this);
|
|
7664
|
+
this.wsConnection = this.options.wsConnection;
|
|
7665
|
+
} else {
|
|
7666
|
+
this.wsConnection = new StableWSConnection({
|
|
7667
|
+
client: this
|
|
7668
|
+
});
|
|
7669
|
+
}
|
|
7670
|
+
|
|
7589
7671
|
_context15.prev = 8;
|
|
7590
7672
|
|
|
7591
7673
|
if (!this.wsFallback) {
|
|
@@ -7711,7 +7793,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7711
7793
|
}; // Make sure we wait for the connect promise if there is a pending one
|
|
7712
7794
|
|
|
7713
7795
|
_context16.next = 5;
|
|
7714
|
-
return this.
|
|
7796
|
+
return this.wsPromise;
|
|
7715
7797
|
|
|
7716
7798
|
case 5:
|
|
7717
7799
|
if (!this._hasConnectionID()) {
|
|
@@ -7891,7 +7973,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7891
7973
|
}; // Make sure we wait for the connect promise if there is a pending one
|
|
7892
7974
|
|
|
7893
7975
|
_context19.next = 7;
|
|
7894
|
-
return this.
|
|
7976
|
+
return this.wsPromise;
|
|
7895
7977
|
|
|
7896
7978
|
case 7:
|
|
7897
7979
|
if (!this._hasConnectionID()) {
|
|
@@ -8026,7 +8108,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
8026
8108
|
|
|
8027
8109
|
case 13:
|
|
8028
8110
|
_context20.next = 15;
|
|
8029
|
-
return this.
|
|
8111
|
+
return this.wsPromise;
|
|
8030
8112
|
|
|
8031
8113
|
case 15:
|
|
8032
8114
|
_context20.next = 17;
|
|
@@ -9715,7 +9797,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
9715
9797
|
}, {
|
|
9716
9798
|
key: "getUserAgent",
|
|
9717
9799
|
value: function getUserAgent() {
|
|
9718
|
-
return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.
|
|
9800
|
+
return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.8.0");
|
|
9719
9801
|
}
|
|
9720
9802
|
}, {
|
|
9721
9803
|
key: "setUserAgent",
|
|
@@ -9888,15 +9970,19 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
9888
9970
|
/** sync - returns all events that happened for a list of channels since last sync
|
|
9889
9971
|
* @param {string[]} channel_cids list of channel CIDs
|
|
9890
9972
|
* @param {string} last_sync_at last time the user was online and in sync. RFC3339 ie. "2020-05-06T15:05:01.207Z"
|
|
9973
|
+
* @param {SyncOptions} options See JSDoc in the type fields for more info
|
|
9974
|
+
*
|
|
9975
|
+
* @returns {Promise<SyncResponse>}
|
|
9891
9976
|
*/
|
|
9892
9977
|
|
|
9893
9978
|
}, {
|
|
9894
9979
|
key: "sync",
|
|
9895
9980
|
value: function sync(channel_cids, last_sync_at) {
|
|
9896
|
-
|
|
9981
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
9982
|
+
return this.post("".concat(this.baseURL, "/sync"), _objectSpread({
|
|
9897
9983
|
channel_cids: channel_cids,
|
|
9898
9984
|
last_sync_at: last_sync_at
|
|
9899
|
-
});
|
|
9985
|
+
}, options));
|
|
9900
9986
|
}
|
|
9901
9987
|
/**
|
|
9902
9988
|
* sendUserCustomEvent - Send a custom event to a user
|