@oxyhq/core 3.4.19 → 3.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/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/mixins/OxyServices.user.js +63 -3
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/mixins/OxyServices.user.js +63 -3
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/mixins/OxyServices.user.d.ts +58 -1
- package/package.json +1 -1
- package/src/index.ts +6 -0
- package/src/mixins/OxyServices.user.ts +99 -3
- package/src/mixins/__tests__/followCacheInvalidation.test.ts +168 -0
|
@@ -318,11 +318,68 @@ export function OxyServicesUserMixin(Base) {
|
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
320
|
/**
|
|
321
|
-
* Follow a user
|
|
321
|
+
* Follow a user.
|
|
322
|
+
*
|
|
323
|
+
* Invalidates the cached `GET /users/<id>/follow-status` response after
|
|
324
|
+
* the write. `getFollowStatus` caches for ~1 minute (identity-scoped);
|
|
325
|
+
* without busting that entry, a `FollowButton` that remounts within the
|
|
326
|
+
* TTL window re-reads the STALE pre-write status and reverts the optimistic
|
|
327
|
+
* UI (the "follow resets after navigating away and back" bug).
|
|
328
|
+
* `clearCacheEntry` deletes every identity-scoped variant of the key.
|
|
322
329
|
*/
|
|
323
330
|
async followUser(userId) {
|
|
324
331
|
try {
|
|
325
|
-
|
|
332
|
+
const result = await this.makeRequest('POST', `/users/${userId}/follow`, undefined, { cache: false });
|
|
333
|
+
this.clearCacheEntry(`GET:/users/${userId}/follow-status`);
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
catch (error) {
|
|
337
|
+
throw this.handleError(error);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Follow multiple users in a single request.
|
|
342
|
+
*
|
|
343
|
+
* POSTs `/users/follow/bulk` with `{ userIds }` (server caps the batch at
|
|
344
|
+
* 200). Returns the per-user outcomes and the count of users newly
|
|
345
|
+
* followed. An empty `userIds` array resolves immediately with an empty
|
|
346
|
+
* result and performs no network call.
|
|
347
|
+
*/
|
|
348
|
+
async followUsers(userIds) {
|
|
349
|
+
if (userIds.length === 0) {
|
|
350
|
+
return { results: [], followedCount: 0 };
|
|
351
|
+
}
|
|
352
|
+
try {
|
|
353
|
+
const result = await this.makeRequest('POST', '/users/follow/bulk', { userIds }, { cache: false });
|
|
354
|
+
// Bust each affected user's cached follow-status (see `followUser`).
|
|
355
|
+
for (const id of userIds) {
|
|
356
|
+
this.clearCacheEntry(`GET:/users/${id}/follow-status`);
|
|
357
|
+
}
|
|
358
|
+
return result;
|
|
359
|
+
}
|
|
360
|
+
catch (error) {
|
|
361
|
+
throw this.handleError(error);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Unfollow multiple users in a single request.
|
|
366
|
+
*
|
|
367
|
+
* POSTs `/users/unfollow/bulk` with `{ userIds }` (server caps the batch at
|
|
368
|
+
* 200). Returns the per-user outcomes and the count of users newly
|
|
369
|
+
* unfollowed. An empty `userIds` array resolves immediately with an empty
|
|
370
|
+
* result and performs no network call.
|
|
371
|
+
*/
|
|
372
|
+
async unfollowUsers(userIds) {
|
|
373
|
+
if (userIds.length === 0) {
|
|
374
|
+
return { results: [], unfollowedCount: 0 };
|
|
375
|
+
}
|
|
376
|
+
try {
|
|
377
|
+
const result = await this.makeRequest('POST', '/users/unfollow/bulk', { userIds }, { cache: false });
|
|
378
|
+
// Bust each affected user's cached follow-status (see `followUser`).
|
|
379
|
+
for (const id of userIds) {
|
|
380
|
+
this.clearCacheEntry(`GET:/users/${id}/follow-status`);
|
|
381
|
+
}
|
|
382
|
+
return result;
|
|
326
383
|
}
|
|
327
384
|
catch (error) {
|
|
328
385
|
throw this.handleError(error);
|
|
@@ -333,7 +390,10 @@ export function OxyServicesUserMixin(Base) {
|
|
|
333
390
|
*/
|
|
334
391
|
async unfollowUser(userId) {
|
|
335
392
|
try {
|
|
336
|
-
|
|
393
|
+
const result = await this.makeRequest('DELETE', `/users/${userId}/follow`, undefined, { cache: false });
|
|
394
|
+
// Bust the cached follow-status so a remount reads fresh truth (see `followUser`).
|
|
395
|
+
this.clearCacheEntry(`GET:/users/${userId}/follow-status`);
|
|
396
|
+
return result;
|
|
337
397
|
}
|
|
338
398
|
catch (error) {
|
|
339
399
|
throw this.handleError(error);
|