@amityco/ts-sdk-react-native 6.24.0 → 6.24.1

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 (89) hide show
  1. package/dist/@types/domains/community.d.ts +15 -1
  2. package/dist/@types/domains/community.d.ts.map +1 -1
  3. package/dist/client/api/secureLogout.d.ts +1 -1
  4. package/dist/client/utils/markerSyncEngine.d.ts.map +1 -1
  5. package/dist/commentRepository/events/utils.d.ts.map +1 -1
  6. package/dist/communityRepository/api/createCommunity.d.ts.map +1 -1
  7. package/dist/communityRepository/api/getCommunities.d.ts.map +1 -1
  8. package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
  9. package/dist/communityRepository/api/queryCommunities.d.ts.map +1 -1
  10. package/dist/communityRepository/api/updateCommunity.d.ts.map +1 -1
  11. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts +14 -0
  12. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts.map +1 -0
  13. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.d.ts +9 -0
  14. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.d.ts.map +1 -0
  15. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts +15 -0
  16. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts.map +1 -0
  17. package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts +11 -0
  18. package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts.map +1 -0
  19. package/dist/communityRepository/communityMembership/observers/getMembers.d.ts.map +1 -1
  20. package/dist/communityRepository/communityMembership/observers/index.d.ts +1 -0
  21. package/dist/communityRepository/communityMembership/observers/index.d.ts.map +1 -1
  22. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.d.ts +14 -0
  23. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.d.ts.map +1 -0
  24. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts +9 -0
  25. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts.map +1 -0
  26. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts +15 -0
  27. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts.map +1 -0
  28. package/dist/communityRepository/communityMembership/observers/searchMembers/enums.d.ts +10 -0
  29. package/dist/communityRepository/communityMembership/observers/searchMembers/enums.d.ts.map +1 -0
  30. package/dist/communityRepository/communityMembership/observers/searchMembers.d.ts +20 -0
  31. package/dist/communityRepository/communityMembership/observers/searchMembers.d.ts.map +1 -0
  32. package/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts.map +1 -1
  33. package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts +3 -2
  34. package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts.map +1 -1
  35. package/dist/communityRepository/observers/getCommunities.d.ts.map +1 -1
  36. package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesLiveCollectionController.d.ts.map +1 -1
  37. package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.d.ts +3 -2
  38. package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.d.ts.map +1 -1
  39. package/dist/communityRepository/observers/searchCommunities.d.ts +1 -1
  40. package/dist/communityRepository/utils/payload.d.ts.map +1 -1
  41. package/dist/communityRepository/utils/saveCommunityUsers.d.ts +2 -0
  42. package/dist/communityRepository/utils/saveCommunityUsers.d.ts.map +1 -0
  43. package/dist/fileRepository/api/createFile.d.ts.map +1 -1
  44. package/dist/fileRepository/api/createImage.d.ts.map +1 -1
  45. package/dist/fileRepository/api/createVideo.d.ts.map +1 -1
  46. package/dist/fileRepository/api/uploadFile.d.ts.map +1 -1
  47. package/dist/fileRepository/api/uploadImage.d.ts.map +1 -1
  48. package/dist/fileRepository/api/uploadVideo.d.ts.map +1 -1
  49. package/dist/index.cjs.js +802 -474
  50. package/dist/index.esm.js +778 -450
  51. package/dist/index.umd.js +4 -4
  52. package/dist/utils/liveObject.d.ts +3 -0
  53. package/dist/utils/liveObject.d.ts.map +1 -1
  54. package/package.json +1 -1
  55. package/src/@types/domains/community.ts +25 -1
  56. package/src/client/api/secureLogout.ts +1 -1
  57. package/src/client/utils/markerSyncEngine.ts +4 -1
  58. package/src/commentRepository/events/utils.ts +8 -5
  59. package/src/communityRepository/api/createCommunity.ts +5 -2
  60. package/src/communityRepository/api/getCommunities.ts +5 -1
  61. package/src/communityRepository/api/getCommunity.ts +5 -1
  62. package/src/communityRepository/api/queryCommunities.ts +2 -2
  63. package/src/communityRepository/api/updateCommunity.ts +5 -1
  64. package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.ts +151 -0
  65. package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.ts +26 -0
  66. package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.ts +114 -0
  67. package/src/communityRepository/communityMembership/observers/getMembers/enums.ts +10 -0
  68. package/src/communityRepository/communityMembership/observers/getMembers.ts +15 -128
  69. package/src/communityRepository/communityMembership/observers/index.ts +1 -0
  70. package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.ts +130 -0
  71. package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.ts +29 -0
  72. package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.ts +105 -0
  73. package/src/communityRepository/communityMembership/observers/searchMembers/enums.ts +9 -0
  74. package/src/communityRepository/communityMembership/observers/searchMembers.ts +60 -0
  75. package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +9 -1
  76. package/src/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.ts +6 -3
  77. package/src/communityRepository/observers/getCommunities.ts +7 -150
  78. package/src/communityRepository/observers/searchCommunities/SearchCommunitiesLiveCollectionController.ts +11 -13
  79. package/src/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.ts +3 -2
  80. package/src/communityRepository/observers/searchCommunities.ts +1 -1
  81. package/src/communityRepository/utils/payload.ts +35 -1
  82. package/src/communityRepository/utils/saveCommunityUsers.ts +16 -0
  83. package/src/fileRepository/api/createFile.ts +5 -2
  84. package/src/fileRepository/api/createImage.ts +6 -2
  85. package/src/fileRepository/api/createVideo.ts +5 -2
  86. package/src/fileRepository/api/uploadFile.ts +5 -2
  87. package/src/fileRepository/api/uploadImage.ts +5 -2
  88. package/src/fileRepository/api/uploadVideo.ts +5 -2
  89. package/src/utils/liveObject.ts +3 -0
@@ -1,31 +1,7 @@
1
- /* eslint-disable no-use-before-define */
2
- import { getResolver } from '~/core/model';
3
- import { dropFromCache, pullFromCache, pushToCache } from '~/cache/api';
1
+ import { dropFromCache } from '~/cache/api';
4
2
  import { getActiveClient } from '~/client/api';
5
- import {
6
- createQuery,
7
- filterByCommunityMembership,
8
- filterByPropEquality,
9
- filterByStringComparePartially,
10
- queryOptions,
11
- runQuery,
12
- sortByDisplayName,
13
- sortByFirstCreated,
14
- sortByLastCreated,
15
- } from '~/core/query';
16
- import {
17
- COLLECTION_DEFAULT_CACHING_POLICY,
18
- COLLECTION_DEFAULT_PAGINATION_LIMIT,
19
- ENABLE_CACHE_MESSAGE,
20
- } from '~/utils/constants';
21
- import { CACHE_SHORTEN_LIFESPAN } from '~/cache/utils';
22
- import { onCommunityCreated, onCommunityDeleted, onCommunityUpdated } from '../events';
23
- import {
24
- onCommunityJoined,
25
- onCommunityLeft,
26
- onCommunityUserChanged,
27
- } from '../communityMembership/events';
28
- import { queryCommunities } from '../api/queryCommunities';
3
+ import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
4
+ import { CommunityLiveCollectionController } from './getCommunities/CommunitiesLiveCollectionController';
29
5
 
30
6
  /* begin_public_function
31
7
  id: community.query
@@ -53,7 +29,7 @@ export const getCommunities = (
53
29
  callback: Amity.LiveCollectionCallback<Amity.Community>,
54
30
  config?: Amity.LiveCollectionConfig,
55
31
  ) => {
56
- const { log, cache, userId } = getActiveClient();
32
+ const { log, cache } = getActiveClient();
57
33
 
58
34
  if (!cache) {
59
35
  console.log(ENABLE_CACHE_MESSAGE);
@@ -62,130 +38,11 @@ export const getCommunities = (
62
38
  const timestamp = Date.now();
63
39
  log(`getCommunities(tmpid: ${timestamp}) > listen`);
64
40
 
65
- const { limit: queryLimit, ...queryParams } = params;
41
+ const communitiesLiveCollection = new CommunityLiveCollectionController(params, callback);
42
+ const disposers = communitiesLiveCollection.startSubscription();
66
43
 
67
- const limit = queryLimit ?? COLLECTION_DEFAULT_PAGINATION_LIMIT;
68
- const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config ?? {};
44
+ const cacheKey = communitiesLiveCollection.getCacheKey();
69
45
 
70
- const disposers: Amity.Unsubscriber[] = [];
71
- const cacheKey = ['community', 'collection', queryParams as Amity.Serializable];
72
-
73
- const responder = (data: Amity.CommunityLiveCollectionCache) => {
74
- let communities: Amity.Community[] =
75
- data.data
76
- .map(communityId => pullFromCache<Amity.Community>(['community', 'get', communityId])!)
77
- .filter(Boolean)
78
- .map(({ data }) => data) ?? [];
79
-
80
- communities = filterByStringComparePartially(communities, 'displayName', params.displayName);
81
-
82
- if (!params.includeDeleted) {
83
- communities = filterByPropEquality(communities, 'isDeleted', false);
84
- }
85
-
86
- if (params.categoryId) {
87
- communities = communities.filter(c => c.categoryIds?.includes(params.categoryId!));
88
- }
89
-
90
- if (params.tags) {
91
- communities = communities.filter(c => c.tags?.some(t => params.tags?.includes(t)));
92
- }
93
-
94
- if (params.membership && userId) {
95
- communities = filterByCommunityMembership(communities, params.membership, userId);
96
- }
97
-
98
- const sortBy = params.sortBy || 'lastCreated';
99
-
100
- if (sortBy === 'lastCreated' || sortBy === 'firstCreated') {
101
- communities = communities.sort(
102
- sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated,
103
- );
104
- }
105
-
106
- /*
107
- * The server returns communities with empty | null displayName's first before
108
- * returning sorted list of communities with displayNames
109
- *
110
- * This section needs to be updated as displayNames can be null as well
111
- */
112
- if (sortBy === 'displayName') {
113
- communities = communities
114
- // this needs to be aligned with the backend data type
115
- .map(c => (c.displayName ? c : { ...c, displayName: '' }))
116
- // @ts-ignore
117
- .sort(sortByDisplayName);
118
- }
119
-
120
- callback({
121
- onNextPage: onFetch,
122
- data: communities,
123
- hasNextPage: !!data.params?.page,
124
- loading: data.loading,
125
- error: data.error,
126
- });
127
- };
128
-
129
- const realtimeRouter = (_: Amity.CommunityActionType) => (community: Amity.Community) => {
130
- const collection = pullFromCache<Amity.CommunityLiveCollectionCache>(cacheKey)?.data;
131
- if (!collection) return;
132
-
133
- /*
134
- * Simply update collection and let responder decide what to do with data
135
- */
136
- collection.data = [...new Set([community.communityId, ...collection.data])];
137
-
138
- pushToCache(cacheKey, collection);
139
- responder(collection);
140
- };
141
-
142
- const onFetch = (initial = false) => {
143
- const collection = pullFromCache<Amity.CommunityLiveCollectionCache>(cacheKey)?.data;
144
-
145
- const communities = collection?.data ?? [];
146
-
147
- if (!initial && communities.length > 0 && !collection?.params.page) return;
148
-
149
- const query = createQuery(queryCommunities, {
150
- ...queryParams,
151
- limit: initial ? limit : undefined,
152
- page: !initial ? collection?.params.page : undefined,
153
- });
154
-
155
- runQuery(
156
- query,
157
- ({ data: result, error, loading, paging }) => {
158
- const data = {
159
- loading,
160
- error,
161
- params: { page: paging?.next },
162
- data: communities,
163
- };
164
-
165
- if (result) {
166
- data.data = initial
167
- ? result.map(getResolver('community'))
168
- : [...new Set([...communities, ...result.map(getResolver('community'))])];
169
- }
170
-
171
- pushToCache(cacheKey, data);
172
-
173
- responder(data);
174
- },
175
- queryOptions(policy, CACHE_SHORTEN_LIFESPAN),
176
- );
177
- };
178
-
179
- disposers.push(
180
- onCommunityCreated(realtimeRouter('onCreate')),
181
- onCommunityDeleted(realtimeRouter('onDelete')),
182
- onCommunityUpdated(realtimeRouter('onUpdate')),
183
- onCommunityJoined(realtimeRouter('onJoin')),
184
- onCommunityLeft(realtimeRouter('onLeft')),
185
- onCommunityUserChanged(realtimeRouter('onMemberCountChanged')),
186
- );
187
-
188
- onFetch(true);
189
46
  disposers.push(() => dropFromCache(cacheKey));
190
47
 
191
48
  return () => {
@@ -1,24 +1,19 @@
1
- /* eslint-disable no-use-before-define */
2
1
  import hash from 'object-hash';
3
2
  import { pullFromCache, pushToCache } from '~/cache/api';
4
3
  import { CommunitiesPaginationController } from './SearchCommunitiesPaginationController';
5
4
  import { CommunitiesQueryStreamController } from './SearchCommunitiesQueryStreamController';
6
5
  import { LiveCollectionController } from '~/core/liveCollection/LiveCollectionController';
7
- import {
8
- onCommunityCreated,
9
- onCommunityDeleted,
10
- onCommunityUpdated,
11
- } from '~/communityRepository/events';
12
- import {
13
- filterByCommunityMembership,
14
- filterByPropEquality,
15
- sortByDisplayName,
16
- sortByFirstCreated,
17
- sortByLastCreated,
18
- } from '~/core/query';
6
+ import { onCommunityDeleted, onCommunityUpdated } from '~/communityRepository/events';
7
+ import { filterByCommunityMembership, filterByPropEquality } from '~/core/query';
19
8
  import { prepareCommunityPayload } from '~/communityRepository/utils';
20
9
  import { getActiveClient } from '~/client';
21
10
  import { EnumCommunityActions } from './enums';
11
+ import { EnumCommunityMemberActions } from '~/communityRepository/communityMembership/observers/getMembers/enums';
12
+ import {
13
+ onCommunityJoined,
14
+ onCommunityLeft,
15
+ onCommunityUserChanged,
16
+ } from '~/communityRepository/communityMembership';
22
17
 
23
18
  export class SearchCommunityLiveCollectionController extends LiveCollectionController<
24
19
  'community',
@@ -78,6 +73,9 @@ export class SearchCommunityLiveCollectionController extends LiveCollectionContr
78
73
  return this.queryStreamController.subscribeRTE([
79
74
  { fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
80
75
  { fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
76
+ { fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
77
+ { fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
78
+ { fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnMemberCountChanged },
81
79
  ]);
82
80
  }
83
81
 
@@ -4,6 +4,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
4
4
  import { getResolver } from '~/core/model';
5
5
  import { getActiveClient } from '~/client';
6
6
  import { EnumCommunityActions } from './enums';
7
+ import { EnumCommunityMemberActions } from '~/communityRepository/communityMembership/observers/getMembers/enums';
7
8
 
8
9
  export class CommunitiesQueryStreamController extends QueryStreamController<
9
10
  Amity.CommunityPayload,
@@ -58,7 +59,7 @@ export class CommunitiesQueryStreamController extends QueryStreamController<
58
59
  }
59
60
  }
60
61
 
61
- reactor(action: EnumCommunityActions) {
62
+ reactor(action: EnumCommunityActions | EnumCommunityMemberActions) {
62
63
  return (community: Amity.Community) => {
63
64
  const collection = pullFromCache<Amity.SearchCommunityLiveCollectionCache>(
64
65
  this.cacheKey,
@@ -73,7 +74,7 @@ export class CommunitiesQueryStreamController extends QueryStreamController<
73
74
  subscribeRTE(
74
75
  createSubscriber: {
75
76
  fn: (reactor: (channel: Amity.Community) => void) => Amity.Unsubscriber;
76
- action: EnumCommunityActions;
77
+ action: EnumCommunityActions | EnumCommunityMemberActions;
77
78
  }[],
78
79
  ) {
79
80
  return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
@@ -8,7 +8,7 @@ import { SearchCommunityLiveCollectionController } from './searchCommunities/Sea
8
8
  */
9
9
  /**
10
10
  * ```js
11
- * import { CommunityRepository } from '@amityco/ts-sdk'
11
+ * import { CommunityRepository } from '@amityco/ts-sdk-react-native'
12
12
  *
13
13
  * let communities = []
14
14
  * const unsub = CommunityRepository.searchCommunities({
@@ -1,4 +1,5 @@
1
1
  import { CommunityPostSettingMaps, DefaultCommunityPostSetting } from '~/@types';
2
+ import { pullFromCache } from '~/cache/api';
2
3
  import { withUsers } from '~/group/utils';
3
4
  import { updateMembershipStatus } from './communityWithMembership';
4
5
 
@@ -13,6 +14,22 @@ const getMatchPostSetting = (value: {
13
14
  value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost,
14
15
  ) ?? DefaultCommunityPostSetting;
15
16
 
17
+ const convertCommunityUsersToUniqueObject = (
18
+ communityUsers: Amity.RawMembership<'community'>[],
19
+ ) => {
20
+ if (!communityUsers) return communityUsers;
21
+
22
+ const result: {
23
+ [key: string]: Amity.RawMembership<'community'>;
24
+ } = {};
25
+
26
+ communityUsers.forEach(user => {
27
+ result[`${user.userId}#${user.communityId}`] = user;
28
+ });
29
+
30
+ return result;
31
+ };
32
+
16
33
  export const prepareCommunityPayload = (
17
34
  rawPayload: Amity.CommunityPayload,
18
35
  ): Amity.ProcessedCommunityPayload => {
@@ -27,7 +44,24 @@ export const prepareCommunityPayload = (
27
44
  }),
28
45
  );
29
46
 
30
- const communityUsers = withUsers(rawPayload.communityUsers);
47
+ const mergeCommunityUsers = communities.reduce<{
48
+ [key: string]: Amity.RawMembership<'community'>;
49
+ }>((acc, { communityId }) => {
50
+ const users = pullFromCache<Amity.RawMembership<'community'>[]>([
51
+ 'communityUsers',
52
+ 'collection',
53
+ communityId,
54
+ ])?.data;
55
+
56
+ if (!users) return acc;
57
+
58
+ return {
59
+ ...convertCommunityUsersToUniqueObject(users),
60
+ ...acc,
61
+ };
62
+ }, convertCommunityUsersToUniqueObject(rawPayload.communityUsers));
63
+
64
+ const communityUsers = withUsers(Object.values(mergeCommunityUsers));
31
65
 
32
66
  const communityWithMembershipStatus = updateMembershipStatus(communities, communityUsers);
33
67
 
@@ -0,0 +1,16 @@
1
+ import { pushToCache } from '~/cache/api';
2
+
3
+ export const saveCommunityUsers = (
4
+ communities: Amity.CommunityPayload['communities'],
5
+ communityUsers: Amity.CommunityPayload['communityUsers'],
6
+ ) => {
7
+ if (communities.length === 0 || communityUsers.length === 0) return;
8
+
9
+ communities.forEach(({ communityId }) => {
10
+ const collection = communityUsers.filter(
11
+ ({ communityId: userCommunityId }) => communityId === userCommunityId,
12
+ );
13
+
14
+ pushToCache(['communityUsers', 'collection', communityId], collection);
15
+ });
16
+ };
@@ -24,8 +24,11 @@ export const createFile = async <T extends Amity.FileType = any>(
24
24
  const client = getActiveClient();
25
25
  client.log('file/createFile', formData);
26
26
 
27
- if (!formData.getAll('files').length)
28
- throw new Error('The formData object must have a `files` key.');
27
+ const files = formData.getAll('files');
28
+
29
+ if (!files.length) throw new Error('The formData object must have a `files` key.');
30
+
31
+ formData.append('preferredFilename', (files[0] as File).name);
29
32
 
30
33
  const headers =
31
34
  'getHeaders' in formData
@@ -23,8 +23,12 @@ export const createImage = async (
23
23
  const client = getActiveClient();
24
24
  client.log('file/createImage', formData);
25
25
 
26
- if (!formData.getAll('files').length)
27
- throw new Error('The formData object must have a `files` key.');
26
+ const files = formData.getAll('files');
27
+
28
+ if (!files.length) throw new Error('The formData object must have a `files` key.');
29
+
30
+ formData.append('preferredFilename', (files[0] as File).name);
31
+
28
32
  const headers =
29
33
  'getHeaders' in formData
30
34
  ? (formData as any).getHeaders()
@@ -26,8 +26,11 @@ export const createVideo = async (
26
26
  const client = getActiveClient();
27
27
  client.log('file/createVideo', formData);
28
28
 
29
- if (!formData.getAll('files').length)
30
- throw new Error('The formData object must have a `files` key.');
29
+ const files = formData.getAll('files');
30
+
31
+ if (!files.length) throw new Error('The formData object must have a `files` key.');
32
+
33
+ formData.append('preferredFilename', (files[0] as File).name);
31
34
 
32
35
  if (feedType) {
33
36
  formData.append('feedType', feedType);
@@ -27,8 +27,11 @@ export const uploadFile = async <T extends Amity.FileType = any>(
27
27
  const client = getActiveClient();
28
28
  client.log('file/uploadFile', formData);
29
29
 
30
- if (!formData.getAll('files').length)
31
- throw new Error('The formData object must have a `files` key.');
30
+ const files = formData.getAll('files');
31
+
32
+ if (!files.length) throw new Error('The formData object must have a `files` key.');
33
+
34
+ formData.append('preferredFilename', (files[0] as File).name);
32
35
 
33
36
  const headers =
34
37
  'getHeaders' in formData
@@ -27,8 +27,11 @@ export const uploadImage = async (
27
27
  const client = getActiveClient();
28
28
  client.log('file/uploadImage', formData);
29
29
 
30
- if (!formData.getAll('files').length)
31
- throw new Error('The formData object must have a `files` key.');
30
+ const files = formData.getAll('files');
31
+
32
+ if (!files.length) throw new Error('The formData object must have a `files` key.');
33
+
34
+ formData.append('preferredFilename', (files[0] as File).name);
32
35
 
33
36
  const headers =
34
37
  'getHeaders' in formData
@@ -29,8 +29,11 @@ export const uploadVideo = async (
29
29
  const client = getActiveClient();
30
30
  client.log('file/uploadVideo', formData);
31
31
 
32
- if (!formData.getAll('files').length)
33
- throw new Error('The formData object must have a `files` key.');
32
+ const files = formData.getAll('files');
33
+
34
+ if (!files.length) throw new Error('The formData object must have a `files` key.');
35
+
36
+ formData.append('preferredFilename', (files[0] as File).name);
34
37
 
35
38
  if (feedType) {
36
39
  formData.append('feedType', feedType);
@@ -10,6 +10,9 @@ import { convertGetterPropsToStatic } from '~/utils/object';
10
10
 
11
11
  import { isEqual } from './isEqual';
12
12
 
13
+ /**
14
+ * @deprecated This function is deprecated
15
+ */
13
16
  export const liveObject = <
14
17
  T extends Amity.Model,
15
18
  K extends keyof T,