Skip to content

Commit a0467cb

Browse files
Further cleanup
1 parent d888f3b commit a0467cb

File tree

10 files changed

+48
-17
lines changed

10 files changed

+48
-17
lines changed

packages/feeds-client/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export * from './src/common/UserSearchSource';
1111
export * from './src/common/FeedSearchSource';
1212
export * from './src/common/Poll';
1313
export * from './src/utils';
14+
export * from './src/type-assertions';

packages/feeds-client/src/Feed.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import {
3939
handleActivityRemovedFromFeed,
4040
handleActivityReactionDeleted,
4141
handleActivityReactionAdded,
42+
handleFeedUpdated,
43+
handleNotificationFeedUpdated,
4244
} from './event-handlers/feed';
4345
import { capitalize } from './common/utils';
4446
import type {
@@ -156,9 +158,7 @@ export class Feed extends FeedApi {
156158
'feeds.comment.updated': handleCommentUpdated.bind(this),
157159
'feeds.feed.created': Feed.noop,
158160
'feeds.feed.deleted': Feed.noop,
159-
'feeds.feed.updated': (event) => {
160-
this.state.partialNext({ ...event.feed });
161-
},
161+
'feeds.feed.updated': handleFeedUpdated.bind(this),
162162
'feeds.feed_group.changed': Feed.noop,
163163
'feeds.feed_group.deleted': Feed.noop,
164164
'feeds.follow.created': handleFollowCreated.bind(this),
@@ -170,10 +170,7 @@ export class Feed extends FeedApi {
170170
'feeds.feed_member.added': handleFeedMemberAdded.bind(this),
171171
'feeds.feed_member.removed': handleFeedMemberRemoved.bind(this),
172172
'feeds.feed_member.updated': handleFeedMemberUpdated.bind(this),
173-
'feeds.notification_feed.updated': (event) => {
174-
console.info('notification feed updated', event);
175-
// TODO: handle notification feed updates
176-
},
173+
'feeds.notification_feed.updated': handleNotificationFeedUpdated.bind(this),
177174
// the poll events should be removed from here
178175
'feeds.poll.closed': Feed.noop,
179176
'feeds.poll.deleted': Feed.noop,

packages/feeds-client/src/event-handlers/feed/activity/activity-reaction-utils.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ describe('activity-reaction-utils', () => {
109109
count: 1,
110110
first_reaction_at: reaction.created_at,
111111
last_reaction_at: reaction.created_at,
112+
sum_scores: 0,
112113
},
113114
};
114115

@@ -123,6 +124,7 @@ describe('activity-reaction-utils', () => {
123124
count: 1,
124125
first_reaction_at: reaction.created_at,
125126
last_reaction_at: reaction.created_at,
127+
sum_scores: 0,
126128
});
127129
});
128130

@@ -136,6 +138,7 @@ describe('activity-reaction-utils', () => {
136138
count: 1,
137139
first_reaction_at: reaction.created_at,
138140
last_reaction_at: reaction.created_at,
141+
sum_scores: 0,
139142
},
140143
};
141144
const event = createMockAddedEvent(reaction, eventActivity);
@@ -150,6 +153,7 @@ describe('activity-reaction-utils', () => {
150153
count: 1,
151154
first_reaction_at: reaction.created_at,
152155
last_reaction_at: reaction.created_at,
156+
sum_scores: 0,
153157
});
154158
});
155159
});
@@ -165,6 +169,7 @@ describe('activity-reaction-utils', () => {
165169
count: 1,
166170
first_reaction_at: reaction.created_at,
167171
last_reaction_at: reaction.created_at,
172+
sum_scores: 0,
168173
},
169174
};
170175
const event = createMockAddedEvent(reaction, eventActivity);
@@ -196,6 +201,7 @@ describe('activity-reaction-utils', () => {
196201
count: 1,
197202
first_reaction_at: reaction.created_at,
198203
last_reaction_at: reaction.created_at,
204+
sum_scores: 0,
199205
},
200206
};
201207
const event = createMockAddedEvent(reaction, eventActivity);
@@ -230,6 +236,7 @@ describe('activity-reaction-utils', () => {
230236
count: 1,
231237
first_reaction_at: reaction.created_at,
232238
last_reaction_at: reaction.created_at,
239+
sum_scores: 0,
233240
},
234241
};
235242
const event = createMockAddedEvent(reaction, eventActivity);
@@ -253,6 +260,7 @@ describe('activity-reaction-utils', () => {
253260
count: 1,
254261
first_reaction_at: reaction.created_at,
255262
last_reaction_at: reaction.created_at,
263+
sum_scores: 0,
256264
},
257265
};
258266
const event = createMockAddedEvent(reaction, eventActivity);
@@ -274,6 +282,7 @@ describe('activity-reaction-utils', () => {
274282
count: 1,
275283
first_reaction_at: reaction.created_at,
276284
last_reaction_at: reaction.created_at,
285+
sum_scores: 0,
277286
},
278287
};
279288
const event = createMockAddedEvent(reaction, eventActivity);
@@ -296,6 +305,7 @@ describe('activity-reaction-utils', () => {
296305
count: 1,
297306
first_reaction_at: reaction.created_at,
298307
last_reaction_at: reaction.created_at,
308+
sum_scores: 0,
299309
},
300310
};
301311
const event = createMockAddedEvent(reaction, eventActivity);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Feed } from '../../../Feed';
2+
import { EventPayload } from '../../../types-internal';
3+
4+
export function handleFeedUpdated(
5+
this: Feed,
6+
event: EventPayload<'feeds.feed.updated'>,
7+
) {
8+
this.state.partialNext({ ...event.feed });
9+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './handle-feed-updated';

packages/feeds-client/src/event-handlers/feed/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ export * from './follow';
22
export * from './comment';
33
export * from './feed-member';
44
export * from './bookmark';
5-
export * from './activity';
5+
export * from './activity';
6+
export * from './feed';
7+
export * from './notification-feed';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { Feed } from '../../../Feed';
2+
import type { EventPayload } from '../../../types-internal';
3+
4+
export function handleNotificationFeedUpdated(
5+
this: Feed,
6+
event: EventPayload<'feeds.notification_feed.updated'>,
7+
) {
8+
console.info('notification feed updated', event);
9+
// TODO: handle notification feed updates
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './handle-notification-feed-updated'
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { FeedResponse, FollowResponse } from './gen/models';
1+
import { CommentResponse, FeedResponse, FollowResponse } from './gen/models';
2+
import { CommentParent } from './types';
23

34
export const isFollowResponse = (data: object): data is FollowResponse => {
45
return 'source_feed' in data && 'target_feed' in data;
@@ -7,3 +8,9 @@ export const isFollowResponse = (data: object): data is FollowResponse => {
78
export const isFeedResponse = (data: object): data is FeedResponse => {
89
return 'created_by' in data;
910
};
11+
12+
export const isCommentResponse = (
13+
entity: CommentParent,
14+
): entity is CommentResponse => {
15+
return typeof (entity as CommentResponse)?.object_id === 'string';
16+
};

packages/feeds-client/src/utils.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { CommentParent, StreamFile } from './types';
2-
import type { CommentResponse } from './gen/models';
1+
import { StreamFile } from './types';
32

43
export const isImageFile = (file: StreamFile) => {
54
// photoshop files begin with 'image/'
@@ -17,12 +16,6 @@ export const checkHasAnotherPage = <T extends unknown | undefined>(
1716
(typeof v === 'undefined' && typeof cursor === 'undefined') ||
1817
typeof cursor === 'string';
1918

20-
export const isCommentResponse = (
21-
entity: CommentParent,
22-
): entity is CommentResponse => {
23-
return typeof (entity as CommentResponse)?.object_id === 'string';
24-
};
25-
2619
export const Constants = {
2720
DEFAULT_COMMENT_PAGINATION: 'first',
2821
} as const;

0 commit comments

Comments
 (0)