@stream-io/feeds-client 0.1.7 → 0.1.9

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 (46) hide show
  1. package/@react-bindings/hooks/util/index.ts +1 -0
  2. package/CHANGELOG.md +20 -0
  3. package/dist/@react-bindings/hooks/util/index.d.ts +1 -0
  4. package/dist/@react-bindings/hooks/util/useBookmarkActions.d.ts +13 -0
  5. package/dist/@react-bindings/hooks/util/useReactionActions.d.ts +1 -1
  6. package/dist/index-react-bindings.browser.cjs +363 -141
  7. package/dist/index-react-bindings.browser.cjs.map +1 -1
  8. package/dist/index-react-bindings.browser.js +363 -142
  9. package/dist/index-react-bindings.browser.js.map +1 -1
  10. package/dist/index-react-bindings.node.cjs +363 -141
  11. package/dist/index-react-bindings.node.cjs.map +1 -1
  12. package/dist/index-react-bindings.node.js +363 -142
  13. package/dist/index-react-bindings.node.js.map +1 -1
  14. package/dist/index.browser.cjs +337 -140
  15. package/dist/index.browser.cjs.map +1 -1
  16. package/dist/index.browser.js +337 -141
  17. package/dist/index.browser.js.map +1 -1
  18. package/dist/index.node.cjs +337 -140
  19. package/dist/index.node.cjs.map +1 -1
  20. package/dist/index.node.js +337 -141
  21. package/dist/index.node.js.map +1 -1
  22. package/dist/src/Feed.d.ts +42 -11
  23. package/dist/src/FeedsClient.d.ts +10 -3
  24. package/dist/src/common/real-time/StableWSConnection.d.ts +3 -3
  25. package/dist/src/gen/models/index.d.ts +25 -2
  26. package/dist/src/gen-imports.d.ts +1 -1
  27. package/dist/src/state-updates/follow-utils.d.ts +19 -0
  28. package/dist/src/state-updates/state-update-queue.d.ts +15 -0
  29. package/dist/src/utils.d.ts +1 -0
  30. package/dist/tsconfig.tsbuildinfo +1 -1
  31. package/package.json +1 -1
  32. package/src/Feed.ts +230 -192
  33. package/src/FeedsClient.ts +75 -3
  34. package/src/gen/feeds/FeedsApi.ts +0 -1
  35. package/src/gen/model-decoders/decoders.ts +16 -0
  36. package/src/gen/model-decoders/event-decoder-mapping.ts +3 -0
  37. package/src/gen/models/index.ts +42 -4
  38. package/src/gen-imports.ts +1 -1
  39. package/src/state-updates/activity-reaction-utils.test.ts +1 -0
  40. package/src/state-updates/activity-utils.test.ts +1 -0
  41. package/src/state-updates/follow-utils.test.ts +552 -0
  42. package/src/state-updates/follow-utils.ts +126 -0
  43. package/src/state-updates/state-update-queue.test.ts +53 -0
  44. package/src/state-updates/state-update-queue.ts +35 -0
  45. package/src/utils.test.ts +175 -0
  46. package/src/utils.ts +20 -0
@@ -3,12 +3,14 @@ import {
3
3
  ActivityResponse,
4
4
  FeedResponse,
5
5
  FileUploadRequest,
6
+ FollowBatchRequest,
6
7
  ImageUploadRequest,
7
8
  OwnUser,
8
9
  PollResponse,
9
10
  PollVotesResponse,
10
11
  QueryFeedsRequest,
11
12
  QueryPollVotesRequest,
13
+ SingleFollowRequest,
12
14
  UserRequest,
13
15
  WSEvent,
14
16
  } from './gen/models';
@@ -97,6 +99,10 @@ export class FeedsClient extends FeedsApi {
97
99
  activeFeed.synchronize();
98
100
  }
99
101
  }
102
+ } else {
103
+ for (const activeFeed of Object.values(this.activeFeeds)) {
104
+ activeFeed.handleWatchStopped();
105
+ }
100
106
  }
101
107
  break;
102
108
  }
@@ -335,7 +341,7 @@ export class FeedsClient extends FeedsApi {
335
341
  const response = await this.feedsQueryFeeds(request);
336
342
 
337
343
  const feeds = response.feeds.map((f) =>
338
- this.getOrCreateActiveFeed(f.group_id, f.id, f),
344
+ this.getOrCreateActiveFeed(f.group_id, f.id, f, request?.watch),
339
345
  );
340
346
 
341
347
  return {
@@ -357,16 +363,82 @@ export class FeedsClient extends FeedsApi {
357
363
  this.eventDispatcher.dispatch(networkEvent);
358
364
  };
359
365
 
366
+ // For follow API endpoints we update the state after HTTP response to allow queryFeeds with watch: false
367
+ async follow(request: SingleFollowRequest) {
368
+ const response = await super.follow(request);
369
+
370
+ [response.follow.source_feed.fid, response.follow.target_feed.fid].forEach(
371
+ (fid) => {
372
+ const feed = this.activeFeeds[fid];
373
+ if (feed) {
374
+ feed.handleFollowCreated(response.follow);
375
+ }
376
+ },
377
+ );
378
+
379
+ return response;
380
+ }
381
+
382
+ async followBatch(request: FollowBatchRequest) {
383
+ const response = await super.followBatch(request);
384
+
385
+ response.follows.forEach((follow) => {
386
+ const feed = this.activeFeeds[follow.source_feed.fid];
387
+ if (feed) {
388
+ feed.handleFollowCreated(follow);
389
+ }
390
+ });
391
+
392
+ return response;
393
+ }
394
+
395
+ async unfollow(request: SingleFollowRequest) {
396
+ const response = await super.unfollow(request);
397
+
398
+ [request.source, request.target].forEach((fid) => {
399
+ const feed = this.activeFeeds[fid];
400
+ if (feed) {
401
+ feed.handleFollowDeleted({
402
+ source_feed: { fid: request.source },
403
+ target_feed: { fid: request.target },
404
+ });
405
+ }
406
+ });
407
+
408
+ return response;
409
+ }
410
+
411
+ async stopWatchingFeed(request: { feed_group_id: string; feed_id: string }) {
412
+ const connectionId = await this.connectionIdManager.getConnectionId();
413
+ const response = await super.stopWatchingFeed({
414
+ ...request,
415
+ connection_id: connectionId,
416
+ });
417
+
418
+ const feed =
419
+ this.activeFeeds[`${request.feed_group_id}:${request.feed_id}`];
420
+ if (feed) {
421
+ feed.handleWatchStopped();
422
+ }
423
+
424
+ return response;
425
+ }
426
+
360
427
  private readonly getOrCreateActiveFeed = (
361
428
  group: string,
362
429
  id: string,
363
430
  data?: FeedResponse,
431
+ watch?: boolean,
364
432
  ) => {
365
433
  const fid = `${group}:${id}`;
366
434
  if (this.activeFeeds[fid]) {
367
- return this.activeFeeds[fid];
435
+ const feed = this.activeFeeds[fid];
436
+ if (watch && !feed.currentState.watch) {
437
+ feed.handleWatchStarted();
438
+ }
439
+ return feed;
368
440
  } else {
369
- const feed = new Feed(this, group, id, data);
441
+ const feed = new Feed(this, group, id, data, watch);
370
442
  this.activeFeeds[fid] = feed;
371
443
  return feed;
372
444
  }
@@ -2225,7 +2225,6 @@ export class FeedsApi {
2225
2225
  request: UpdateLiveLocationRequest,
2226
2226
  ): Promise<StreamResponse<SharedLocationResponse>> {
2227
2227
  const body = {
2228
- created_by_device_id: request?.created_by_device_id,
2229
2228
  message_id: request?.message_id,
2230
2229
  end_at: request?.end_at,
2231
2230
  latitude: request?.latitude,
@@ -1226,6 +1226,22 @@ decoders.MuteResponse = (input?: Record<string, any>) => {
1226
1226
  return decode(typeMappings, input);
1227
1227
  };
1228
1228
 
1229
+ decoders.NotificationFeedUpdatedEvent = (input?: Record<string, any>) => {
1230
+ const typeMappings: TypeMapping = {
1231
+ created_at: { type: 'DatetimeType', isSingle: true },
1232
+
1233
+ received_at: { type: 'DatetimeType', isSingle: true },
1234
+
1235
+ aggregated_activities: {
1236
+ type: 'AggregatedActivityResponse',
1237
+ isSingle: false,
1238
+ },
1239
+
1240
+ notification_status: { type: 'NotificationStatusResponse', isSingle: true },
1241
+ };
1242
+ return decode(typeMappings, input);
1243
+ };
1244
+
1229
1245
  decoders.NotificationStatusResponse = (input?: Record<string, any>) => {
1230
1246
  const typeMappings: TypeMapping = {
1231
1247
  last_seen_at: { type: 'DatetimeType', isSingle: true },
@@ -103,6 +103,9 @@ const eventDecoderMapping: Record<
103
103
  'feeds.follow.updated': (data: Record<string, any>) =>
104
104
  decoders.FollowUpdatedEvent(data),
105
105
 
106
+ 'feeds.notification_feed.updated': (data: Record<string, any>) =>
107
+ decoders.NotificationFeedUpdatedEvent(data),
108
+
106
109
  'feeds.poll.closed': (data: Record<string, any>) =>
107
110
  decoders.PollClosedFeedEvent(data),
108
111
 
@@ -427,11 +427,11 @@ export interface ActivityResponse {
427
427
 
428
428
  moderation?: ModerationV2Response;
429
429
 
430
+ object?: Record<string, any>;
431
+
430
432
  parent?: ActivityResponse;
431
433
 
432
434
  poll?: PollResponseData;
433
-
434
- target?: Record<string, any>;
435
435
  }
436
436
 
437
437
  export interface ActivityUnpinnedEvent {
@@ -1182,6 +1182,8 @@ export interface CallParticipant {
1182
1182
 
1183
1183
  teams_role: Record<string, string>;
1184
1184
 
1185
+ avg_response_time?: number;
1186
+
1185
1187
  ban_expires?: Date;
1186
1188
 
1187
1189
  created_at?: Date;
@@ -2354,6 +2356,8 @@ export interface EntityCreator {
2354
2356
 
2355
2357
  teams_role: Record<string, string>;
2356
2358
 
2359
+ avg_response_time?: number;
2360
+
2357
2361
  ban_expires?: Date;
2358
2362
 
2359
2363
  created_at?: Date;
@@ -2406,6 +2410,8 @@ export interface EntityCreatorResponse {
2406
2410
 
2407
2411
  custom: Record<string, any>;
2408
2412
 
2413
+ avg_response_time?: number;
2414
+
2409
2415
  deactivated_at?: Date;
2410
2416
 
2411
2417
  deleted_at?: Date;
@@ -3010,6 +3016,8 @@ export interface FullUserResponse {
3010
3016
 
3011
3017
  custom: Record<string, any>;
3012
3018
 
3019
+ avg_response_time?: number;
3020
+
3013
3021
  ban_expires?: Date;
3014
3022
 
3015
3023
  deactivated_at?: Date;
@@ -3697,6 +3705,24 @@ export interface NotificationConfig {
3697
3705
  track_seen?: boolean;
3698
3706
  }
3699
3707
 
3708
+ export interface NotificationFeedUpdatedEvent {
3709
+ created_at: Date;
3710
+
3711
+ fid: string;
3712
+
3713
+ custom: Record<string, any>;
3714
+
3715
+ type: string;
3716
+
3717
+ received_at?: Date;
3718
+
3719
+ aggregated_activities?: AggregatedActivityResponse[];
3720
+
3721
+ notification_status?: NotificationStatusResponse;
3722
+
3723
+ user?: UserResponseCommonFields;
3724
+ }
3725
+
3700
3726
  export interface NotificationSettings {
3701
3727
  enabled: boolean;
3702
3728
 
@@ -3772,6 +3798,8 @@ export interface OwnUser {
3772
3798
 
3773
3799
  total_unread_count_by_team: Record<string, number>;
3774
3800
 
3801
+ avg_response_time?: number;
3802
+
3775
3803
  deactivated_at?: Date;
3776
3804
 
3777
3805
  deleted_at?: Date;
@@ -3830,6 +3858,8 @@ export interface OwnUserResponse {
3830
3858
 
3831
3859
  custom: Record<string, any>;
3832
3860
 
3861
+ avg_response_time?: number;
3862
+
3833
3863
  deactivated_at?: Date;
3834
3864
 
3835
3865
  deleted_at?: Date;
@@ -5475,8 +5505,6 @@ export interface UpdateFollowResponse {
5475
5505
  }
5476
5506
 
5477
5507
  export interface UpdateLiveLocationRequest {
5478
- created_by_device_id: string;
5479
-
5480
5508
  message_id: string;
5481
5509
 
5482
5510
  end_at?: Date;
@@ -5611,6 +5639,8 @@ export interface User {
5611
5639
 
5612
5640
  teams_role: Record<string, string>;
5613
5641
 
5642
+ avg_response_time?: number;
5643
+
5614
5644
  ban_expires?: Date;
5615
5645
 
5616
5646
  created_at?: Date;
@@ -5755,6 +5785,8 @@ export interface UserResponse {
5755
5785
 
5756
5786
  custom: Record<string, any>;
5757
5787
 
5788
+ avg_response_time?: number;
5789
+
5758
5790
  deactivated_at?: Date;
5759
5791
 
5760
5792
  deleted_at?: Date;
@@ -5791,6 +5823,8 @@ export interface UserResponseCommonFields {
5791
5823
 
5792
5824
  custom: Record<string, any>;
5793
5825
 
5826
+ avg_response_time?: number;
5827
+
5794
5828
  deactivated_at?: Date;
5795
5829
 
5796
5830
  deleted_at?: Date;
@@ -5827,6 +5861,8 @@ export interface UserResponsePrivacyFields {
5827
5861
 
5828
5862
  custom: Record<string, any>;
5829
5863
 
5864
+ avg_response_time?: number;
5865
+
5830
5866
  deactivated_at?: Date;
5831
5867
 
5832
5868
  deleted_at?: Date;
@@ -6006,6 +6042,7 @@ export type WSClientEvent =
6006
6042
  | ({ type: 'feeds.follow.created' } & FollowCreatedEvent)
6007
6043
  | ({ type: 'feeds.follow.deleted' } & FollowDeletedEvent)
6008
6044
  | ({ type: 'feeds.follow.updated' } & FollowUpdatedEvent)
6045
+ | ({ type: 'feeds.notification_feed.updated' } & NotificationFeedUpdatedEvent)
6009
6046
  | ({ type: 'feeds.poll.closed' } & PollClosedFeedEvent)
6010
6047
  | ({ type: 'feeds.poll.deleted' } & PollDeletedFeedEvent)
6011
6048
  | ({ type: 'feeds.poll.updated' } & PollUpdatedFeedEvent)
@@ -6051,6 +6088,7 @@ export type WSEvent =
6051
6088
  | ({ type: 'feeds.follow.created' } & FollowCreatedEvent)
6052
6089
  | ({ type: 'feeds.follow.deleted' } & FollowDeletedEvent)
6053
6090
  | ({ type: 'feeds.follow.updated' } & FollowUpdatedEvent)
6091
+ | ({ type: 'feeds.notification_feed.updated' } & NotificationFeedUpdatedEvent)
6054
6092
  | ({ type: 'feeds.poll.closed' } & PollClosedFeedEvent)
6055
6093
  | ({ type: 'feeds.poll.deleted' } & PollDeletedFeedEvent)
6056
6094
  | ({ type: 'feeds.poll.updated' } & PollUpdatedFeedEvent)
@@ -1,3 +1,3 @@
1
1
  export type { ApiClient } from './common/ApiClient';
2
2
  export type { StreamResponse } from './common/types';
3
- export { FeedsApi } from './gen/feeds/FeedsApi';
3
+ export { FeedsClient as FeedsApi } from './FeedsClient';
@@ -35,6 +35,7 @@ const createMockActivity = (id: string): ActivityResponse => ({
35
35
  search_data: {},
36
36
  popularity: 0,
37
37
  score: 0,
38
+ reaction_count: 0,
38
39
  user: {
39
40
  id: 'user1',
40
41
  created_at: new Date(),
@@ -31,6 +31,7 @@ const createMockActivity = (id: string, text?: string): ActivityResponse =>
31
31
  text: text,
32
32
  popularity: 0,
33
33
  score: 0,
34
+ reaction_count: 0,
34
35
  user: {
35
36
  id: 'user1',
36
37
  created_at: new Date(),