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/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 = [];
|
|
@@ -831,40 +834,46 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
831
834
|
var _loadMessageIntoState = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(messageId, parentMessageId) {
|
|
832
835
|
var _this$threads$parentM;
|
|
833
836
|
|
|
834
|
-
var
|
|
837
|
+
var limit,
|
|
838
|
+
messageSetIndex,
|
|
839
|
+
switchedToMessageSet,
|
|
840
|
+
loadedMessageThread,
|
|
841
|
+
messageIdToFind,
|
|
842
|
+
_args = arguments;
|
|
835
843
|
return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
|
|
836
844
|
while (1) {
|
|
837
845
|
switch (_context.prev = _context.next) {
|
|
838
846
|
case 0:
|
|
847
|
+
limit = _args.length > 2 && _args[2] !== undefined ? _args[2] : 25;
|
|
839
848
|
switchedToMessageSet = false;
|
|
840
849
|
loadedMessageThread = false;
|
|
841
850
|
messageIdToFind = parentMessageId || messageId;
|
|
842
851
|
|
|
843
852
|
if (!(messageId === 'latest')) {
|
|
844
|
-
_context.next =
|
|
853
|
+
_context.next = 10;
|
|
845
854
|
break;
|
|
846
855
|
}
|
|
847
856
|
|
|
848
857
|
if (!(this.messages === this.latestMessages)) {
|
|
849
|
-
_context.next =
|
|
858
|
+
_context.next = 7;
|
|
850
859
|
break;
|
|
851
860
|
}
|
|
852
861
|
|
|
853
862
|
return _context.abrupt("return");
|
|
854
863
|
|
|
855
|
-
case
|
|
864
|
+
case 7:
|
|
856
865
|
messageSetIndex = this.messageSets.findIndex(function (s) {
|
|
857
866
|
return s.isLatest;
|
|
858
867
|
});
|
|
859
|
-
_context.next =
|
|
868
|
+
_context.next = 11;
|
|
860
869
|
break;
|
|
861
870
|
|
|
862
|
-
case
|
|
871
|
+
case 10:
|
|
863
872
|
messageSetIndex = this.findMessageSetIndex({
|
|
864
873
|
id: messageIdToFind
|
|
865
874
|
});
|
|
866
875
|
|
|
867
|
-
case
|
|
876
|
+
case 11:
|
|
868
877
|
if (messageSetIndex !== -1) {
|
|
869
878
|
this.switchToMessageSet(messageSetIndex);
|
|
870
879
|
switchedToMessageSet = true;
|
|
@@ -875,39 +884,39 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
875
884
|
}));
|
|
876
885
|
|
|
877
886
|
if (!(switchedToMessageSet && loadedMessageThread)) {
|
|
878
|
-
_context.next =
|
|
887
|
+
_context.next = 15;
|
|
879
888
|
break;
|
|
880
889
|
}
|
|
881
890
|
|
|
882
891
|
return _context.abrupt("return");
|
|
883
892
|
|
|
884
|
-
case
|
|
893
|
+
case 15:
|
|
885
894
|
if (switchedToMessageSet) {
|
|
886
|
-
_context.next =
|
|
895
|
+
_context.next = 18;
|
|
887
896
|
break;
|
|
888
897
|
}
|
|
889
898
|
|
|
890
|
-
_context.next =
|
|
899
|
+
_context.next = 18;
|
|
891
900
|
return this._channel.query({
|
|
892
901
|
messages: {
|
|
893
902
|
id_around: messageIdToFind,
|
|
894
|
-
limit:
|
|
903
|
+
limit: limit
|
|
895
904
|
}
|
|
896
905
|
}, 'new');
|
|
897
906
|
|
|
898
|
-
case
|
|
907
|
+
case 18:
|
|
899
908
|
if (!(!loadedMessageThread && parentMessageId)) {
|
|
900
|
-
_context.next =
|
|
909
|
+
_context.next = 21;
|
|
901
910
|
break;
|
|
902
911
|
}
|
|
903
912
|
|
|
904
|
-
_context.next =
|
|
913
|
+
_context.next = 21;
|
|
905
914
|
return this._channel.getReplies(parentMessageId, {
|
|
906
915
|
id_around: messageId,
|
|
907
|
-
limit:
|
|
916
|
+
limit: limit
|
|
908
917
|
});
|
|
909
918
|
|
|
910
|
-
case
|
|
919
|
+
case 21:
|
|
911
920
|
messageSetIndex = this.findMessageSetIndex({
|
|
912
921
|
id: messageIdToFind
|
|
913
922
|
});
|
|
@@ -916,7 +925,7 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
916
925
|
this.switchToMessageSet(messageSetIndex);
|
|
917
926
|
}
|
|
918
927
|
|
|
919
|
-
case
|
|
928
|
+
case 23:
|
|
920
929
|
case "end":
|
|
921
930
|
return _context.stop();
|
|
922
931
|
}
|
|
@@ -930,6 +939,42 @@ var ChannelState = /*#__PURE__*/function () {
|
|
|
930
939
|
|
|
931
940
|
return loadMessageIntoState;
|
|
932
941
|
}()
|
|
942
|
+
/**
|
|
943
|
+
* findMessage - Finds a message inside the state
|
|
944
|
+
*
|
|
945
|
+
* @param {string} messageId The id of the message
|
|
946
|
+
* @param {string} parentMessageId The id of the parent message, if we want load a thread reply
|
|
947
|
+
*
|
|
948
|
+
* @return {ReturnType<ChannelState<StreamChatGenerics>['formatMessage']>} Returns the message, or undefined if the message wasn't found
|
|
949
|
+
*/
|
|
950
|
+
|
|
951
|
+
}, {
|
|
952
|
+
key: "findMessage",
|
|
953
|
+
value: function findMessage(messageId, parentMessageId) {
|
|
954
|
+
if (parentMessageId) {
|
|
955
|
+
var messages = this.threads[parentMessageId];
|
|
956
|
+
|
|
957
|
+
if (!messages) {
|
|
958
|
+
return undefined;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
return messages.find(function (m) {
|
|
962
|
+
return m.id === messageId;
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
var messageSetIndex = this.findMessageSetIndex({
|
|
967
|
+
id: messageId
|
|
968
|
+
});
|
|
969
|
+
|
|
970
|
+
if (messageSetIndex === -1) {
|
|
971
|
+
return undefined;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
return this.messageSets[messageSetIndex].messages.find(function (m) {
|
|
975
|
+
return m.id === messageId;
|
|
976
|
+
});
|
|
977
|
+
}
|
|
933
978
|
}, {
|
|
934
979
|
key: "switchToMessageSet",
|
|
935
980
|
value: function switchToMessageSet(index) {
|
|
@@ -1518,6 +1563,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
1518
1563
|
* @param {Message<StreamChatGenerics>} message The Message object
|
|
1519
1564
|
* @param {boolean} [options.skip_enrich_url] Do not try to enrich the URLs within message
|
|
1520
1565
|
* @param {boolean} [options.skip_push] Skip sending push notifications
|
|
1566
|
+
* @param {boolean} [options.is_pending_message] Make this message pending
|
|
1567
|
+
* @param {Record<string,string>} [options.pending_message_metadata] Metadata for the pending message
|
|
1521
1568
|
*
|
|
1522
1569
|
* @return {Promise<SendMessageAPIResponse<StreamChatGenerics>>} The Server Response
|
|
1523
1570
|
*/
|
|
@@ -1924,6 +1971,7 @@ var Channel = /*#__PURE__*/function () {
|
|
|
1924
1971
|
key: "updatePartial",
|
|
1925
1972
|
value: function () {
|
|
1926
1973
|
var _updatePartial = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee8(update) {
|
|
1974
|
+
var data;
|
|
1927
1975
|
return _regeneratorRuntime__default['default'].wrap(function _callee8$(_context8) {
|
|
1928
1976
|
while (1) {
|
|
1929
1977
|
switch (_context8.prev = _context8.next) {
|
|
@@ -1932,9 +1980,11 @@ var Channel = /*#__PURE__*/function () {
|
|
|
1932
1980
|
return this.getClient().patch(this._channelURL(), update);
|
|
1933
1981
|
|
|
1934
1982
|
case 2:
|
|
1935
|
-
|
|
1983
|
+
data = _context8.sent;
|
|
1984
|
+
this.data = data.channel;
|
|
1985
|
+
return _context8.abrupt("return", data);
|
|
1936
1986
|
|
|
1937
|
-
case
|
|
1987
|
+
case 5:
|
|
1938
1988
|
case "end":
|
|
1939
1989
|
return _context8.stop();
|
|
1940
1990
|
}
|
|
@@ -3176,9 +3226,10 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3176
3226
|
|
|
3177
3227
|
this._initializeState(state, messageSetToAddToIfDoesNotExist);
|
|
3178
3228
|
|
|
3229
|
+
this.data = state.channel;
|
|
3179
3230
|
return _context31.abrupt("return", state);
|
|
3180
3231
|
|
|
3181
|
-
case
|
|
3232
|
+
case 13:
|
|
3182
3233
|
case "end":
|
|
3183
3234
|
return _context31.stop();
|
|
3184
3235
|
}
|
|
@@ -3623,6 +3674,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3623
3674
|
|
|
3624
3675
|
case 'message.deleted':
|
|
3625
3676
|
if (event.message) {
|
|
3677
|
+
this._extendEventWithOwnReactions(event);
|
|
3678
|
+
|
|
3626
3679
|
if (event.hard_delete) channelState.removeMessage(event.message);else channelState.addMessageSorted(event.message, false, false);
|
|
3627
3680
|
channelState.removeQuotedMessageReferences(event.message);
|
|
3628
3681
|
|
|
@@ -3665,6 +3718,8 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3665
3718
|
|
|
3666
3719
|
case 'message.updated':
|
|
3667
3720
|
if (event.message) {
|
|
3721
|
+
this._extendEventWithOwnReactions(event);
|
|
3722
|
+
|
|
3668
3723
|
channelState.addMessageSorted(event.message, false, false);
|
|
3669
3724
|
|
|
3670
3725
|
if (event.message.pinned) {
|
|
@@ -3826,6 +3881,11 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3826
3881
|
}
|
|
3827
3882
|
|
|
3828
3883
|
this.state.addPinnedMessages(state.pinned_messages || []);
|
|
3884
|
+
|
|
3885
|
+
if (state.pending_messages) {
|
|
3886
|
+
this.state.pending_messages = state.pending_messages;
|
|
3887
|
+
}
|
|
3888
|
+
|
|
3829
3889
|
this.state.watcher_count = state.watcher_count || 0; // convert the arrays into objects for easier syncing...
|
|
3830
3890
|
|
|
3831
3891
|
if (state.watchers) {
|
|
@@ -3909,6 +3969,19 @@ var Channel = /*#__PURE__*/function () {
|
|
|
3909
3969
|
}
|
|
3910
3970
|
}
|
|
3911
3971
|
}
|
|
3972
|
+
}, {
|
|
3973
|
+
key: "_extendEventWithOwnReactions",
|
|
3974
|
+
value: function _extendEventWithOwnReactions(event) {
|
|
3975
|
+
if (!event.message) {
|
|
3976
|
+
return;
|
|
3977
|
+
}
|
|
3978
|
+
|
|
3979
|
+
var message = this.state.findMessage(event.message.id, event.message.parent_id);
|
|
3980
|
+
|
|
3981
|
+
if (message) {
|
|
3982
|
+
event.message.own_reactions = message.own_reactions;
|
|
3983
|
+
}
|
|
3984
|
+
}
|
|
3912
3985
|
}, {
|
|
3913
3986
|
key: "_disconnect",
|
|
3914
3987
|
value: function _disconnect() {
|
|
@@ -4484,6 +4557,11 @@ var StableWSConnection = /*#__PURE__*/function () {
|
|
|
4484
4557
|
tags: ['connection']
|
|
4485
4558
|
}, extra));
|
|
4486
4559
|
}
|
|
4560
|
+
}, {
|
|
4561
|
+
key: "setClient",
|
|
4562
|
+
value: function setClient(client) {
|
|
4563
|
+
this.client = client;
|
|
4564
|
+
}
|
|
4487
4565
|
/**
|
|
4488
4566
|
* connect - Connect to the WS URL
|
|
4489
4567
|
* the default 15s timeout allows between 2~3 tries
|
|
@@ -6146,7 +6224,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6146
6224
|
throw Error('User is not set on client, use client.connectUser or client.connectAnonymousUser instead');
|
|
6147
6225
|
|
|
6148
6226
|
case 2:
|
|
6149
|
-
if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting)) {
|
|
6227
|
+
if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting && _this.wsPromise)) {
|
|
6150
6228
|
_context3.next = 5;
|
|
6151
6229
|
break;
|
|
6152
6230
|
}
|
|
@@ -6155,7 +6233,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6155
6233
|
tags: ['connection', 'client']
|
|
6156
6234
|
});
|
|
6157
6235
|
|
|
6158
|
-
return _context3.abrupt("return",
|
|
6236
|
+
return _context3.abrupt("return", _this.wsPromise);
|
|
6159
6237
|
|
|
6160
6238
|
case 5:
|
|
6161
6239
|
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())) {
|
|
@@ -6911,23 +6989,28 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
6911
6989
|
*/
|
|
6912
6990
|
function () {
|
|
6913
6991
|
var _updateAppSettings = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee7(options) {
|
|
6914
|
-
var
|
|
6915
|
-
|
|
6992
|
+
var apn_config;
|
|
6916
6993
|
return _regeneratorRuntime__default['default'].wrap(function _callee7$(_context7) {
|
|
6917
6994
|
while (1) {
|
|
6918
6995
|
switch (_context7.prev = _context7.next) {
|
|
6919
6996
|
case 0:
|
|
6920
|
-
|
|
6921
|
-
|
|
6997
|
+
apn_config = options.apn_config;
|
|
6998
|
+
|
|
6999
|
+
if (apn_config !== null && apn_config !== void 0 && apn_config.p12_cert) {
|
|
7000
|
+
options = _objectSpread(_objectSpread({}, options), {}, {
|
|
7001
|
+
apn_config: _objectSpread(_objectSpread({}, apn_config), {}, {
|
|
7002
|
+
p12_cert: Buffer.from(apn_config.p12_cert).toString('base64')
|
|
7003
|
+
})
|
|
7004
|
+
});
|
|
6922
7005
|
}
|
|
6923
7006
|
|
|
6924
|
-
_context7.next =
|
|
7007
|
+
_context7.next = 4;
|
|
6925
7008
|
return this.patch(this.baseURL + '/app', options);
|
|
6926
7009
|
|
|
6927
|
-
case
|
|
7010
|
+
case 4:
|
|
6928
7011
|
return _context7.abrupt("return", _context7.sent);
|
|
6929
7012
|
|
|
6930
|
-
case
|
|
7013
|
+
case 5:
|
|
6931
7014
|
case "end":
|
|
6932
7015
|
return _context7.stop();
|
|
6933
7016
|
}
|
|
@@ -7615,9 +7698,16 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7615
7698
|
} // The StableWSConnection handles all the reconnection logic.
|
|
7616
7699
|
|
|
7617
7700
|
|
|
7618
|
-
this.wsConnection
|
|
7619
|
-
|
|
7620
|
-
|
|
7701
|
+
if (this.options.wsConnection && this.node) {
|
|
7702
|
+
// Intentionally avoiding adding ts generics on wsConnection in options since its only useful for unit test purpose.
|
|
7703
|
+
this.options.wsConnection.setClient(this);
|
|
7704
|
+
this.wsConnection = this.options.wsConnection;
|
|
7705
|
+
} else {
|
|
7706
|
+
this.wsConnection = new StableWSConnection({
|
|
7707
|
+
client: this
|
|
7708
|
+
});
|
|
7709
|
+
}
|
|
7710
|
+
|
|
7621
7711
|
_context15.prev = 8;
|
|
7622
7712
|
|
|
7623
7713
|
if (!this.wsFallback) {
|
|
@@ -7743,7 +7833,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7743
7833
|
}; // Make sure we wait for the connect promise if there is a pending one
|
|
7744
7834
|
|
|
7745
7835
|
_context16.next = 5;
|
|
7746
|
-
return this.
|
|
7836
|
+
return this.wsPromise;
|
|
7747
7837
|
|
|
7748
7838
|
case 5:
|
|
7749
7839
|
if (!this._hasConnectionID()) {
|
|
@@ -7923,7 +8013,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
7923
8013
|
}; // Make sure we wait for the connect promise if there is a pending one
|
|
7924
8014
|
|
|
7925
8015
|
_context19.next = 7;
|
|
7926
|
-
return this.
|
|
8016
|
+
return this.wsPromise;
|
|
7927
8017
|
|
|
7928
8018
|
case 7:
|
|
7929
8019
|
if (!this._hasConnectionID()) {
|
|
@@ -8058,7 +8148,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
8058
8148
|
|
|
8059
8149
|
case 13:
|
|
8060
8150
|
_context20.next = 15;
|
|
8061
|
-
return this.
|
|
8151
|
+
return this.wsPromise;
|
|
8062
8152
|
|
|
8063
8153
|
case 15:
|
|
8064
8154
|
_context20.next = 17;
|
|
@@ -9747,7 +9837,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
9747
9837
|
}, {
|
|
9748
9838
|
key: "getUserAgent",
|
|
9749
9839
|
value: function getUserAgent() {
|
|
9750
|
-
return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.
|
|
9840
|
+
return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.9.0");
|
|
9751
9841
|
}
|
|
9752
9842
|
}, {
|
|
9753
9843
|
key: "setUserAgent",
|
|
@@ -9920,15 +10010,19 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
9920
10010
|
/** sync - returns all events that happened for a list of channels since last sync
|
|
9921
10011
|
* @param {string[]} channel_cids list of channel CIDs
|
|
9922
10012
|
* @param {string} last_sync_at last time the user was online and in sync. RFC3339 ie. "2020-05-06T15:05:01.207Z"
|
|
10013
|
+
* @param {SyncOptions} options See JSDoc in the type fields for more info
|
|
10014
|
+
*
|
|
10015
|
+
* @returns {Promise<SyncResponse>}
|
|
9923
10016
|
*/
|
|
9924
10017
|
|
|
9925
10018
|
}, {
|
|
9926
10019
|
key: "sync",
|
|
9927
10020
|
value: function sync(channel_cids, last_sync_at) {
|
|
9928
|
-
|
|
10021
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
10022
|
+
return this.post("".concat(this.baseURL, "/sync"), _objectSpread({
|
|
9929
10023
|
channel_cids: channel_cids,
|
|
9930
10024
|
last_sync_at: last_sync_at
|
|
9931
|
-
});
|
|
10025
|
+
}, options));
|
|
9932
10026
|
}
|
|
9933
10027
|
/**
|
|
9934
10028
|
* sendUserCustomEvent - Send a custom event to a user
|