Adds ability to update a subscription (#2935)
* Adds ability to update a subscription * Adds unsubscribe to the RequestSchema, makes sure to not fire unsubscribe to the client when updating * Fix failing tests * More extensive tests * fix annotation
This commit is contained in:
@@ -257,6 +257,9 @@ class ParseLiveQueryServer {
|
||||
case 'subscribe':
|
||||
this._handleSubscribe(parseWebsocket, request);
|
||||
break;
|
||||
case 'update':
|
||||
this._handleUpdateSubscription(parseWebsocket, request);
|
||||
break;
|
||||
case 'unsubscribe':
|
||||
this._handleUnsubscribe(parseWebsocket, request);
|
||||
break;
|
||||
@@ -471,7 +474,12 @@ class ParseLiveQueryServer {
|
||||
logger.verbose('Current client number: %d', this.clients.size);
|
||||
}
|
||||
|
||||
_handleUnsubscribe(parseWebsocket: any, request: any): any {
|
||||
_handleUpdateSubscription(parseWebsocket: any, request: any): any {
|
||||
this._handleUnsubscribe(parseWebsocket, request, false);
|
||||
this._handleSubscribe(parseWebsocket, request);
|
||||
}
|
||||
|
||||
_handleUnsubscribe(parseWebsocket: any, request: any, notifyClient: bool = true): any {
|
||||
// If we can not find this client, return error to client
|
||||
if (!parseWebsocket.hasOwnProperty('clientId')) {
|
||||
Client.pushError(parseWebsocket, 2, 'Can not find this client, make sure you connect to server before unsubscribing');
|
||||
@@ -510,6 +518,10 @@ class ParseLiveQueryServer {
|
||||
if (classSubscriptions.size === 0) {
|
||||
this.subscriptions.delete(className);
|
||||
}
|
||||
|
||||
if (!notifyClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
client.pushUnsubscribe(request.requestId);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ let general = {
|
||||
'properties': {
|
||||
'op': {
|
||||
'type': 'string',
|
||||
'enum': ['connect', 'subscribe', 'unsubscribe']
|
||||
'enum': ['connect', 'subscribe', 'unsubscribe', 'update']
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -78,6 +78,44 @@ let subscribe = {
|
||||
'additionalProperties': false
|
||||
};
|
||||
|
||||
let update = {
|
||||
'title': 'Update operation schema',
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'op': 'update',
|
||||
'requestId': {
|
||||
'type': 'number'
|
||||
},
|
||||
'query': {
|
||||
'title': 'Query field schema',
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'className': {
|
||||
'type': 'string'
|
||||
},
|
||||
'where': {
|
||||
'type': 'object'
|
||||
},
|
||||
'fields': {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
'required': ['where', 'className'],
|
||||
'additionalProperties': false
|
||||
},
|
||||
'sessionToken': {
|
||||
'type': 'string'
|
||||
}
|
||||
},
|
||||
'required': ['op', 'requestId', 'query'],
|
||||
'additionalProperties': false
|
||||
};
|
||||
|
||||
let unsubscribe = {
|
||||
'title': 'Unsubscribe operation schema',
|
||||
'type': 'object',
|
||||
@@ -95,6 +133,7 @@ let RequestSchema = {
|
||||
'general': general,
|
||||
'connect': connect,
|
||||
'subscribe': subscribe,
|
||||
'update': update,
|
||||
'unsubscribe': unsubscribe
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user