stream-chat 6.7.2 → 6.9.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 +133 -39
- 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 +133 -39
- package/dist/browser.js.map +1 -1
- package/dist/index.es.js +133 -39
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +133 -39
- 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 +12 -2
- 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 +29 -0
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/channel.ts +28 -2
- package/src/channel_state.ts +30 -3
- package/src/client.ts +28 -16
- package/src/connection.ts +4 -0
- package/src/types.ts +37 -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 = [];
|
|
@@ -807,40 +810,46 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
807
810
|
var _loadMessageIntoState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(messageId, parentMessageId) {
|
|
808
811
|
var _this$threads$parentM;
|
|
809
812
|
|
|
810
|
-
var
|
|
813
|
+
var limit,
|
|
814
|
+
messageSetIndex,
|
|
815
|
+
switchedToMessageSet,
|
|
816
|
+
loadedMessageThread,
|
|
817
|
+
messageIdToFind,
|
|
818
|
+
_args = arguments;
|
|
811
819
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
812
820
|
while (1) {
|
|
813
821
|
switch (_context.prev = _context.next) {
|
|
814
822
|
case 0:
|
|
823
|
+
limit = _args.length > 2 && _args[2] !== undefined ? _args[2] : 25;
|
|
815
824
|
switchedToMessageSet = false;
|
|
816
825
|
loadedMessageThread = false;
|
|
817
826
|
messageIdToFind = parentMessageId || messageId;
|
|
818
827
|
|
|
819
828
|
if (!(messageId === 'latest')) {
|
|
820
|
-
_context.next =
|
|
829
|
+
_context.next = 10;
|
|
821
830
|
break;
|
|
822
831
|
}
|
|
823
832
|
|
|
824
833
|
if (!(this.messages === this.latestMessages)) {
|
|
825
|
-
_context.next =
|
|
834
|
+
_context.next = 7;
|
|
826
835
|
break;
|
|
827
836
|
}
|
|
828
837
|
|
|
829
838
|
return _context.abrupt("return");
|
|
830
839
|
|
|
831
|
-
case
|
|
840
|
+
case 7:
|
|
832
841
|
messageSetIndex = this.messageSets.findIndex(function (s) {
|
|
833
842
|
return s.isLatest;
|
|
834
843
|
});
|
|
835
|
-
_context.next =
|
|
844
|
+
_context.next = 11;
|
|
836
845
|
break;
|
|
837
846
|
|
|
838
|
-
case
|
|
847
|
+
case 10:
|
|
839
848
|
messageSetIndex = this.findMessageSetIndex({
|
|
840
849
|
id: messageIdToFind
|
|
841
850
|
});
|
|
842
851
|
|
|
843
|
-
case
|
|
852
|
+
case 11:
|
|
844
853
|
if (messageSetIndex !== -1) {
|
|
845
854
|
this.switchToMessageSet(messageSetIndex);
|
|
846
855
|
switchedToMessageSet = true;
|
|
@@ -851,39 +860,39 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
851
860
|
}));
|
|
852
861
|
|
|
853
862
|
if (!(switchedToMessageSet && loadedMessageThread)) {
|
|
854
|
-
_context.next =
|
|
863
|
+
_context.next = 15;
|
|
855
864
|
break;
|
|
856
865
|
}
|
|
857
866
|
|
|
858
867
|
return _context.abrupt("return");
|
|
859
868
|
|
|
860
|
-
case
|
|
869
|
+
case 15:
|
|
861
870
|
if (switchedToMessageSet) {
|
|
862
|
-
_context.next =
|
|
871
|
+
_context.next = 18;
|
|
863
872
|
break;
|
|
864
873
|
}
|
|
865
874
|
|
|
866
|
-
_context.next =
|
|
875
|
+
_context.next = 18;
|
|
867
876
|
return this._channel.query({
|
|
868
877
|
messages: {
|
|
869
878
|
id_around: messageIdToFind,
|
|
870
|
-
limit:
|
|
879
|
+
limit: limit
|
|
871
880
|
}
|
|
872
881
|
}, 'new');
|
|
873
882
|
|
|
874
|
-
case
|
|
883
|
+
case 18:
|
|
875
884
|
if (!(!loadedMessageThread && parentMessageId)) {
|
|
876
|
-
_context.next =
|
|
885
|
+
_context.next = 21;
|
|
877
886
|
break;
|
|
878
887
|
}
|
|
879
888
|
|
|
880
|
-
_context.next =
|
|
889
|
+
_context.next = 21;
|
|
881
890
|
return this._channel.getReplies(parentMessageId, {
|
|
882
891
|
id_around: messageId,
|
|
883
|
-
limit:
|
|
892
|
+
limit: limit
|
|
884
893
|
});
|
|
885
894
|
|
|
886
|
-
case
|
|
895
|
+
case 21:
|
|
887
896
|
messageSetIndex = this.findMessageSetIndex({
|
|
888
897
|
id: messageIdToFind
|
|
889
898
|
});
|
|
@@ -892,7 +901,7 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
892
901
|
this.switchToMessageSet(messageSetIndex);
|
|
893
902
|
}
|
|
894
903
|
|
|
895
|
-
case
|
|
904
|
+
case 23:
|
|
896
905
|
case "end":
|
|
897
906
|
return _context.stop();
|
|
898
907
|
}
|
|
@@ -906,6 +915,42 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
906
915
|
|
|
907
916
|
return loadMessageIntoState;
|
|
908
917
|
}()
|
|
918
|
+
/**
|
|
919
|
+
* findMessage - Finds a message inside the state
|
|
920
|
+
*
|
|
921
|
+
* @param {string} messageId The id of the message
|
|
922
|
+
* @param {string} parentMessageId The id of the parent message, if we want load a thread reply
|
|
923
|
+
*
|
|
924
|
+
* @return {ReturnType<ChannelState<StreamChatGenerics>['formatMessage']>} Returns the message, or undefined if the message wasn't found
|
|
925
|
+
*/
|
|
926
|
+
|
|
927
|
+
}, {
|
|
928
|
+
key: "findMessage",
|
|
929
|
+
value: function findMessage(messageId, parentMessageId) {
|
|
930
|
+
if (parentMessageId) {
|
|
931
|
+
var messages = this.threads[parentMessageId];
|
|
932
|
+
|
|
933
|
+
if (!messages) {
|
|
934
|
+
return undefined;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
return messages.find(function (m) {
|
|
938
|
+
return m.id === messageId;
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
var messageSetIndex = this.findMessageSetIndex({
|
|
943
|
+
id: messageId
|
|
944
|
+
});
|
|
945
|
+
|
|
946
|
+
if (messageSetIndex === -1) {
|
|
947
|
+
return undefined;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
return this.messageSets[messageSetIndex].messages.find(function (m) {
|
|
951
|
+
return m.id === messageId;
|
|
952
|
+
});
|
|
953
|
+
}
|
|
909
954
|
}, {
|
|
910
955
|
key: "switchToMessageSet",
|
|
911
956
|
value: function switchToMessageSet(index) {
|
|
@@ -1494,6 +1539,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
1494
1539
|
* @param {Message<StreamChatGenerics>} message The Message object
|
|
1495
1540
|
* @param {boolean} [options.skip_enrich_url] Do not try to enrich the URLs within message
|
|
1496
1541
|
* @param {boolean} [options.skip_push] Skip sending push notifications
|
|
1542
|
+
* @param {boolean} [options.is_pending_message] Make this message pending
|
|
1543
|
+
* @param {Record<string,string>} [options.pending_message_metadata] Metadata for the pending message
|
|
1497
1544
|
*
|
|
1498
1545
|
* @return {Promise<SendMessageAPIResponse<StreamChatGenerics>>} The Server Response
|
|
1499
1546
|
*/
|
|
@@ -1900,6 +1947,7 @@ var Channel = /*#__PURE__*/function () {
|
|
|
1900
1947
|
key: "updatePartial",
|
|
1901
1948
|
value: function () {
|
|
1902
1949
|
var _updatePartial = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(update) {
|
|
1950
|
+
var data;
|
|
1903
1951
|
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
1904
1952
|
while (1) {
|
|
1905
1953
|
switch (_context8.prev = _context8.next) {
|
|
@@ -1908,9 +1956,11 @@ var Channel = /*#__PURE__*/function () {
|
|
|
1908
1956
|
return this.getClient().patch(this._channelURL(), update);
|
|
1909
1957
|
|
|
1910
1958
|
case 2:
|
|
1911
|
-
|
|
1959
|
+
data = _context8.sent;
|
|
1960
|
+
this.data = data.channel;
|
|
1961
|
+
return _context8.abrupt("return", data);
|
|
1912
1962
|
|
|
1913
|
-
case
|
|
1963
|
+
case 5:
|
|
1914
1964
|
case "end":
|
|
1915
1965
|
return _context8.stop();
|
|
1916
1966
|
}
|
|
@@ -3152,9 +3202,10 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3152
3202
|
|
|
3153
3203
|
this._initializeState(state, messageSetToAddToIfDoesNotExist);
|
|
3154
3204
|
|
|
3205
|
+
this.data = state.channel;
|
|
3155
3206
|
return _context31.abrupt("return", state);
|
|
3156
3207
|
|
|
3157
|
-
case
|
|
3208
|
+
case 13:
|
|
3158
3209
|
case "end":
|
|
3159
3210
|
return _context31.stop();
|
|
3160
3211
|
}
|
|
@@ -3599,6 +3650,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3599
3650
|
|
|
3600
3651
|
case 'message.deleted':
|
|
3601
3652
|
if (event.message) {
|
|
3653
|
+
this._extendEventWithOwnReactions(event);
|
|
3654
|
+
|
|
3602
3655
|
if (event.hard_delete) channelState.removeMessage(event.message);else channelState.addMessageSorted(event.message, false, false);
|
|
3603
3656
|
channelState.removeQuotedMessageReferences(event.message);
|
|
3604
3657
|
|
|
@@ -3641,6 +3694,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3641
3694
|
|
|
3642
3695
|
case 'message.updated':
|
|
3643
3696
|
if (event.message) {
|
|
3697
|
+
this._extendEventWithOwnReactions(event);
|
|
3698
|
+
|
|
3644
3699
|
channelState.addMessageSorted(event.message, false, false);
|
|
3645
3700
|
|
|
3646
3701
|
if (event.message.pinned) {
|
|
@@ -3802,6 +3857,11 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3802
3857
|
}
|
|
3803
3858
|
|
|
3804
3859
|
this.state.addPinnedMessages(state.pinned_messages || []);
|
|
3860
|
+
|
|
3861
|
+
if (state.pending_messages) {
|
|
3862
|
+
this.state.pending_messages = state.pending_messages;
|
|
3863
|
+
}
|
|
3864
|
+
|
|
3805
3865
|
this.state.watcher_count = state.watcher_count || 0; // convert the arrays into objects for easier syncing...
|
|
3806
3866
|
|
|
3807
3867
|
if (state.watchers) {
|
|
@@ -3885,6 +3945,19 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3885
3945
|
}
|
|
3886
3946
|
}
|
|
3887
3947
|
}
|
|
3948
|
+
}, {
|
|
3949
|
+
key: "_extendEventWithOwnReactions",
|
|
3950
|
+
value: function _extendEventWithOwnReactions(event) {
|
|
3951
|
+
if (!event.message) {
|
|
3952
|
+
return;
|
|
3953
|
+
}
|
|
3954
|
+
|
|
3955
|
+
var message = this.state.findMessage(event.message.id, event.message.parent_id);
|
|
3956
|
+
|
|
3957
|
+
if (message) {
|
|
3958
|
+
event.message.own_reactions = message.own_reactions;
|
|
3959
|
+
}
|
|
3960
|
+
}
|
|
3888
3961
|
}, {
|
|
3889
3962
|
key: "_disconnect",
|
|
3890
3963
|
value: function _disconnect() {
|
|
@@ -4460,6 +4533,11 @@ var StableWSConnection = /*#__PURE__*/function () {
|
|
|
4460
4533
|
tags: ['connection']
|
|
4461
4534
|
}, extra));
|
|
4462
4535
|
}
|
|
4536
|
+
}, {
|
|
4537
|
+
key: "setClient",
|
|
4538
|
+
value: function setClient(client) {
|
|
4539
|
+
this.client = client;
|
|
4540
|
+
}
|
|
4463
4541
|
/**
|
|
4464
4542
|
* connect - Connect to the WS URL
|
|
4465
4543
|
* the default 15s timeout allows between 2~3 tries
|
|
@@ -6124,7 +6202,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6124
6202
|
throw Error('User is not set on client, use client.connectUser or client.connectAnonymousUser instead');
|
|
6125
6203
|
|
|
6126
6204
|
case 2:
|
|
6127
|
-
if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting)) {
|
|
6205
|
+
if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting && _this.wsPromise)) {
|
|
6128
6206
|
_context3.next = 5;
|
|
6129
6207
|
break;
|
|
6130
6208
|
}
|
|
@@ -6133,7 +6211,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6133
6211
|
tags: ['connection', 'client']
|
|
6134
6212
|
});
|
|
6135
6213
|
|
|
6136
|
-
return _context3.abrupt("return",
|
|
6214
|
+
return _context3.abrupt("return", _this.wsPromise);
|
|
6137
6215
|
|
|
6138
6216
|
case 5:
|
|
6139
6217
|
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())) {
|
|
@@ -6889,23 +6967,28 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6889
6967
|
*/
|
|
6890
6968
|
function () {
|
|
6891
6969
|
var _updateAppSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(options) {
|
|
6892
|
-
var
|
|
6893
|
-
|
|
6970
|
+
var apn_config;
|
|
6894
6971
|
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
6895
6972
|
while (1) {
|
|
6896
6973
|
switch (_context7.prev = _context7.next) {
|
|
6897
6974
|
case 0:
|
|
6898
|
-
|
|
6899
|
-
|
|
6975
|
+
apn_config = options.apn_config;
|
|
6976
|
+
|
|
6977
|
+
if (apn_config !== null && apn_config !== void 0 && apn_config.p12_cert) {
|
|
6978
|
+
options = _objectSpread(_objectSpread({}, options), {}, {
|
|
6979
|
+
apn_config: _objectSpread(_objectSpread({}, apn_config), {}, {
|
|
6980
|
+
p12_cert: Buffer.from(apn_config.p12_cert).toString('base64')
|
|
6981
|
+
})
|
|
6982
|
+
});
|
|
6900
6983
|
}
|
|
6901
6984
|
|
|
6902
|
-
_context7.next =
|
|
6985
|
+
_context7.next = 4;
|
|
6903
6986
|
return this.patch(this.baseURL + '/app', options);
|
|
6904
6987
|
|
|
6905
|
-
case
|
|
6988
|
+
case 4:
|
|
6906
6989
|
return _context7.abrupt("return", _context7.sent);
|
|
6907
6990
|
|
|
6908
|
-
case
|
|
6991
|
+
case 5:
|
|
6909
6992
|
case "end":
|
|
6910
6993
|
return _context7.stop();
|
|
6911
6994
|
}
|
|
@@ -7593,9 +7676,16 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7593
7676
|
} // The StableWSConnection handles all the reconnection logic.
|
|
7594
7677
|
|
|
7595
7678
|
|
|
7596
|
-
this.wsConnection
|
|
7597
|
-
|
|
7598
|
-
|
|
7679
|
+
if (this.options.wsConnection && this.node) {
|
|
7680
|
+
// Intentionally avoiding adding ts generics on wsConnection in options since its only useful for unit test purpose.
|
|
7681
|
+
this.options.wsConnection.setClient(this);
|
|
7682
|
+
this.wsConnection = this.options.wsConnection;
|
|
7683
|
+
} else {
|
|
7684
|
+
this.wsConnection = new StableWSConnection({
|
|
7685
|
+
client: this
|
|
7686
|
+
});
|
|
7687
|
+
}
|
|
7688
|
+
|
|
7599
7689
|
_context15.prev = 8;
|
|
7600
7690
|
|
|
7601
7691
|
if (!this.wsFallback) {
|
|
@@ -7721,7 +7811,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7721
7811
|
}; // Make sure we wait for the connect promise if there is a pending one
|
|
7722
7812
|
|
|
7723
7813
|
_context16.next = 5;
|
|
7724
|
-
return this.
|
|
7814
|
+
return this.wsPromise;
|
|
7725
7815
|
|
|
7726
7816
|
case 5:
|
|
7727
7817
|
if (!this._hasConnectionID()) {
|
|
@@ -7901,7 +7991,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7901
7991
|
}; // Make sure we wait for the connect promise if there is a pending one
|
|
7902
7992
|
|
|
7903
7993
|
_context19.next = 7;
|
|
7904
|
-
return this.
|
|
7994
|
+
return this.wsPromise;
|
|
7905
7995
|
|
|
7906
7996
|
case 7:
|
|
7907
7997
|
if (!this._hasConnectionID()) {
|
|
@@ -8036,7 +8126,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
8036
8126
|
|
|
8037
8127
|
case 13:
|
|
8038
8128
|
_context20.next = 15;
|
|
8039
|
-
return this.
|
|
8129
|
+
return this.wsPromise;
|
|
8040
8130
|
|
|
8041
8131
|
case 15:
|
|
8042
8132
|
_context20.next = 17;
|
|
@@ -9725,7 +9815,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
9725
9815
|
}, {
|
|
9726
9816
|
key: "getUserAgent",
|
|
9727
9817
|
value: function getUserAgent() {
|
|
9728
|
-
return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.
|
|
9818
|
+
return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.9.0");
|
|
9729
9819
|
}
|
|
9730
9820
|
}, {
|
|
9731
9821
|
key: "setUserAgent",
|
|
@@ -9898,15 +9988,19 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
9898
9988
|
/** sync - returns all events that happened for a list of channels since last sync
|
|
9899
9989
|
* @param {string[]} channel_cids list of channel CIDs
|
|
9900
9990
|
* @param {string} last_sync_at last time the user was online and in sync. RFC3339 ie. "2020-05-06T15:05:01.207Z"
|
|
9991
|
+
* @param {SyncOptions} options See JSDoc in the type fields for more info
|
|
9992
|
+
*
|
|
9993
|
+
* @returns {Promise<SyncResponse>}
|
|
9901
9994
|
*/
|
|
9902
9995
|
|
|
9903
9996
|
}, {
|
|
9904
9997
|
key: "sync",
|
|
9905
9998
|
value: function sync(channel_cids, last_sync_at) {
|
|
9906
|
-
|
|
9999
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
10000
|
+
return this.post("".concat(this.baseURL, "/sync"), _objectSpread({
|
|
9907
10001
|
channel_cids: channel_cids,
|
|
9908
10002
|
last_sync_at: last_sync_at
|
|
9909
|
-
});
|
|
10003
|
+
}, options));
|
|
9910
10004
|
}
|
|
9911
10005
|
/**
|
|
9912
10006
|
* sendUserCustomEvent - Send a custom event to a user
|