stream-chat-react 10.10.1 → 10.10.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/index.d.ts CHANGED
@@ -2,4 +2,5 @@ export * from './components';
2
2
  export * from './context';
3
3
  export * from './i18n';
4
4
  export * from './utils';
5
+ export { getChannel } from './utils/getChannel';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AAEvB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AAEvB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -3,3 +3,4 @@ export * from './context';
3
3
  export * from './i18n';
4
4
  // todo: distribute utils into separate files
5
5
  export * from './utils';
6
+ export { getChannel } from './utils/getChannel';
@@ -0,0 +1,20 @@
1
+ import type { Channel, StreamChat } from 'stream-chat';
2
+ import type { DefaultStreamChatGenerics } from '../types/types';
3
+ declare type GetChannelParams<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = {
4
+ client: StreamChat<StreamChatGenerics>;
5
+ channel?: Channel<StreamChatGenerics>;
6
+ id?: string;
7
+ members?: string[];
8
+ type?: string;
9
+ };
10
+ /**
11
+ * Calls channel.watch() if it was not already recently called. Waits for watch promise to resolve even if it was invoked previously.
12
+ * @param client
13
+ * @param members
14
+ * @param type
15
+ * @param id
16
+ * @param channel
17
+ */
18
+ export declare const getChannel: <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>({ channel, client, id, members, type, }: GetChannelParams<StreamChatGenerics>) => Promise<Channel<StreamChatGenerics>>;
19
+ export {};
20
+ //# sourceMappingURL=getChannel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getChannel.d.ts","sourceRoot":"","sources":["../../src/utils/getChannel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAA2B,UAAU,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAWhE,aAAK,gBAAgB,CACnB,kBAAkB,SAAS,yBAAyB,GAAG,yBAAyB,IAC9E;IACF,MAAM,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC;IACvC,OAAO,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACtC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AACF;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,2MAuCtB,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { __awaiter, __generator, __spreadArray } from "tslib";
2
+ /**
3
+ * prevent from duplicate invocation of channel.watch()
4
+ * when events 'notification.message_new' and 'notification.added_to_channel' arrive at the same time
5
+ */
6
+ var WATCH_QUERY_IN_PROGRESS_FOR_CHANNEL = {};
7
+ /**
8
+ * Calls channel.watch() if it was not already recently called. Waits for watch promise to resolve even if it was invoked previously.
9
+ * @param client
10
+ * @param members
11
+ * @param type
12
+ * @param id
13
+ * @param channel
14
+ */
15
+ export var getChannel = function (_a) {
16
+ var channel = _a.channel, client = _a.client, id = _a.id, members = _a.members, type = _a.type;
17
+ return __awaiter(void 0, void 0, void 0, function () {
18
+ var theChannel, originalCid, queryPromise;
19
+ return __generator(this, function (_b) {
20
+ switch (_b.label) {
21
+ case 0:
22
+ if (!channel && !type) {
23
+ throw new Error('Channel or channel type have to be provided to query a channel.');
24
+ }
25
+ theChannel = channel || client.channel(type, id, { members: members });
26
+ originalCid = (theChannel === null || theChannel === void 0 ? void 0 : theChannel.id)
27
+ ? theChannel.cid
28
+ : members && members.length
29
+ ? generateChannelTempCid(theChannel.type, members)
30
+ : undefined;
31
+ if (!originalCid) {
32
+ throw new Error('Channel ID or channel members array have to be provided to query a channel.');
33
+ }
34
+ queryPromise = WATCH_QUERY_IN_PROGRESS_FOR_CHANNEL[originalCid];
35
+ if (!queryPromise) return [3 /*break*/, 2];
36
+ return [4 /*yield*/, queryPromise];
37
+ case 1:
38
+ _b.sent();
39
+ return [3 /*break*/, 4];
40
+ case 2:
41
+ WATCH_QUERY_IN_PROGRESS_FOR_CHANNEL[originalCid] = theChannel.watch();
42
+ return [4 /*yield*/, WATCH_QUERY_IN_PROGRESS_FOR_CHANNEL[originalCid]];
43
+ case 3:
44
+ _b.sent();
45
+ delete WATCH_QUERY_IN_PROGRESS_FOR_CHANNEL[originalCid];
46
+ _b.label = 4;
47
+ case 4: return [2 /*return*/, theChannel];
48
+ }
49
+ });
50
+ });
51
+ };
52
+ // Channels created without ID need to be referenced by an identifier until the back-end generates the final ID.
53
+ var generateChannelTempCid = function (channelType, members) {
54
+ if (!members)
55
+ return;
56
+ var membersStr = __spreadArray([], members, true).sort().join(',');
57
+ return "".concat(channelType, ":!members-").concat(membersStr);
58
+ };
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const version = "10.10.1";
1
+ export declare const version = "10.10.2";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export var version = '10.10.1';
1
+ export var version = '10.10.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stream-chat-react",
3
- "version": "10.10.1",
3
+ "version": "10.10.2",
4
4
  "description": "React components to create chat conversations or livestream style chat",
5
5
  "author": "GetStream",
6
6
  "homepage": "https://getstream.io/chat/",
@@ -169,7 +169,7 @@
169
169
  "rollup-plugin-url": "^3.0.1",
170
170
  "rollup-plugin-visualizer": "^4.2.0",
171
171
  "semantic-release": "^19.0.5",
172
- "stream-chat": "^8.4.1",
172
+ "stream-chat": "^8.12.0",
173
173
  "style-loader": "^2.0.0",
174
174
  "ts-jest": "^26.5.1",
175
175
  "typescript": "^4.7.4",