stream-chat 6.7.3 → 7.0.0-offline-support.2
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 +222 -91
- package/dist/browser.es.js.map +1 -1
- package/dist/browser.full-bundle.min.js +3 -1
- package/dist/browser.full-bundle.min.js.map +1 -1
- package/dist/browser.js +222 -91
- package/dist/browser.js.map +1 -1
- package/dist/index.es.js +222 -91
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +222 -91
- package/dist/index.js.map +1 -1
- package/dist/types/channel.d.ts +16 -8
- package/dist/types/channel.d.ts.map +1 -1
- package/dist/types/channel_state.d.ts +23 -2
- package/dist/types/channel_state.d.ts.map +1 -1
- package/dist/types/client.d.ts +3 -1
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/connection.d.ts.map +1 -1
- package/dist/types/events.d.ts +1 -0
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/types.d.ts +14 -2
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/channel.ts +36 -8
- package/src/channel_state.ts +28 -0
- package/src/client.ts +45 -13
- package/src/connection.ts +15 -3
- package/src/events.ts +1 -0
- package/src/types.ts +17 -2
package/dist/browser.es.js
CHANGED
|
@@ -437,6 +437,10 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
437
437
|
this.threads[parentID] = threadMessages;
|
|
438
438
|
}
|
|
439
439
|
}
|
|
440
|
+
|
|
441
|
+
return {
|
|
442
|
+
messageSet: this.messageSets[targetMessageSetIndex]
|
|
443
|
+
};
|
|
440
444
|
}
|
|
441
445
|
/**
|
|
442
446
|
* addPinnedMessages - adds messages in pinnedMessages property
|
|
@@ -905,6 +909,42 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
905
909
|
|
|
906
910
|
return loadMessageIntoState;
|
|
907
911
|
}()
|
|
912
|
+
/**
|
|
913
|
+
* findMessage - Finds a message inside the state
|
|
914
|
+
*
|
|
915
|
+
* @param {string} messageId The id of the message
|
|
916
|
+
* @param {string} parentMessageId The id of the parent message, if we want load a thread reply
|
|
917
|
+
*
|
|
918
|
+
* @return {ReturnType<ChannelState<StreamChatGenerics>['formatMessage']>} Returns the message, or undefined if the message wasn't found
|
|
919
|
+
*/
|
|
920
|
+
|
|
921
|
+
}, {
|
|
922
|
+
key: "findMessage",
|
|
923
|
+
value: function findMessage(messageId, parentMessageId) {
|
|
924
|
+
if (parentMessageId) {
|
|
925
|
+
var messages = this.threads[parentMessageId];
|
|
926
|
+
|
|
927
|
+
if (!messages) {
|
|
928
|
+
return undefined;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
return messages.find(function (m) {
|
|
932
|
+
return m.id === messageId;
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
var messageSetIndex = this.findMessageSetIndex({
|
|
937
|
+
id: messageId
|
|
938
|
+
});
|
|
939
|
+
|
|
940
|
+
if (messageSetIndex === -1) {
|
|
941
|
+
return undefined;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
return this.messageSets[messageSetIndex].messages.find(function (m) {
|
|
945
|
+
return m.id === messageId;
|
|
946
|
+
});
|
|
947
|
+
}
|
|
908
948
|
}, {
|
|
909
949
|
key: "switchToMessageSet",
|
|
910
950
|
value: function switchToMessageSet(index) {
|
|
@@ -1077,6 +1117,7 @@ var EVENT_MAP = {
|
|
|
1077
1117
|
'user.watching.start': true,
|
|
1078
1118
|
'user.watching.stop': true,
|
|
1079
1119
|
// local events
|
|
1120
|
+
'channels.queried': true,
|
|
1080
1121
|
'connection.changed': true,
|
|
1081
1122
|
'connection.recovered': true,
|
|
1082
1123
|
'transport.changed': true
|
|
@@ -1368,6 +1409,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
1368
1409
|
|
|
1369
1410
|
_defineProperty(this, "initialized", void 0);
|
|
1370
1411
|
|
|
1412
|
+
_defineProperty(this, "staticState", void 0);
|
|
1413
|
+
|
|
1371
1414
|
_defineProperty(this, "lastKeyStroke", void 0);
|
|
1372
1415
|
|
|
1373
1416
|
_defineProperty(this, "lastTypingEvent", void 0);
|
|
@@ -1455,6 +1498,7 @@ var Channel = /*#__PURE__*/function () {
|
|
|
1455
1498
|
|
|
1456
1499
|
this.state = new ChannelState(this);
|
|
1457
1500
|
this.initialized = false;
|
|
1501
|
+
this.staticState = true;
|
|
1458
1502
|
this.lastTypingEvent = null;
|
|
1459
1503
|
this.isTyping = false;
|
|
1460
1504
|
this.disconnected = false;
|
|
@@ -2774,7 +2818,7 @@ var Channel = /*#__PURE__*/function () {
|
|
|
2774
2818
|
*
|
|
2775
2819
|
* @param {ChannelQueryOptions<StreamChatGenerics>} options additional options for the query endpoint
|
|
2776
2820
|
*
|
|
2777
|
-
* @return {Promise<
|
|
2821
|
+
* @return {Promise<QueryChannelAPIResponse<StreamChatGenerics>>} The server response
|
|
2778
2822
|
*/
|
|
2779
2823
|
|
|
2780
2824
|
}, {
|
|
@@ -3077,7 +3121,7 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3077
3121
|
/**
|
|
3078
3122
|
* create - Creates a new channel
|
|
3079
3123
|
*
|
|
3080
|
-
* @return {Promise<
|
|
3124
|
+
* @return {Promise<QueryChannelAPIResponse<StreamChatGenerics>>} The Server Response
|
|
3081
3125
|
*/
|
|
3082
3126
|
|
|
3083
3127
|
}, {
|
|
@@ -3089,7 +3133,7 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3089
3133
|
* @param {ChannelQueryOptions<StreamChatGenerics>} options The query options
|
|
3090
3134
|
* @param {MessageSetType} messageSetToAddToIfDoesNotExist It's possible to load disjunct sets of a channel's messages into state, use `current` to load the initial channel state or if you want to extend the currently displayed messages, use `latest` if you want to load/extend the latest messages, `new` is used for loading a specific message and it's surroundings
|
|
3091
3135
|
*
|
|
3092
|
-
* @return {Promise<
|
|
3136
|
+
* @return {Promise<QueryChannelAPIResponse<StreamChatGenerics>>} Returns a query response
|
|
3093
3137
|
*/
|
|
3094
3138
|
function () {
|
|
3095
3139
|
var _query = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee31(options) {
|
|
@@ -3098,7 +3142,10 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3098
3142
|
state,
|
|
3099
3143
|
membersStr,
|
|
3100
3144
|
tempChannelCid,
|
|
3145
|
+
_this$_initializeStat,
|
|
3146
|
+
messageSet,
|
|
3101
3147
|
_args31 = arguments;
|
|
3148
|
+
|
|
3102
3149
|
return _regeneratorRuntime.wrap(function _callee31$(_context31) {
|
|
3103
3150
|
while (1) {
|
|
3104
3151
|
switch (_context31.prev = _context31.next) {
|
|
@@ -3149,11 +3196,17 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3149
3196
|
this.getClient()._addChannelConfig(state); // add any messages to our channel state
|
|
3150
3197
|
|
|
3151
3198
|
|
|
3152
|
-
this._initializeState(state, messageSetToAddToIfDoesNotExist);
|
|
3153
|
-
|
|
3199
|
+
_this$_initializeStat = this._initializeState(state, messageSetToAddToIfDoesNotExist), messageSet = _this$_initializeStat.messageSet;
|
|
3200
|
+
this.getClient().dispatchEvent({
|
|
3201
|
+
type: 'channels.queried',
|
|
3202
|
+
queriedChannels: {
|
|
3203
|
+
channels: [state],
|
|
3204
|
+
isLatestMessageSet: messageSet.isLatest
|
|
3205
|
+
}
|
|
3206
|
+
});
|
|
3154
3207
|
return _context31.abrupt("return", state);
|
|
3155
3208
|
|
|
3156
|
-
case
|
|
3209
|
+
case 13:
|
|
3157
3210
|
case "end":
|
|
3158
3211
|
return _context31.stop();
|
|
3159
3212
|
}
|
|
@@ -3598,6 +3651,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3598
3651
|
|
|
3599
3652
|
case 'message.deleted':
|
|
3600
3653
|
if (event.message) {
|
|
3654
|
+
this._extendEventWithOwnReactions(event);
|
|
3655
|
+
|
|
3601
3656
|
if (event.hard_delete) channelState.removeMessage(event.message);else channelState.addMessageSorted(event.message, false, false);
|
|
3602
3657
|
channelState.removeQuotedMessageReferences(event.message);
|
|
3603
3658
|
|
|
@@ -3640,6 +3695,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3640
3695
|
|
|
3641
3696
|
case 'message.updated':
|
|
3642
3697
|
if (event.message) {
|
|
3698
|
+
this._extendEventWithOwnReactions(event);
|
|
3699
|
+
|
|
3643
3700
|
channelState.addMessageSorted(event.message, false, false);
|
|
3644
3701
|
|
|
3645
3702
|
if (event.message.pinned) {
|
|
@@ -3752,7 +3809,7 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3752
3809
|
}, {
|
|
3753
3810
|
key: "_checkInitialized",
|
|
3754
3811
|
value: function _checkInitialized() {
|
|
3755
|
-
if (!this.initialized && !this.getClient()._isUsingServerAuth()) {
|
|
3812
|
+
if (!this.initialized && !this.staticState && !this.getClient()._isUsingServerAuth()) {
|
|
3756
3813
|
throw Error("Channel ".concat(this.cid, " hasn't been initialized yet. Make sure to call .watch() and wait for it to resolve"));
|
|
3757
3814
|
}
|
|
3758
3815
|
} // eslint-disable-next-line sonarjs/cognitive-complexity
|
|
@@ -3794,7 +3851,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3794
3851
|
this.state.initMessages();
|
|
3795
3852
|
}
|
|
3796
3853
|
|
|
3797
|
-
this.state.addMessagesSorted(messages, false, true, true, messageSetToAddToIfDoesNotExist)
|
|
3854
|
+
var _this$state$addMessag = this.state.addMessagesSorted(messages, false, true, true, messageSetToAddToIfDoesNotExist),
|
|
3855
|
+
messageSet = _this$state$addMessag.messageSet;
|
|
3798
3856
|
|
|
3799
3857
|
if (!this.state.pinnedMessages) {
|
|
3800
3858
|
this.state.pinnedMessages = [];
|
|
@@ -3883,6 +3941,23 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3883
3941
|
_iterator4.f();
|
|
3884
3942
|
}
|
|
3885
3943
|
}
|
|
3944
|
+
|
|
3945
|
+
return {
|
|
3946
|
+
messageSet: messageSet
|
|
3947
|
+
};
|
|
3948
|
+
}
|
|
3949
|
+
}, {
|
|
3950
|
+
key: "_extendEventWithOwnReactions",
|
|
3951
|
+
value: function _extendEventWithOwnReactions(event) {
|
|
3952
|
+
if (!event.message) {
|
|
3953
|
+
return;
|
|
3954
|
+
}
|
|
3955
|
+
|
|
3956
|
+
var message = this.state.findMessage(event.message.id, event.message.parent_id);
|
|
3957
|
+
|
|
3958
|
+
if (message) {
|
|
3959
|
+
event.message.own_reactions = message.own_reactions;
|
|
3960
|
+
}
|
|
3886
3961
|
}
|
|
3887
3962
|
}, {
|
|
3888
3963
|
key: "_disconnect",
|
|
@@ -4747,12 +4822,12 @@ var StableWSConnection = /*#__PURE__*/function () {
|
|
|
4747
4822
|
key: "_connect",
|
|
4748
4823
|
value: function () {
|
|
4749
4824
|
var _connect3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
|
4750
|
-
var wsURL, response, insights;
|
|
4825
|
+
var isTokenReady, wsURL, response, insights;
|
|
4751
4826
|
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
4752
4827
|
while (1) {
|
|
4753
4828
|
switch (_context5.prev = _context5.next) {
|
|
4754
4829
|
case 0:
|
|
4755
|
-
if (!(this.isConnecting || this.isDisconnected)) {
|
|
4830
|
+
if (!(this.isConnecting || this.isDisconnected && this.client.options.enableWSFallback)) {
|
|
4756
4831
|
_context5.next = 2;
|
|
4757
4832
|
break;
|
|
4758
4833
|
}
|
|
@@ -4764,14 +4839,37 @@ var StableWSConnection = /*#__PURE__*/function () {
|
|
|
4764
4839
|
this.isConnecting = true;
|
|
4765
4840
|
this.requestID = randomId();
|
|
4766
4841
|
this.client.insightMetrics.connectionStartTimestamp = new Date().getTime();
|
|
4767
|
-
|
|
4842
|
+
isTokenReady = false;
|
|
4843
|
+
_context5.prev = 6;
|
|
4768
4844
|
|
|
4769
4845
|
this._log("_connect() - waiting for token");
|
|
4770
4846
|
|
|
4771
|
-
_context5.next =
|
|
4847
|
+
_context5.next = 10;
|
|
4772
4848
|
return this.client.tokenManager.tokenReady();
|
|
4773
4849
|
|
|
4774
|
-
case
|
|
4850
|
+
case 10:
|
|
4851
|
+
isTokenReady = true;
|
|
4852
|
+
_context5.next = 15;
|
|
4853
|
+
break;
|
|
4854
|
+
|
|
4855
|
+
case 13:
|
|
4856
|
+
_context5.prev = 13;
|
|
4857
|
+
_context5.t0 = _context5["catch"](6);
|
|
4858
|
+
|
|
4859
|
+
case 15:
|
|
4860
|
+
_context5.prev = 15;
|
|
4861
|
+
|
|
4862
|
+
if (isTokenReady) {
|
|
4863
|
+
_context5.next = 20;
|
|
4864
|
+
break;
|
|
4865
|
+
}
|
|
4866
|
+
|
|
4867
|
+
this._log("_connect() - tokenProvider failed before, so going to retry");
|
|
4868
|
+
|
|
4869
|
+
_context5.next = 20;
|
|
4870
|
+
return this.client.tokenManager.loadToken();
|
|
4871
|
+
|
|
4872
|
+
case 20:
|
|
4775
4873
|
this._setupConnectionPromise();
|
|
4776
4874
|
|
|
4777
4875
|
wsURL = this._buildUrl();
|
|
@@ -4786,15 +4884,15 @@ var StableWSConnection = /*#__PURE__*/function () {
|
|
|
4786
4884
|
this.ws.onclose = this.onclose.bind(this, this.wsID);
|
|
4787
4885
|
this.ws.onerror = this.onerror.bind(this, this.wsID);
|
|
4788
4886
|
this.ws.onmessage = this.onmessage.bind(this, this.wsID);
|
|
4789
|
-
_context5.next =
|
|
4887
|
+
_context5.next = 30;
|
|
4790
4888
|
return this.connectionOpen;
|
|
4791
4889
|
|
|
4792
|
-
case
|
|
4890
|
+
case 30:
|
|
4793
4891
|
response = _context5.sent;
|
|
4794
4892
|
this.isConnecting = false;
|
|
4795
4893
|
|
|
4796
4894
|
if (!response) {
|
|
4797
|
-
_context5.next =
|
|
4895
|
+
_context5.next = 36;
|
|
4798
4896
|
break;
|
|
4799
4897
|
}
|
|
4800
4898
|
|
|
@@ -4807,30 +4905,32 @@ var StableWSConnection = /*#__PURE__*/function () {
|
|
|
4807
4905
|
|
|
4808
4906
|
return _context5.abrupt("return", response);
|
|
4809
4907
|
|
|
4810
|
-
case
|
|
4811
|
-
_context5.next =
|
|
4908
|
+
case 36:
|
|
4909
|
+
_context5.next = 44;
|
|
4812
4910
|
break;
|
|
4813
4911
|
|
|
4814
|
-
case
|
|
4815
|
-
_context5.prev =
|
|
4816
|
-
_context5.
|
|
4912
|
+
case 38:
|
|
4913
|
+
_context5.prev = 38;
|
|
4914
|
+
_context5.t1 = _context5["catch"](15);
|
|
4817
4915
|
this.isConnecting = false;
|
|
4818
4916
|
|
|
4917
|
+
this._log("_connect() - Error - ", _context5.t1);
|
|
4918
|
+
|
|
4819
4919
|
if (this.client.options.enableInsights) {
|
|
4820
4920
|
this.client.insightMetrics.wsConsecutiveFailures++;
|
|
4821
4921
|
this.client.insightMetrics.wsTotalFailures++;
|
|
4822
|
-
insights = buildWsFatalInsight(this, convertErrorToJson(_context5.
|
|
4922
|
+
insights = buildWsFatalInsight(this, convertErrorToJson(_context5.t1));
|
|
4823
4923
|
postInsights === null || postInsights === void 0 ? void 0 : postInsights('ws_fatal', insights);
|
|
4824
4924
|
}
|
|
4825
4925
|
|
|
4826
|
-
throw _context5.
|
|
4926
|
+
throw _context5.t1;
|
|
4827
4927
|
|
|
4828
|
-
case
|
|
4928
|
+
case 44:
|
|
4829
4929
|
case "end":
|
|
4830
4930
|
return _context5.stop();
|
|
4831
4931
|
}
|
|
4832
4932
|
}
|
|
4833
|
-
}, _callee5, this, [[
|
|
4933
|
+
}, _callee5, this, [[6, 13], [15, 38]]);
|
|
4834
4934
|
}));
|
|
4835
4935
|
|
|
4836
4936
|
function _connect() {
|
|
@@ -4897,7 +4997,7 @@ var StableWSConnection = /*#__PURE__*/function () {
|
|
|
4897
4997
|
return _context6.abrupt("return");
|
|
4898
4998
|
|
|
4899
4999
|
case 12:
|
|
4900
|
-
if (!this.isDisconnected) {
|
|
5000
|
+
if (!(this.isDisconnected && this.client.options.enableWSFallback)) {
|
|
4901
5001
|
_context6.next = 15;
|
|
4902
5002
|
break;
|
|
4903
5003
|
}
|
|
@@ -5913,7 +6013,8 @@ function isString(x) {
|
|
|
5913
6013
|
|
|
5914
6014
|
var StreamChat = /*#__PURE__*/function () {
|
|
5915
6015
|
function StreamChat(_key, secretOrOptions, _options) {
|
|
5916
|
-
var _this = this
|
|
6016
|
+
var _this = this,
|
|
6017
|
+
_this$options;
|
|
5917
6018
|
|
|
5918
6019
|
_classCallCheck(this, StreamChat);
|
|
5919
6020
|
|
|
@@ -5923,6 +6024,8 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
5923
6024
|
|
|
5924
6025
|
_defineProperty(this, "anonymous", void 0);
|
|
5925
6026
|
|
|
6027
|
+
_defineProperty(this, "persistUserOnConnectionFailure", void 0);
|
|
6028
|
+
|
|
5926
6029
|
_defineProperty(this, "axiosInstance", void 0);
|
|
5927
6030
|
|
|
5928
6031
|
_defineProperty(this, "baseURL", void 0);
|
|
@@ -6050,8 +6153,12 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6050
6153
|
_context.prev = 20;
|
|
6051
6154
|
_context.t0 = _context["catch"](14);
|
|
6052
6155
|
|
|
6053
|
-
|
|
6054
|
-
|
|
6156
|
+
if (_this.persistUserOnConnectionFailure) {
|
|
6157
|
+
// cleanup client to allow the user to retry connectUser again
|
|
6158
|
+
_this.closeConnection();
|
|
6159
|
+
} else {
|
|
6160
|
+
_this.disconnectUser();
|
|
6161
|
+
}
|
|
6055
6162
|
|
|
6056
6163
|
throw _context.t0;
|
|
6057
6164
|
|
|
@@ -6728,7 +6835,8 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6728
6835
|
this.activeChannels = {}; // mapping between channel groups and configs
|
|
6729
6836
|
|
|
6730
6837
|
this.configs = {};
|
|
6731
|
-
this.anonymous = false;
|
|
6838
|
+
this.anonymous = false;
|
|
6839
|
+
this.persistUserOnConnectionFailure = (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.persistUserOnConnectionFailure; // If its a server-side client, then lets initialize the tokenManager, since token will be
|
|
6732
6840
|
// generated from secret.
|
|
6733
6841
|
|
|
6734
6842
|
this.tokenManager = new TokenManager(this.secret);
|
|
@@ -6837,7 +6945,8 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6837
6945
|
* This one is used by the frontend. This is a copy of the current user object stored on backend.
|
|
6838
6946
|
* It contains reserved properties and own user properties which are not present in `this._user`.
|
|
6839
6947
|
*/
|
|
6840
|
-
this.user = user;
|
|
6948
|
+
this.user = user;
|
|
6949
|
+
this.userID = user.id; // this one is actually used for requests. This is a copy of current user provided to `connectUser` function.
|
|
6841
6950
|
|
|
6842
6951
|
this._user = _objectSpread({}, user);
|
|
6843
6952
|
}
|
|
@@ -7869,20 +7978,10 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7869
7978
|
var sort,
|
|
7870
7979
|
options,
|
|
7871
7980
|
stateOptions,
|
|
7872
|
-
skipInitialization,
|
|
7873
7981
|
defaultOptions,
|
|
7874
7982
|
payload,
|
|
7875
7983
|
data,
|
|
7876
|
-
channels,
|
|
7877
|
-
_iterator2,
|
|
7878
|
-
_step2,
|
|
7879
|
-
channelState,
|
|
7880
|
-
_iterator3,
|
|
7881
|
-
_step3,
|
|
7882
|
-
_channelState,
|
|
7883
|
-
c,
|
|
7884
7984
|
_args19 = arguments;
|
|
7885
|
-
|
|
7886
7985
|
return _regeneratorRuntime.wrap(function _callee19$(_context19) {
|
|
7887
7986
|
while (1) {
|
|
7888
7987
|
switch (_context19.prev = _context19.next) {
|
|
@@ -7890,17 +7989,16 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7890
7989
|
sort = _args19.length > 1 && _args19[1] !== undefined ? _args19[1] : [];
|
|
7891
7990
|
options = _args19.length > 2 && _args19[2] !== undefined ? _args19[2] : {};
|
|
7892
7991
|
stateOptions = _args19.length > 3 && _args19[3] !== undefined ? _args19[3] : {};
|
|
7893
|
-
skipInitialization = stateOptions.skipInitialization;
|
|
7894
7992
|
defaultOptions = {
|
|
7895
7993
|
state: true,
|
|
7896
7994
|
watch: true,
|
|
7897
7995
|
presence: false
|
|
7898
7996
|
}; // Make sure we wait for the connect promise if there is a pending one
|
|
7899
7997
|
|
|
7900
|
-
_context19.next =
|
|
7998
|
+
_context19.next = 6;
|
|
7901
7999
|
return this.setUserPromise;
|
|
7902
8000
|
|
|
7903
|
-
case
|
|
8001
|
+
case 6:
|
|
7904
8002
|
if (!this._hasConnectionID()) {
|
|
7905
8003
|
defaultOptions.watch = false;
|
|
7906
8004
|
} // Return a list of channels
|
|
@@ -7910,55 +8008,21 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7910
8008
|
filter_conditions: filterConditions,
|
|
7911
8009
|
sort: normalizeQuerySort(sort)
|
|
7912
8010
|
}, defaultOptions), options);
|
|
7913
|
-
_context19.next =
|
|
8011
|
+
_context19.next = 10;
|
|
7914
8012
|
return this.post(this.baseURL + '/channels', payload);
|
|
7915
8013
|
|
|
7916
|
-
case
|
|
8014
|
+
case 10:
|
|
7917
8015
|
data = _context19.sent;
|
|
7918
|
-
|
|
7919
|
-
|
|
7920
|
-
|
|
7921
|
-
|
|
7922
|
-
|
|
7923
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
7924
|
-
channelState = _step2.value;
|
|
7925
|
-
|
|
7926
|
-
this._addChannelConfig(channelState);
|
|
7927
|
-
}
|
|
7928
|
-
} catch (err) {
|
|
7929
|
-
_iterator2.e(err);
|
|
7930
|
-
} finally {
|
|
7931
|
-
_iterator2.f();
|
|
7932
|
-
}
|
|
7933
|
-
|
|
7934
|
-
_iterator3 = _createForOfIteratorHelper(data.channels);
|
|
7935
|
-
|
|
7936
|
-
try {
|
|
7937
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
7938
|
-
_channelState = _step3.value;
|
|
7939
|
-
c = this.channel(_channelState.channel.type, _channelState.channel.id);
|
|
7940
|
-
c.data = _channelState.channel;
|
|
7941
|
-
c.initialized = true;
|
|
7942
|
-
|
|
7943
|
-
if (skipInitialization === undefined) {
|
|
7944
|
-
c._initializeState(_channelState, 'latest');
|
|
7945
|
-
} else if (!skipInitialization.includes(_channelState.channel.id)) {
|
|
7946
|
-
c.state.clearMessages();
|
|
7947
|
-
|
|
7948
|
-
c._initializeState(_channelState, 'latest');
|
|
7949
|
-
}
|
|
7950
|
-
|
|
7951
|
-
channels.push(c);
|
|
8016
|
+
this.dispatchEvent({
|
|
8017
|
+
type: 'channels.queried',
|
|
8018
|
+
queriedChannels: {
|
|
8019
|
+
channels: data.channels,
|
|
8020
|
+
isLatestMessageSet: true
|
|
7952
8021
|
}
|
|
7953
|
-
}
|
|
7954
|
-
|
|
7955
|
-
} finally {
|
|
7956
|
-
_iterator3.f();
|
|
7957
|
-
}
|
|
7958
|
-
|
|
7959
|
-
return _context19.abrupt("return", channels);
|
|
8022
|
+
});
|
|
8023
|
+
return _context19.abrupt("return", this.hydrateActiveChannels(data.channels, stateOptions));
|
|
7960
8024
|
|
|
7961
|
-
case
|
|
8025
|
+
case 13:
|
|
7962
8026
|
case "end":
|
|
7963
8027
|
return _context19.stop();
|
|
7964
8028
|
}
|
|
@@ -7972,6 +8036,73 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7972
8036
|
|
|
7973
8037
|
return queryChannels;
|
|
7974
8038
|
}()
|
|
8039
|
+
}, {
|
|
8040
|
+
key: "hydrateActiveChannels",
|
|
8041
|
+
value: function hydrateActiveChannels() {
|
|
8042
|
+
var channelsFromApi = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
8043
|
+
var stateOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
8044
|
+
var skipInitialization = stateOptions.skipInitialization,
|
|
8045
|
+
_stateOptions$staticS = stateOptions.staticState,
|
|
8046
|
+
staticState = _stateOptions$staticS === void 0 ? false : _stateOptions$staticS;
|
|
8047
|
+
|
|
8048
|
+
var _iterator2 = _createForOfIteratorHelper(channelsFromApi),
|
|
8049
|
+
_step2;
|
|
8050
|
+
|
|
8051
|
+
try {
|
|
8052
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
8053
|
+
var channelState = _step2.value;
|
|
8054
|
+
|
|
8055
|
+
this._addChannelConfig(channelState);
|
|
8056
|
+
}
|
|
8057
|
+
} catch (err) {
|
|
8058
|
+
_iterator2.e(err);
|
|
8059
|
+
} finally {
|
|
8060
|
+
_iterator2.f();
|
|
8061
|
+
}
|
|
8062
|
+
|
|
8063
|
+
var channels = [];
|
|
8064
|
+
|
|
8065
|
+
var _iterator3 = _createForOfIteratorHelper(channelsFromApi),
|
|
8066
|
+
_step3;
|
|
8067
|
+
|
|
8068
|
+
try {
|
|
8069
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
8070
|
+
var _channelState = _step3.value;
|
|
8071
|
+
var c = this.channel(_channelState.channel.type, _channelState.channel.id);
|
|
8072
|
+
c.data = _channelState.channel;
|
|
8073
|
+
c.staticState = staticState;
|
|
8074
|
+
c.initialized = !staticState;
|
|
8075
|
+
|
|
8076
|
+
if (skipInitialization === undefined) {
|
|
8077
|
+
c._initializeState(_channelState, 'latest');
|
|
8078
|
+
} else if (!skipInitialization.includes(_channelState.channel.id)) {
|
|
8079
|
+
c.state.clearMessages();
|
|
8080
|
+
|
|
8081
|
+
c._initializeState(_channelState, 'latest');
|
|
8082
|
+
}
|
|
8083
|
+
|
|
8084
|
+
channels.push(c);
|
|
8085
|
+
}
|
|
8086
|
+
} catch (err) {
|
|
8087
|
+
_iterator3.e(err);
|
|
8088
|
+
} finally {
|
|
8089
|
+
_iterator3.f();
|
|
8090
|
+
}
|
|
8091
|
+
|
|
8092
|
+
if (!staticState) {
|
|
8093
|
+
// If the channels are coming from server, then clear out the
|
|
8094
|
+
// previously help offline channels.
|
|
8095
|
+
for (var _key5 in this.activeChannels) {
|
|
8096
|
+
var _channel7 = this.activeChannels[_key5];
|
|
8097
|
+
|
|
8098
|
+
if (_channel7.staticState) {
|
|
8099
|
+
delete this.activeChannels[_key5];
|
|
8100
|
+
}
|
|
8101
|
+
}
|
|
8102
|
+
}
|
|
8103
|
+
|
|
8104
|
+
return channels;
|
|
8105
|
+
}
|
|
7975
8106
|
/**
|
|
7976
8107
|
* search - Query messages
|
|
7977
8108
|
*
|
|
@@ -9722,7 +9853,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
9722
9853
|
}, {
|
|
9723
9854
|
key: "getUserAgent",
|
|
9724
9855
|
value: function getUserAgent() {
|
|
9725
|
-
return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "
|
|
9856
|
+
return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "7.0.0-offline-support.2");
|
|
9726
9857
|
}
|
|
9727
9858
|
}, {
|
|
9728
9859
|
key: "setUserAgent",
|
|
@@ -9786,9 +9917,9 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
9786
9917
|
this.cleaningIntervalRef = setInterval(function () {
|
|
9787
9918
|
// call clean on the channel, used for calling the stop.typing event etc.
|
|
9788
9919
|
for (var _i3 = 0, _Object$values2 = Object.values(that.activeChannels); _i3 < _Object$values2.length; _i3++) {
|
|
9789
|
-
var
|
|
9920
|
+
var _channel8 = _Object$values2[_i3];
|
|
9790
9921
|
|
|
9791
|
-
|
|
9922
|
+
_channel8.clean();
|
|
9792
9923
|
}
|
|
9793
9924
|
}, 500);
|
|
9794
9925
|
}
|