@amityco/ts-sdk 0.0.1-beta.22 → 0.0.1-beta.23

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.
Files changed (33) hide show
  1. package/dist/@types/domains/reaction.d.ts +1 -1
  2. package/dist/@types/domains/reaction.d.ts.map +1 -1
  3. package/dist/channel/api/queryChannelMembers.d.ts +2 -1
  4. package/dist/channel/api/queryChannelMembers.d.ts.map +1 -1
  5. package/dist/client/api/connectClient.d.ts +3 -1
  6. package/dist/client/api/connectClient.d.ts.map +1 -1
  7. package/dist/comment/api/queryComments.d.ts +1 -0
  8. package/dist/comment/api/queryComments.d.ts.map +1 -1
  9. package/dist/core/model/identifyModel.d.ts +1 -0
  10. package/dist/core/model/identifyModel.d.ts.map +1 -1
  11. package/dist/core/query/query.d.ts.map +1 -1
  12. package/dist/index.cjs.js +198 -65
  13. package/dist/index.esm.js +197 -65
  14. package/dist/index.umd.js +5 -5
  15. package/dist/message/api/createMessage.d.ts.map +1 -1
  16. package/dist/message/events/onMessageUpdated.d.ts.map +1 -1
  17. package/dist/reaction/events/onReactionAdded.d.ts.map +1 -1
  18. package/dist/reaction/utils/index.d.ts +1 -0
  19. package/dist/reaction/utils/index.d.ts.map +1 -1
  20. package/dist/reaction/utils/prepareMessagePayloadForCache.d.ts +3 -0
  21. package/dist/reaction/utils/prepareMessagePayloadForCache.d.ts.map +1 -0
  22. package/package.json +1 -1
  23. package/src/@types/domains/reaction.ts +1 -1
  24. package/src/channel/api/queryChannelMembers.ts +4 -4
  25. package/src/client/api/connectClient.ts +12 -7
  26. package/src/comment/api/queryComments.ts +6 -3
  27. package/src/core/model/identifyModel.ts +18 -0
  28. package/src/core/query/query.ts +19 -1
  29. package/src/message/api/createMessage.ts +19 -6
  30. package/src/message/events/onMessageUpdated.ts +9 -1
  31. package/src/reaction/events/onReactionAdded.ts +4 -0
  32. package/src/reaction/utils/index.ts +1 -0
  33. package/src/reaction/utils/prepareMessagePayloadForCache.ts +40 -0
@@ -13,7 +13,7 @@ declare global {
13
13
  reactions: Record<string, number>;
14
14
  myReactions?: string[];
15
15
  latestReaction?: Amity.Reaction & {
16
- eventName: 'added' | 'removed';
16
+ eventName: 'add' | 'remove';
17
17
  };
18
18
  };
19
19
  type ReactionQuery = {
@@ -1 +1 @@
1
- {"version":3,"file":"reaction.d.ts","sourceRoot":"","sources":["../../../src/@types/domains/reaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC;AAEV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK,CAAC;QACd,KAAK,aAAa,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;QAEpD,KAAK,OAAO,GAAG;YACb,UAAU,EAAE,MAAM,CAAC;YACnB,YAAY,EAAE,MAAM,CAAC;YACrB,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC9B,GAAG,KAAK,CAAC,SAAS,CAAC;QAEpB,KAAK,QAAQ,GAAG,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;QAElE,KAAK,SAAS,GAAG;YACf,cAAc,EAAE,MAAM,CAAC;YACvB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAClC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;YAEvB,cAAc,CAAC,EAAE,KAAK,CAAC,QAAQ,GAAG;gBAChC,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;aAChC,CAAC;SACH,CAAC;QAEF,KAAK,aAAa,GAAG;YACnB,QAAQ,EAAE,OAAO,EAAE,CAAC;SACrB,GAAG,KAAK,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;KACvC;CACF"}
1
+ {"version":3,"file":"reaction.d.ts","sourceRoot":"","sources":["../../../src/@types/domains/reaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC;AAEV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK,CAAC;QACd,KAAK,aAAa,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;QAEpD,KAAK,OAAO,GAAG;YACb,UAAU,EAAE,MAAM,CAAC;YACnB,YAAY,EAAE,MAAM,CAAC;YACrB,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC9B,GAAG,KAAK,CAAC,SAAS,CAAC;QAEpB,KAAK,QAAQ,GAAG,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;QAElE,KAAK,SAAS,GAAG;YACf,cAAc,EAAE,MAAM,CAAC;YACvB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAClC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;YAEvB,cAAc,CAAC,EAAE,KAAK,CAAC,QAAQ,GAAG;gBAChC,SAAS,EAAE,KAAK,GAAG,QAAQ,CAAC;aAC7B,CAAC;SACH,CAAC;QAEF,KAAK,aAAa,GAAG;YACnB,QAAQ,EAAE,OAAO,EAAE,CAAC;SACrB,GAAG,KAAK,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;KACvC;CACF"}
@@ -15,9 +15,10 @@
15
15
  export declare const queryChannelMembers: {
16
16
  (query: {
17
17
  channelId: string;
18
- membership?: 'all' | 'muted' | 'banned' | 'member&banned';
18
+ memberships?: ('muted' | 'banned' | 'member')[];
19
19
  roles?: string[];
20
20
  sortBy?: 'firstCreated' | 'lastCreated';
21
+ search?: string;
21
22
  page?: Amity.Page;
22
23
  }): Promise<Amity.Cached<Amity.Paged<Amity.Membership<'channel'>>>>;
23
24
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"queryChannelMembers.d.ts","sourceRoot":"","sources":["../../../src/channel/api/queryChannelMembers.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;KAaK;AACL,eAAO,MAAM,mBAAmB;YAAiB;QAC/C,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,eAAe,CAAC;QAC1D,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QACjB,MAAM,CAAC,EAAE,cAAc,GAAG,aAAa,CAAC;QACxC,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC;KACnB,GAAG,QAAQ,MAAM,MAAM,CAAC,MAAM,KAAK,CAAC,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAiCnE;;;;;;;;;;;;OAYG;mBACmC,WAAW,0BAA0B,CAAC,CAAC,CAAC,CAAC;CAf9E,CAAC"}
1
+ {"version":3,"file":"queryChannelMembers.d.ts","sourceRoot":"","sources":["../../../src/channel/api/queryChannelMembers.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;KAaK;AACL,eAAO,MAAM,mBAAmB;YAAiB;QAC/C,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,CAAC,EAAE,CAAC,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC,EAAE,CAAC;QAChD,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QACjB,MAAM,CAAC,EAAE,cAAc,GAAG,aAAa,CAAC;QACxC,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC;KACnB,GAAG,QAAQ,MAAM,MAAM,CAAC,MAAM,KAAK,CAAC,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAgCnE;;;;;;;;;;;;OAYG;mBACmC,WAAW,0BAA0B,CAAC,CAAC,CAAC,CAAC;CAf9E,CAAC"}
@@ -23,5 +23,7 @@ export declare const connectClient: (params: {
23
23
  displayName?: Amity.User['displayName'];
24
24
  authToken?: string;
25
25
  deviceId?: Amity.Device['deviceId'];
26
- }) => Promise<boolean>;
26
+ }, config?: {
27
+ disableRTE: boolean;
28
+ } | undefined) => Promise<boolean>;
27
29
  //# sourceMappingURL=connectClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connectClient.d.ts","sourceRoot":"","sources":["../../../src/client/api/connectClient.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,aAAa,WAAkB;IAC1C,MAAM,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC,aAAa,CAAC,CAAC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;CACrC,KAAG,QAAQ,OAAO,CA4ClB,CAAC"}
1
+ {"version":3,"file":"connectClient.d.ts","sourceRoot":"","sources":["../../../src/client/api/connectClient.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,aAAa,WAChB;IACN,MAAM,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC,aAAa,CAAC,CAAC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;CACrC;gBACsB,OAAO;kBAC7B,QAAQ,OAAO,CA8CjB,CAAC"}
@@ -16,6 +16,7 @@ export declare const queryComments: {
16
16
  (query: {
17
17
  referenceType: Amity.Comment['referenceType'];
18
18
  referenceId: Amity.Comment['referenceId'];
19
+ sortBy?: 'lastCreated' | 'firstCreated' | 'lastUpdated' | 'firstUpdated';
19
20
  parentId?: Amity.Comment['commentId'] | null;
20
21
  hasFlag?: boolean;
21
22
  isDeleted?: Amity.Comment['isDeleted'];
@@ -1 +1 @@
1
- {"version":3,"file":"queryComments.d.ts","sourceRoot":"","sources":["../../../src/comment/api/queryComments.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa;YAAiB;QACzC,aAAa,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;QAC9C,WAAW,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;QAC1C,QAAQ,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC;QAC7C,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,SAAS,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;QACvC,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC;KACnB,GAAG,QAAQ,MAAM,MAAM,CAAC,MAAM,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC;IAgDrD;;;;;;;;;;;;OAYG;mBAEM,WAAW,oBAAoB,CAAC,CAAC,CAAC,CAAC,GACzC,MAAM,MAAM,CAAC,MAAM,KAAK,CAAC,aAAa,CAAC,CAAC,GAAG,SAAS;CAjBtD,CAAC"}
1
+ {"version":3,"file":"queryComments.d.ts","sourceRoot":"","sources":["../../../src/comment/api/queryComments.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa;YAAiB;QACzC,aAAa,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;QAC9C,WAAW,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;QAC1C,MAAM,CAAC,EAAE,aAAa,GAAG,cAAc,GAAG,aAAa,GAAG,cAAc,CAAC;QACzE,QAAQ,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC;QAC7C,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,SAAS,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;QACvC,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC;KACnB,GAAG,QAAQ,MAAM,MAAM,CAAC,MAAM,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC;IAkDrD;;;;;;;;;;;;OAYG;mBAEM,WAAW,oBAAoB,CAAC,CAAC,CAAC,CAAC,GACzC,MAAM,MAAM,CAAC,MAAM,KAAK,CAAC,aAAa,CAAC,CAAC,GAAG,SAAS;CAjBtD,CAAC"}
@@ -5,4 +5,5 @@
5
5
  * @returns the name of the corresponding store
6
6
  */
7
7
  export declare const identifyModel: (model: Record<string, unknown>) => keyof Amity.Model | undefined;
8
+ export declare const identifyModelKey: (model: Record<string, unknown>) => string | undefined;
8
9
  //# sourceMappingURL=identifyModel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"identifyModel.d.ts","sourceRoot":"","sources":["../../../src/core/model/identifyModel.ts"],"names":[],"mappings":"AA8CA;;;;;GAKG;AACH,eAAO,MAAM,aAAa,UAAW,OAAO,MAAM,EAAE,OAAO,CAAC,kCAM3D,CAAC"}
1
+ {"version":3,"file":"identifyModel.d.ts","sourceRoot":"","sources":["../../../src/core/model/identifyModel.ts"],"names":[],"mappings":"AA8CA;;;;;GAKG;AACH,eAAO,MAAM,aAAa,UAAW,OAAO,MAAM,EAAE,OAAO,CAAC,kCAM3D,CAAC;AAUF,eAAO,MAAM,gBAAgB,UAAW,OAAO,MAAM,EAAE,OAAO,CAAC,KAAG,MAAM,GAAG,SAQ1E,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/core/query/query.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,oIAE2C,CAAC;AAElE;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,oIAEkD,CAAC;AAEzE;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,oIAE4D,CAAC;AAEnF;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,UAAW,GAAG,4BACF,CAAC;AAEpC;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,WAAY,GAAG,yBAElC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,oEAEnB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,WAAW;;;CAGH,CAAC;AAEtB;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,WACf,MAAM,WAAW,aACf,MAAM,KACf,MAAM,YAKR,CAAC;AA4BF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,QAAQ,8IAE4B,IAAI,yBAC1C,MAAM,YAAY,SA0D5B,CAAC"}
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/core/query/query.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,oIAE2C,CAAC;AAElE;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,oIAEkD,CAAC;AAEzE;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,oIAE4D,CAAC;AAEnF;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,UAAW,GAAG,4BACF,CAAC;AAEpC;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,WAAY,GAAG,yBAElC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,oEAEnB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,WAAW;;;CAGH,CAAC;AAEtB;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,WACf,MAAM,WAAW,aACf,MAAM,KACf,MAAM,YAKR,CAAC;AA4BF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,QAAQ,8IAE4B,IAAI,yBAC1C,MAAM,YAAY,SA2E5B,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -9,6 +9,7 @@ var debug = require('debug');
9
9
  var axios = require('axios');
10
10
  var HttpAgent = require('agentkeepalive');
11
11
  var io = require('socket.io-client');
12
+ var nativeIdGenerator = require('react-native-uuid');
12
13
 
13
14
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
15
 
@@ -18,6 +19,7 @@ var debug__default = /*#__PURE__*/_interopDefaultLegacy(debug);
18
19
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
19
20
  var HttpAgent__default = /*#__PURE__*/_interopDefaultLegacy(HttpAgent);
20
21
  var io__default = /*#__PURE__*/_interopDefaultLegacy(io);
22
+ var nativeIdGenerator__default = /*#__PURE__*/_interopDefaultLegacy(nativeIdGenerator);
21
23
 
22
24
  var _a$1;
23
25
  /* eslint-disable no-undef */
@@ -179,6 +181,121 @@ const toPageRaw = (token) => {
179
181
  return undefined;
180
182
  };
181
183
 
184
+ /** @hidden */
185
+ const idResolvers = {
186
+ user: ({ userId }) => userId,
187
+ file: ({ fileId }) => fileId,
188
+ role: ({ roleId }) => roleId,
189
+ channel: ({ channelId }) => channelId,
190
+ channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
191
+ message: ({ messageId }) => messageId,
192
+ community: ({ communityId }) => communityId,
193
+ category: ({ categoryId }) => categoryId,
194
+ communityUsers: ({ communityId, userId }) => `${communityId}#${userId}`,
195
+ post: ({ postId }) => postId,
196
+ comment: ({ commentId }) => commentId,
197
+ poll: ({ pollId }) => pollId,
198
+ reaction: ({ reactionId }) => reactionId,
199
+ stream: ({ streamId }) => streamId,
200
+ follow: ({ from, to }) => `${from}#${to}`,
201
+ followCount: ({ userId }) => userId,
202
+ };
203
+ /**
204
+ * Retrieve the id resolver matching a domain name
205
+ *
206
+ * @param name the domain name for the resolve
207
+ * @returns an idResolver function for the given domain name
208
+ */
209
+ const getResolver = (name) => idResolvers[name];
210
+
211
+ /**
212
+ * Identification criterias
213
+ *
214
+ * As key, the name of the identified model ;
215
+ * As value, the list of properties to consider a given model as of type
216
+ *
217
+ * Used as source of truth for {@link identifyModel}
218
+ *
219
+ * @hidden
220
+ */
221
+ const CRITERIAS = {
222
+ file: ['fileId', 'attributes'],
223
+ user: ['userId', 'avatarFileId'],
224
+ role: ['roleId'],
225
+ channel: ['channelId', 'rateLimit'],
226
+ channelUsers: ['channelId', 'userId', 'membership'],
227
+ message: ['messageId'],
228
+ community: ['communityId', 'onlyAdminCanPost'],
229
+ category: ['categoryId'],
230
+ communityUsers: ['userId', 'communityId', 'communityMembership'],
231
+ post: ['postId', 'feedId'],
232
+ comment: ['commentId', 'referenceId'],
233
+ poll: ['pollId'],
234
+ reaction: ['reactionId'],
235
+ stream: ['streamId'],
236
+ follow: ['from', 'to'],
237
+ followCount: ['userId', 'followerCount'],
238
+ };
239
+ /** @hidden */
240
+ const hasKeys = (object, needles) => {
241
+ const haystack = Object.keys(object);
242
+ return needles.every(needle => haystack.includes(needle));
243
+ };
244
+ /**
245
+ * Finds the name of the store for a given unknown model
246
+ *
247
+ * @param model one of the {@link Amity.Model} to identify
248
+ * @returns the name of the corresponding store
249
+ */
250
+ const identifyModel = (model) => {
251
+ var _a;
252
+ // we cannot avoid "as" in here because Object.entries does not
253
+ // allow anything else than "string" as key in the iterator type
254
+ const criterias = Object.entries(CRITERIAS);
255
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
256
+ return (_a = criterias.find(([_, keys]) => hasKeys(model, keys))) === null || _a === void 0 ? void 0 : _a[0];
257
+ };
258
+ /*
259
+ * Identify the modal key for a model
260
+ * Used to get args for optimistic updates
261
+ * Example: createMessage: get messageId on optimistic message creation
262
+ *
263
+ * @param model to be recognized
264
+ * @returns model key array if one if found or undefined
265
+ */
266
+ const identifyModelKey = (model) => {
267
+ var _a;
268
+ const modalKey = identifyModel(model);
269
+ if (!modalKey) {
270
+ return undefined;
271
+ }
272
+ return (_a = CRITERIAS[modalKey]) === null || _a === void 0 ? void 0 : _a[0];
273
+ };
274
+
275
+ /**
276
+ * A map of v3 response keys to a store name.
277
+ * @hidden
278
+ */
279
+ const PAYLOAD2MODEL = {
280
+ users: 'user',
281
+ files: 'file',
282
+ roles: 'role',
283
+ channels: 'channel',
284
+ channelUsers: 'channelUsers',
285
+ messages: 'message',
286
+ communities: 'community',
287
+ categories: 'category',
288
+ communityUsers: 'communityUsers',
289
+ posts: 'post',
290
+ postChildren: 'post',
291
+ comments: 'comment',
292
+ polls: 'poll',
293
+ reactions: 'reaction',
294
+ videoStreamings: 'stream',
295
+ follows: 'follow',
296
+ followCounts: 'followCount',
297
+ };
298
+
182
299
  /* eslint-disable no-use-before-define */
183
300
  /**
184
301
  * Type guard to check and cast that a given async function is has the ".locally" property
@@ -323,7 +440,23 @@ const runQuery = ({ func, args }, callback, options = queryOptions('cache_then_s
323
440
  loading: true,
324
441
  }));
325
442
  }
326
- func(...args)
443
+ let optimisticArgs = args;
444
+ /* get args for optimistic method calls
445
+ *
446
+ * On optimistic updates, the modal key for the update needs to be passed to
447
+ * the server so as to avoid duplicate modal creation
448
+ *
449
+ * ex: on creating a new message pass the modalKey is messageId, pass this
450
+ * id onto the server so that a duplicate with seperate messageId is not
451
+ * created.
452
+ */
453
+ if (isMutator(func)) {
454
+ // @ts-ignore
455
+ const modelKey = local && local.data && identifyModelKey(local.data);
456
+ // @ts-ignore
457
+ optimisticArgs = modelKey ? [Object.assign(Object.assign({}, args[0]), { [modelKey]: local.data[modelKey] })] : args;
458
+ }
459
+ func(...optimisticArgs)
327
460
  .then(fresh => {
328
461
  // @ts-ignore i know.
329
462
  // isLocal(local) && syncInCache(local, fresh)
@@ -20216,57 +20349,6 @@ const onClientBanned = (callback) => {
20216
20349
  });
20217
20350
  };
20218
20351
 
20219
- /** @hidden */
20220
- const idResolvers = {
20221
- user: ({ userId }) => userId,
20222
- file: ({ fileId }) => fileId,
20223
- role: ({ roleId }) => roleId,
20224
- channel: ({ channelId }) => channelId,
20225
- channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
20226
- message: ({ messageId }) => messageId,
20227
- community: ({ communityId }) => communityId,
20228
- category: ({ categoryId }) => categoryId,
20229
- communityUsers: ({ communityId, userId }) => `${communityId}#${userId}`,
20230
- post: ({ postId }) => postId,
20231
- comment: ({ commentId }) => commentId,
20232
- poll: ({ pollId }) => pollId,
20233
- reaction: ({ reactionId }) => reactionId,
20234
- stream: ({ streamId }) => streamId,
20235
- follow: ({ from, to }) => `${from}#${to}`,
20236
- followCount: ({ userId }) => userId,
20237
- };
20238
- /**
20239
- * Retrieve the id resolver matching a domain name
20240
- *
20241
- * @param name the domain name for the resolve
20242
- * @returns an idResolver function for the given domain name
20243
- */
20244
- const getResolver = (name) => idResolvers[name];
20245
-
20246
- /**
20247
- * A map of v3 response keys to a store name.
20248
- * @hidden
20249
- */
20250
- const PAYLOAD2MODEL = {
20251
- users: 'user',
20252
- files: 'file',
20253
- roles: 'role',
20254
- channels: 'channel',
20255
- channelUsers: 'channelUsers',
20256
- messages: 'message',
20257
- communities: 'community',
20258
- categories: 'category',
20259
- communityUsers: 'communityUsers',
20260
- posts: 'post',
20261
- postChildren: 'post',
20262
- comments: 'comment',
20263
- polls: 'poll',
20264
- reactions: 'reaction',
20265
- videoStreamings: 'stream',
20266
- follows: 'follow',
20267
- followCounts: 'followCount',
20268
- };
20269
-
20270
20352
  /**
20271
20353
  * Ingest a payload (v3) into the cache
20272
20354
  *
@@ -20340,7 +20422,7 @@ const onUserDeleted = (callback) => createUserEventSubscriber('user.deleted', ca
20340
20422
  * @category Client API
20341
20423
  * @async
20342
20424
  */
20343
- const connectClient = async (params) => {
20425
+ const connectClient = async (params, config) => {
20344
20426
  var _a;
20345
20427
  const client = getActiveClient();
20346
20428
  client.log('client/api/connectClient', Object.assign({ apiKey: client.apiKey }, params));
@@ -20365,7 +20447,9 @@ const connectClient = async (params) => {
20365
20447
  client.userId = params.userId;
20366
20448
  client.accessToken = accessToken;
20367
20449
  setActiveUser(users[0]);
20368
- subscribeTopic(getNetworkTopic());
20450
+ if ((config === null || config === void 0 ? void 0 : config.disableRTE) !== true) {
20451
+ subscribeTopic(getNetworkTopic());
20452
+ }
20369
20453
  const subscriptions = [
20370
20454
  onClientBanned(() => {
20371
20455
  disconnectClient();
@@ -21311,6 +21395,8 @@ queryMessages.locally = (query) => {
21311
21395
  : undefined;
21312
21396
  };
21313
21397
 
21398
+ const uuid = () => nativeIdGenerator__default["default"].v4().toString();
21399
+
21314
21400
  /**
21315
21401
  * ```js
21316
21402
  * import { createMessage } from '@amityco/ts-sdk'
@@ -21361,12 +21447,20 @@ const createMessage = async (bundle) => {
21361
21447
  createMessage.optimistically = (bundle) => {
21362
21448
  var _a, _b;
21363
21449
  const client = getActiveClient();
21364
- client.log('user/createMessage.locally', bundle);
21365
21450
  if (!client.cache)
21366
21451
  return;
21367
- const channel = pullFromCache(['channel', 'get', bundle.channelId]);
21368
- upsertInCache(['channel', 'get', bundle.channelId], Object.assign(Object.assign({}, channel === null || channel === void 0 ? void 0 : channel.data), { messageCount: ((_a = channel === null || channel === void 0 ? void 0 : channel.data.messageCount) !== null && _a !== void 0 ? _a : 0) + 1 }));
21369
- const message = Object.assign({ messageId: Math.random().toString(16), userId: client.userId, channelSegment: ((_b = channel === null || channel === void 0 ? void 0 : channel.data.messageCount) !== null && _b !== void 0 ? _b : 0) + 1, createdAt: new Date().toISOString() }, bundle);
21452
+ /*
21453
+ * when creating messages optimistically a messageId needs to be added by the
21454
+ * client, created a new variable so as to allow backward compatibility of API
21455
+ */
21456
+ const bundleWithMessageId = Object.assign(Object.assign({}, bundle), { messageId: uuid() });
21457
+ // only log if cache is enabled
21458
+ client.log('user/createMessage.locally', bundleWithMessageId);
21459
+ const channel = pullFromCache(['channel', 'get', bundleWithMessageId.channelId]);
21460
+ upsertInCache(['channel', 'get', bundleWithMessageId.channelId], Object.assign(Object.assign({}, channel === null || channel === void 0 ? void 0 : channel.data), { messageCount: ((_a = channel === null || channel === void 0 ? void 0 : channel.data.messageCount) !== null && _a !== void 0 ? _a : 0) + 1 }));
21461
+ // as reused to update created and updated time, which should be the same
21462
+ const createdTime = new Date().toISOString();
21463
+ const message = Object.assign({ userId: client.userId, channelSegment: ((_b = channel === null || channel === void 0 ? void 0 : channel.data.messageCount) !== null && _b !== void 0 ? _b : 0) + 1, createdAt: createdTime, updatedAt: createdTime }, bundleWithMessageId);
21370
21464
  pushToCache(['message', 'get', message.messageId], message, { cachedAt: -1 });
21371
21465
  fireEvent('v3.message.didCreate', { messages: [message] });
21372
21466
  return {
@@ -22427,6 +22521,10 @@ const queryComments = async (query) => {
22427
22521
  const client = getActiveClient();
22428
22522
  client.log('comment/queryComments', query);
22429
22523
  const { page = { limit: 10 } } = query, params = __rest(query, ["page"]);
22524
+ const options = {
22525
+ type: params.sortBy ? 'pagination' : undefined,
22526
+ token: toToken(page, params.sortBy ? 'skiplimit' : 'afterbefore'),
22527
+ };
22430
22528
  // const filterByParentId = query.parentId !== undefined
22431
22529
  // API-FIX: parameters should be querystring. (1)
22432
22530
  // API-FIX: backend should answer Amity.Response (2)
@@ -22434,9 +22532,7 @@ const queryComments = async (query) => {
22434
22532
  const { data } = await client.http.get(`/api/v3/comments`, {
22435
22533
  params: Object.assign(Object.assign({}, params), {
22436
22534
  // filterByParentId, API-FIX: backend does not support this boolean LOL. what the hell seriously.
22437
- options: {
22438
- token: toToken(page, 'afterbefore'),
22439
- } }),
22535
+ options }),
22440
22536
  });
22441
22537
  // API-FIX: backend should answer Amity.Response (2)
22442
22538
  // const { paging, comments } = unwrapPayload(data)
@@ -22771,6 +22867,38 @@ const preparePayloadForCache = (event, payload) => {
22771
22867
  }
22772
22868
  };
22773
22869
 
22870
+ /** @hidden */
22871
+ /*
22872
+ * @param message payload from http request without myReactions
22873
+ * add myReactions to http response if the event was a reaction event
22874
+ */
22875
+ const prepareMessagePayloadForCache = (payload) => {
22876
+ const client = getActiveClient();
22877
+ const cached = pullFromCache(['message', 'get', payload.messageId]);
22878
+ // '[]' in cases where the new reaction is the first one
22879
+ const myReactions = (cached === null || cached === void 0 ? void 0 : cached.data.myReactions) || [];
22880
+ // add myReactions to the payload
22881
+ Object.assign(payload, { myReactions });
22882
+ // check if there are any updates to the reactions
22883
+ const latestReaction = payload === null || payload === void 0 ? void 0 : payload.latestReaction;
22884
+ const isLatestReactionMine = latestReaction && latestReaction.userId === client.userId;
22885
+ if (!isLatestReactionMine) {
22886
+ return;
22887
+ }
22888
+ // new reaction added
22889
+ if (latestReaction.eventName === 'add' && !myReactions.includes(latestReaction.reactionName)) {
22890
+ Object.assign(payload, {
22891
+ myReactions: [...myReactions, latestReaction.reactionName],
22892
+ });
22893
+ }
22894
+ // existing reaction removed
22895
+ if (latestReaction.eventName === 'remove' && myReactions.includes(latestReaction.reactionName)) {
22896
+ Object.assign(payload, {
22897
+ myReactions: myReactions.filter(x => x !== latestReaction.reactionName),
22898
+ });
22899
+ }
22900
+ };
22901
+
22774
22902
  /**
22775
22903
  * ```js
22776
22904
  * import { addReaction } from '@amityco/ts-sdk'
@@ -23819,9 +23947,9 @@ const leaveChannel = async (channelId) => {
23819
23947
  const queryChannelMembers = async (query) => {
23820
23948
  const client = getActiveClient();
23821
23949
  client.log('channel/queryChannelMembers', query);
23822
- const _a = query !== null && query !== void 0 ? query : {}, { page, channelId, membership } = _a, params = __rest(_a, ["page", "channelId", "membership"]);
23823
- const { data } = await client.http.get(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, {
23824
- params: Object.assign(Object.assign({}, params), { filter: membership, options: {
23950
+ const _a = query !== null && query !== void 0 ? query : {}, { page, channelId } = _a, params = __rest(_a, ["page", "channelId"]);
23951
+ const { data } = await client.http.get(`/api/v4/channels/${encodeURIComponent(channelId)}/users`, {
23952
+ params: Object.assign(Object.assign({}, params), { options: {
23825
23953
  token: toToken(page, 'skiplimit'),
23826
23954
  } }),
23827
23955
  });
@@ -24192,7 +24320,12 @@ const onMessageUpdated = (callback) => {
24192
24320
  const client = getActiveClient();
24193
24321
  const filter = (payload) => {
24194
24322
  ingestInCache(payload);
24195
- callback(payload.messages[0]);
24323
+ const message = payload.messages[0];
24324
+ // if payload does not have myReactions
24325
+ if (!(message === null || message === void 0 ? void 0 : message.myReactions)) {
24326
+ prepareMessagePayloadForCache(message);
24327
+ }
24328
+ callback(message);
24196
24329
  };
24197
24330
  return createEventSubscriber(client, 'message/onMessageUpdated', 'v3.message.didUpdate', filter);
24198
24331
  };