@amityco/ts-sdk 0.0.1-beta.20 → 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 (72) hide show
  1. package/dist/@types/core/events.d.ts +2 -2
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/payload.d.ts +1 -1
  4. package/dist/@types/core/payload.d.ts.map +1 -1
  5. package/dist/@types/domains/content.d.ts +5 -2
  6. package/dist/@types/domains/content.d.ts.map +1 -1
  7. package/dist/@types/domains/message.d.ts +2 -2
  8. package/dist/@types/domains/message.d.ts.map +1 -1
  9. package/dist/@types/domains/reaction.d.ts +1 -1
  10. package/dist/@types/domains/reaction.d.ts.map +1 -1
  11. package/dist/channel/api/addChannelMembers.d.ts.map +1 -1
  12. package/dist/channel/api/queryChannelMembers.d.ts +2 -1
  13. package/dist/channel/api/queryChannelMembers.d.ts.map +1 -1
  14. package/dist/channel/api/queryChannels.d.ts +1 -0
  15. package/dist/channel/api/queryChannels.d.ts.map +1 -1
  16. package/dist/channel/api/removeChannelMembers.d.ts.map +1 -1
  17. package/dist/channel/events/index.d.ts +2 -2
  18. package/dist/channel/events/index.d.ts.map +1 -1
  19. package/dist/channel/events/onChannelMemberAdded.d.ts +17 -0
  20. package/dist/channel/events/onChannelMemberAdded.d.ts.map +1 -0
  21. package/dist/channel/events/onChannelMemberRemoved.d.ts +17 -0
  22. package/dist/channel/events/onChannelMemberRemoved.d.ts.map +1 -0
  23. package/dist/channel/observers/observeChannel.d.ts.map +1 -1
  24. package/dist/client/api/connectClient.d.ts +3 -1
  25. package/dist/client/api/connectClient.d.ts.map +1 -1
  26. package/dist/comment/api/queryComments.d.ts +1 -0
  27. package/dist/comment/api/queryComments.d.ts.map +1 -1
  28. package/dist/core/model/identifyModel.d.ts +1 -0
  29. package/dist/core/model/identifyModel.d.ts.map +1 -1
  30. package/dist/core/query/query.d.ts.map +1 -1
  31. package/dist/index.cjs.js +216 -81
  32. package/dist/index.esm.js +214 -80
  33. package/dist/index.umd.js +5 -5
  34. package/dist/message/api/createMessage.d.ts +2 -2
  35. package/dist/message/api/createMessage.d.ts.map +1 -1
  36. package/dist/message/api/updateMessage.d.ts +2 -2
  37. package/dist/message/api/updateMessage.d.ts.map +1 -1
  38. package/dist/message/events/onMessageUpdated.d.ts.map +1 -1
  39. package/dist/reaction/events/onReactionAdded.d.ts.map +1 -1
  40. package/dist/reaction/utils/index.d.ts +1 -0
  41. package/dist/reaction/utils/index.d.ts.map +1 -1
  42. package/dist/reaction/utils/prepareMessagePayloadForCache.d.ts +3 -0
  43. package/dist/reaction/utils/prepareMessagePayloadForCache.d.ts.map +1 -0
  44. package/package.json +1 -1
  45. package/src/@types/core/events.ts +2 -2
  46. package/src/@types/core/payload.ts +1 -1
  47. package/src/@types/domains/content.ts +7 -1
  48. package/src/@types/domains/message.ts +2 -1
  49. package/src/@types/domains/reaction.ts +1 -1
  50. package/src/channel/api/addChannelMembers.ts +2 -1
  51. package/src/channel/api/queryChannelMembers.ts +4 -4
  52. package/src/channel/api/queryChannels.ts +1 -0
  53. package/src/channel/api/removeChannelMembers.ts +2 -1
  54. package/src/channel/events/index.ts +2 -2
  55. package/src/channel/events/{onMemberAdded.ts → onChannelMemberAdded.ts} +8 -6
  56. package/src/channel/events/{onMemberRemoved.ts → onChannelMemberRemoved.ts} +13 -6
  57. package/src/channel/observers/observeChannel.ts +8 -4
  58. package/src/client/api/connectClient.ts +12 -7
  59. package/src/comment/api/queryComments.ts +6 -3
  60. package/src/core/model/identifyModel.ts +18 -0
  61. package/src/core/query/paging.ts +3 -3
  62. package/src/core/query/query.ts +19 -1
  63. package/src/message/api/createMessage.ts +21 -8
  64. package/src/message/api/updateMessage.ts +2 -2
  65. package/src/message/events/onMessageUpdated.ts +9 -1
  66. package/src/reaction/events/onReactionAdded.ts +4 -0
  67. package/src/reaction/utils/index.ts +1 -0
  68. package/src/reaction/utils/prepareMessagePayloadForCache.ts +40 -0
  69. package/dist/channel/events/onMemberAdded.d.ts +0 -17
  70. package/dist/channel/events/onMemberAdded.d.ts.map +0 -1
  71. package/dist/channel/events/onMemberRemoved.d.ts +0 -17
  72. package/dist/channel/events/onMemberRemoved.d.ts.map +0 -1
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 */
@@ -98,19 +100,19 @@ const toToken = (paging, style) => {
98
100
  "before" or "after" value. if that would change,
99
101
  we'd need to move toward a more simple: `!paging.before`
100
102
  */
101
- if (!Number.isNaN(paging === null || paging === void 0 ? void 0 : paging.before)) {
103
+ if (!Number.isNaN(Number(paging === null || paging === void 0 ? void 0 : paging.before))) {
102
104
  payload = {
103
105
  before: paging.before,
104
106
  last: paging.limit,
105
107
  };
106
108
  }
107
- else if (!Number.isNaN(paging === null || paging === void 0 ? void 0 : paging.after)) {
109
+ else if (!Number.isNaN(Number(paging === null || paging === void 0 ? void 0 : paging.after))) {
108
110
  payload = {
109
111
  after: paging.after,
110
112
  first: paging.limit,
111
113
  };
112
114
  }
113
- else if (!Number.isNaN(paging === null || paging === void 0 ? void 0 : paging.limit)) {
115
+ else if (!Number.isNaN(Number(paging === null || paging === void 0 ? void 0 : paging.limit))) {
114
116
  payload = {
115
117
  last: paging.limit,
116
118
  };
@@ -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
  });
@@ -23877,6 +24005,7 @@ const addChannelMembers = async (channelId, userIds) => {
23877
24005
  ingestInCache(data);
23878
24006
  fireEvent('v3.channel.didAddUsers', {
23879
24007
  channels: data.channels,
24008
+ channelUsers: data.channelUsers,
23880
24009
  });
23881
24010
  const { channelUsers } = data;
23882
24011
  return !!channelUsers.find(channelUser => channelUser.channelId === channelId && channelUser.membership === 'member');
@@ -23905,6 +24034,7 @@ const removeChannelMembers = async (channelId, userIds) => {
23905
24034
  ingestInCache(data);
23906
24035
  fireEvent('v3.channel.didRemoveUsers', {
23907
24036
  channels: data.channels,
24037
+ channelUsers: data.channelUsers,
23908
24038
  });
23909
24039
  const { channelUsers } = data;
23910
24040
  return !!channelUsers.find(channelUser => channelUser.channelId === channelId && channelUser.membership !== 'member');
@@ -24060,8 +24190,8 @@ const onChannelLeft = (callback) => {
24060
24190
 
24061
24191
  /**
24062
24192
  * ```js
24063
- * import { onMemberAdded } from '@amityco/ts-sdk'
24064
- * const dispose = onMemberAdded(channel => {
24193
+ * import { onChannelMemberAdded } from '@amityco/ts-sdk'
24194
+ * const dispose = onChannelMemberAdded((channel, member) => {
24065
24195
  * // ...
24066
24196
  * })
24067
24197
  * ```
@@ -24073,19 +24203,19 @@ const onChannelLeft = (callback) => {
24073
24203
  *
24074
24204
  * @category Channel Events
24075
24205
  */
24076
- const onMemberAdded = (callback) => {
24206
+ const onChannelMemberAdded = (callback) => {
24077
24207
  const client = getActiveClient();
24078
24208
  const filter = (payload) => {
24079
24209
  ingestInCache(payload);
24080
- callback(payload.channels[0]);
24210
+ callback(payload.channels[0], payload.channelUsers[0]);
24081
24211
  };
24082
- return createEventSubscriber(client, 'onMemberAdded', 'v3.channel.didAddUsers', filter);
24212
+ return createEventSubscriber(client, 'onChannelMemberAdded', 'v3.channel.didAddUsers', filter);
24083
24213
  };
24084
24214
 
24085
24215
  /**
24086
24216
  * ```js
24087
- * import { onMemberRemoved } from '@amityco/ts-sdk'
24088
- * const dispose = onMemberRemoved(channel => {
24217
+ * import { onChannelMemberRemoved } from '@amityco/ts-sdk'
24218
+ * const dispose = onChannelMemberRemoved((channel, member) => {
24089
24219
  * // ...
24090
24220
  * })
24091
24221
  * ```
@@ -24097,13 +24227,13 @@ const onMemberAdded = (callback) => {
24097
24227
  *
24098
24228
  * @category Channel Events
24099
24229
  */
24100
- const onMemberRemoved = (callback) => {
24230
+ const onChannelMemberRemoved = (callback) => {
24101
24231
  const client = getActiveClient();
24102
24232
  const filter = (payload) => {
24103
24233
  ingestInCache(payload);
24104
- callback(payload.channels[0]);
24234
+ callback(payload.channels[0], payload.channelUsers[0]);
24105
24235
  };
24106
- return createEventSubscriber(client, 'onMemberRemoved', 'v3.channel.didRemoveUsers', filter);
24236
+ return createEventSubscriber(client, 'onChannelMemberRemoved', 'v3.channel.didRemoveUsers', filter);
24107
24237
  };
24108
24238
 
24109
24239
  /**
@@ -24139,7 +24269,7 @@ const observeChannel = (channelId, callback) => {
24139
24269
  (_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, result);
24140
24270
  };
24141
24271
  const disposers = [];
24142
- disposers.push(onChannelUpdated(data => router({ data, loading: false, origin: 'event' }, 'onUpdate')), onChannelDeleted(data => router({ data, loading: false, origin: 'event' }, 'onDelete')), onChannelJoined(data => router({ data, loading: false, origin: 'event' }, 'onJoin')), onChannelLeft(data => router({ data, loading: false, origin: 'event' }, 'onLeft')), onMemberAdded(data => router({ data, loading: false, origin: 'event' }, 'onMemberAdded')), onMemberRemoved(data => router({ data, loading: false, origin: 'event' }, 'onMemberRemoved')));
24272
+ disposers.push(onChannelUpdated(data => router({ data, loading: false, origin: 'event' }, 'onUpdate')), onChannelDeleted(data => router({ data, loading: false, origin: 'event' }, 'onDelete')), onChannelJoined(data => router({ data, loading: false, origin: 'event' }, 'onJoin')), onChannelLeft(data => router({ data, loading: false, origin: 'event' }, 'onLeft')), onChannelMemberAdded(data => router({ data, loading: false, origin: 'event' }, 'onMemberAdded')), onChannelMemberRemoved(data => router({ data, loading: false, origin: 'event' }, 'onMemberRemoved')));
24143
24273
  runQuery(createQuery(getChannel, channelId), result => result.data && router(result, 'onFetch'));
24144
24274
  return () => {
24145
24275
  log(`observeChannel(tmpid: ${timestamp}) > dispose`);
@@ -24190,7 +24320,12 @@ const onMessageUpdated = (callback) => {
24190
24320
  const client = getActiveClient();
24191
24321
  const filter = (payload) => {
24192
24322
  ingestInCache(payload);
24193
- 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);
24194
24329
  };
24195
24330
  return createEventSubscriber(client, 'message/onMessageUpdated', 'v3.message.didUpdate', filter);
24196
24331
  };
@@ -26107,6 +26242,8 @@ exports.observeUser = observeUser;
26107
26242
  exports.onChannelDeleted = onChannelDeleted;
26108
26243
  exports.onChannelJoined = onChannelJoined;
26109
26244
  exports.onChannelLeft = onChannelLeft;
26245
+ exports.onChannelMemberAdded = onChannelMemberAdded;
26246
+ exports.onChannelMemberRemoved = onChannelMemberRemoved;
26110
26247
  exports.onChannelUpdated = onChannelUpdated;
26111
26248
  exports.onClientBanned = onClientBanned;
26112
26249
  exports.onClientDisconnected = onClientDisconnected;
@@ -26133,8 +26270,6 @@ exports.onFollowRequestCanceled = onFollowRequestCanceled;
26133
26270
  exports.onFollowRequestDeclined = onFollowRequestDeclined;
26134
26271
  exports.onFollowerDeleted = onFollowerDeleted;
26135
26272
  exports.onFollowerRequested = onFollowerRequested;
26136
- exports.onMemberAdded = onMemberAdded;
26137
- exports.onMemberRemoved = onMemberRemoved;
26138
26273
  exports.onMessageCreated = onMessageCreated;
26139
26274
  exports.onMessageDeleted = onMessageDeleted;
26140
26275
  exports.onMessageUpdated = onMessageUpdated;