From 039cb4bfbe5e8e2e3bf1045a89b4909196d32cbd Mon Sep 17 00:00:00 2001 From: iCrawl Date: Sun, 28 Apr 2019 10:46:22 +0200 Subject: [PATCH] fix: clean up session and party presence --- .vscode/launch.json | 3 +-- .vscode/tasks.json | 15 --------------- src/structures/Activity.ts | 37 +++++++++++++++++++++++-------------- 3 files changed, 24 insertions(+), 31 deletions(-) delete mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json index e16168d..f6447bf 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,8 +9,7 @@ "args": ["--extensionDevelopmentPath=${workspaceRoot}" ], "stopOnEntry": false, "sourceMaps": true, - "outFiles": [ "${workspaceRoot}/dist/**/*.js" ], - "preLaunchTask": "build" + "outFiles": [ "${workspaceRoot}/dist/**/*.js" ] } ] } diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 7e3b23f..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - { - "label": "build", - "type": "gulp", - "task": "build", - "problemMatcher": [ - "$gulp-tsc" - ] - } - ] -} diff --git a/src/structures/Activity.ts b/src/structures/Activity.ts index cb63187..c52553c 100644 --- a/src/structures/Activity.ts +++ b/src/structures/Activity.ts @@ -96,6 +96,7 @@ export default class Activity implements Disposable { } public async allowSpectate(): Promise { + if (!this._state) return; const liveshare = await vsls.getApi(); if (!liveshare) return; const join = await liveshare.share({ suppressNotification: true, access: vsls.Access.ReadOnly }); @@ -109,19 +110,19 @@ export default class Activity implements Disposable { } public async disableSpectate(): Promise { + if (!this._state) return; const liveshare = await vsls.getApi(); if (!liveshare) return; await liveshare.end(); - this._state = { - ...this._state, - spectateSecret: undefined, - instance: false - }; + + delete this._state.spectateSecret; + this._state.instance = false; return this._state; } public async allowJoinRequests(): Promise { + if (!this._state) return; const liveshare = await vsls.getApi(); if (!liveshare) return; const join = await liveshare.share({ suppressNotification: true }); @@ -138,28 +139,36 @@ export default class Activity implements Disposable { } public async disableJoinRequests(): Promise { + if (!this._state) return; const liveshare = await vsls.getApi(); if (!liveshare) return; await liveshare.end(); - this._state = { - ...this._state, - partyId: undefined, - partySize: undefined, - partyMax: undefined, - joinSecret: undefined, - instance: false - }; + + delete this._state.partyId; + delete this._state.partySize; + delete this._state.partyMax; + delete this._state.joinSecret; + this._state.instance = false; return this._state; } public changePartyId(id?: string): State | void { if (!this._state) return; + if (!id) { + delete this._state.partyId; + delete this._state.partySize; + delete this._state.partyMax; + this._state.instance = false; + + return this._state; + } this._state = { ...this._state, partyId: id, partySize: this._state.partySize ? this._state.partySize + 1 : 1, - partyMax: id ? 5 : undefined + partyMax: 5, + instance: true }; return this._state;