@amityco/ts-sdk-react-native 6.27.0 → 6.28.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.
Files changed (49) hide show
  1. package/dist/@types/domains/file.d.ts +6 -0
  2. package/dist/@types/domains/file.d.ts.map +1 -1
  3. package/dist/@types/domains/post.d.ts +3 -3
  4. package/dist/@types/domains/post.d.ts.map +1 -1
  5. package/dist/client/api/getToken.d.ts +10 -5
  6. package/dist/client/api/getToken.d.ts.map +1 -1
  7. package/dist/client/api/index.d.ts +1 -0
  8. package/dist/client/api/index.d.ts.map +1 -1
  9. package/dist/client/api/login.d.ts.map +1 -1
  10. package/dist/client/api/logout.d.ts.map +1 -1
  11. package/dist/client/api/renewal.d.ts.map +1 -1
  12. package/dist/client/api/setUploadedFileAccessType.d.ts +2 -0
  13. package/dist/client/api/setUploadedFileAccessType.d.ts.map +1 -0
  14. package/dist/client/utils/GlobalFileAccessType.d.ts +10 -0
  15. package/dist/client/utils/GlobalFileAccessType.d.ts.map +1 -0
  16. package/dist/fileRepository/api/createFile.d.ts.map +1 -1
  17. package/dist/fileRepository/api/createImage.d.ts.map +1 -1
  18. package/dist/fileRepository/api/createVideo.d.ts.map +1 -1
  19. package/dist/fileRepository/api/uploadFile.d.ts.map +1 -1
  20. package/dist/fileRepository/api/uploadImage.d.ts.map +1 -1
  21. package/dist/fileRepository/api/uploadVideo.d.ts.map +1 -1
  22. package/dist/index.cjs.js +106 -75
  23. package/dist/index.esm.js +109 -76
  24. package/dist/index.umd.js +3 -3
  25. package/dist/postRepository/api/editPost.d.ts +1 -1
  26. package/dist/postRepository/api/editPost.d.ts.map +1 -1
  27. package/dist/postRepository/api/updatePost.d.ts +1 -1
  28. package/dist/postRepository/api/updatePost.d.ts.map +1 -1
  29. package/dist/utils/linkedObject/categoryLinkedObject.d.ts.map +1 -1
  30. package/dist/utils/linkedObject/userLinkedObject.d.ts.map +1 -1
  31. package/package.json +1 -1
  32. package/src/@types/domains/file.ts +8 -0
  33. package/src/@types/domains/post.ts +3 -4
  34. package/src/client/api/getToken.ts +15 -7
  35. package/src/client/api/index.ts +1 -0
  36. package/src/client/api/login.ts +11 -7
  37. package/src/client/api/logout.ts +4 -0
  38. package/src/client/api/renewal.ts +6 -1
  39. package/src/client/api/setUploadedFileAccessType.ts +5 -0
  40. package/src/client/api/tests/getToken.test.ts +3 -3
  41. package/src/client/utils/GlobalFileAccessType.ts +23 -0
  42. package/src/fileRepository/api/createFile.ts +4 -0
  43. package/src/fileRepository/api/createImage.ts +4 -0
  44. package/src/fileRepository/api/createVideo.ts +4 -0
  45. package/src/fileRepository/api/uploadFile.ts +4 -0
  46. package/src/fileRepository/api/uploadImage.ts +4 -0
  47. package/src/fileRepository/api/uploadVideo.ts +4 -0
  48. package/src/utils/linkedObject/categoryLinkedObject.ts +6 -28
  49. package/src/utils/linkedObject/userLinkedObject.ts +8 -27
@@ -15,7 +15,7 @@
15
15
  * @category Post API
16
16
  * @async
17
17
  */
18
- export declare const editPost: <T extends Amity.PostContentType>(postId: Amity.Post['postId'], patch: Partial<Pick<Amity.Post<any>, "data" | "metadata" | "mentionees" | "tags">> & {
18
+ export declare const editPost: <T extends string>(postId: Amity.Post['postId'], patch: Partial<Pick<Amity.Post<any>, "data" | "metadata" | "mentionees" | "tags">> & {
19
19
  attachments?: {
20
20
  type: T;
21
21
  fileId: Amity.File['fileId'];
@@ -1 +1 @@
1
- {"version":3,"file":"editPost.d.ts","sourceRoot":"","sources":["../../../src/postRepository/api/editPost.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,QAAQ,4CACX,MAAM,IAAI,CAAC,QAAQ,CAAC;;;gBAIhB,UAAU,CAAC,QAAQ,CAAC;;MAG/B,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,CAAC,CAsBlC,CAAC"}
1
+ {"version":3,"file":"editPost.d.ts","sourceRoot":"","sources":["../../../src/postRepository/api/editPost.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,QAAQ,6BACX,MAAM,IAAI,CAAC,QAAQ,CAAC;;;gBAIhB,UAAU,CAAC,QAAQ,CAAC;;MAG/B,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,CAAC,CAsBlC,CAAC"}
@@ -15,7 +15,7 @@
15
15
  * @category Post API
16
16
  * @async
17
17
  */
18
- export declare const updatePost: <T extends Amity.PostContentType>(postId: Amity.Post['postId'], patch: Partial<Pick<Amity.Post<any>, "data" | "metadata" | "mentionees" | "tags">> & {
18
+ export declare const updatePost: <T extends string>(postId: Amity.Post['postId'], patch: Partial<Pick<Amity.Post<any>, "data" | "metadata" | "mentionees" | "tags">> & {
19
19
  attachments?: {
20
20
  type: T;
21
21
  fileId: Amity.File['fileId'];
@@ -1 +1 @@
1
- {"version":3,"file":"updatePost.d.ts","sourceRoot":"","sources":["../../../src/postRepository/api/updatePost.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,UAAU,4CACb,MAAM,IAAI,CAAC,QAAQ,CAAC;;;gBAIhB,UAAU,CAAC,QAAQ,CAAC;;MAG/B,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,CAAC,CA0BlC,CAAC"}
1
+ {"version":3,"file":"updatePost.d.ts","sourceRoot":"","sources":["../../../src/postRepository/api/updatePost.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,UAAU,6BACb,MAAM,IAAI,CAAC,QAAQ,CAAC;;;gBAIhB,UAAU,CAAC,QAAQ,CAAC;;MAG/B,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,CAAC,CA0BlC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"categoryLinkedObject.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/categoryLinkedObject.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,aAAc,MAAM,gBAAgB,KAAG,MAAM,QAqC7E,CAAC"}
1
+ {"version":3,"file":"categoryLinkedObject.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/categoryLinkedObject.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,aAAc,MAAM,gBAAgB,KAAG,MAAM,QAe7E,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"userLinkedObject.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/userLinkedObject.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,SAAU,MAAM,YAAY,KAAG,MAAM,IAiCjE,CAAC"}
1
+ {"version":3,"file":"userLinkedObject.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/userLinkedObject.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,SAAU,MAAM,YAAY,KAAG,MAAM,IAcjE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk-react-native",
3
- "version": "6.27.0",
3
+ "version": "6.28.0",
4
4
  "license": "CC-BY-ND-4.0",
5
5
  "author": "amity.co <developers@amity.co> (https://amity.co)",
6
6
  "description": "Amity Social Cloud Typescript SDK",
@@ -26,8 +26,15 @@ export const VideoSize = Object.freeze({
26
26
  ORIGINAL: 'original',
27
27
  });
28
28
 
29
+ export enum FileAccessTypeEnum {
30
+ PUBLIC = 'public',
31
+ NETWORK = 'network',
32
+ }
33
+
29
34
  declare global {
30
35
  namespace Amity {
36
+ type FileAccessType = `${FileAccessTypeEnum}`;
37
+
31
38
  type FileType = ValueOf<typeof FileType>;
32
39
 
33
40
  type VideoResolution = ValueOf<typeof VideoResolution>;
@@ -73,6 +80,7 @@ declare global {
73
80
  mimeType: string;
74
81
  metadata: MetadataFor<T>;
75
82
  };
83
+ accessType: FileAccessType;
76
84
  } & (T extends 'video' ? VideoFileExtraPayload : unknown) &
77
85
  Amity.Timestamps &
78
86
  Amity.SoftDelete;
@@ -12,7 +12,7 @@ declare global {
12
12
  // bad hack until we get proper feed objects in backend
13
13
  type PostTargetType = Amity.Feed['targetType'] | 'content';
14
14
 
15
- type PostContentType = ValueOf<typeof PostContentType>;
15
+ type PostContentType = ValueOf<typeof PostContentType> | string;
16
16
 
17
17
  type PostActionType =
18
18
  | 'onFetch'
@@ -26,7 +26,7 @@ declare global {
26
26
  | 'onReactionAdded'
27
27
  | 'onReactionRemoved';
28
28
 
29
- type InternalPost<T extends PostContentType | string = any> = {
29
+ type InternalPost<T extends PostContentType = any> = {
30
30
  postId: string;
31
31
  postedUserId: Amity.InternalUser['userId']; // API-FIX: it should be "userId"
32
32
  parentId: Amity.InternalPost['postId'];
@@ -59,8 +59,7 @@ declare global {
59
59
  };
60
60
  };
61
61
 
62
- type Post<T extends PostContentType | string = any> = Amity.InternalPost<T> &
63
- Amity.PostLinkObject;
62
+ type Post<T extends PostContentType = any> = Amity.InternalPost<T> & Amity.PostLinkObject;
64
63
 
65
64
  type QueryPosts = {
66
65
  targetId: string;
@@ -14,11 +14,17 @@ import { getDeviceInfo } from '~/core/device';
14
14
  * @category Client API
15
15
  * @hidden
16
16
  */
17
- export const getToken = async (params: {
18
- userId: Amity.InternalUser['userId'];
19
- displayName?: Amity.InternalUser['displayName'];
20
- authToken?: string;
21
- deviceId: Amity.Device['deviceId'];
17
+ export const getToken = async ({
18
+ params,
19
+ options,
20
+ }: {
21
+ params: {
22
+ userId: Amity.InternalUser['userId'];
23
+ displayName?: Amity.InternalUser['displayName'];
24
+ authToken?: string;
25
+ deviceId: Amity.Device['deviceId'];
26
+ };
27
+ options?: { setAccessTokenCookie?: boolean };
22
28
  }) => {
23
29
  const client = getActiveClient();
24
30
  client.log('client/api/getToken', params);
@@ -32,8 +38,10 @@ export const getToken = async (params: {
32
38
  deviceInfo,
33
39
  },
34
40
  {
35
- // @ts-ignore
36
- headers: { 'X-API-Key': client.apiKey },
41
+ headers: {
42
+ 'X-API-Key': client.apiKey,
43
+ 'set-access-token-cookie': options?.setAccessTokenCookie || false,
44
+ },
37
45
  },
38
46
  );
39
47
 
@@ -19,3 +19,4 @@ export * from './enableUnreadCount';
19
19
 
20
20
  export * from './registerPushNotification';
21
21
  export * from './unregisterPushNotification';
22
+ export * from './setUploadedFileAccessType';
@@ -18,8 +18,6 @@ import { getActiveClient } from './activeClient';
18
18
  import { terminateClient } from './terminateClient';
19
19
  import { setActiveUser } from './activeUser';
20
20
 
21
- import { setSessionState } from './setSessionState';
22
-
23
21
  import { onClientBanned } from '../events';
24
22
  import { onTokenExpired } from '../events/onTokenExpired';
25
23
  import { onTokenTerminated } from '../events/onTokenTerminated';
@@ -29,6 +27,7 @@ import { removeChannelMarkerCache } from '../utils/removeChannelMarkerCache';
29
27
  import { initializeMessagePreviewSetting } from '../utils/messagePreviewEngine';
30
28
  import { startMarkerSync } from '../utils/markerSyncEngine';
31
29
  import { ASCError } from '~/core/errors';
30
+ import SessionWatcher from '../utils/SessionWatcher';
32
31
 
33
32
  /*
34
33
  * declared earlier to accomodate case when logging in with a different user
@@ -92,9 +91,14 @@ export const login = async (
92
91
 
93
92
  try {
94
93
  const { users } = await setClientToken({
95
- ...params,
96
- displayName: params?.displayName,
97
- deviceId: params?.deviceId || defaultDeviceId,
94
+ params: {
95
+ ...params,
96
+ displayName: params?.displayName,
97
+ deviceId: params?.deviceId || defaultDeviceId,
98
+ },
99
+ options: {
100
+ setAccessTokenCookie: true,
101
+ },
98
102
  });
99
103
 
100
104
  const user = users.find(u => u.userId === params.userId);
@@ -139,7 +143,7 @@ export const login = async (
139
143
  * if getting token failed session state reverts to initial state when app
140
144
  * is first launched
141
145
  */
142
- setSessionState(Amity.SessionStates.NOT_LOGGED_IN);
146
+ SessionWatcher.getInstance().setSessionState(Amity.SessionStates.NOT_LOGGED_IN);
143
147
 
144
148
  // pass error down tree so the calling function handle it
145
149
  throw error;
@@ -181,7 +185,7 @@ export const login = async (
181
185
  }),
182
186
 
183
187
  onTokenExpired(state => {
184
- setSessionState(state);
188
+ SessionWatcher.getInstance().setSessionState(state);
185
189
 
186
190
  logout();
187
191
 
@@ -60,6 +60,10 @@ export const logout = async (): Promise<boolean> => {
60
60
  };
61
61
  client.ws.io.opts.query = { token: '' };
62
62
 
63
+ if (typeof document !== 'undefined') {
64
+ document.cookie = '_ascSession=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
65
+ }
66
+
63
67
  /*
64
68
  * Cache should be usable if tokenExpired
65
69
  * https://ekoapp.atlassian.net/wiki/spaces/UP/pages/2082537485/ASC+Core+-+Session+Management+3.0#SDK-usability-based-on-Session-State
@@ -40,7 +40,12 @@ export const renewal = (): Amity.AccessTokenRenewal => {
40
40
  } else {
41
41
  // about to expire
42
42
 
43
- await refreshToken(params);
43
+ await refreshToken({
44
+ params,
45
+ options: {
46
+ setAccessTokenCookie: true,
47
+ },
48
+ });
44
49
  }
45
50
 
46
51
  tokenRenewed = true;
@@ -0,0 +1,5 @@
1
+ import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
2
+
3
+ export function setUploadedFileAccessType(accessType: Amity.FileAccessType) {
4
+ GlobalFileAccessType.getInstance().setFileAccessType(accessType);
5
+ }
@@ -13,7 +13,7 @@ describe('getToken', () => {
13
13
  const mockApi = jest.fn().mockResolvedValue(sessionResponse);
14
14
  client.http.post = mockApi;
15
15
 
16
- await getToken(params);
16
+ await getToken({ params });
17
17
  const [recieved] = mockApi.mock.lastCall;
18
18
 
19
19
  expect(recieved).toBe(expected);
@@ -23,7 +23,7 @@ describe('getToken', () => {
23
23
  const expected = sessionResponse.data;
24
24
  client.http.post = jest.fn().mockResolvedValue(sessionResponse);
25
25
 
26
- const recieved = await getToken(params);
26
+ const recieved = await getToken({ params });
27
27
 
28
28
  expect(recieved).toStrictEqual(expected);
29
29
  });
@@ -31,6 +31,6 @@ describe('getToken', () => {
31
31
  test('it should throw error', async () => {
32
32
  client.http.post = jest.fn().mockRejectedValue(new Error('error'));
33
33
 
34
- await expect(getToken(params)).rejects.toThrow();
34
+ await expect(getToken({ params })).rejects.toThrow();
35
35
  });
36
36
  });
@@ -0,0 +1,23 @@
1
+ import { FileAccessTypeEnum } from '~/@types';
2
+
3
+ export class GlobalFileAccessType {
4
+ #fileAccessType: Amity.FileAccessType = FileAccessTypeEnum.PUBLIC;
5
+
6
+ public setFileAccessType(fileAccessType: Amity.FileAccessType) {
7
+ this.#fileAccessType = fileAccessType;
8
+ }
9
+
10
+ public getFileAccessType() {
11
+ return this.#fileAccessType;
12
+ }
13
+ }
14
+
15
+ let instance: GlobalFileAccessType;
16
+ export default {
17
+ getInstance: () => {
18
+ if (!instance) {
19
+ instance = new GlobalFileAccessType();
20
+ }
21
+ return instance;
22
+ },
23
+ };
@@ -1,6 +1,7 @@
1
1
  import { getActiveClient } from '~/client/api';
2
2
 
3
3
  import { ingestInCache } from '~/cache/api/ingestInCache';
4
+ import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
4
5
 
5
6
  /**
6
7
  * ```js
@@ -28,6 +29,9 @@ export const createFile = async <T extends Amity.FileType = any>(
28
29
 
29
30
  if (!files.length) throw new Error('The formData object must have a `files` key.');
30
31
 
32
+ const accessType = GlobalFileAccessType.getInstance().getFileAccessType();
33
+ formData.append('accessType', accessType);
34
+
31
35
  formData.append('preferredFilename', (files[0] as File).name);
32
36
 
33
37
  const headers =
@@ -1,5 +1,6 @@
1
1
  import { getActiveClient } from '~/client/api';
2
2
  import { ingestInCache } from '~/cache/api/ingestInCache';
3
+ import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
3
4
 
4
5
  /**
5
6
  * ```js
@@ -27,6 +28,9 @@ export const createImage = async (
27
28
 
28
29
  if (!files.length) throw new Error('The formData object must have a `files` key.');
29
30
 
31
+ const accessType = GlobalFileAccessType.getInstance().getFileAccessType();
32
+ formData.append('accessType', accessType);
33
+
30
34
  formData.append('preferredFilename', (files[0] as File).name);
31
35
 
32
36
  const headers =
@@ -1,6 +1,7 @@
1
1
  import { getActiveClient } from '~/client/api';
2
2
 
3
3
  import { ingestInCache } from '~/cache/api/ingestInCache';
4
+ import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
4
5
 
5
6
  /**
6
7
  * ```js
@@ -30,6 +31,9 @@ export const createVideo = async (
30
31
 
31
32
  if (!files.length) throw new Error('The formData object must have a `files` key.');
32
33
 
34
+ const accessType = GlobalFileAccessType.getInstance().getFileAccessType();
35
+ formData.append('accessType', accessType);
36
+
33
37
  formData.append('preferredFilename', (files[0] as File).name);
34
38
 
35
39
  if (feedType) {
@@ -1,6 +1,7 @@
1
1
  import { getActiveClient } from '~/client/api';
2
2
 
3
3
  import { ingestInCache } from '~/cache/api/ingestInCache';
4
+ import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
4
5
 
5
6
  /* begin_public_function
6
7
  id: file.upload.file
@@ -31,6 +32,9 @@ export const uploadFile = async <T extends Amity.FileType = any>(
31
32
 
32
33
  if (!files.length) throw new Error('The formData object must have a `files` key.');
33
34
 
35
+ const accessType = GlobalFileAccessType.getInstance().getFileAccessType();
36
+ formData.append('accessType', accessType);
37
+
34
38
  formData.append('preferredFilename', (files[0] as File).name);
35
39
 
36
40
  const headers =
@@ -1,6 +1,7 @@
1
1
  import { getActiveClient } from '~/client/api';
2
2
 
3
3
  import { ingestInCache } from '~/cache/api/ingestInCache';
4
+ import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
4
5
 
5
6
  /* begin_public_function
6
7
  id: file.upload.image
@@ -31,6 +32,9 @@ export const uploadImage = async (
31
32
 
32
33
  if (!files.length) throw new Error('The formData object must have a `files` key.');
33
34
 
35
+ const accessType = GlobalFileAccessType.getInstance().getFileAccessType();
36
+ formData.append('accessType', accessType);
37
+
34
38
  formData.append('preferredFilename', (files[0] as File).name);
35
39
 
36
40
  const headers =
@@ -1,6 +1,7 @@
1
1
  import { getActiveClient } from '~/client/api';
2
2
 
3
3
  import { ingestInCache } from '~/cache/api/ingestInCache';
4
+ import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
4
5
 
5
6
  /* begin_public_function
6
7
  id: file.upload.video, file.upload.audio
@@ -33,6 +34,9 @@ export const uploadVideo = async (
33
34
 
34
35
  if (!files.length) throw new Error('The formData object must have a `files` key.');
35
36
 
37
+ const accessType = GlobalFileAccessType.getInstance().getFileAccessType();
38
+ formData.append('accessType', accessType);
39
+
36
40
  formData.append('preferredFilename', (files[0] as File).name);
37
41
 
38
42
  if (feedType) {
@@ -3,38 +3,16 @@ import { pullFromCache } from '~/cache/api';
3
3
  export const categoryLinkedObject = (category: Amity.InternalCategory): Amity.Category => {
4
4
  return {
5
5
  ...category,
6
- get avatar(): Amity.File<'image'> | null {
7
- if (!category.avatarFileId) return null;
8
- let avatar: Amity.File<'image'> = {
9
- fileId: category.avatarFileId?.toString() ? category.avatarFileId.toString() : '',
10
- type: 'image',
11
- fileUrl: '',
12
- createdAt: '',
13
- attributes: {
14
- name: '',
15
- extension: '',
16
- size: '',
17
- mimeType: '',
18
- metadata: {
19
- exif: {},
20
- gps: {},
21
- width: 0,
22
- height: 0,
23
- isFull: false,
24
- },
25
- },
26
- };
27
- const cacheData = pullFromCache<Amity.File<'image'>>([
6
+ get avatar(): Amity.File<'image'> | undefined {
7
+ if (!category.avatarFileId) return undefined;
8
+
9
+ const avatar = pullFromCache<Amity.File<'image'>>([
28
10
  'file',
29
11
  'get',
30
12
  `${category.avatarFileId}`,
31
- ]);
32
-
33
- if (cacheData?.data) {
34
- avatar = cacheData?.data;
35
- }
13
+ ])?.data;
36
14
 
37
- return avatar as Amity.File<'image'>;
15
+ return avatar;
38
16
  },
39
17
  };
40
18
  };
@@ -3,34 +3,15 @@ import { pullFromCache } from '~/cache/api/pullFromCache';
3
3
  export const userLinkedObject = (user: Amity.InternalUser): Amity.User => {
4
4
  return {
5
5
  ...user,
6
- get avatar(): Amity.File<'image'> | null {
7
- if (!user.avatarFileId) return null;
8
- let avatar: Amity.File<'image'> = {
9
- fileId: user.avatarFileId?.toString() ? user.avatarFileId.toString() : '',
10
- type: 'image',
11
- fileUrl: '',
12
- createdAt: '',
13
- attributes: {
14
- name: '',
15
- extension: '',
16
- size: '',
17
- mimeType: '',
18
- metadata: {
19
- exif: {},
20
- gps: {},
21
- width: 0,
22
- height: 0,
23
- isFull: false,
24
- },
25
- },
26
- };
27
- const cacheData = pullFromCache<Amity.File<'image'>>(['file', 'get', `${user.avatarFileId}`]);
6
+ get avatar(): Amity.File<'image'> | undefined {
7
+ if (!user.avatarFileId) return undefined;
8
+ const avatar = pullFromCache<Amity.File<'image'>>([
9
+ 'file',
10
+ 'get',
11
+ `${user.avatarFileId}`,
12
+ ])?.data;
28
13
 
29
- if (cacheData?.data) {
30
- avatar = cacheData?.data;
31
- }
32
-
33
- return avatar as Amity.File<'image'>;
14
+ return avatar;
34
15
  },
35
16
  };
36
17
  };