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.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) {
|
|
@@ -3689,6 +3734,13 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3689
3734
|
});
|
|
3690
3735
|
});
|
|
3691
3736
|
});
|
|
3737
|
+
channelState.pinnedMessages.forEach(function (_ref3) {
|
|
3738
|
+
var id = _ref3.id,
|
|
3739
|
+
createdAt = _ref3.created_at;
|
|
3740
|
+
if (truncatedAt > +createdAt) channelState.removePinnedMessage({
|
|
3741
|
+
id: id
|
|
3742
|
+
});
|
|
3743
|
+
});
|
|
3692
3744
|
} else {
|
|
3693
3745
|
channelState.clearMessages();
|
|
3694
3746
|
}
|
|
@@ -3819,6 +3871,11 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3819
3871
|
}
|
|
3820
3872
|
|
|
3821
3873
|
this.state.addPinnedMessages(state.pinned_messages || []);
|
|
3874
|
+
|
|
3875
|
+
if (state.pending_messages) {
|
|
3876
|
+
this.state.pending_messages = state.pending_messages;
|
|
3877
|
+
}
|
|
3878
|
+
|
|
3822
3879
|
this.state.watcher_count = state.watcher_count || 0; // convert the arrays into objects for easier syncing...
|
|
3823
3880
|
|
|
3824
3881
|
if (state.watchers) {
|
|
@@ -3902,6 +3959,19 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3902
3959
|
}
|
|
3903
3960
|
}
|
|
3904
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
|
+
}
|
|
3905
3975
|
}, {
|
|
3906
3976
|
key: "_disconnect",
|
|
3907
3977
|
value: function _disconnect() {
|
|
@@ -4477,6 +4547,11 @@ var StableWSConnection = /*#__PURE__*/function () {
|
|
|
4477
4547
|
tags: ['connection']
|
|
4478
4548
|
}, extra));
|
|
4479
4549
|
}
|
|
4550
|
+
}, {
|
|
4551
|
+
key: "setClient",
|
|
4552
|
+
value: function setClient(client) {
|
|
4553
|
+
this.client = client;
|
|
4554
|
+
}
|
|
4480
4555
|
/**
|
|
4481
4556
|
* connect - Connect to the WS URL
|
|
4482
4557
|
* the default 15s timeout allows between 2~3 tries
|
|
@@ -6139,7 +6214,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6139
6214
|
throw Error('User is not set on client, use client.connectUser or client.connectAnonymousUser instead');
|
|
6140
6215
|
|
|
6141
6216
|
case 2:
|
|
6142
|
-
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)) {
|
|
6143
6218
|
_context3.next = 5;
|
|
6144
6219
|
break;
|
|
6145
6220
|
}
|
|
@@ -6148,7 +6223,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6148
6223
|
tags: ['connection', 'client']
|
|
6149
6224
|
});
|
|
6150
6225
|
|
|
6151
|
-
return _context3.abrupt("return",
|
|
6226
|
+
return _context3.abrupt("return", _this.wsPromise);
|
|
6152
6227
|
|
|
6153
6228
|
case 5:
|
|
6154
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())) {
|
|
@@ -7608,9 +7683,16 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7608
7683
|
} // The StableWSConnection handles all the reconnection logic.
|
|
7609
7684
|
|
|
7610
7685
|
|
|
7611
|
-
this.wsConnection
|
|
7612
|
-
|
|
7613
|
-
|
|
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
|
+
|
|
7614
7696
|
_context15.prev = 8;
|
|
7615
7697
|
|
|
7616
7698
|
if (!this.wsFallback) {
|
|
@@ -7736,7 +7818,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7736
7818
|
}; // Make sure we wait for the connect promise if there is a pending one
|
|
7737
7819
|
|
|
7738
7820
|
_context16.next = 5;
|
|
7739
|
-
return this.
|
|
7821
|
+
return this.wsPromise;
|
|
7740
7822
|
|
|
7741
7823
|
case 5:
|
|
7742
7824
|
if (!this._hasConnectionID()) {
|
|
@@ -7916,7 +7998,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7916
7998
|
}; // Make sure we wait for the connect promise if there is a pending one
|
|
7917
7999
|
|
|
7918
8000
|
_context19.next = 7;
|
|
7919
|
-
return this.
|
|
8001
|
+
return this.wsPromise;
|
|
7920
8002
|
|
|
7921
8003
|
case 7:
|
|
7922
8004
|
if (!this._hasConnectionID()) {
|
|
@@ -8051,7 +8133,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
8051
8133
|
|
|
8052
8134
|
case 13:
|
|
8053
8135
|
_context20.next = 15;
|
|
8054
|
-
return this.
|
|
8136
|
+
return this.wsPromise;
|
|
8055
8137
|
|
|
8056
8138
|
case 15:
|
|
8057
8139
|
_context20.next = 17;
|
|
@@ -9740,7 +9822,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
9740
9822
|
}, {
|
|
9741
9823
|
key: "getUserAgent",
|
|
9742
9824
|
value: function getUserAgent() {
|
|
9743
|
-
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");
|
|
9744
9826
|
}
|
|
9745
9827
|
}, {
|
|
9746
9828
|
key: "setUserAgent",
|
|
@@ -9913,15 +9995,19 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
9913
9995
|
/** sync - returns all events that happened for a list of channels since last sync
|
|
9914
9996
|
* @param {string[]} channel_cids list of channel CIDs
|
|
9915
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>}
|
|
9916
10001
|
*/
|
|
9917
10002
|
|
|
9918
10003
|
}, {
|
|
9919
10004
|
key: "sync",
|
|
9920
10005
|
value: function sync(channel_cids, last_sync_at) {
|
|
9921
|
-
|
|
10006
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
10007
|
+
return this.post("".concat(this.baseURL, "/sync"), _objectSpread({
|
|
9922
10008
|
channel_cids: channel_cids,
|
|
9923
10009
|
last_sync_at: last_sync_at
|
|
9924
|
-
});
|
|
10010
|
+
}, options));
|
|
9925
10011
|
}
|
|
9926
10012
|
/**
|
|
9927
10013
|
* sendUserCustomEvent - Send a custom event to a user
|