33namespace STS2RitsuLib . Telemetry
44{
55 /// <summary>
6- /// Process-wide registry for telemetry applicants and shared contribution providers.
7- /// 进程级 telemetry 申请方和共享 contribution provider 注册表。
6+ /// Process-wide registry for telemetry applicants and contribution providers.
7+ /// 进程级 telemetry 申请方和 contribution provider 注册表。
88 /// </summary>
99 public static class TelemetryRegistry
1010 {
@@ -39,8 +39,8 @@ public static void RegisterApplicant(TelemetryApplicant applicant)
3939 }
4040
4141 /// <summary>
42- /// Registers or replaces a shared contribution provider.
43- /// 注册或替换一个共享 contribution provider。
42+ /// Registers or replaces a telemetry contribution provider.
43+ /// 注册或替换一个 telemetry contribution provider。
4444 /// </summary>
4545 public static void RegisterContributionProvider ( ITelemetryContributionProvider provider )
4646 {
@@ -109,7 +109,7 @@ internal static IReadOnlyList<ITelemetryContributionProvider> ResolveSharedContr
109109 TelemetryApplicant applicant ,
110110 TelemetryRequest request )
111111 {
112- var subscriptions = request . SharedContributionSubscriptions ;
112+ var subscriptions = request . ContributionSubscriptions ;
113113 if ( subscriptions . Count == 0 )
114114 return [ ] ;
115115
@@ -119,8 +119,7 @@ internal static IReadOnlyList<ITelemetryContributionProvider> ResolveSharedContr
119119 . Where ( provider =>
120120 provider . Visibility == TelemetryContributionVisibility . SharedToAuthorizedSubscribers )
121121 . Where ( provider => provider . Category == request . Category )
122- . Where ( provider =>
123- subscriptions . Contains ( provider . ContributionId , StringComparer . OrdinalIgnoreCase ) )
122+ . Where ( provider => SubscriptionMatches ( provider , applicant , subscriptions , false ) )
124123 . Where ( provider => TelemetryConsentStore . IsSharedContributionGranted (
125124 applicant . ApplicantId ,
126125 provider . ContributorModId ,
@@ -129,6 +128,81 @@ internal static IReadOnlyList<ITelemetryContributionProvider> ResolveSharedContr
129128 }
130129 }
131130
131+ internal static IReadOnlyList < ITelemetryContributionProvider > ResolvePrivateContributions (
132+ TelemetryApplicant applicant ,
133+ TelemetryRequest request )
134+ {
135+ var subscriptions = request . ContributionSubscriptions ;
136+ if ( subscriptions . Count == 0 )
137+ return [ ] ;
138+
139+ lock ( Sync )
140+ {
141+ return ContributionProviders . Values
142+ . Where ( provider => provider . Visibility == TelemetryContributionVisibility . PrivateToApplicant )
143+ . Where ( provider => provider . Category == request . Category )
144+ . Where ( provider => SubscriptionMatches ( provider , applicant , subscriptions , true ) )
145+ . Where ( provider => IsOwnedByApplicant ( provider , applicant ) )
146+ . ToArray ( ) ;
147+ }
148+ }
149+
150+ internal static IReadOnlyList < ITelemetryContributionProvider > GetRequestedSharedContributions (
151+ TelemetryApplicant applicant )
152+ {
153+ lock ( Sync )
154+ {
155+ return ContributionProviders . Values
156+ . Where ( provider =>
157+ provider . Visibility == TelemetryContributionVisibility . SharedToAuthorizedSubscribers )
158+ . Where ( provider => applicant . Requests . Any ( request =>
159+ request . Category == provider . Category &&
160+ SubscriptionMatches ( provider , applicant , request . ContributionSubscriptions , false ) ) )
161+ . OrderBy ( provider => provider . ContributorModId , StringComparer . OrdinalIgnoreCase )
162+ . ThenBy ( provider => provider . ContributionId , StringComparer . OrdinalIgnoreCase )
163+ . ToArray ( ) ;
164+ }
165+ }
166+
167+ private static bool IsOwnedByApplicant (
168+ ITelemetryContributionProvider provider ,
169+ TelemetryApplicant applicant )
170+ {
171+ return string . Equals ( provider . ContributorModId , applicant . OwnerModId , StringComparison . OrdinalIgnoreCase ) ||
172+ string . Equals ( provider . ContributorModId , applicant . ApplicantId , StringComparison . OrdinalIgnoreCase ) ;
173+ }
174+
175+ private static bool SubscriptionMatches (
176+ ITelemetryContributionProvider provider ,
177+ TelemetryApplicant applicant ,
178+ IReadOnlyList < string > subscriptions ,
179+ bool allowUnqualifiedOwnedContribution )
180+ {
181+ foreach ( var subscription in subscriptions )
182+ {
183+ var value = subscription . Trim ( ) ;
184+ if ( string . IsNullOrEmpty ( value ) )
185+ continue ;
186+
187+ if ( allowUnqualifiedOwnedContribution &&
188+ IsOwnedByApplicant ( provider , applicant ) &&
189+ string . Equals ( value , provider . ContributionId , StringComparison . OrdinalIgnoreCase ) )
190+ return true ;
191+
192+ if ( string . Equals (
193+ value ,
194+ $ "{ provider . ContributorModId } /{ provider . ContributionId } ",
195+ StringComparison . OrdinalIgnoreCase ) ||
196+ string . Equals (
197+ value ,
198+ $ "{ provider . ContributorModId } :{ provider . ContributionId } ",
199+ StringComparison . OrdinalIgnoreCase ) )
200+ return true ;
201+ }
202+
203+ return false ;
204+ }
205+
132206 private static string BuildContributionKey ( string contributorModId , string contributionId )
133207 {
134208 return $ "{ contributorModId } \n { contributionId } ";
0 commit comments