@oxyhq/services 22.4.2 → 22.6.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.
- package/LICENSE +661 -21
- package/README.md +1 -1
- package/lib/commonjs/index.js +20 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/ui/client.js +1 -1
- package/lib/commonjs/ui/components/FontLoader.js +18 -145
- package/lib/commonjs/ui/components/FontLoader.js.map +1 -1
- package/lib/commonjs/ui/components/FontLoader.native.js +88 -0
- package/lib/commonjs/ui/components/FontLoader.native.js.map +1 -0
- package/lib/commonjs/ui/components/OxyProvider.js +1 -1
- package/lib/commonjs/ui/components/fileManagement/FileDetailsModal.js +16 -27
- package/lib/commonjs/ui/components/fileManagement/FileDetailsModal.js.map +1 -1
- package/lib/commonjs/ui/components/fileManagement/UploadPreview.js.map +1 -1
- package/lib/commonjs/ui/components/fileManagement/styles.js +1 -225
- package/lib/commonjs/ui/components/fileManagement/styles.js.map +1 -1
- package/lib/commonjs/ui/context/hooks/useAuthOperations.js +5 -2
- package/lib/commonjs/ui/context/hooks/useAuthOperations.js.map +1 -1
- package/lib/commonjs/ui/context/useOxyAccountGraph.js +7 -0
- package/lib/commonjs/ui/context/useOxyAccountGraph.js.map +1 -1
- package/lib/commonjs/ui/hooks/queries/useAccountQueries.js +14 -5
- package/lib/commonjs/ui/hooks/queries/useAccountQueries.js.map +1 -1
- package/lib/commonjs/ui/hooks/queries/userCache.js +286 -0
- package/lib/commonjs/ui/hooks/queries/userCache.js.map +1 -0
- package/lib/commonjs/ui/hooks/useAvatarPicker.js +23 -8
- package/lib/commonjs/ui/hooks/useAvatarPicker.js.map +1 -1
- package/lib/commonjs/ui/hooks/useFileDownloadUrl.js +7 -21
- package/lib/commonjs/ui/hooks/useFileDownloadUrl.js.map +1 -1
- package/lib/commonjs/ui/hooks/useResolvedFileUrls.js +163 -0
- package/lib/commonjs/ui/hooks/useResolvedFileUrls.js.map +1 -0
- package/lib/commonjs/ui/index.js +1 -1
- package/lib/commonjs/ui/screens/FileManagementScreen.js +51 -22
- package/lib/commonjs/ui/screens/FileManagementScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/fileManagement/PhotoPickerSection.js +216 -203
- package/lib/commonjs/ui/screens/fileManagement/PhotoPickerSection.js.map +1 -1
- package/lib/commonjs/ui/screens/fileManagement/hooks/useFileUploadState.js +26 -9
- package/lib/commonjs/ui/screens/fileManagement/hooks/useFileUploadState.js.map +1 -1
- package/lib/commonjs/ui/screens/fileManagement/photoGridLayout.js +44 -0
- package/lib/commonjs/ui/screens/fileManagement/photoGridLayout.js.map +1 -0
- package/lib/commonjs/ui/session/tokenTransport.js +21 -10
- package/lib/commonjs/ui/session/tokenTransport.js.map +1 -1
- package/lib/commonjs/ui/utils/fileManagement.js +0 -40
- package/lib/commonjs/ui/utils/fileManagement.js.map +1 -1
- package/lib/module/index.js +7 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/ui/client.js +1 -1
- package/lib/module/ui/client.js.map +1 -1
- package/lib/module/ui/components/FontLoader.js +18 -146
- package/lib/module/ui/components/FontLoader.js.map +1 -1
- package/lib/module/ui/components/FontLoader.native.js +83 -0
- package/lib/module/ui/components/FontLoader.native.js.map +1 -0
- package/lib/module/ui/components/OxyProvider.js +1 -1
- package/lib/module/ui/components/OxyProvider.js.map +1 -1
- package/lib/module/ui/components/fileManagement/FileDetailsModal.js +16 -27
- package/lib/module/ui/components/fileManagement/FileDetailsModal.js.map +1 -1
- package/lib/module/ui/components/fileManagement/UploadPreview.js.map +1 -1
- package/lib/module/ui/components/fileManagement/styles.js +0 -224
- package/lib/module/ui/components/fileManagement/styles.js.map +1 -1
- package/lib/module/ui/context/hooks/useAuthOperations.js +5 -2
- package/lib/module/ui/context/hooks/useAuthOperations.js.map +1 -1
- package/lib/module/ui/context/useOxyAccountGraph.js +7 -0
- package/lib/module/ui/context/useOxyAccountGraph.js.map +1 -1
- package/lib/module/ui/hooks/queries/useAccountQueries.js +14 -5
- package/lib/module/ui/hooks/queries/useAccountQueries.js.map +1 -1
- package/lib/module/ui/hooks/queries/userCache.js +282 -0
- package/lib/module/ui/hooks/queries/userCache.js.map +1 -0
- package/lib/module/ui/hooks/useAvatarPicker.js +23 -8
- package/lib/module/ui/hooks/useAvatarPicker.js.map +1 -1
- package/lib/module/ui/hooks/useFileDownloadUrl.js +7 -21
- package/lib/module/ui/hooks/useFileDownloadUrl.js.map +1 -1
- package/lib/module/ui/hooks/useResolvedFileUrls.js +157 -0
- package/lib/module/ui/hooks/useResolvedFileUrls.js.map +1 -0
- package/lib/module/ui/index.js +1 -1
- package/lib/module/ui/index.js.map +1 -1
- package/lib/module/ui/screens/FileManagementScreen.js +52 -23
- package/lib/module/ui/screens/FileManagementScreen.js.map +1 -1
- package/lib/module/ui/screens/fileManagement/PhotoPickerSection.js +218 -205
- package/lib/module/ui/screens/fileManagement/PhotoPickerSection.js.map +1 -1
- package/lib/module/ui/screens/fileManagement/hooks/useFileUploadState.js +26 -9
- package/lib/module/ui/screens/fileManagement/hooks/useFileUploadState.js.map +1 -1
- package/lib/module/ui/screens/fileManagement/photoGridLayout.js +39 -0
- package/lib/module/ui/screens/fileManagement/photoGridLayout.js.map +1 -0
- package/lib/module/ui/session/tokenTransport.js +21 -10
- package/lib/module/ui/session/tokenTransport.js.map +1 -1
- package/lib/module/ui/utils/fileManagement.js +0 -39
- package/lib/module/ui/utils/fileManagement.js.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +2 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/FontLoader.d.ts +14 -5
- package/lib/typescript/commonjs/ui/components/FontLoader.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/FontLoader.native.d.ts +13 -0
- package/lib/typescript/commonjs/ui/components/FontLoader.native.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/fileManagement/FileDetailsModal.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/fileManagement/styles.d.ts +0 -218
- package/lib/typescript/commonjs/ui/components/fileManagement/styles.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/context/hooks/useAuthOperations.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/context/useOxyAccountGraph.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/queries/useAccountQueries.d.ts +9 -0
- package/lib/typescript/commonjs/ui/hooks/queries/useAccountQueries.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/queries/userCache.d.ts +96 -0
- package/lib/typescript/commonjs/ui/hooks/queries/userCache.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/hooks/useAvatarPicker.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/useFileDownloadUrl.d.ts +3 -2
- package/lib/typescript/commonjs/ui/hooks/useFileDownloadUrl.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/useResolvedFileUrls.d.ts +48 -0
- package/lib/typescript/commonjs/ui/hooks/useResolvedFileUrls.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/FileManagementScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/fileManagement/PhotoPickerSection.d.ts +1 -1
- package/lib/typescript/commonjs/ui/screens/fileManagement/PhotoPickerSection.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/fileManagement/hooks/useFileUploadState.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/fileManagement/photoGridLayout.d.ts +37 -0
- package/lib/typescript/commonjs/ui/screens/fileManagement/photoGridLayout.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/session/tokenTransport.d.ts +15 -8
- package/lib/typescript/commonjs/ui/session/tokenTransport.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/utils/fileManagement.d.ts +4 -11
- package/lib/typescript/commonjs/ui/utils/fileManagement.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +3 -1
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/ui/client.d.ts +1 -1
- package/lib/typescript/module/ui/client.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/FontLoader.d.ts +14 -5
- package/lib/typescript/module/ui/components/FontLoader.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/FontLoader.native.d.ts +13 -0
- package/lib/typescript/module/ui/components/FontLoader.native.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/fileManagement/FileDetailsModal.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/fileManagement/styles.d.ts +0 -218
- package/lib/typescript/module/ui/components/fileManagement/styles.d.ts.map +1 -1
- package/lib/typescript/module/ui/context/hooks/useAuthOperations.d.ts.map +1 -1
- package/lib/typescript/module/ui/context/useOxyAccountGraph.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/queries/useAccountQueries.d.ts +9 -0
- package/lib/typescript/module/ui/hooks/queries/useAccountQueries.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/queries/userCache.d.ts +96 -0
- package/lib/typescript/module/ui/hooks/queries/userCache.d.ts.map +1 -0
- package/lib/typescript/module/ui/hooks/useAvatarPicker.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/useFileDownloadUrl.d.ts +3 -2
- package/lib/typescript/module/ui/hooks/useFileDownloadUrl.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/useResolvedFileUrls.d.ts +48 -0
- package/lib/typescript/module/ui/hooks/useResolvedFileUrls.d.ts.map +1 -0
- package/lib/typescript/module/ui/index.d.ts +1 -1
- package/lib/typescript/module/ui/index.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/FileManagementScreen.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/fileManagement/PhotoPickerSection.d.ts +1 -1
- package/lib/typescript/module/ui/screens/fileManagement/PhotoPickerSection.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/fileManagement/hooks/useFileUploadState.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/fileManagement/photoGridLayout.d.ts +37 -0
- package/lib/typescript/module/ui/screens/fileManagement/photoGridLayout.d.ts.map +1 -0
- package/lib/typescript/module/ui/session/tokenTransport.d.ts +15 -8
- package/lib/typescript/module/ui/session/tokenTransport.d.ts.map +1 -1
- package/lib/typescript/module/ui/utils/fileManagement.d.ts +4 -11
- package/lib/typescript/module/ui/utils/fileManagement.d.ts.map +1 -1
- package/package.json +6 -11
- package/src/index.ts +8 -0
- package/src/ui/components/FontLoader.native.tsx +88 -0
- package/src/ui/components/FontLoader.tsx +16 -151
- package/src/ui/components/fileManagement/FileDetailsModal.tsx +17 -18
- package/src/ui/components/fileManagement/UploadPreview.tsx +1 -1
- package/src/ui/components/fileManagement/styles.ts +0 -225
- package/src/ui/context/hooks/useAuthOperations.ts +5 -2
- package/src/ui/context/useOxyAccountGraph.ts +5 -0
- package/src/ui/hooks/queries/__tests__/userCache.test.ts +361 -0
- package/src/ui/hooks/queries/useAccountQueries.ts +14 -5
- package/src/ui/hooks/queries/userCache.ts +308 -0
- package/src/ui/hooks/useAvatarPicker.ts +27 -7
- package/src/ui/hooks/useFileDownloadUrl.ts +7 -23
- package/src/ui/hooks/useResolvedFileUrls.ts +170 -0
- package/src/ui/screens/FileManagementScreen.tsx +55 -27
- package/src/ui/screens/__tests__/photoGridLayout.test.ts +57 -0
- package/src/ui/screens/fileManagement/PhotoPickerSection.tsx +215 -213
- package/src/ui/screens/fileManagement/hooks/useFileUploadState.ts +27 -3
- package/src/ui/screens/fileManagement/photoGridLayout.ts +45 -0
- package/src/ui/session/__tests__/tokenTransport.test.ts +25 -10
- package/src/ui/session/tokenTransport.ts +21 -10
- package/src/ui/utils/fileManagement.ts +3 -46
- package/lib/typescript/types/expo-vector-icons.d.ts +0 -22
- package/src/types/expo-vector-icons.d.ts +0 -22
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.upsertCachedUser = upsertCachedUser;
|
|
7
|
+
exports.upsertCachedUsers = upsertCachedUsers;
|
|
8
|
+
var _queryKeys = require("./queryKeys.js");
|
|
9
|
+
var _authStore = require("../../stores/authStore.js");
|
|
10
|
+
/**
|
|
11
|
+
* Canonical user-cache UPSERT for the Oxy React Query cache.
|
|
12
|
+
*
|
|
13
|
+
* The problem this solves: many places across an app write a user object into
|
|
14
|
+
* the React Query cache and REPLACE the existing entry — profile fetch, feed /
|
|
15
|
+
* post hydration, search, notifications, lists. Each of those sources carries a
|
|
16
|
+
* DIFFERENT (often sparse) slice of the user: a feed author has no viewer
|
|
17
|
+
* `relationship`, a search hit has no `createdAt`, a notification actor has no
|
|
18
|
+
* `_count`. A plain `setQueryData(key, sparseUser)` therefore STRIPS whatever
|
|
19
|
+
* fields the authoritative single-profile fetch had already stored — the
|
|
20
|
+
* "Follows you tag vanishes when the feed loads" / "counts flash to zero" class
|
|
21
|
+
* of bug.
|
|
22
|
+
*
|
|
23
|
+
* The fix (owned here, in the SDK): ONE canonical upsert that MERGES. It writes
|
|
24
|
+
* under BOTH keys the SDK's user hooks read from:
|
|
25
|
+
* - by-id: `queryKeys.users.detail(id)` (read by `useUserById`)
|
|
26
|
+
* - by-username: `queryKeys.users.byUsername(username, viewerId)` (viewer-scoped;
|
|
27
|
+
* read by `useUserByUsername`, carries the viewer `relationship`)
|
|
28
|
+
*
|
|
29
|
+
* Merge semantics (per key):
|
|
30
|
+
* - No existing entry -> seed the (normalized) incoming object and mark it
|
|
31
|
+
* STALE (`updatedAt: 0`) so react-query refetches the full authoritative
|
|
32
|
+
* profile (viewer-relative `relationship`, counts, `createdAt`, …). Instant
|
|
33
|
+
* first paint, then the real fetch.
|
|
34
|
+
* - Existing entry -> `{ ...existing, ...pickMeaningful(incoming) }`: only
|
|
35
|
+
* the DEFINED, non-empty fields of `incoming` win; every other field is kept
|
|
36
|
+
* from `existing`. A sparse source can never NULL-out or STRIP a field the
|
|
37
|
+
* authoritative fetch set. The entry's freshness is left untouched (never
|
|
38
|
+
* marked stale — it is already managed).
|
|
39
|
+
* - Nested objects (`name`, `_count`, `relationship`) merge field-by-field, so
|
|
40
|
+
* a partial `name`/`_count`/`relationship` never replaces a fuller one.
|
|
41
|
+
* - `relationship` is written ONLY under the viewer-scoped by-username key —
|
|
42
|
+
* the viewer-independent by-id key never stores it (prevents one viewer's
|
|
43
|
+
* follow state from leaking into every other viewer's identity cache).
|
|
44
|
+
* - Anti-degradation: a good `username` / `name.displayName` / `avatar` is
|
|
45
|
+
* never overwritten by a degraded/empty one (empty username, the
|
|
46
|
+
* `'Unknown user'` ghost-author sentinel, `null` avatar).
|
|
47
|
+
*
|
|
48
|
+
* It is a cache write only — zero network, one `setQueryData` per key.
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A user-shaped object that can be upserted into the cache. Intentionally
|
|
53
|
+
* permissive: it covers the SDK `User` PLUS the looser actor objects embedded on
|
|
54
|
+
* posts / notifications / lists, where `name` may be a plain string and the id
|
|
55
|
+
* may arrive as Mongo `_id`. Every field is optional — a sparse feed author is a
|
|
56
|
+
* valid `CacheableUser`. The index signature lets any additional `User` field
|
|
57
|
+
* pass through untouched (so the upsert never has to know the full DTO shape).
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/** The degraded display-name sentinel (ghost-author rule). */
|
|
61
|
+
const DEGRADED_DISPLAY_NAME = 'Unknown user';
|
|
62
|
+
|
|
63
|
+
/** A cache entry always carries a resolved string `id`. */
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Whether a value is "meaningful" — i.e. it should override an existing field.
|
|
67
|
+
* Drops `undefined` / `null` / empty-or-whitespace strings so a sparse source
|
|
68
|
+
* can never strip a field. `false`, `0` and other falsy-but-defined values ARE
|
|
69
|
+
* meaningful (a real `verified: false` or `_count.followers: 0`).
|
|
70
|
+
*/
|
|
71
|
+
function isMeaningful(value) {
|
|
72
|
+
if (value === undefined || value === null) return false;
|
|
73
|
+
if (typeof value === 'string') return value.trim() !== '';
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** A display name is meaningful only when non-empty AND not the degraded sentinel. */
|
|
78
|
+
function isMeaningfulDisplayName(value) {
|
|
79
|
+
return typeof value === 'string' && value.trim() !== '' && value !== DEGRADED_DISPLAY_NAME;
|
|
80
|
+
}
|
|
81
|
+
function isPlainObject(value) {
|
|
82
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Normalize the polymorphic `name` (string | object | nullish) to the canonical object shape. */
|
|
86
|
+
function normalizeName(name) {
|
|
87
|
+
if (name === undefined || name === null) return undefined;
|
|
88
|
+
if (typeof name === 'string') {
|
|
89
|
+
const trimmed = name.trim();
|
|
90
|
+
return trimmed ? {
|
|
91
|
+
displayName: trimmed
|
|
92
|
+
} : undefined;
|
|
93
|
+
}
|
|
94
|
+
return name;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Coerce a user-shaped object to a cache entry: resolve the id from
|
|
99
|
+
* `id ?? _id ?? fallbackId` and normalize `name` to the canonical object shape
|
|
100
|
+
* (the polymorphic `string` name is dropped from the spread and re-set as an
|
|
101
|
+
* object so the cache never holds a bare-string name).
|
|
102
|
+
*/
|
|
103
|
+
function toCachedUser(user, fallbackId) {
|
|
104
|
+
const {
|
|
105
|
+
name: rawName,
|
|
106
|
+
...rest
|
|
107
|
+
} = user;
|
|
108
|
+
const id = String(user.id ?? user._id ?? fallbackId);
|
|
109
|
+
const name = normalizeName(rawName);
|
|
110
|
+
const normalized = {
|
|
111
|
+
...rest,
|
|
112
|
+
id
|
|
113
|
+
};
|
|
114
|
+
if (name !== undefined) normalized.name = name;
|
|
115
|
+
return normalized;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Normalize an incoming (possibly partial) user to a cache entry. Returns `null`
|
|
120
|
+
* when no id can be resolved (nothing to key on).
|
|
121
|
+
*/
|
|
122
|
+
function normalizeIncoming(user) {
|
|
123
|
+
const cached = toCachedUser(user, '');
|
|
124
|
+
return cached.id ? cached : null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Merge two `name` objects field-by-field, with anti-degradation on `displayName`. */
|
|
128
|
+
function mergeName(existing, incoming) {
|
|
129
|
+
if (incoming === undefined) return existing;
|
|
130
|
+
if (existing === undefined) return incoming;
|
|
131
|
+
const merged = {
|
|
132
|
+
...existing
|
|
133
|
+
};
|
|
134
|
+
for (const [key, value] of Object.entries(incoming)) {
|
|
135
|
+
if (key === 'displayName') continue;
|
|
136
|
+
if (isMeaningful(value)) merged[key] = value;
|
|
137
|
+
}
|
|
138
|
+
// Never let an empty / `'Unknown user'` displayName overwrite a real one.
|
|
139
|
+
if (isMeaningfulDisplayName(incoming.displayName)) {
|
|
140
|
+
merged.displayName = incoming.displayName;
|
|
141
|
+
}
|
|
142
|
+
return merged;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Merge `_count` field-by-field so a partial count never replaces a fuller one. */
|
|
146
|
+
function mergeCount(existing, incoming) {
|
|
147
|
+
if (!isPlainObject(incoming)) return existing;
|
|
148
|
+
const merged = {
|
|
149
|
+
...(isPlainObject(existing) ? existing : {})
|
|
150
|
+
};
|
|
151
|
+
if (typeof incoming.followers === 'number') merged.followers = incoming.followers;
|
|
152
|
+
if (typeof incoming.following === 'number') merged.following = incoming.following;
|
|
153
|
+
return merged;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Merge `relationship`. A source without a relationship (feed/list/notification,
|
|
158
|
+
* or an anon/self/bulk `null`) must NEVER strip an existing viewer relationship.
|
|
159
|
+
*/
|
|
160
|
+
function mergeRelationship(existing, incoming) {
|
|
161
|
+
if (!isPlainObject(incoming)) return existing;
|
|
162
|
+
const merged = {
|
|
163
|
+
...(isPlainObject(existing) ? existing : {})
|
|
164
|
+
};
|
|
165
|
+
if (typeof incoming.isFollowing === 'boolean') merged.isFollowing = incoming.isFollowing;
|
|
166
|
+
if (typeof incoming.followsYou === 'boolean') merged.followsYou = incoming.followsYou;
|
|
167
|
+
return merged;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Merge a (normalized) incoming user over an existing cache entry: keep every
|
|
172
|
+
* existing field, override only with the meaningful fields of `incoming`.
|
|
173
|
+
*
|
|
174
|
+
* When `includeRelationship` is false (the viewer-independent by-id key), the
|
|
175
|
+
* viewer-relative `relationship` field is never read, written, or preserved —
|
|
176
|
+
* only the by-username key carries it (`useUserByUsername`).
|
|
177
|
+
*/
|
|
178
|
+
function mergeUsers(existing, incoming, options) {
|
|
179
|
+
const includeRelationship = options?.includeRelationship ?? true;
|
|
180
|
+
const merged = {
|
|
181
|
+
...existing
|
|
182
|
+
};
|
|
183
|
+
for (const [key, value] of Object.entries(incoming)) {
|
|
184
|
+
if (key === 'name' || key === '_count' || key === 'relationship') continue;
|
|
185
|
+
if (key === 'id') {
|
|
186
|
+
merged.id = incoming.id;
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (isMeaningful(value)) merged[key] = value;
|
|
190
|
+
}
|
|
191
|
+
const name = mergeName(existing.name, incoming.name);
|
|
192
|
+
if (name !== undefined) merged.name = name;
|
|
193
|
+
const count = mergeCount(existing._count, incoming._count);
|
|
194
|
+
if (count !== undefined) merged._count = count;
|
|
195
|
+
if (includeRelationship) {
|
|
196
|
+
const relationship = mergeRelationship(existing.relationship, incoming.relationship);
|
|
197
|
+
if (relationship !== undefined) merged.relationship = relationship;
|
|
198
|
+
} else {
|
|
199
|
+
delete merged.relationship;
|
|
200
|
+
}
|
|
201
|
+
return merged;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Merge-upsert a normalized user into one cache key (see module docs for semantics). */
|
|
205
|
+
function upsertOneKey(queryClient, key, incoming, options) {
|
|
206
|
+
const mergeOpts = {
|
|
207
|
+
includeRelationship: options.includeRelationship
|
|
208
|
+
};
|
|
209
|
+
const existing = queryClient.getQueryData(key);
|
|
210
|
+
if (existing === undefined) {
|
|
211
|
+
// Cold slot: seed the full incoming object, STALE, so react-query refetches
|
|
212
|
+
// the full authoritative profile (relationship, counts, createdAt, …).
|
|
213
|
+
const seeded = mergeUsers({
|
|
214
|
+
id: incoming.id
|
|
215
|
+
}, incoming, mergeOpts);
|
|
216
|
+
queryClient.setQueryData(key, seeded, {
|
|
217
|
+
updatedAt: 0
|
|
218
|
+
});
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
// Existing entry: merge and leave its freshness lifecycle untouched. The
|
|
222
|
+
// existing entry is keyed by `incoming.id`, so use it as the fallback id.
|
|
223
|
+
const merged = mergeUsers(toCachedUser(existing, incoming.id), incoming, mergeOpts);
|
|
224
|
+
const dataUpdatedAt = queryClient.getQueryState(key)?.dataUpdatedAt ?? 0;
|
|
225
|
+
queryClient.setQueryData(key, merged, {
|
|
226
|
+
updatedAt: dataUpdatedAt
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Resolve the active viewer id. The by-username cache key is viewer-scoped; the
|
|
232
|
+
* seed must land on the exact key `useUserByUsername` reads. When a caller does
|
|
233
|
+
* not pass `viewerId`, read it from the auth store — the same store behind the
|
|
234
|
+
* hook's `useOxy().user?.id`, so seed and read stay in lockstep. An explicit
|
|
235
|
+
* empty string is honoured (anonymous scope).
|
|
236
|
+
*/
|
|
237
|
+
function resolveViewerId(viewerId) {
|
|
238
|
+
return viewerId ?? _authStore.useAuthStore.getState().user?.id ?? '';
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Merge-upsert a (possibly partial) user into the SDK's user query cache under
|
|
243
|
+
* both the by-id key and, when a username is present, the viewer-scoped
|
|
244
|
+
* by-username key.
|
|
245
|
+
*
|
|
246
|
+
* @param queryClient The app's React Query client.
|
|
247
|
+
* @param user A `User`-shaped object (may be sparse).
|
|
248
|
+
* @param viewerId The active viewer id for the by-username key. Defaults to
|
|
249
|
+
* the current auth-store user id.
|
|
250
|
+
*/
|
|
251
|
+
function upsertCachedUser(queryClient, user, viewerId) {
|
|
252
|
+
const incoming = normalizeIncoming(user);
|
|
253
|
+
if (!incoming) return;
|
|
254
|
+
|
|
255
|
+
// By-id identity entry (read by `useUserById`). Not viewer-scoped — never store
|
|
256
|
+
// the viewer-relative `relationship` here or one viewer's follow state leaks
|
|
257
|
+
// into every other viewer's by-id cache entry.
|
|
258
|
+
upsertOneKey(queryClient, _queryKeys.queryKeys.users.detail(incoming.id), incoming, {
|
|
259
|
+
includeRelationship: false
|
|
260
|
+
});
|
|
261
|
+
const username = incoming.username;
|
|
262
|
+
if (typeof username === 'string' && username.trim() !== '') {
|
|
263
|
+
// By-username entry (read by `useUserByUsername`). Viewer-scoped because the
|
|
264
|
+
// authenticated single-profile fetch embeds the viewer `relationship`. Build
|
|
265
|
+
// the key through the SAME helper the hook uses so username normalization
|
|
266
|
+
// (`trim().toLowerCase()`) matches byte-for-byte.
|
|
267
|
+
const key = _queryKeys.queryKeys.users.byUsername(username, resolveViewerId(viewerId));
|
|
268
|
+
upsertOneKey(queryClient, key, incoming, {
|
|
269
|
+
includeRelationship: true
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Batch merge-upsert many users at once (for a feed / list / search response).
|
|
276
|
+
* Resolves the viewer id once and upserts each user cumulatively — a user that
|
|
277
|
+
* appears twice merges both slices into the single cache entry.
|
|
278
|
+
*/
|
|
279
|
+
function upsertCachedUsers(queryClient, users, viewerId) {
|
|
280
|
+
if (!Array.isArray(users) || users.length === 0) return;
|
|
281
|
+
const resolvedViewerId = resolveViewerId(viewerId);
|
|
282
|
+
for (const user of users) {
|
|
283
|
+
if (user) upsertCachedUser(queryClient, user, resolvedViewerId);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
//# sourceMappingURL=userCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_queryKeys","require","_authStore","DEGRADED_DISPLAY_NAME","isMeaningful","value","undefined","trim","isMeaningfulDisplayName","isPlainObject","Array","isArray","normalizeName","name","trimmed","displayName","toCachedUser","user","fallbackId","rawName","rest","id","String","_id","normalized","normalizeIncoming","cached","mergeName","existing","incoming","merged","key","Object","entries","mergeCount","followers","following","mergeRelationship","isFollowing","followsYou","mergeUsers","options","includeRelationship","count","_count","relationship","upsertOneKey","queryClient","mergeOpts","getQueryData","seeded","setQueryData","updatedAt","dataUpdatedAt","getQueryState","resolveViewerId","viewerId","useAuthStore","getState","upsertCachedUser","queryKeys","users","detail","username","byUsername","upsertCachedUsers","length","resolvedViewerId"],"sourceRoot":"../../../../../src","sources":["ui/hooks/queries/userCache.ts"],"mappings":";;;;;;;AA2CA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AA5CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAwBA;AACA,MAAME,qBAAqB,GAAG,cAAc;;AAE5C;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,YAAYA,CAACC,KAAc,EAAW;EAC7C,IAAIA,KAAK,KAAKC,SAAS,IAAID,KAAK,KAAK,IAAI,EAAE,OAAO,KAAK;EACvD,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE,OAAOA,KAAK,CAACE,IAAI,CAAC,CAAC,KAAK,EAAE;EACzD,OAAO,IAAI;AACb;;AAEA;AACA,SAASC,uBAAuBA,CAACH,KAAc,EAAmB;EAChE,OAAO,OAAOA,KAAK,K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AgB,CAACZ,WAAW,EAAE9B,IAAI,EAAEkD,gBAAgB,CAAC;EACjE;AACF","ignoreList":[]}
|
|
@@ -68,19 +68,34 @@ function useAvatarPicker({
|
|
|
68
68
|
}, [activeSessionId, currentLanguage, oxyServices, queryClient]);
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
|
-
* After the user picks a file in the FileManagement sheet,
|
|
72
|
-
*
|
|
71
|
+
* After the user picks a file in the FileManagement sheet, resolve a working
|
|
72
|
+
* source URL and route to the crop screen.
|
|
73
|
+
*
|
|
74
|
+
* The picked file is usually PRIVATE, so the synchronous
|
|
75
|
+
* `getFileDownloadUrl` (public CDN origin) would 404 and the crop screen's
|
|
76
|
+
* `Image.getSize` would fail silently. We resolve the authenticated URL via
|
|
77
|
+
* `assetGetUrl` (which throws on failure — unlike `getFileDownloadUrlAsync`,
|
|
78
|
+
* which swallows errors and falls back to the broken public URL) so a
|
|
79
|
+
* failure surfaces a real user-facing error instead of a blank crop canvas.
|
|
80
|
+
* No variant is requested — cropping needs the original.
|
|
73
81
|
*/
|
|
74
|
-
const handleFilePicked = (0, _react.useCallback)(file => {
|
|
82
|
+
const handleFilePicked = (0, _react.useCallback)(async file => {
|
|
75
83
|
if (!file.contentType?.startsWith('image/')) {
|
|
76
84
|
_bloom.toast.error((0, _core.translate)(currentLanguage ?? undefined, 'editProfile.toasts.selectImage') || 'Please select an image file');
|
|
77
85
|
return;
|
|
78
86
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
let sourceUri;
|
|
88
|
+
try {
|
|
89
|
+
const resolved = await oxyServices.assetGetUrl(file.id);
|
|
90
|
+
if (!resolved?.url) {
|
|
91
|
+
throw new Error('No download URL returned for the selected image');
|
|
92
|
+
}
|
|
93
|
+
sourceUri = resolved.url;
|
|
94
|
+
} catch (e) {
|
|
95
|
+
const message = e instanceof Error ? e.message : undefined;
|
|
96
|
+
_bloom.toast.error(message || (0, _core.translate)(currentLanguage ?? undefined, 'editProfile.toasts.cropMeasureFailed') || 'Could not load the selected image');
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
84
99
|
showBottomSheet({
|
|
85
100
|
screen: 'AvatarCrop',
|
|
86
101
|
props: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_core","_bloom","_avatarUtils","extractUploadedFileId","result","undefined","id","file","first","files","useAvatarPicker","oxyServices","currentLanguage","activeSessionId","queryClient","showBottomSheet","finalizeCroppedAvatar","useCallback","cropped","uploadResult","assetUpload","uri","type","mime","name","Date","now","newFileId","Error","updateAvatarVisibility","updateProfileWithAvatar","avatar","toast","success","translate","e","message","error","handleFilePicked","contentType","startsWith","sourceUri","
|
|
1
|
+
{"version":3,"names":["_react","require","_core","_bloom","_avatarUtils","extractUploadedFileId","result","undefined","id","file","first","files","useAvatarPicker","oxyServices","currentLanguage","activeSessionId","queryClient","showBottomSheet","finalizeCroppedAvatar","useCallback","cropped","uploadResult","assetUpload","uri","type","mime","name","Date","now","newFileId","Error","updateAvatarVisibility","updateProfileWithAvatar","avatar","toast","success","translate","e","message","error","handleFilePicked","contentType","startsWith","sourceUri","resolved","assetGetUrl","url","screen","props","imageUri","onConfirm","openAvatarPicker","selectMode","multiSelect","disabledMimeTypes","afterSelect","onSelect"],"sourceRoot":"../../../../src","sources":["ui/hooks/useAvatarPicker.ts"],"mappings":";;;;;;AAgBA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AAEA,IAAAG,YAAA,GAAAH,OAAA;AAtBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAmBA;;AAOA,SAASI,qBAAqBA,CAACC,MAAqC,EAAsB;EACxF,IAAI,CAACA,MAAM,EAAE,OAAOC,SAAS;EAC7B,IAAI,OAAOD,MAAM,CAACE,EAAE,KAAK,QAAQ,EAAE,O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AqB,EAAEL,WAAW,EAAEI,eAAe,CACvE,CAAC;EAED,MAAMkC,gBAAgB,GAAG,IAAAhC,kBAAW,EAAC,MAAM;IACzCF,eAAe,CAAC;MACd8B,MAAM,EAAE,gBAAgB;MACxBC,KAAK,EAAE;QACLI,UAAU,EAAE,IAAI;QAChBC,WAAW,EAAE,KAAK;QAClBC,iBAAiB,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,iBAAiB,CAAC;QAC1DC,WAAW,EAAE,MAAM;QACnBC,QAAQ,EAAEhB;MACZ;IACF,CAAC,CAAC;EACJ,CAAC,EAAE,CAACA,gBAAgB,EAAEvB,eAAe,CAAC,CAAC;EAEvC,OAAO;IAAEkC;EAAiB,CAAC;AAC7B","ignoreList":[]}
|
|
@@ -8,8 +8,9 @@ var _react = require("react");
|
|
|
8
8
|
/**
|
|
9
9
|
* Hook to resolve a file's download URL asynchronously.
|
|
10
10
|
*
|
|
11
|
-
* Uses `getFileDownloadUrlAsync
|
|
12
|
-
*
|
|
11
|
+
* Uses `getFileDownloadUrlAsync`, which returns a scoped media-token stream URL
|
|
12
|
+
* for private assets. There is no sync CDN fallback — the synchronous
|
|
13
|
+
* `getFileDownloadUrl` is public-CDN-only and 404s for private uploads.
|
|
13
14
|
*/
|
|
14
15
|
const useFileDownloadUrl = (oxyServices, fileId, options) => {
|
|
15
16
|
const [url, setUrl] = (0, _react.useState)(null);
|
|
@@ -37,31 +38,16 @@ const useFileDownloadUrl = (oxyServices, fileId, options) => {
|
|
|
37
38
|
setLoading(true);
|
|
38
39
|
setError(null);
|
|
39
40
|
try {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
resolvedUrl = await instance.getFileDownloadUrlAsync(targetFileId, variant, expiresIn);
|
|
43
|
-
}
|
|
44
|
-
if (!resolvedUrl && typeof instance.getFileDownloadUrl === 'function') {
|
|
45
|
-
resolvedUrl = instance.getFileDownloadUrl(targetFileId, variant, expiresIn);
|
|
41
|
+
if (typeof instance.getFileDownloadUrlAsync !== 'function') {
|
|
42
|
+
throw new Error('getFileDownloadUrlAsync is not available on this OxyServices instance');
|
|
46
43
|
}
|
|
44
|
+
const resolvedUrl = await instance.getFileDownloadUrlAsync(targetFileId, variant, expiresIn);
|
|
47
45
|
if (!cancelled) {
|
|
48
46
|
setUrl(resolvedUrl || null);
|
|
49
47
|
}
|
|
50
48
|
} catch (err) {
|
|
51
|
-
// Fallback to sync URL on error where possible
|
|
52
|
-
try {
|
|
53
|
-
if (typeof instance.getFileDownloadUrl === 'function') {
|
|
54
|
-
const fallbackUrl = instance.getFileDownloadUrl(targetFileId, variant, expiresIn);
|
|
55
|
-
if (!cancelled) {
|
|
56
|
-
setUrl(fallbackUrl || null);
|
|
57
|
-
setError(err instanceof Error ? err : new Error(String(err)));
|
|
58
|
-
}
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
} catch {
|
|
62
|
-
// Secondary failure: surface the original error below.
|
|
63
|
-
}
|
|
64
49
|
if (!cancelled) {
|
|
50
|
+
setUrl(null);
|
|
65
51
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
66
52
|
}
|
|
67
53
|
} finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","useFileDownloadUrl","oxyServices","fileId","options","url","setUrl","useState","loading","setLoading","error","setError","variant","expiresIn","useEffect","Error","cancelled","instance","targetFileId","load","
|
|
1
|
+
{"version":3,"names":["_react","require","useFileDownloadUrl","oxyServices","fileId","options","url","setUrl","useState","loading","setLoading","error","setError","variant","expiresIn","useEffect","Error","cancelled","instance","targetFileId","load","getFileDownloadUrlAsync","resolvedUrl","err","String","exports"],"sourceRoot":"../../../../src","sources":["ui/hooks/useFileDownloadUrl.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,kBAAkB,GAAGA,CAChCC,WAA2C,EAC3CC,MAAiC,EACjCC,OAAmC,KACN;EAC7B,MAA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S,EAAE;UACdV,MAAM,CAAC,IAAI,CAAC;UACZK,QAAQ,CAACW,GAAG,YAAYP,KAAK,GAAGO,GAAG,GAAG,IAAIP,KAAK,CAACQ,MAAM,CAACD,GAAG,CAAC,CAAC,CAAC;QAC/D;MACF,CAAC,SAAS;QACR,IAAI,CAACN,SAAS,EAAE;UACdP,UAAU,CAAC,KAAK,CAAC;QACnB;MACF;IACF,CAAC;IAEDU,IAAI,CAAC,CAAC;IAEN,OAAO,MAAM;MACXH,SAAS,GAAG,IAAI;IAClB,CAAC;EACH,CAAC,EAAE,CAACb,MAAM,EAAED,WAAW,EAAEU,OAAO,EAAEC,SAAS,CAAC,CAAC;EAE7C,OAAO;IAAER,GAAG;IAAEG,OAAO;IAAEE;EAAM,CAAC;AAChC,CAAC;AAACc,OAAA,CAAAvB,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ASSET_DOWNLOAD_URLS_QUERY_KEY = void 0;
|
|
7
|
+
exports.fileThumbSource = fileThumbSource;
|
|
8
|
+
exports.isOptimisticFile = isOptimisticFile;
|
|
9
|
+
exports.useResolvedFileUrls = useResolvedFileUrls;
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
var _reactQuery = require("@tanstack/react-query");
|
|
12
|
+
/**
|
|
13
|
+
* The variant-aware batch resolver contract (`@oxyhq/core`).
|
|
14
|
+
*
|
|
15
|
+
* `getFileDownloadUrls` takes a per-file `{ fileId, variant }` list and returns
|
|
16
|
+
* a map keyed by `fileId`; ids that are denied or missing are OMITTED (never an
|
|
17
|
+
* empty string), and PRIVATE assets resolve to a working scoped-media-token
|
|
18
|
+
* stream URL. Typed here rather than `Pick<OxyServices, …>` so this file states
|
|
19
|
+
* the exact contract it depends on.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Private-safe grid/thumbnail URL resolution.
|
|
24
|
+
*
|
|
25
|
+
* The synchronous `oxyServices.getFileDownloadUrl(id, variant)` always yields
|
|
26
|
+
* the public CDN origin (`cloud.oxy.so/<id>`), which 404s for PRIVATE assets —
|
|
27
|
+
* and uploads default to private. Thumbnails and previews therefore have to be
|
|
28
|
+
* resolved through the authenticated batch endpoint, which returns a working
|
|
29
|
+
* `/assets/:id/stream?…&mt=<scoped media token>` URL for private files.
|
|
30
|
+
*
|
|
31
|
+
* This hook resolves an ENTIRE page of files in ONE (chunked) batch request
|
|
32
|
+
* rather than N per-tile calls, and caches the result in React Query keyed by
|
|
33
|
+
* the (fileId, variant) set. `staleTime` is deliberately shorter than the
|
|
34
|
+
* server media-token TTL so a tile never renders a URL whose token has already
|
|
35
|
+
* expired.
|
|
36
|
+
*
|
|
37
|
+
* Optimistic (`temp-…` / `uploading`) entries are NEVER resolved here — an
|
|
38
|
+
* asset URL must never be built from an id the server does not yet know. Their
|
|
39
|
+
* preview comes from the locally-picked uri (see {@link fileThumbSource}).
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/** Server media-token lifetime we request for each resolved URL (seconds). */
|
|
43
|
+
const ASSET_URL_TTL_SECONDS = 600; // 10 minutes
|
|
44
|
+
/**
|
|
45
|
+
* Refresh window. Kept below {@link ASSET_URL_TTL_SECONDS} so React Query
|
|
46
|
+
* re-resolves in the background before a rendered URL's token can die.
|
|
47
|
+
*/
|
|
48
|
+
const ASSET_URL_STALE_MS = 5 * 60 * 1000; // 5 minutes
|
|
49
|
+
const ASSET_URL_GC_MS = 30 * 60 * 1000;
|
|
50
|
+
/** Server-side batch cap for `POST /assets/batch-access` — chunk beyond this. */
|
|
51
|
+
const BATCH_CAP = 100;
|
|
52
|
+
|
|
53
|
+
/** React Query prefix — scoped media URLs must never leak across accounts. */
|
|
54
|
+
const ASSET_DOWNLOAD_URLS_QUERY_KEY = exports.ASSET_DOWNLOAD_URLS_QUERY_KEY = 'assetDownloadUrls';
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* True when a file is an optimistic placeholder that has not been persisted by
|
|
58
|
+
* the server yet — either its id is still the client-minted `temp-…` id, or it
|
|
59
|
+
* carries the `uploading` flag. Mirrors the `temp-` id guard precedent in
|
|
60
|
+
* `@oxyhq/core`'s `avatarUtils.updateAvatarVisibility`.
|
|
61
|
+
*/
|
|
62
|
+
function isOptimisticFile(file) {
|
|
63
|
+
if (typeof file.id === 'string' && file.id.startsWith('temp-')) return true;
|
|
64
|
+
return file.metadata?.uploading === true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Grid thumbnail variant for a file, or `undefined` when it needs no URL. */
|
|
68
|
+
function thumbVariantFor(file) {
|
|
69
|
+
if (file.contentType.startsWith('video/')) return 'poster';
|
|
70
|
+
if (file.contentType.startsWith('image/')) return 'thumb';
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Locally-picked preview uri stashed on an optimistic entry's metadata by the
|
|
76
|
+
* upload flow, if present.
|
|
77
|
+
*/
|
|
78
|
+
function localPreviewUri(file) {
|
|
79
|
+
const uri = file.metadata?.localPreviewUri;
|
|
80
|
+
return typeof uri === 'string' && uri.length > 0 ? uri : undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Resolve the image source for a grid tile.
|
|
85
|
+
*
|
|
86
|
+
* - Optimistic entry → its locally-picked preview uri (never an asset URL).
|
|
87
|
+
* - Persisted entry → the private-safe URL from {@link useResolvedFileUrls},
|
|
88
|
+
* or `undefined` while it is still resolving / was denied (tile shows a
|
|
89
|
+
* placeholder instead of a guaranteed-404 CDN URL).
|
|
90
|
+
*/
|
|
91
|
+
function fileThumbSource(file, resolved) {
|
|
92
|
+
if (isOptimisticFile(file)) {
|
|
93
|
+
return localPreviewUri(file);
|
|
94
|
+
}
|
|
95
|
+
return resolved.get(file.id);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Batch-resolve private-safe thumbnail URLs for the given files.
|
|
100
|
+
*
|
|
101
|
+
* Only image/video, non-optimistic files are resolved (documents render an
|
|
102
|
+
* icon, optimistic entries render their local preview). Returns a stable
|
|
103
|
+
* `Map<fileId, url>`; missing entries mean "not resolved yet or access denied".
|
|
104
|
+
*/
|
|
105
|
+
function useResolvedFileUrls(oxyServices, files, /** Active viewer account id — media tokens are minted per user; must be in the query key. */
|
|
106
|
+
viewerId) {
|
|
107
|
+
const viewerKey = viewerId ?? '';
|
|
108
|
+
const requests = (0, _react.useMemo)(() => {
|
|
109
|
+
const list = [];
|
|
110
|
+
for (const file of files) {
|
|
111
|
+
if (isOptimisticFile(file)) continue;
|
|
112
|
+
const variant = thumbVariantFor(file);
|
|
113
|
+
if (!variant) continue;
|
|
114
|
+
list.push({
|
|
115
|
+
fileId: file.id,
|
|
116
|
+
variant
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return list;
|
|
120
|
+
}, [files]);
|
|
121
|
+
|
|
122
|
+
// A content signature so the query key is stable across renders while the
|
|
123
|
+
// resolvable set is unchanged (the `files` array is a fresh reference every
|
|
124
|
+
// render). Sorted so ordering churn does not force a refetch.
|
|
125
|
+
const signature = (0, _react.useMemo)(() => requests.map(r => `${r.fileId}:${r.variant ?? ''}`).sort().join('|'), [requests]);
|
|
126
|
+
const query = (0, _reactQuery.useQuery)({
|
|
127
|
+
queryKey: [ASSET_DOWNLOAD_URLS_QUERY_KEY, viewerKey, signature],
|
|
128
|
+
enabled: requests.length > 0 && viewerKey.length > 0,
|
|
129
|
+
staleTime: ASSET_URL_STALE_MS,
|
|
130
|
+
gcTime: ASSET_URL_GC_MS,
|
|
131
|
+
// Keep previously-resolved URLs on screen while the SAME viewer's file set
|
|
132
|
+
// grows (pagination), but never carry another account's scoped media tokens
|
|
133
|
+
// across a switch — `keepPreviousData` alone would do that.
|
|
134
|
+
placeholderData: (previousData, previousQuery) => {
|
|
135
|
+
if (!previousData || !previousQuery) return undefined;
|
|
136
|
+
const prevViewer = previousQuery.queryKey[1];
|
|
137
|
+
if (prevViewer !== viewerKey) return undefined;
|
|
138
|
+
return previousData;
|
|
139
|
+
},
|
|
140
|
+
queryFn: async () => {
|
|
141
|
+
const merged = {};
|
|
142
|
+
for (let i = 0; i < requests.length; i += BATCH_CAP) {
|
|
143
|
+
const chunk = requests.slice(i, i + BATCH_CAP);
|
|
144
|
+
const urls = await oxyServices.getFileDownloadUrls(chunk, {
|
|
145
|
+
expiresIn: ASSET_URL_TTL_SECONDS
|
|
146
|
+
});
|
|
147
|
+
Object.assign(merged, urls);
|
|
148
|
+
}
|
|
149
|
+
return merged;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
return (0, _react.useMemo)(() => {
|
|
153
|
+
const map = new Map();
|
|
154
|
+
const data = query.data;
|
|
155
|
+
if (data) {
|
|
156
|
+
for (const [id, url] of Object.entries(data)) {
|
|
157
|
+
if (typeof url === 'string' && url.length > 0) map.set(id, url);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return map;
|
|
161
|
+
}, [query.data]);
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=useResolvedFileUrls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_reactQuery","ASSET_URL_TTL_SECONDS","ASSET_URL_STALE_MS","ASSET_URL_GC_MS","BATCH_CAP","ASSET_DOWNLOAD_URLS_QUERY_KEY","exports","isOptimisticFile","file","id","startsWith","metadata","uploading","thumbVariantFor","contentType","undefined","localPreviewUri","uri","length","fileThumbSource","resolved","get","useResolvedFileUrls","oxyServices","files","viewerId","viewerKey","requests","useMemo","list","variant","push","fileId","signature","map","r","sort","join","query","useQuery","queryKey","enabled","staleTime","gcTime","placeholderData","previousData","previousQuery","prevViewer","queryFn","merged","i","chunk","slice","urls","getFileDownloadUrls","expiresIn","Object","assign","Map","data","url","entries","set"],"sourceRoot":"../../../../src","sources":["ui/hooks/useResolvedFileUrls.ts"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,MAAME,qBAAqB,GAAG,GAAG,CAAC,CAAC;AACnC;AACA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AAC1C,MAAMC,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;AACtC;AACA,MAAMC,SAAS,GAAG,GAAG;;AAErB;AACO,MAAMC,6BAA6B,GAAAC,OAAA,CAAAD,6BAAA,GAAG,mBAA4B;;AAEzE;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,gBAAgBA,CAACC,IAA2C,EAAW;EACrF,IAAI,OAAOA,IAAI,CAACC,EAAE,KAAK,QAAQ,IAAID,IAAI,CAACC,EAAE,CAACC,UAAU,CAAC,OAAO,CAAC,EAAE,OAAO,IAAI;EAC3E,OAAOF,IAAI,CAACG,QAAQ,EAAEC,SAAS,KAAK,IAAI;AAC1C;;AAEA;AACA,SAASC,eAAeA,CAACL,IAAkB,EAAsB;EAC/D,IAAIA,IAAI,CAACM,WAAW,CAACJ,UAAU,CAAC,QAAQ,CAAC,EAAE,OAAO,QAAQ;EAC1D,IAAIF,IAAI,CAACM,WAAW,CAACJ,UAAU,CAAC,QAAQ,CAAC,EAAE,OAAO,OAAO;EACzD,OAAOK,SAAS;AAClB;;AAEA;AACA;AACA;AACA;AACA,SAASC,eAAeA,CAACR,IAAkB,EAAsB;EAC/D,MAAMS,GAAG,GAAIT,IAAI,CAACG,QAAQ,EAA0CK,eAAe;EACnF,OAAO,OAAOC,GAAG,KAAK,QAAQ,I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AO,CAACF,IAAI,CAAC,EAAE;QAC5C,IAAI,OAAOC,GAAG,KAAK,QAAQ,IAAIA,GAAG,CAAC1C,MAAM,GAAG,CAAC,EAAEgB,GAAG,CAAC4B,GAAG,CAACrD,EAAE,EAAEmD,GAAG,CAAC;MACjE;IACF;IACA,OAAO1B,GAAG;EACZ,CAAC,EAAE,CAACI,KAAK,CAACqB,IAAI,CAAC,CAAC;AAClB","ignoreList":[]}
|
package/lib/commonjs/ui/index.js
CHANGED
|
@@ -173,7 +173,7 @@ var _LogoText = require("./components/logo/LogoText.js");
|
|
|
173
173
|
var _RequireOxyAuth = require("./components/RequireOxyAuth.js");
|
|
174
174
|
var _FollowButton = _interopRequireDefault(require("./components/FollowButton.js"));
|
|
175
175
|
var _OxyPayButton = _interopRequireDefault(require("./components/OxyPayButton.js"));
|
|
176
|
-
var _FontLoader = require("./components/FontLoader
|
|
176
|
+
var _FontLoader = require("./components/FontLoader");
|
|
177
177
|
var _ProfileButton = _interopRequireDefault(require("./components/ProfileButton.js"));
|
|
178
178
|
var _OxyContext = require("./context/OxyContext.js");
|
|
179
179
|
var _useAuth = require("./hooks/useAuth.js");
|