-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: Add trigger beforeUnsubscribe
for LiveQuery
#7419
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
base: alpha
Are you sure you want to change the base?
Changes from all commits
41daddb
98d48de
7bb0d2d
157f452
927ca63
55be103
d2c37b0
1d1660a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -968,7 +968,7 @@ class ParseLiveQueryServer { | |
this._handleSubscribe(parseWebsocket, request); | ||
} | ||
|
||
_handleUnsubscribe(parseWebsocket: any, request: any, notifyClient: boolean = true): any { | ||
async _handleUnsubscribe(parseWebsocket: any, request: any, notifyClient: boolean = true): any { | ||
// If we can not find this client, return error to client | ||
if (!Object.prototype.hasOwnProperty.call(parseWebsocket, 'clientId')) { | ||
Client.pushError( | ||
|
@@ -1015,11 +1015,33 @@ class ParseLiveQueryServer { | |
return; | ||
} | ||
|
||
const subscription = subscriptionInfo.subscription; | ||
const className = subscription.className; | ||
const trigger = getTrigger(className, 'beforeUnsubscribe', Parse.applicationId); | ||
if (trigger) { | ||
const auth = await this.getAuthFromClient(client, request.requestId, request.sessionToken); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the other uses, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sadortun Could you address this comment, then I believe this should be good to merge. |
||
if (auth && auth.user) { | ||
request.user = auth.user; | ||
} | ||
|
||
request.sessionToken = subscriptionInfo.sessionToken; | ||
request.useMasterKey = client.hasMasterKey; | ||
request.installationId = client.installationId; | ||
|
||
try { | ||
await runTrigger(trigger, `beforeUnsubscribe.${className}`, request, auth); | ||
} catch (error) { | ||
Client.pushError(parseWebsocket, error.code || Parse.Error.SCRIPT_FAILED, error.message || error, false); | ||
logger.error( | ||
`Failed running beforeUnsubscribe for session ${request.sessionToken} with:\n Error: ` + | ||
JSON.stringify(error) | ||
); | ||
} | ||
} | ||
|
||
// Remove subscription from client | ||
client.deleteSubscriptionInfo(requestId); | ||
// Remove client from subscription | ||
const subscription = subscriptionInfo.subscription; | ||
const className = subscription.className; | ||
subscription.deleteClientSubscription(parseWebsocket.clientId, requestId); | ||
// If there is no client which is subscribing this subscription, remove it from subscriptions | ||
const classSubscriptions = this.subscriptions.get(className); | ||
|
Uh oh!
There was an error while loading. Please reload this page.