1+ using System . Text . Json . Serialization ;
2+ using Lagrange . Core ;
3+ using Lagrange . Core . Common . Entity ;
4+ using Lagrange . Core . Common . Interface ;
5+ using Lagrange . Milky . Entity ;
6+ using Lagrange . Milky . Utility ;
7+
8+ namespace Lagrange . Milky . Api . Handler . Group ;
9+
10+ [ Api ( "get_group_notifications" ) ]
11+ public class GetGroupNotificationsHandler ( BotContext bot , EntityConvert convert ) : IApiHandler < GetGroupNotificationsParameter , GetGroupNotificationsResult >
12+ {
13+ private readonly BotContext _bot = bot ;
14+ private readonly EntityConvert _convert = convert ;
15+
16+ public async Task < GetGroupNotificationsResult > HandleAsync ( GetGroupNotificationsParameter parameter , CancellationToken token )
17+ {
18+ List < BotGroupNotificationBase > notifications = await ( parameter . IsFiltered
19+ ? _bot . FetchFilteredGroupNotifications ( ( ulong ) parameter . Limit , ( ulong ) parameter . StartNotificationSeq )
20+ : _bot . FetchGroupNotifications ( ( ulong ) parameter . Limit , ( ulong ) parameter . StartNotificationSeq ) ) ;
21+
22+ return new GetGroupNotificationsResult (
23+ notifications . Select ( _convert . GroupNotification ) . Where ( n => n != null ) ! ,
24+ notifications . Count == 0 ? null : ( long ) notifications [ ^ 1 ] . Sequence
25+ ) ;
26+ }
27+ }
28+
29+ public class GetGroupNotificationsParameter ( long startNotificationSeq = 0 , bool isFiltered = false , int limit = 20 )
30+ {
31+ [ JsonPropertyName ( "start_notification_seq" ) ]
32+ public long StartNotificationSeq { get ; } = startNotificationSeq ;
33+
34+ [ JsonPropertyName ( "is_filtered" ) ]
35+ public bool IsFiltered { get ; } = isFiltered ;
36+
37+ [ JsonPropertyName ( "limit" ) ]
38+ public int Limit { get ; } = limit ;
39+ }
40+
41+ public class GetGroupNotificationsResult ( IEnumerable < GroupNotificationBase > notifications , long ? nextNotificationSeq )
42+ {
43+ [ JsonPropertyName ( "notifications" ) ]
44+ public IEnumerable < GroupNotificationBase > Notifications { get ; } = notifications ;
45+
46+ [ JsonPropertyName ( "next_notification_seq" ) ]
47+ public long ? NextNotificationSeq { get ; } = nextNotificationSeq ;
48+ }
0 commit comments