@oxyhq/services 5.16.10 → 5.16.11

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 (32) hide show
  1. package/lib/commonjs/ui/context/OxyContext.js +9 -27
  2. package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
  3. package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js +9 -13
  4. package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js.map +1 -1
  5. package/lib/commonjs/ui/screens/WelcomeNewUserScreen.js +3 -12
  6. package/lib/commonjs/ui/screens/WelcomeNewUserScreen.js.map +1 -1
  7. package/lib/commonjs/ui/utils/avatarUtils.js +51 -0
  8. package/lib/commonjs/ui/utils/avatarUtils.js.map +1 -0
  9. package/lib/commonjs/ui/utils/fileManagement.js +3 -12
  10. package/lib/commonjs/ui/utils/fileManagement.js.map +1 -1
  11. package/lib/module/ui/context/OxyContext.js +9 -27
  12. package/lib/module/ui/context/OxyContext.js.map +1 -1
  13. package/lib/module/ui/hooks/mutations/useAccountMutations.js +9 -13
  14. package/lib/module/ui/hooks/mutations/useAccountMutations.js.map +1 -1
  15. package/lib/module/ui/screens/WelcomeNewUserScreen.js +3 -12
  16. package/lib/module/ui/screens/WelcomeNewUserScreen.js.map +1 -1
  17. package/lib/module/ui/utils/avatarUtils.js +47 -0
  18. package/lib/module/ui/utils/avatarUtils.js.map +1 -0
  19. package/lib/module/ui/utils/fileManagement.js +4 -12
  20. package/lib/module/ui/utils/fileManagement.js.map +1 -1
  21. package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
  22. package/lib/typescript/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -1
  23. package/lib/typescript/ui/screens/WelcomeNewUserScreen.d.ts.map +1 -1
  24. package/lib/typescript/ui/utils/avatarUtils.d.ts +20 -0
  25. package/lib/typescript/ui/utils/avatarUtils.d.ts.map +1 -0
  26. package/lib/typescript/ui/utils/fileManagement.d.ts.map +1 -1
  27. package/package.json +1 -1
  28. package/src/ui/context/OxyContext.tsx +9 -23
  29. package/src/ui/hooks/mutations/useAccountMutations.ts +9 -9
  30. package/src/ui/screens/WelcomeNewUserScreen.tsx +3 -12
  31. package/src/ui/utils/avatarUtils.ts +53 -0
  32. package/src/ui/utils/fileManagement.ts +3 -12
@@ -3,6 +3,7 @@ import type { User } from '../../../models/interfaces';
3
3
  import { queryKeys, invalidateAccountQueries, invalidateUserQueries } from '../queries/queryKeys';
4
4
  import { useOxy } from '../../context/OxyContext';
5
5
  import { toast } from '../../../lib/sonner';
6
+ import { refreshAvatarInStore } from '../../utils/avatarUtils';
6
7
 
7
8
  /**
8
9
  * Update user profile with optimistic updates and offline queue support
@@ -99,22 +100,21 @@ export const useUpdateProfile = () => {
99
100
  toast.error(error instanceof Error ? error.message : 'Failed to update profile');
100
101
  },
101
102
  // On success, invalidate and refetch
102
- onSuccess: (data) => {
103
+ onSuccess: (data, updates) => {
103
104
  // Update cache with server response
104
105
  queryClient.setQueryData(queryKeys.accounts.current(), data);
105
106
  if (activeSessionId) {
106
107
  queryClient.setQueryData(queryKeys.users.profile(activeSessionId), data);
107
108
  }
108
109
 
109
- // Invalidate related queries
110
- invalidateUserQueries(queryClient);
111
- },
112
- // Always refetch after error or success
113
- onSettled: () => {
114
- queryClient.invalidateQueries({ queryKey: queryKeys.accounts.current() });
115
- if (activeSessionId) {
116
- queryClient.invalidateQueries({ queryKey: queryKeys.users.profile(activeSessionId) });
110
+ // If avatar was updated, refresh accountStore with cache-busted URL
111
+ if (updates.avatar && activeSessionId && oxyServices) {
112
+ refreshAvatarInStore(activeSessionId, updates.avatar, oxyServices);
117
113
  }
114
+
115
+ // Invalidate all related queries to refresh everywhere
116
+ invalidateUserQueries(queryClient);
117
+ invalidateAccountQueries(queryClient);
118
118
  },
119
119
  });
120
120
  };
@@ -12,6 +12,7 @@ import GroupedPillButtons from '../components/internal/GroupedPillButtons';
12
12
  import { useI18n } from '../hooks/useI18n';
13
13
  import { useOxy } from '../context/OxyContext';
14
14
  import { useUpdateProfile } from '../hooks/mutations/useAccountMutations';
15
+ import { updateAvatarVisibility } from '../utils/avatarUtils';
15
16
 
16
17
  const GAP = 12;
17
18
  const INNER_GAP = 8;
@@ -147,18 +148,8 @@ const WelcomeNewUserScreen: React.FC<BaseScreenProps & { newUser?: any }> = ({
147
148
  return;
148
149
  }
149
150
  try {
150
- // Update file visibility to public for avatar (skip if temporary asset ID)
151
- if (file.id && !file.id.startsWith('temp-')) {
152
- try {
153
- await oxyServices.assetUpdateVisibility(file.id, 'public');
154
- console.log('[WelcomeNewUser] Avatar visibility updated to public');
155
- } catch (visError: any) {
156
- // Only log non-404 errors (404 means asset doesn't exist yet, which is OK)
157
- if (visError?.response?.status !== 404) {
158
- console.warn('[WelcomeNewUser] Failed to update avatar visibility, continuing anyway:', visError);
159
- }
160
- }
161
- }
151
+ // Update file visibility to public for avatar
152
+ await updateAvatarVisibility(file.id, oxyServices, 'WelcomeNewUser');
162
153
 
163
154
  // Update the avatar immediately in local state
164
155
  setSelectedAvatarId(file.id);
@@ -0,0 +1,53 @@
1
+ import type { OxyServices } from '../../core';
2
+ import { useAccountStore } from '../stores/accountStore';
3
+
4
+ /**
5
+ * Updates file visibility to public for avatar use.
6
+ * Handles errors gracefully, only logging non-404 errors.
7
+ *
8
+ * @param fileId - The file ID to update visibility for
9
+ * @param oxyServices - OxyServices instance
10
+ * @param contextName - Optional context name for logging
11
+ * @returns Promise that resolves when visibility is updated (or skipped)
12
+ */
13
+ export async function updateAvatarVisibility(
14
+ fileId: string | undefined,
15
+ oxyServices: OxyServices,
16
+ contextName: string = 'AvatarUtils'
17
+ ): Promise<void> {
18
+ // Skip if temporary asset ID or no file ID
19
+ if (!fileId || fileId.startsWith('temp-')) {
20
+ return;
21
+ }
22
+
23
+ try {
24
+ await oxyServices.assetUpdateVisibility(fileId, 'public');
25
+ console.log(`[${contextName}] Avatar visibility updated to public`);
26
+ } catch (visError: any) {
27
+ // Only log non-404 errors (404 means asset doesn't exist yet, which is OK)
28
+ if (visError?.response?.status !== 404) {
29
+ console.warn(`[${contextName}] Failed to update avatar visibility, continuing anyway:`, visError);
30
+ }
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Refreshes avatar in accountStore with cache-busted URL to force image reload.
36
+ *
37
+ * @param sessionId - The session ID for the account to update
38
+ * @param avatarFileId - The new avatar file ID
39
+ * @param oxyServices - OxyServices instance to generate download URL
40
+ */
41
+ export function refreshAvatarInStore(
42
+ sessionId: string,
43
+ avatarFileId: string,
44
+ oxyServices: OxyServices
45
+ ): void {
46
+ const { updateAccount } = useAccountStore.getState();
47
+ const cacheBustedUrl = oxyServices.getFileDownloadUrl(avatarFileId, 'thumb') + `?t=${Date.now()}`;
48
+ updateAccount(sessionId, {
49
+ avatar: avatarFileId,
50
+ avatarUrl: cacheBustedUrl,
51
+ });
52
+ }
53
+
@@ -3,6 +3,7 @@ import type { FileMetadata } from '../../models/interfaces';
3
3
  import { File as ExpoFile } from 'expo-file-system';
4
4
  import { toast } from '../../lib/sonner';
5
5
  import type { RouteName } from '../navigation/routes';
6
+ import { updateAvatarVisibility } from './avatarUtils';
6
7
 
7
8
  /**
8
9
  * Format file size in bytes to human-readable string
@@ -263,18 +264,8 @@ export function createAvatarPickerHandler(config: AvatarPickerConfig): () => voi
263
264
  }
264
265
 
265
266
  try {
266
- // Update file visibility to public for avatar (skip if temporary asset ID)
267
- if (file.id && !file.id.startsWith('temp-')) {
268
- try {
269
- await oxyServices.assetUpdateVisibility(file.id, 'public');
270
- console.log(`[${contextName}] Avatar visibility updated to public`);
271
- } catch (visError: any) {
272
- // Only log non-404 errors (404 means asset doesn't exist yet, which is OK)
273
- if (visError?.response?.status !== 404) {
274
- console.warn(`[${contextName}] Failed to update avatar visibility, continuing anyway:`, visError);
275
- }
276
- }
277
- }
267
+ // Update file visibility to public for avatar
268
+ await updateAvatarVisibility(file.id, oxyServices, contextName);
278
269
 
279
270
  // Update local state if callback provided
280
271
  if (onAvatarSelected) {