@@ -15,10 +15,12 @@ import '../feed_state.dart';
1515
1616import '../query/feed_query.dart' ;
1717import 'feed_capabilities_mixin.dart' ;
18+ import 'partial_activity_event_handler.dart' ;
19+ import 'partial_activity_list_event_handler.dart' ;
1820import 'state_event_handler.dart' ;
1921
2022class FeedEventHandler with FeedCapabilitiesMixin implements StateEventHandler {
21- const FeedEventHandler ({
23+ FeedEventHandler ({
2224 required this .query,
2325 required this .state,
2426 required this .capabilitiesRepository,
@@ -30,100 +32,27 @@ class FeedEventHandler with FeedCapabilitiesMixin implements StateEventHandler {
3032 @override
3133 final CapabilitiesRepository capabilitiesRepository;
3234
35+ late final PartialActivityListEventHandler _partialActivityListEventHandler =
36+ PartialActivityListEventHandler (
37+ state: state,
38+ capabilitiesRepository: capabilitiesRepository,
39+ fid: query.fid,
40+ activityFilter: query.activityFilter,
41+ );
42+
43+ late final PartialActivityEventHandler _partialActivityEventHandler =
44+ PartialActivityEventHandler (
45+ state: state,
46+ capabilitiesRepository: capabilitiesRepository,
47+ fid: query.fid,
48+ );
49+
3350 @override
3451 Future <void > handleEvent (WsEvent event) async {
35- final fid = query.fid;
36-
37- bool matchesQueryFilter (ActivityData activity) {
38- final filter = query.activityFilter;
39- if (filter == null ) return true ;
40- return filter.matches (activity);
41- }
42-
43- if (event is api.ActivityAddedEvent ) {
44- if (event.fid != fid.rawValue) return ;
45-
46- final activity = event.activity.toModel ();
47- if (! matchesQueryFilter (activity)) return ;
48-
49- state.onActivityAdded (activity);
50-
51- final updatedActivity = await withUpdatedFeedCapabilities (activity);
52- if (updatedActivity != null ) state.onActivityUpdated (updatedActivity);
53-
54- return ;
55- }
56-
57- if (event is api.ActivityUpdatedEvent ) {
58- if (event.fid != fid.rawValue) return ;
59-
60- final activity = event.activity.toModel ();
61- if (! matchesQueryFilter (activity)) {
62- // If the updated activity no longer matches the filter, remove it
63- return state.onActivityRemoved (activity);
64- }
65-
66- final updatedActivity = await withUpdatedFeedCapabilities (activity);
67- return state.onActivityUpdated (updatedActivity ?? activity);
68- }
69-
70- if (event is api.ActivityDeletedEvent ) {
71- if (event.fid != fid.rawValue) return ;
72- return state.onActivityRemoved (event.activity.toModel ());
73- }
74-
75- if (event is api.ActivityReactionAddedEvent ) {
76- if (event.fid != fid.rawValue) return ;
77-
78- final activity = event.activity.toModel ();
79- if (! matchesQueryFilter (activity)) {
80- // If the reaction's activity no longer matches the filter, remove it
81- return state.onActivityRemoved (activity);
82- }
83-
84- return state.onReactionAdded (event.reaction.toModel ());
85- }
86-
87- if (event is api.ActivityReactionDeletedEvent ) {
88- if (event.fid != fid.rawValue) return ;
89-
90- final activity = event.activity.toModel ();
91- if (! matchesQueryFilter (activity)) {
92- // If the reaction's activity no longer matches the filter, remove it
93- return state.onActivityRemoved (activity);
94- }
95-
96- return state.onReactionRemoved (event.reaction.toModel ());
97- }
52+ if (await _partialActivityListEventHandler.handleEvent (event)) return ;
53+ if (await _partialActivityEventHandler.handleEvent (event)) return ;
9854
99- if (event is api.ActivityPinnedEvent ) {
100- if (event.fid != fid.rawValue) return ;
101-
102- final activity = event.pinnedActivity.activity.toModel ();
103- if (! matchesQueryFilter (activity)) {
104- // If the pinned activity no longer matches the filter, remove it
105- return state.onActivityRemoved (activity);
106- }
107-
108- return state.onActivityPinned (event.pinnedActivity.toModel ());
109- }
110-
111- if (event is api.ActivityUnpinnedEvent ) {
112- if (event.fid != fid.rawValue) return ;
113-
114- final activity = event.pinnedActivity.activity.toModel ();
115- if (! matchesQueryFilter (activity)) {
116- // If the unpinned activity no longer matches the filter, remove it
117- return state.onActivityRemoved (activity);
118- }
119-
120- return state.onActivityUnpinned (event.pinnedActivity.activity.id);
121- }
122-
123- if (event is api.ActivityMarkEvent ) {
124- if (event.fid != fid.rawValue) return ;
125- return state.onActivityMarked (event.toModel ());
126- }
55+ final fid = query.fid;
12756
12857 if (event is api.NotificationFeedUpdatedEvent ) {
12958 if (event.fid != fid.rawValue) return ;
@@ -133,48 +62,6 @@ class FeedEventHandler with FeedCapabilitiesMixin implements StateEventHandler {
13362 );
13463 }
13564
136- if (event is api.BookmarkAddedEvent ) {
137- final activity = event.bookmark.activity.toModel ();
138- if (! activity.feeds.contains (fid.rawValue)) return ;
139-
140- if (! matchesQueryFilter (activity)) {
141- // If the bookmark's activity no longer matches the filter, remove it
142- return state.onActivityRemoved (activity);
143- }
144-
145- return state.onBookmarkAdded (event.bookmark.toModel ());
146- }
147-
148- if (event is api.BookmarkDeletedEvent ) {
149- final activity = event.bookmark.activity.toModel ();
150- if (! activity.feeds.contains (fid.rawValue)) return ;
151-
152- if (! matchesQueryFilter (activity)) {
153- // If the bookmark's activity no longer matches the filter, remove it
154- return state.onActivityRemoved (activity);
155- }
156-
157- return state.onBookmarkRemoved (event.bookmark.toModel ());
158- }
159-
160- if (event is api.CommentAddedEvent ) {
161- if (event.fid != fid.rawValue) return ;
162-
163- final activity = event.activity.toModel ();
164- if (! matchesQueryFilter (activity)) {
165- // If the comment's activity no longer matches the filter, remove it
166- return state.onActivityRemoved (activity);
167- }
168-
169- return state.onCommentAdded (event.comment.toModel ());
170- }
171-
172- if (event is api.CommentDeletedEvent ) {
173- if (event.fid != fid.rawValue) return ;
174- // TODO: Match event activity against filter once available in the event
175- return state.onCommentRemoved (event.comment.toModel ());
176- }
177-
17865 if (event is api.FeedDeletedEvent ) {
17966 if (event.fid != fid.rawValue) return ;
18067 return state.onFeedDeleted ();
0 commit comments