@stream-io/feeds-client 0.1.11 → 0.2.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/CHANGELOG.md +17 -0
- package/dist/index-react-bindings.browser.cjs +172 -124
- package/dist/index-react-bindings.browser.cjs.map +1 -1
- package/dist/index-react-bindings.browser.js +172 -124
- package/dist/index-react-bindings.browser.js.map +1 -1
- package/dist/index-react-bindings.node.cjs +172 -124
- package/dist/index-react-bindings.node.cjs.map +1 -1
- package/dist/index-react-bindings.node.js +172 -124
- package/dist/index-react-bindings.node.js.map +1 -1
- package/dist/index.browser.cjs +170 -122
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +170 -122
- package/dist/index.browser.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.node.cjs +170 -122
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +170 -122
- package/dist/index.node.js.map +1 -1
- package/dist/src/feed/event-handlers/index.d.ts +1 -0
- package/dist/src/feed/event-handlers/watch/handle-watch-started.d.ts +2 -0
- package/dist/src/feed/event-handlers/watch/handle-watch-stopped.d.ts +2 -0
- package/dist/src/feed/event-handlers/watch/index.d.ts +2 -0
- package/dist/src/feed/feed.d.ts +4 -12
- package/dist/src/feeds-client/event-handlers/index.d.ts +1 -0
- package/dist/src/feeds-client/event-handlers/user/handle-user-updated.d.ts +3 -0
- package/dist/src/{feeds-client.d.ts → feeds-client/feeds-client.d.ts} +16 -16
- package/dist/src/feeds-client/index.d.ts +2 -0
- package/dist/src/gen/feeds/FeedsApi.d.ts +27 -23
- package/dist/src/gen/models/index.d.ts +163 -23
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/index.ts +1 -1
- package/package.json +2 -2
- package/src/feed/event-handlers/follow/handle-follow-created.test.ts +16 -12
- package/src/feed/event-handlers/follow/handle-follow-created.ts +4 -7
- package/src/feed/event-handlers/follow/handle-follow-deleted.test.ts +19 -15
- package/src/feed/event-handlers/follow/handle-follow-deleted.ts +6 -6
- package/src/feed/event-handlers/follow/handle-follow-updated.ts +7 -10
- package/src/feed/event-handlers/index.ts +2 -1
- package/src/feed/event-handlers/watch/handle-watch-started.ts +5 -0
- package/src/feed/event-handlers/watch/handle-watch-stopped.ts +5 -0
- package/src/feed/event-handlers/watch/index.ts +2 -0
- package/src/feed/feed.ts +15 -33
- package/src/feeds-client/event-handlers/index.ts +1 -0
- package/src/feeds-client/event-handlers/user/handle-user-updated.test.ts +53 -0
- package/src/feeds-client/event-handlers/user/handle-user-updated.ts +28 -0
- package/src/{feeds-client.ts → feeds-client/feeds-client.ts} +48 -39
- package/src/feeds-client/index.ts +2 -0
- package/src/gen/feeds/FeedsApi.ts +164 -138
- package/src/gen/model-decoders/decoders.ts +15 -0
- package/src/gen/models/index.ts +278 -29
- package/src/test-utils/response-generators.ts +10 -11
- package/src/utils/state-update-queue.ts +1 -1
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stream-io/feeds-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"packageManager": "yarn@3.2.4",
|
|
5
5
|
"main": "./dist/index.node.js",
|
|
6
6
|
"exports": {
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@rollup/plugin-replace": "^6.0.1",
|
|
65
65
|
"@rollup/plugin-typescript": "^12.1.0",
|
|
66
|
-
"@stream-io/node-sdk": "0.
|
|
66
|
+
"@stream-io/node-sdk": "0.6.0",
|
|
67
67
|
"@types/react": "^19.1.8",
|
|
68
68
|
"@vitest/coverage-v8": "3.2.4",
|
|
69
69
|
"dotenv": "^16.4.5",
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
FeedResponse,
|
|
3
|
+
FollowResponse,
|
|
4
|
+
UserResponse,
|
|
5
|
+
} from '../../../gen/models';
|
|
2
6
|
import { generateFollowResponse } from '../../../test-utils';
|
|
3
7
|
import { updateStateFollowCreated } from './handle-follow-created';
|
|
4
8
|
|
|
@@ -44,7 +48,7 @@ describe('handle-follow-created', () => {
|
|
|
44
48
|
source_feed: {
|
|
45
49
|
...mockFeed,
|
|
46
50
|
id: 'feed-x',
|
|
47
|
-
|
|
51
|
+
feed: 'user:feed-x',
|
|
48
52
|
created_by: {
|
|
49
53
|
...mockUser,
|
|
50
54
|
id: 'user-x',
|
|
@@ -54,7 +58,7 @@ describe('handle-follow-created', () => {
|
|
|
54
58
|
target_feed: {
|
|
55
59
|
...mockFeed,
|
|
56
60
|
id: 'other-feed',
|
|
57
|
-
|
|
61
|
+
feed: 'user:other-feed',
|
|
58
62
|
created_by: mockUser,
|
|
59
63
|
},
|
|
60
64
|
};
|
|
@@ -86,7 +90,7 @@ describe('handle-follow-created', () => {
|
|
|
86
90
|
source_feed: {
|
|
87
91
|
...mockFeed,
|
|
88
92
|
id: 'other-feed',
|
|
89
|
-
|
|
93
|
+
feed: 'user:other-feed',
|
|
90
94
|
created_by: {
|
|
91
95
|
...mockUser,
|
|
92
96
|
id: 'other-user',
|
|
@@ -95,7 +99,7 @@ describe('handle-follow-created', () => {
|
|
|
95
99
|
target_feed: {
|
|
96
100
|
...mockFeed,
|
|
97
101
|
id: 'feed-1',
|
|
98
|
-
|
|
102
|
+
feed: 'user:feed-1',
|
|
99
103
|
created_by: mockUser,
|
|
100
104
|
follower_count: 1,
|
|
101
105
|
},
|
|
@@ -128,13 +132,13 @@ describe('handle-follow-created', () => {
|
|
|
128
132
|
source_feed: {
|
|
129
133
|
...mockFeed,
|
|
130
134
|
id: 'feed-1',
|
|
131
|
-
|
|
135
|
+
feed: 'user:feed-1',
|
|
132
136
|
created_by: { ...mockUser, id: 'user-1' },
|
|
133
137
|
},
|
|
134
138
|
target_feed: {
|
|
135
139
|
...mockFeed,
|
|
136
140
|
id: 'feed-x',
|
|
137
|
-
|
|
141
|
+
feed: 'user:feed-x',
|
|
138
142
|
created_by: {
|
|
139
143
|
...mockUser,
|
|
140
144
|
id: 'user-x',
|
|
@@ -166,13 +170,13 @@ describe('handle-follow-created', () => {
|
|
|
166
170
|
source_feed: {
|
|
167
171
|
...mockFeed,
|
|
168
172
|
id: 'other-feed',
|
|
169
|
-
|
|
173
|
+
feed: 'user:other-feed',
|
|
170
174
|
created_by: mockUser,
|
|
171
175
|
},
|
|
172
176
|
target_feed: {
|
|
173
177
|
...mockFeed,
|
|
174
178
|
id: 'feed-1',
|
|
175
|
-
|
|
179
|
+
feed: 'user:feed-1',
|
|
176
180
|
created_by: mockUser,
|
|
177
181
|
},
|
|
178
182
|
};
|
|
@@ -202,7 +206,7 @@ describe('handle-follow-created', () => {
|
|
|
202
206
|
source_feed: {
|
|
203
207
|
...mockFeed,
|
|
204
208
|
id: 'existing-feed',
|
|
205
|
-
|
|
209
|
+
feed: 'user:existing-feed',
|
|
206
210
|
created_by: mockUser,
|
|
207
211
|
},
|
|
208
212
|
};
|
|
@@ -212,13 +216,13 @@ describe('handle-follow-created', () => {
|
|
|
212
216
|
source_feed: {
|
|
213
217
|
...mockFeed,
|
|
214
218
|
id: 'other-feed',
|
|
215
|
-
|
|
219
|
+
feed: 'user:other-feed',
|
|
216
220
|
created_by: mockUser,
|
|
217
221
|
},
|
|
218
222
|
target_feed: {
|
|
219
223
|
...mockFeed,
|
|
220
224
|
id: 'feed-1',
|
|
221
|
-
|
|
225
|
+
feed: 'user:feed-1',
|
|
222
226
|
created_by: mockUser,
|
|
223
227
|
},
|
|
224
228
|
};
|
|
@@ -5,10 +5,7 @@ import type {
|
|
|
5
5
|
PartializeAllBut,
|
|
6
6
|
UpdateStateResult,
|
|
7
7
|
} from '../../../types-internal';
|
|
8
|
-
import {
|
|
9
|
-
getStateUpdateQueueId,
|
|
10
|
-
shouldUpdateState,
|
|
11
|
-
} from '../../../utils';
|
|
8
|
+
import { getStateUpdateQueueId, shouldUpdateState } from '../../../utils';
|
|
12
9
|
|
|
13
10
|
export const updateStateFollowCreated = (
|
|
14
11
|
follow: FollowResponse,
|
|
@@ -24,7 +21,7 @@ export const updateStateFollowCreated = (
|
|
|
24
21
|
let newState: FeedState = { ...currentState };
|
|
25
22
|
|
|
26
23
|
// this feed followed someone
|
|
27
|
-
if (follow.source_feed.
|
|
24
|
+
if (follow.source_feed.feed === currentFeedId) {
|
|
28
25
|
newState = {
|
|
29
26
|
...newState,
|
|
30
27
|
// Update FeedResponse fields, that has the new follower/following count
|
|
@@ -37,7 +34,7 @@ export const updateStateFollowCreated = (
|
|
|
37
34
|
}
|
|
38
35
|
} else if (
|
|
39
36
|
// someone followed this feed
|
|
40
|
-
follow.target_feed.
|
|
37
|
+
follow.target_feed.feed === currentFeedId
|
|
41
38
|
) {
|
|
42
39
|
const source = follow.source_feed;
|
|
43
40
|
|
|
@@ -84,7 +81,7 @@ export function handleFollowCreated(
|
|
|
84
81
|
const result = updateStateFollowCreated(
|
|
85
82
|
follow,
|
|
86
83
|
this.currentState,
|
|
87
|
-
this.
|
|
84
|
+
this.feed,
|
|
88
85
|
connectedUser?.id,
|
|
89
86
|
);
|
|
90
87
|
if (result.changed) {
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
FollowResponse,
|
|
3
|
+
FeedResponse,
|
|
4
|
+
UserResponse,
|
|
5
|
+
} from '../../../gen/models';
|
|
2
6
|
import { generateFollowResponse } from '../../../test-utils';
|
|
3
7
|
import { updateStateFollowDeleted } from './handle-follow-deleted';
|
|
4
8
|
|
|
@@ -22,13 +26,13 @@ describe('handle-follow-deleted', () => {
|
|
|
22
26
|
source_feed: {
|
|
23
27
|
...mockFeed,
|
|
24
28
|
id: 'feed-1',
|
|
25
|
-
|
|
29
|
+
feed: 'user:feed-1',
|
|
26
30
|
created_by: mockUser,
|
|
27
31
|
},
|
|
28
32
|
target_feed: {
|
|
29
33
|
...mockFeed,
|
|
30
34
|
id: 'other-feed',
|
|
31
|
-
|
|
35
|
+
feed: 'user:other-feed',
|
|
32
36
|
created_by: mockUser,
|
|
33
37
|
},
|
|
34
38
|
};
|
|
@@ -59,7 +63,7 @@ describe('handle-follow-deleted', () => {
|
|
|
59
63
|
source_feed: {
|
|
60
64
|
...mockFeed,
|
|
61
65
|
id: 'other-feed',
|
|
62
|
-
|
|
66
|
+
feed: 'user:other-feed',
|
|
63
67
|
created_by: {
|
|
64
68
|
...mockUser,
|
|
65
69
|
id: 'other-user',
|
|
@@ -68,7 +72,7 @@ describe('handle-follow-deleted', () => {
|
|
|
68
72
|
target_feed: {
|
|
69
73
|
...mockFeed,
|
|
70
74
|
id: 'feed-1',
|
|
71
|
-
|
|
75
|
+
feed: 'user:feed-1',
|
|
72
76
|
created_by: mockUser,
|
|
73
77
|
},
|
|
74
78
|
};
|
|
@@ -101,13 +105,13 @@ describe('handle-follow-deleted', () => {
|
|
|
101
105
|
source_feed: {
|
|
102
106
|
...mockFeed,
|
|
103
107
|
id: 'other-feed',
|
|
104
|
-
|
|
108
|
+
feed: 'user:other-feed',
|
|
105
109
|
created_by: { ...mockUser, id: 'user-1' },
|
|
106
110
|
},
|
|
107
111
|
target_feed: {
|
|
108
112
|
...mockFeed,
|
|
109
113
|
id: 'feed-1',
|
|
110
|
-
|
|
114
|
+
feed: 'user:feed-1',
|
|
111
115
|
created_by: mockUser,
|
|
112
116
|
},
|
|
113
117
|
};
|
|
@@ -139,13 +143,13 @@ describe('handle-follow-deleted', () => {
|
|
|
139
143
|
source_feed: {
|
|
140
144
|
...mockFeed,
|
|
141
145
|
id: 'other-feed',
|
|
142
|
-
|
|
146
|
+
feed: 'user:other-feed',
|
|
143
147
|
created_by: { ...mockUser, id: 'other-user' },
|
|
144
148
|
},
|
|
145
149
|
target_feed: {
|
|
146
150
|
...mockFeed,
|
|
147
151
|
id: 'feed-1',
|
|
148
|
-
|
|
152
|
+
feed: 'user:feed-1',
|
|
149
153
|
created_by: mockUser,
|
|
150
154
|
},
|
|
151
155
|
};
|
|
@@ -176,13 +180,13 @@ describe('handle-follow-deleted', () => {
|
|
|
176
180
|
source_feed: {
|
|
177
181
|
...mockFeed,
|
|
178
182
|
id: 'other-feed',
|
|
179
|
-
|
|
183
|
+
feed: 'user:other-feed',
|
|
180
184
|
created_by: mockUser,
|
|
181
185
|
},
|
|
182
186
|
target_feed: {
|
|
183
187
|
...mockFeed,
|
|
184
188
|
id: 'feed-1',
|
|
185
|
-
|
|
189
|
+
feed: 'user:feed-1',
|
|
186
190
|
created_by: mockUser,
|
|
187
191
|
},
|
|
188
192
|
};
|
|
@@ -214,13 +218,13 @@ describe('handle-follow-deleted', () => {
|
|
|
214
218
|
source_feed: {
|
|
215
219
|
...mockFeed,
|
|
216
220
|
id: 'feed-1',
|
|
217
|
-
|
|
221
|
+
feed: 'user:feed-1',
|
|
218
222
|
created_by: mockUser,
|
|
219
223
|
},
|
|
220
224
|
target_feed: {
|
|
221
225
|
...mockFeed,
|
|
222
226
|
id: 'target-to-remove',
|
|
223
|
-
|
|
227
|
+
feed: 'user:target-to-remove',
|
|
224
228
|
created_by: mockUser,
|
|
225
229
|
},
|
|
226
230
|
};
|
|
@@ -230,13 +234,13 @@ describe('handle-follow-deleted', () => {
|
|
|
230
234
|
source_feed: {
|
|
231
235
|
...mockFeed,
|
|
232
236
|
id: 'feed-1',
|
|
233
|
-
|
|
237
|
+
feed: 'user:feed-1',
|
|
234
238
|
created_by: mockUser,
|
|
235
239
|
},
|
|
236
240
|
target_feed: {
|
|
237
241
|
...mockFeed,
|
|
238
242
|
id: 'target-to-keep',
|
|
239
|
-
|
|
243
|
+
feed: 'user:target-to-keep',
|
|
240
244
|
created_by: mockUser,
|
|
241
245
|
},
|
|
242
246
|
};
|
|
@@ -17,7 +17,7 @@ export const updateStateFollowDeleted = (
|
|
|
17
17
|
let newState: FeedState = { ...currentState };
|
|
18
18
|
|
|
19
19
|
// this feed unfollowed someone
|
|
20
|
-
if (follow.source_feed.
|
|
20
|
+
if (follow.source_feed.feed === currentFeedId) {
|
|
21
21
|
newState = {
|
|
22
22
|
...newState,
|
|
23
23
|
// Update FeedResponse fields, that has the new follower/following count
|
|
@@ -27,12 +27,12 @@ export const updateStateFollowDeleted = (
|
|
|
27
27
|
// Only update if following array already exists
|
|
28
28
|
if (currentState.following !== undefined) {
|
|
29
29
|
newState.following = currentState.following.filter(
|
|
30
|
-
(followItem) => followItem.target_feed.
|
|
30
|
+
(followItem) => followItem.target_feed.feed !== follow.target_feed.feed,
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
33
|
} else if (
|
|
34
34
|
// someone unfollowed this feed
|
|
35
|
-
follow.target_feed.
|
|
35
|
+
follow.target_feed.feed === currentFeedId
|
|
36
36
|
) {
|
|
37
37
|
const source = follow.source_feed;
|
|
38
38
|
|
|
@@ -47,14 +47,14 @@ export const updateStateFollowDeleted = (
|
|
|
47
47
|
currentState.own_follows !== undefined
|
|
48
48
|
) {
|
|
49
49
|
newState.own_follows = currentState.own_follows.filter(
|
|
50
|
-
(followItem) => followItem.source_feed.
|
|
50
|
+
(followItem) => followItem.source_feed.feed !== follow.source_feed.feed,
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
// Only update if followers array already exists
|
|
55
55
|
if (currentState.followers !== undefined) {
|
|
56
56
|
newState.followers = currentState.followers.filter(
|
|
57
|
-
(followItem) => followItem.source_feed.
|
|
57
|
+
(followItem) => followItem.source_feed.feed !== follow.source_feed.feed,
|
|
58
58
|
);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -85,7 +85,7 @@ export function handleFollowDeleted(
|
|
|
85
85
|
const result = updateStateFollowDeleted(
|
|
86
86
|
follow,
|
|
87
87
|
this.currentState,
|
|
88
|
-
this.
|
|
88
|
+
this.feed,
|
|
89
89
|
connectedUser?.id,
|
|
90
90
|
);
|
|
91
91
|
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { Feed, FeedState } from '../../../feed';
|
|
2
|
-
import {
|
|
3
|
-
getStateUpdateQueueId,
|
|
4
|
-
shouldUpdateState,
|
|
5
|
-
} from '../../../utils';
|
|
2
|
+
import { getStateUpdateQueueId, shouldUpdateState } from '../../../utils';
|
|
6
3
|
import { EventPayload, PartializeAllBut } from '../../../types-internal';
|
|
7
4
|
|
|
8
5
|
export function handleFollowUpdated(
|
|
@@ -14,7 +11,7 @@ export function handleFollowUpdated(
|
|
|
14
11
|
) {
|
|
15
12
|
const follow = eventOrResponse.follow;
|
|
16
13
|
const connectedUserId = this.client.state.getLatestValue().connected_user?.id;
|
|
17
|
-
const currentFeedId = this.
|
|
14
|
+
const currentFeedId = this.feed;
|
|
18
15
|
|
|
19
16
|
if (
|
|
20
17
|
!shouldUpdateState({
|
|
@@ -30,7 +27,7 @@ export function handleFollowUpdated(
|
|
|
30
27
|
let newState: FeedState | undefined;
|
|
31
28
|
|
|
32
29
|
// this feed followed someone
|
|
33
|
-
if (follow.source_feed.
|
|
30
|
+
if (follow.source_feed.feed === currentFeedId) {
|
|
34
31
|
newState ??= {
|
|
35
32
|
...currentState,
|
|
36
33
|
// Update FeedResponse fields, that has the new follower/following count
|
|
@@ -39,7 +36,7 @@ export function handleFollowUpdated(
|
|
|
39
36
|
|
|
40
37
|
const index =
|
|
41
38
|
currentState.following?.findIndex(
|
|
42
|
-
(f) => f.target_feed.
|
|
39
|
+
(f) => f.target_feed.feed === follow.target_feed.feed,
|
|
43
40
|
) ?? -1;
|
|
44
41
|
|
|
45
42
|
if (index >= 0) {
|
|
@@ -48,7 +45,7 @@ export function handleFollowUpdated(
|
|
|
48
45
|
}
|
|
49
46
|
} else if (
|
|
50
47
|
// someone followed this feed
|
|
51
|
-
follow.target_feed.
|
|
48
|
+
follow.target_feed.feed === currentFeedId
|
|
52
49
|
) {
|
|
53
50
|
const source = follow.source_feed;
|
|
54
51
|
|
|
@@ -63,7 +60,7 @@ export function handleFollowUpdated(
|
|
|
63
60
|
currentState.own_follows
|
|
64
61
|
) {
|
|
65
62
|
const index = currentState.own_follows.findIndex(
|
|
66
|
-
(f) => f.source_feed.
|
|
63
|
+
(f) => f.source_feed.feed === follow.source_feed.feed,
|
|
67
64
|
);
|
|
68
65
|
|
|
69
66
|
if (index >= 0) {
|
|
@@ -74,7 +71,7 @@ export function handleFollowUpdated(
|
|
|
74
71
|
|
|
75
72
|
const index =
|
|
76
73
|
currentState.followers?.findIndex(
|
|
77
|
-
(f) => f.source_feed.
|
|
74
|
+
(f) => f.source_feed.feed === follow.source_feed.feed,
|
|
78
75
|
) ?? -1;
|
|
79
76
|
|
|
80
77
|
if (index >= 0) {
|
package/src/feed/feed.ts
CHANGED
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
ActivityResponse,
|
|
9
9
|
CommentResponse,
|
|
10
10
|
PagerResponse,
|
|
11
|
-
SingleFollowRequest,
|
|
12
11
|
QueryFeedMembersRequest,
|
|
13
12
|
SortParamRequest,
|
|
14
13
|
ThreadedCommentResponse,
|
|
14
|
+
FollowRequest,
|
|
15
15
|
} from '../gen/models';
|
|
16
16
|
import { StreamResponse } from '../gen-imports';
|
|
17
17
|
import { StateStore } from '../common/StateStore';
|
|
@@ -205,7 +205,7 @@ export class Feed extends FeedApi {
|
|
|
205
205
|
) {
|
|
206
206
|
super(client, groupId, id);
|
|
207
207
|
this.state = new StateStore<FeedState>({
|
|
208
|
-
|
|
208
|
+
feed: `${groupId}:${id}`,
|
|
209
209
|
group_id: groupId,
|
|
210
210
|
id,
|
|
211
211
|
...(data ?? {}),
|
|
@@ -219,7 +219,7 @@ export class Feed extends FeedApi {
|
|
|
219
219
|
|
|
220
220
|
protected readonly client: FeedsClient;
|
|
221
221
|
|
|
222
|
-
get
|
|
222
|
+
get feed() {
|
|
223
223
|
return `${this.group}:${this.id}`;
|
|
224
224
|
}
|
|
225
225
|
|
|
@@ -270,7 +270,7 @@ export class Feed extends FeedApi {
|
|
|
270
270
|
this.stateUpdateQueue.clear();
|
|
271
271
|
const responseCopy: Partial<
|
|
272
272
|
StreamResponse<GetOrCreateFeedResponse>['feed'] &
|
|
273
|
-
StreamResponse<GetOrCreateFeedResponse
|
|
273
|
+
StreamResponse<Omit<GetOrCreateFeedResponse, 'feed'>>
|
|
274
274
|
> = {
|
|
275
275
|
...response,
|
|
276
276
|
...response.feed,
|
|
@@ -316,24 +316,6 @@ export class Feed extends FeedApi {
|
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
-
/**
|
|
320
|
-
* @internal
|
|
321
|
-
*/
|
|
322
|
-
handleWatchStopped() {
|
|
323
|
-
this.state.partialNext({
|
|
324
|
-
watch: false,
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* @internal
|
|
330
|
-
*/
|
|
331
|
-
handleWatchStarted() {
|
|
332
|
-
this.state.partialNext({
|
|
333
|
-
watch: true,
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
|
|
337
319
|
/**
|
|
338
320
|
* Returns index of the provided comment object.
|
|
339
321
|
*/
|
|
@@ -569,7 +551,7 @@ export class Feed extends FeedApi {
|
|
|
569
551
|
base: () =>
|
|
570
552
|
this.client.getCommentReplies({
|
|
571
553
|
...request,
|
|
572
|
-
|
|
554
|
+
id: comment.id,
|
|
573
555
|
// use known sort first (prevents broken pagination)
|
|
574
556
|
sort,
|
|
575
557
|
next: currentNextCursor,
|
|
@@ -623,7 +605,7 @@ export class Feed extends FeedApi {
|
|
|
623
605
|
currentState[type],
|
|
624
606
|
follows,
|
|
625
607
|
(follow) =>
|
|
626
|
-
`${follow.source_feed.
|
|
608
|
+
`${follow.source_feed.feed}-${follow.target_feed.feed}`,
|
|
627
609
|
),
|
|
628
610
|
[paginationKey]: {
|
|
629
611
|
...currentState[paginationKey],
|
|
@@ -734,7 +716,7 @@ export class Feed extends FeedApi {
|
|
|
734
716
|
*/
|
|
735
717
|
async queryFollowers(request: Omit<QueryFollowsRequest, 'filter'>) {
|
|
736
718
|
const filter: QueryFollowsRequest['filter'] = {
|
|
737
|
-
target_feed: this.
|
|
719
|
+
target_feed: this.feed,
|
|
738
720
|
};
|
|
739
721
|
|
|
740
722
|
const response = await this.client.queryFollows({
|
|
@@ -752,7 +734,7 @@ export class Feed extends FeedApi {
|
|
|
752
734
|
*/
|
|
753
735
|
async queryFollowing(request: Omit<QueryFollowsRequest, 'filter'>) {
|
|
754
736
|
const filter: QueryFollowsRequest['filter'] = {
|
|
755
|
-
source_feed: this.
|
|
737
|
+
source_feed: this.feed,
|
|
756
738
|
};
|
|
757
739
|
|
|
758
740
|
const response = await this.client.queryFollows({
|
|
@@ -765,13 +747,13 @@ export class Feed extends FeedApi {
|
|
|
765
747
|
|
|
766
748
|
async follow(
|
|
767
749
|
feedOrFid: Feed | string,
|
|
768
|
-
options?: Omit<
|
|
750
|
+
options?: Omit<FollowRequest, 'source' | 'target'>,
|
|
769
751
|
) {
|
|
770
|
-
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.
|
|
752
|
+
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.feed;
|
|
771
753
|
|
|
772
754
|
const response = await this.client.follow({
|
|
773
755
|
...options,
|
|
774
|
-
source: this.
|
|
756
|
+
source: this.feed,
|
|
775
757
|
target: fid,
|
|
776
758
|
});
|
|
777
759
|
|
|
@@ -779,10 +761,10 @@ export class Feed extends FeedApi {
|
|
|
779
761
|
}
|
|
780
762
|
|
|
781
763
|
async unfollow(feedOrFid: Feed | string) {
|
|
782
|
-
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.
|
|
764
|
+
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.feed;
|
|
783
765
|
|
|
784
766
|
const response = await this.client.unfollow({
|
|
785
|
-
source: this.
|
|
767
|
+
source: this.feed,
|
|
786
768
|
target: fid,
|
|
787
769
|
});
|
|
788
770
|
|
|
@@ -807,10 +789,10 @@ export class Feed extends FeedApi {
|
|
|
807
789
|
});
|
|
808
790
|
}
|
|
809
791
|
|
|
810
|
-
addActivity(request: Omit<ActivityRequest, '
|
|
792
|
+
addActivity(request: Omit<ActivityRequest, 'feeds'>) {
|
|
811
793
|
return this.feedsApi.addActivity({
|
|
812
794
|
...request,
|
|
813
|
-
|
|
795
|
+
feeds: [this.feed],
|
|
814
796
|
});
|
|
815
797
|
}
|
|
816
798
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './user/handle-user-updated';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { describe, it, beforeEach, expect } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { FeedsClient, handleUserUpdated } from '../..';
|
|
4
|
+
import { generateOwnUser, generateUserResponse } from '../../../test-utils';
|
|
5
|
+
import { EventPayload } from '../../../types-internal';
|
|
6
|
+
|
|
7
|
+
describe('handleUserUpdated', () => {
|
|
8
|
+
let feedsClient: FeedsClient;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
feedsClient = new FeedsClient('mock-api-key');
|
|
12
|
+
const connectedUser = generateOwnUser();
|
|
13
|
+
|
|
14
|
+
feedsClient.state.partialNext({ connected_user: connectedUser });
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should update the connected user in the state', () => {
|
|
18
|
+
const stateBefore = feedsClient.state.getLatestValue();
|
|
19
|
+
|
|
20
|
+
const event: EventPayload<'user.updated'> = {
|
|
21
|
+
type: 'user.updated',
|
|
22
|
+
created_at: new Date(),
|
|
23
|
+
custom: {},
|
|
24
|
+
user: {
|
|
25
|
+
...generateUserResponse(),
|
|
26
|
+
...stateBefore.connected_user!,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
handleUserUpdated.call(feedsClient, event);
|
|
31
|
+
|
|
32
|
+
const stateAfter = feedsClient.state.getLatestValue();
|
|
33
|
+
|
|
34
|
+
expect(stateAfter.connected_user).toMatchObject({ name: event.user.name });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should not update the connected user if the incoming event contains other user', () => {
|
|
38
|
+
const event: EventPayload<'user.updated'> = {
|
|
39
|
+
type: 'user.updated',
|
|
40
|
+
created_at: new Date(),
|
|
41
|
+
custom: {},
|
|
42
|
+
user: generateUserResponse(),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const stateBefore = feedsClient.state.getLatestValue();
|
|
46
|
+
|
|
47
|
+
handleUserUpdated.call(feedsClient, event);
|
|
48
|
+
|
|
49
|
+
const stateAfter = feedsClient.state.getLatestValue();
|
|
50
|
+
|
|
51
|
+
expect(stateAfter.connected_user).toBe(stateBefore.connected_user);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { EventPayload } from '../../../types-internal';
|
|
2
|
+
import type { FeedsClient, FeedsClientState } from '../../feeds-client';
|
|
3
|
+
|
|
4
|
+
export function handleUserUpdated(
|
|
5
|
+
this: FeedsClient,
|
|
6
|
+
event: EventPayload<'user.updated'>,
|
|
7
|
+
) {
|
|
8
|
+
this.state.next((currentState) => {
|
|
9
|
+
let newState: FeedsClientState | undefined;
|
|
10
|
+
|
|
11
|
+
const { connected_user } = currentState;
|
|
12
|
+
|
|
13
|
+
if (connected_user && connected_user.id === event.user.id) {
|
|
14
|
+
newState ??= {
|
|
15
|
+
...currentState,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
newState.connected_user = {
|
|
19
|
+
...connected_user,
|
|
20
|
+
...event.user,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// TODO: update other users in user map (if/once applicable)
|
|
25
|
+
|
|
26
|
+
return newState ?? currentState;
|
|
27
|
+
});
|
|
28
|
+
}
|