@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.
@@ -318,11 +318,20 @@ 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
- return await this.makeRequest('POST', `/users/${userId}/follow`, undefined, { cache: false });
332
+ const result = await this.makeRequest('POST', `/users/${userId}/follow`, undefined, { cache: false });
333
+ this.clearCacheEntry(`GET:/users/${userId}/follow-status`);
334
+ return result;
326
335
  }
327
336
  catch (error) {
328
337
  throw this.handleError(error);
@@ -341,7 +350,36 @@ export function OxyServicesUserMixin(Base) {
341
350
  return { results: [], followedCount: 0 };
342
351
  }
343
352
  try {
344
- return await this.makeRequest('POST', '/users/follow/bulk', { userIds }, { cache: false });
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;
345
383
  }
346
384
  catch (error) {
347
385
  throw this.handleError(error);
@@ -352,7 +390,10 @@ export function OxyServicesUserMixin(Base) {
352
390
  */
353
391
  async unfollowUser(userId) {
354
392
  try {
355
- return await this.makeRequest('DELETE', `/users/${userId}/follow`, undefined, { cache: false });
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;
356
397
  }
357
398
  catch (error) {
358
399
  throw this.handleError(error);