Skip to content

Adds ability to update a subscription #2935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 31, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/LiveQuery/ParseLiveQueryServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,18 @@ class ParseLiveQueryServer {
}

_handleUpdateSubscription(parseWebsocket: any, request: any): any {
this._handleUnsubscribe(parseWebsocket, request);
this._removeClientSubscription(parseWebsocket, request);
this._handleSubscribe(parseWebsocket, request);
}

_handleUnsubscribe(parseWebsocket: any, request: any): any {
let client = this._removeClientSubscription(parseWebsocket, request);
client.pushUnsubscribe(request.requestId);

logger.verbose('Delete client: %d | subscription: %d', parseWebsocket.clientId, request.requestId);
}

_removeClientSubscription(parseWebsocket: any, request: any): 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');
Expand Down Expand Up @@ -520,10 +527,7 @@ class ParseLiveQueryServer {
if (classSubscriptions.size === 0) {
this.subscriptions.delete(className);
}

client.pushUnsubscribe(request.requestId);

logger.verbose('Delete client: %d | subscription: %d', parseWebsocket.clientId, request.requestId);
return client;
}
}

Expand Down
41 changes: 40 additions & 1 deletion src/LiveQuery/RequestSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let general = {
'properties': {
'op': {
'type': 'string',
'enum': ['connect', 'subscribe', 'unsubscribe']
'enum': ['connect', 'subscribe', 'unsubscribe', 'update']
},
},
};
Expand Down Expand Up @@ -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',
Expand All @@ -95,6 +133,7 @@ let RequestSchema = {
'general': general,
'connect': connect,
'subscribe': subscribe,
'update': update,
'unsubscribe': unsubscribe
}

Expand Down