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