11using System ;
22using System . Collections . Generic ;
33using System . Collections . ObjectModel ;
4- using System . Diagnostics ;
54using System . Linq ;
6- using System . Net . WebSockets ;
7- using System . Numerics ;
8- using System . Text ;
95using System . Threading ;
106using System . Threading . Tasks ;
11- using Microsoft . VisualBasic . CompilerServices ;
127using Parse . Abstractions . Infrastructure ;
8+ using Parse . Abstractions . Platform . LiveQueries ;
139using Parse . Infrastructure . Data ;
14- using Parse . Infrastructure . Utilities ;
1510
1611namespace Parse ;
1712
@@ -35,7 +30,7 @@ public class ParseLiveQuery<T> where T : ParseObject
3530 /// <summary>
3631 /// Serialized keys watched.
3732 /// </summary>
38- ReadOnlyCollection < string > KeyWatch { get ; }
33+ ReadOnlyCollection < string > KeyWatchers { get ; }
3934
4035 internal string ClassName { get ; }
4136
@@ -61,7 +56,7 @@ public ParseLiveQuery(IServiceHub serviceHub, string className, IDictionary<stri
6156
6257 if ( watchedKeys is not null )
6358 {
64- KeyWatch = new ReadOnlyCollection < string > ( watchedKeys . ToList ( ) ) ;
59+ KeyWatchers = new ReadOnlyCollection < string > ( watchedKeys . ToList ( ) ) ;
6560 }
6661 }
6762
@@ -70,7 +65,7 @@ public ParseLiveQuery(IServiceHub serviceHub, string className, IDictionary<stri
7065 /// but the remaining values can be null if they aren't changed in this
7166 /// composition.
7267 /// </summary>
73- internal ParseLiveQuery ( ParseLiveQuery < T > source , IEnumerable < string > watchedKeys = null )
68+ internal ParseLiveQuery ( ParseLiveQuery < T > source , IEnumerable < string > watchedKeys = null , Func < IDictionary < string , object > > onCreate = null )
7469 {
7570 if ( source == null )
7671 {
@@ -81,14 +76,15 @@ internal ParseLiveQuery(ParseLiveQuery<T> source, IEnumerable<string> watchedKey
8176 ClassName = source . ClassName ;
8277 Filters = source . Filters ;
8378 KeySelections = source . KeySelections ;
79+ KeyWatchers = source . KeyWatchers ;
8480
8581 if ( watchedKeys is { } )
8682 {
87- KeyWatch = new ReadOnlyCollection < string > ( MergeKeys ( watchedKeys ) . ToList ( ) ) ;
83+ KeyWatchers = new ReadOnlyCollection < string > ( MergeWatchers ( watchedKeys ) . ToList ( ) ) ;
8884 }
8985 }
9086
91- HashSet < string > MergeKeys ( IEnumerable < string > selectedKeys ) => new ( ( KeySelections ?? Enumerable . Empty < string > ( ) ) . Concat ( selectedKeys ) ) ;
87+ HashSet < string > MergeWatchers ( IEnumerable < string > keys ) => new ( ( KeyWatchers ?? Enumerable . Empty < string > ( ) ) . Concat ( keys ) ) ;
9288
9389 /// <summary>
9490 /// Add the provided key to the watched fields of returned ParseObjects.
@@ -106,23 +102,13 @@ internal IDictionary<string, object> BuildParameters(bool includeClassName = fal
106102 result [ "where" ] = PointerOrLocalIdEncoder . Instance . Encode ( Filters , Services ) ;
107103 if ( KeySelections != null )
108104 result [ "keys" ] = String . Join ( "," , KeySelections . ToArray ( ) ) ;
109- if ( KeyWatch != null )
110- result [ "watch" ] = String . Join ( "," , KeyWatch . ToArray ( ) ) ;
105+ if ( KeyWatchers != null )
106+ result [ "watch" ] = String . Join ( "," , KeyWatchers . ToArray ( ) ) ;
111107 if ( includeClassName )
112108 result [ "className" ] = ClassName ;
113109 return result ;
114110 }
115111
116- /// <summary>
117- /// Establishes a connection to the Parse Live Query server using the ClientWebSocket instance.
118- /// Prepares and sends a connection message containing required identifiers such as application ID, client key, and session token.
119- /// </summary>
120- /// <returns>A Task representing the asynchronous operation, returning true if the connection attempt is initialized successfully, false otherwise.</returns>
121- public async Task ConnectAsync ( )
122- {
123- await Services . LiveQueryController . ConnectAsync ( CancellationToken . None ) ;
124- }
125-
126112 /// <summary>
127113 /// Subscribes to the live query, allowing the client to receive real-time updates
128114 /// for the query's results. This establishes a subscription with the Live Query service.
@@ -131,30 +117,8 @@ public async Task ConnectAsync()
131117 /// A task representing the asynchronous subscription operation. Upon completion
132118 /// of the task, the subscription is successfully registered.
133119 /// </returns>
134- public async Task SubscribeAsync ( )
135- {
136- RequestId = await Services . LiveQueryController . SubscribeAsync ( this , CancellationToken . None ) ;
137- }
138-
139- /// <summary>
140- /// Unsubscribes from the live query, stopping the client from receiving further updates related to the subscription.
141- /// </summary>
142- /// <returns>A task representing the asynchronous operation of unsubscribing from the live query.</returns>
143- public async Task UnsubscribeAsync ( )
144- {
145- if ( RequestId > 0 )
146- await Services . LiveQueryController . UnsubscribeAsync ( RequestId , CancellationToken . None ) ;
147- }
148-
149- /// <summary>
150- /// Closes the connection to the live query server asynchronously.
151- /// </summary>
152- /// <returns>
153- /// A task representing the asynchronous operation of closing the live query connection.
154- /// </returns>
155- public async Task CloseAsync ( )
120+ public async Task < IParseLiveQuerySubscription > SubscribeAsync ( )
156121 {
157- await Services . LiveQueryController . CloseAsync ( CancellationToken . None ) ;
122+ return await Services . LiveQueryController . SubscribeAsync ( this , CancellationToken . None ) ;
158123 }
159-
160124}
0 commit comments