@@ -10,7 +10,11 @@ import '../../../models/feed_data.dart';
1010import '../../../models/feeds_reaction_data.dart' ;
1111import '../../../models/follow_data.dart' ;
1212import '../../../models/mark_activity_data.dart' ;
13+ import '../../../models/poll_data.dart' ;
14+ import '../../../models/poll_vote_data.dart' ;
1315import '../../../repository/capabilities_repository.dart' ;
16+ import '../../../resolvers/resolvers.dart' ;
17+ import '../../../utils/filter.dart' ;
1418import '../../feed_state.dart' ;
1519
1620import '../../query/feed_query.dart' ;
@@ -37,16 +41,8 @@ class FeedEventHandler with FeedCapabilitiesMixin implements StateEventHandler {
3741
3842 @override
3943 Future <void > handleEvent (WsEvent event) async {
40- final fid = query.fid;
41-
42- bool matchesQueryFilter (ActivityData activity) {
43- final filter = query.activityFilter;
44- if (filter == null ) return true ;
45- return filter.matches (activity);
46- }
47-
4844 if (event is api.ActivityAddedEvent ) {
49- if (event.fid != fid.rawValue) return ;
45+ if (event.fid != query. fid.rawValue) return ;
5046 final activity = event.activity.toModel ();
5147
5248 final insertionAction = onNewActivity (query, activity, currentUserId);
@@ -59,10 +55,10 @@ class FeedEventHandler with FeedCapabilitiesMixin implements StateEventHandler {
5955 }
6056
6157 if (event is api.ActivityUpdatedEvent ) {
62- if (event.fid != fid.rawValue) return ;
58+ if (event.fid != query. fid.rawValue) return ;
6359
6460 final activity = event.activity.toModel ();
65- if (! matchesQueryFilter ( activity)) {
61+ if (! activity. matches (query.activityFilter )) {
6662 // If the updated activity no longer matches the filter, remove it
6763 return state.onActivityRemoved (activity);
6864 }
@@ -72,169 +68,206 @@ class FeedEventHandler with FeedCapabilitiesMixin implements StateEventHandler {
7268 }
7369
7470 if (event is api.ActivityDeletedEvent ) {
75- if (event.fid != fid.rawValue) return ;
71+ if (event.fid != query. fid.rawValue) return ;
7672 return state.onActivityRemoved (event.activity.toModel ());
7773 }
7874
79- if (event is api.ActivityReactionAddedEvent ) {
80- if (event.fid != fid.rawValue) return ;
75+ if (event is api.ActivityRemovedFromFeedEvent ) {
76+ if (event.fid != query.fid.rawValue) return ;
77+ return state.onActivityRemoved (event.activity.toModel ());
78+ }
8179
82- final activity = event.activity.toModel ();
83- if (! matchesQueryFilter (activity)) {
84- // If the reaction's activity no longer matches the filter, remove it
85- return state.onActivityRemoved (activity);
80+ if (event is api.ActivityPinnedEvent ) {
81+ if (event.fid != query.fid.rawValue) return ;
82+ return state.onActivityPinned (event.pinnedActivity.toModel ());
83+ }
84+
85+ if (event is api.ActivityUnpinnedEvent ) {
86+ if (event.fid != query.fid.rawValue) return ;
87+ return state.onActivityUnpinned (event.pinnedActivity.activity.id);
88+ }
89+
90+ if (event is api.ActivityFeedbackEvent ) {
91+ final payload = event.activityFeedback;
92+ final userId = payload.user.id;
93+
94+ // Only process events for the current user
95+ if (userId != currentUserId) return ;
96+
97+ // Only handle hide action for now
98+ if (payload.action == api.ActivityFeedbackEventPayloadAction .hide) {
99+ return state.onActivityHidden (
100+ activityId: payload.activityId,
101+ hidden: payload.value == 'true' ,
102+ );
86103 }
104+ }
87105
106+ if (event is api.ActivityMarkEvent ) {
107+ if (event.fid != query.fid.rawValue) return ;
108+ return state.onActivityMarked (event.toModel ());
109+ }
110+
111+ if (event is api.ActivityReactionAddedEvent ) {
112+ if (event.fid != query.fid.rawValue) return ;
113+
114+ final activity = event.activity.toModel ();
88115 final reaction = event.reaction.toModel ();
89116 return state.onReactionAdded (activity, reaction);
90117 }
91118
92119 if (event is api.ActivityReactionUpdatedEvent ) {
93- if (event.fid != fid.rawValue) return ;
120+ if (event.fid != query. fid.rawValue) return ;
94121
95122 final activity = event.activity.toModel ();
96- if (! matchesQueryFilter (activity)) {
97- // If the reaction's activity no longer matches the filter, remove it
98- return state.onActivityRemoved (activity);
99- }
100-
101123 final reaction = event.reaction.toModel ();
102124 return state.onReactionUpdated (activity, reaction);
103125 }
104126
105127 if (event is api.ActivityReactionDeletedEvent ) {
106- if (event.fid != fid.rawValue) return ;
128+ if (event.fid != query. fid.rawValue) return ;
107129
108130 final activity = event.activity.toModel ();
109- if (! matchesQueryFilter (activity)) {
110- // If the reaction's activity no longer matches the filter, remove it
111- return state.onActivityRemoved (activity);
112- }
113-
114131 final reaction = event.reaction.toModel ();
115132 return state.onReactionRemoved (activity, reaction);
116133 }
117134
118- if (event is api.ActivityPinnedEvent ) {
119- if (event.fid != fid.rawValue) return ;
120-
121- final activity = event.pinnedActivity.activity.toModel ();
122- if (! matchesQueryFilter (activity)) {
123- // If the pinned activity no longer matches the filter, remove it
124- return state.onActivityRemoved (activity);
125- }
126-
127- return state.onActivityPinned (event.pinnedActivity.toModel ());
128- }
129-
130- if (event is api.ActivityUnpinnedEvent ) {
131- if (event.fid != fid.rawValue) return ;
132-
133- final activity = event.pinnedActivity.activity.toModel ();
134- if (! matchesQueryFilter (activity)) {
135- // If the unpinned activity no longer matches the filter, remove it
136- return state.onActivityRemoved (activity);
137- }
138-
139- return state.onActivityUnpinned (event.pinnedActivity.activity.id);
140- }
141-
142- if (event is api.ActivityMarkEvent ) {
143- if (event.fid != fid.rawValue) return ;
144- return state.onActivityMarked (event.toModel ());
145- }
146-
147- if (event is api.NotificationFeedUpdatedEvent ) {
148- if (event.fid != fid.rawValue) return ;
149- return state.onNotificationFeedUpdated (
150- event.aggregatedActivities? .map ((it) => it.toModel ()).toList (),
151- event.notificationStatus,
152- );
153- }
154-
155135 if (event is api.BookmarkAddedEvent ) {
156136 return state.onBookmarkAdded (event.bookmark.toModel ());
157137 }
158138
139+ if (event is api.BookmarkUpdatedEvent ) {
140+ return state.onBookmarkUpdated (event.bookmark.toModel ());
141+ }
142+
159143 if (event is api.BookmarkDeletedEvent ) {
160144 return state.onBookmarkRemoved (event.bookmark.toModel ());
161145 }
162146
163147 if (event is api.CommentAddedEvent ) {
164- if (event.fid != fid.rawValue) return ;
165-
166- final activity = event.activity.toModel ();
167- if (! matchesQueryFilter (activity)) {
168- // If the comment's activity no longer matches the filter, remove it
169- return state.onActivityRemoved (activity);
170- }
171-
148+ if (event.fid != query.fid.rawValue) return ;
172149 return state.onCommentAdded (event.comment.toModel ());
173150 }
174151
175152 if (event is api.CommentUpdatedEvent ) {
176- if (event.fid != fid.rawValue) return ;
177- // TODO: Match event activity against filter once available in the event
153+ if (event.fid != query.fid.rawValue) return ;
178154 return state.onCommentUpdated (event.comment.toModel ());
179155 }
180156
181157 if (event is api.CommentDeletedEvent ) {
182- if (event.fid != fid.rawValue) return ;
183- // TODO: Match event activity against filter once available in the event
158+ if (event.fid != query.fid.rawValue) return ;
184159 return state.onCommentRemoved (event.comment.toModel ());
185160 }
186161
162+ if (event is api.CommentReactionAddedEvent ) {
163+ if (event.fid != query.fid.rawValue) return ;
164+
165+ final comment = event.comment.toModel ();
166+ final reaction = event.reaction.toModel ();
167+ return state.onCommentReactionAdded (comment, reaction);
168+ }
169+
170+ if (event is api.CommentReactionUpdatedEvent ) {
171+ if (event.fid != query.fid.rawValue) return ;
172+
173+ final comment = event.comment.toModel ();
174+ final reaction = event.reaction.toModel ();
175+ return state.onCommentReactionUpdated (comment, reaction);
176+ }
177+
178+ if (event is api.CommentReactionDeletedEvent ) {
179+ if (event.fid != query.fid.rawValue) return ;
180+
181+ final comment = event.comment.toModel ();
182+ final reaction = event.reaction.toModel ();
183+ return state.onCommentReactionRemoved (comment, reaction);
184+ }
185+
187186 if (event is api.FeedDeletedEvent ) {
188- if (event.fid != fid.rawValue) return ;
187+ if (event.fid != query. fid.rawValue) return ;
189188 return state.onFeedDeleted ();
190189 }
191190
192191 if (event is api.FeedUpdatedEvent ) {
193- if (event.fid != fid.rawValue) return ;
192+ if (event.fid != query. fid.rawValue) return ;
194193 return state.onFeedUpdated (event.feed.toModel ());
195194 }
196195
197196 if (event is api.FollowCreatedEvent ) {
198- if (event.fid != fid.rawValue) return ;
197+ if (event.fid != query. fid.rawValue) return ;
199198 return state.onFollowAdded (event.follow.toModel ());
200199 }
201200
202201 if (event is api.FollowDeletedEvent ) {
203- if (event.fid != fid.rawValue) return ;
202+ if (event.fid != query. fid.rawValue) return ;
204203 return state.onFollowRemoved (event.follow.toModel ());
205204 }
206205
207206 if (event is api.FollowUpdatedEvent ) {
208- if (event.fid != fid.rawValue) return ;
207+ if (event.fid != query. fid.rawValue) return ;
209208 return state.onFollowUpdated (event.follow.toModel ());
210209 }
211210
212211 // Member events are already handled in MemberListEventHandler
213212 if (event is api.FeedMemberRemovedEvent ) return ;
214213 if (event is api.FeedMemberUpdatedEvent ) return ;
215214
216- if (event is api.StoriesFeedUpdatedEvent ) {
217- if (event.fid != fid.rawValue) return ;
215+ if (event is api.NotificationFeedUpdatedEvent ) {
216+ if (event.fid != query.fid.rawValue) return ;
217+ return state.onNotificationFeedUpdated (
218+ event.notificationStatus,
219+ event.aggregatedActivities? .map ((it) => it.toModel ()).toList (),
220+ );
221+ }
218222
219- return state.onAggregatedActivitiesUpdated (
223+ if (event is api.StoriesFeedUpdatedEvent ) {
224+ if (event.fid != query.fid.rawValue) return ;
225+ return state.onStoriesFeedUpdated (
220226 event.aggregatedActivities? .map ((it) => it.toModel ()).toList (),
221227 );
222228 }
223229
224- if (event is api.ActivityFeedbackEvent ) {
225- final payload = event.activityFeedback ;
226- final userId = payload.user.id;
230+ if (event is api.PollClosedFeedEvent ) {
231+ return state. onPollClosed ( event.poll.id) ;
232+ }
227233
228- // Only process events for the current user
229- if (userId != currentUserId) return ;
234+ if (event is api.PollDeletedFeedEvent ) {
235+ return state.onPollDeleted (event.poll.id);
236+ }
230237
231- // Only handle hide action for now
232- if (payload.action == api.ActivityFeedbackEventPayloadAction .hide) {
233- return state.onActivityHidden (
234- activityId: payload.activityId,
235- hidden: payload.value == 'true' ,
236- );
237- }
238+ if (event is api.PollUpdatedFeedEvent ) {
239+ final poll = event.poll.toModel ();
240+ return state.onPollUpdated (poll);
241+ }
242+
243+ if (event is PollAnswerCastedFeedEvent ) {
244+ final poll = event.poll.toModel ();
245+ final answer = event.pollVote.toModel ();
246+ return state.onPollAnswerCasted (poll, answer);
247+ }
248+
249+ if (event is api.PollVoteCastedFeedEvent ) {
250+ final poll = event.poll.toModel ();
251+ final vote = event.pollVote.toModel ();
252+ return state.onPollVoteCasted (poll, vote);
253+ }
254+
255+ if (event is api.PollVoteChangedFeedEvent ) {
256+ final poll = event.poll.toModel ();
257+ final vote = event.pollVote.toModel ();
258+ return state.onPollVoteChanged (poll, vote);
259+ }
260+
261+ if (event is PollAnswerRemovedFeedEvent ) {
262+ final poll = event.poll.toModel ();
263+ final answer = event.pollVote.toModel ();
264+ return state.onPollAnswerRemoved (poll, answer);
265+ }
266+
267+ if (event is api.PollVoteRemovedFeedEvent ) {
268+ final poll = event.poll.toModel ();
269+ final vote = event.pollVote.toModel ();
270+ return state.onPollVoteRemoved (poll, vote);
238271 }
239272
240273 // Handle other events if necessary
0 commit comments