Skip to content

Commit b61af6b

Browse files
committed
Update to new structure
1 parent 32e85ad commit b61af6b

File tree

7 files changed

+81
-64
lines changed

7 files changed

+81
-64
lines changed

packages/feeds-client/__integration-tests__/notification-feed.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import {
55
getTestUser,
66
waitForEvent,
77
} from './utils';
8-
import { FeedsClient } from '../src/FeedsClient';
9-
import { Feed } from '../src/Feed';
8+
109
import { UserRequest } from '../src/gen/models';
10+
import { FeedsClient } from '../src/feeds-client';
11+
import { Feed } from '../src/feed';
1112

1213
describe('Notification Feed Test Setup', () => {
1314
let client1: FeedsClient;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { describe, it, expect } from 'vitest';
2-
import { ActivityMarkEvent, NotificationStatusResponse } from '../gen/models';
3-
import { updateNotificationStatusFromActivityMarked } from './activity-marked-utils';
2+
import {
3+
ActivityMarkEvent,
4+
NotificationStatusResponse,
5+
} from '../../../gen/models';
6+
import { updateNotificationStatusFromActivityMarked } from './handle-activity-marked';
47

58
const createMockActivityMarkEvent = (
69
overrides: Partial<ActivityMarkEvent> = {},

packages/feeds-client/src/feed/event-handlers/activity/activity-marked-utils.ts renamed to packages/feeds-client/src/feed/event-handlers/activity/handle-activity-marked.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { ActivityMarkEvent, NotificationStatusResponse } from '../gen/models';
2-
import { UpdateStateResult } from '../types-internal';
1+
import {
2+
ActivityMarkEvent,
3+
NotificationStatusResponse,
4+
} from '../../../gen/models';
5+
import { EventPayload, UpdateStateResult } from '../../../types-internal';
6+
import { Feed } from '../../feed';
37

48
export const updateNotificationStatusFromActivityMarked = (
59
event: ActivityMarkEvent,
@@ -46,3 +50,19 @@ export const updateNotificationStatusFromActivityMarked = (
4650
data: { notification_status: newState },
4751
};
4852
};
53+
54+
export function handleActivityMarked(
55+
this: Feed,
56+
event: EventPayload<'feeds.activity.marked'>,
57+
) {
58+
const result = updateNotificationStatusFromActivityMarked(
59+
event,
60+
this.currentState.notification_status,
61+
this.currentState.aggregated_activities,
62+
);
63+
if (result.changed) {
64+
this.state.partialNext({
65+
notification_status: result.data?.notification_status,
66+
});
67+
}
68+
}

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

Lines changed: 0 additions & 40 deletions
This file was deleted.

packages/feeds-client/src/feed/event-handlers/activity/notification-feed-utils.test.ts renamed to packages/feeds-client/src/feed/event-handlers/notification-feed/handle-notification-feed-updated.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {
33
NotificationFeedUpdatedEvent,
44
NotificationStatusResponse,
55
AggregatedActivityResponse,
6-
} from '../gen/models';
7-
import { updateNotificationFeedFromEvent } from './notification-feed-utils';
6+
} from '../../../gen/models';
7+
import { updateNotificationFeedFromEvent } from './handle-notification-feed-updated';
88

99
const createMockNotificationFeedUpdatedEvent = (
1010
overrides: Partial<NotificationFeedUpdatedEvent> = {},
Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,54 @@
11
import type { Feed } from '../../../feed';
2-
import type { EventPayload } from '../../../types-internal';
2+
import {
3+
AggregatedActivityResponse,
4+
NotificationFeedUpdatedEvent,
5+
NotificationStatusResponse,
6+
} from '../../../gen/models';
7+
import type { EventPayload, UpdateStateResult } from '../../../types-internal';
8+
9+
export const updateNotificationFeedFromEvent = (
10+
event: NotificationFeedUpdatedEvent,
11+
): UpdateStateResult<{
12+
data?: {
13+
notification_status?: NotificationStatusResponse;
14+
aggregated_activities?: AggregatedActivityResponse[];
15+
};
16+
}> => {
17+
const updates: {
18+
notification_status?: NotificationStatusResponse;
19+
aggregated_activities?: AggregatedActivityResponse[];
20+
} = {};
21+
22+
if (event.notification_status) {
23+
updates.notification_status = event.notification_status;
24+
}
25+
26+
if (event.aggregated_activities) {
27+
updates.aggregated_activities = event.aggregated_activities;
28+
}
29+
30+
// Only return changed if we have actual updates
31+
if (Object.keys(updates).length > 0) {
32+
return {
33+
changed: true,
34+
data: updates,
35+
};
36+
}
37+
38+
return {
39+
changed: false,
40+
};
41+
};
342

443
export function handleNotificationFeedUpdated(
544
this: Feed,
645
event: EventPayload<'feeds.notification_feed.updated'>,
746
) {
8-
console.info('notification feed updated', event);
9-
// TODO: handle notification feed updates
47+
const result = updateNotificationFeedFromEvent(event);
48+
if (result.changed) {
49+
this.state.partialNext({
50+
notification_status: result.data?.notification_status,
51+
aggregated_activities: result.data?.aggregated_activities,
52+
});
53+
}
1054
}

packages/feeds-client/src/feed/feed.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import type {
5151
PagerResponseWithLoadingStates,
5252
} from '../types';
5353
import { checkHasAnotherPage, Constants, uniqueArrayMerge } from '../utils';
54+
import { handleActivityMarked } from './event-handlers/activity/handle-activity-marked';
5455

5556
export type FeedState = Omit<
5657
Partial<GetOrCreateFeedResponse & FeedResponse>,
@@ -180,19 +181,7 @@ export class Feed extends FeedApi {
180181
'feeds.poll.vote_removed': Feed.noop,
181182
'feeds.activity.pinned': Feed.noop,
182183
'feeds.activity.unpinned': Feed.noop,
183-
'feeds.activity.marked': (event) => {
184-
const currentState = this.currentState;
185-
const result = updateNotificationStatusFromActivityMarked(
186-
event,
187-
currentState.notification_status,
188-
currentState.aggregated_activities,
189-
);
190-
if (result.changed) {
191-
this.state.partialNext({
192-
...result.data,
193-
});
194-
}
195-
},
184+
'feeds.activity.marked': handleActivityMarked.bind(this),
196185
'moderation.custom_action': Feed.noop,
197186
'moderation.flagged': Feed.noop,
198187
'moderation.mark_reviewed': Feed.noop,

0 commit comments

Comments
 (0)