From 3c92e836856c0da1e56a961c306d5ec9f5c72a71 Mon Sep 17 00:00:00 2001 From: Raphiiko Date: Sun, 23 Jun 2024 11:33:58 +0200 Subject: [PATCH] Fix updating status message with same visibility Fix updating status message with same visibility --- CHANGELOG.md | 3 ++ ...nge-for-player-count-automation.service.ts | 46 ++++++++++--------- ...hange-general-events-automation.service.ts | 42 +++++++++-------- src-ui/app/services/vrchat.service.ts | 16 +++---- 4 files changed, 58 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7af16680..fcd986f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Exposed HMD activity level over MQTT as "HMD On Head" (Experimental). +### Added +- Issue where the status message wasn't updated when the visibility remained the same + ## [1.13.1] ### Fixed diff --git a/src-ui/app/services/status-automations/status-change-for-player-count-automation.service.ts b/src-ui/app/services/status-automations/status-change-for-player-count-automation.service.ts index 7bc2de81..d2be19f0 100644 --- a/src-ui/app/services/status-automations/status-change-for-player-count-automation.service.ts +++ b/src-ui/app/services/status-automations/status-change-for-player-count-automation.service.ts @@ -81,28 +81,32 @@ export class StatusChangeForPlayerCountAutomationService { ) .subscribe(async (newStatus) => { // Set new status - await this.vrchat.setStatus(newStatus.status, newStatus.statusMessage); - if (await this.notifications.notificationTypeEnabled('AUTO_UPDATED_VRC_STATUS')) { - await this.notifications.send( - this.translate.instant('notifications.vrcStatusChanged.content', { - newStatus: ( - (newStatus.statusMessage ?? newStatus.oldStatusMessage) + - ' (' + - (newStatus.status ?? newStatus.oldStatus) + - ')' - ).trim(), - }) - ); + let success = await this.vrchat + .setStatus(newStatus.status, newStatus.statusMessage) + .catch(() => false); + if (success) { + if (await this.notifications.notificationTypeEnabled('AUTO_UPDATED_VRC_STATUS')) { + await this.notifications.send( + this.translate.instant('notifications.vrcStatusChanged.content', { + newStatus: ( + (newStatus.statusMessage ?? newStatus.oldStatusMessage) + + ' (' + + (newStatus.status ?? newStatus.oldStatus) + + ')' + ).trim(), + }) + ); + } + this.eventLog.logEvent({ + type: 'statusChangedOnPlayerCountChange', + reason: newStatus.reason, + threshold: this.config.limit, + newStatus: newStatus.status, + oldStatus: newStatus.oldStatus, + newStatusMessage: newStatus.statusMessage, + oldStatusMessage: newStatus.oldStatusMessage, + } as EventLogStatusChangedOnPlayerCountChange); } - this.eventLog.logEvent({ - type: 'statusChangedOnPlayerCountChange', - reason: newStatus.reason, - threshold: this.config.limit, - newStatus: newStatus.status, - oldStatus: newStatus.oldStatus, - newStatusMessage: newStatus.statusMessage, - oldStatusMessage: newStatus.oldStatusMessage, - } as EventLogStatusChangedOnPlayerCountChange); }); } diff --git a/src-ui/app/services/status-automations/status-change-general-events-automation.service.ts b/src-ui/app/services/status-automations/status-change-general-events-automation.service.ts index 85a95aca..e4a8a132 100644 --- a/src-ui/app/services/status-automations/status-change-general-events-automation.service.ts +++ b/src-ui/app/services/status-automations/status-change-general-events-automation.service.ts @@ -76,27 +76,29 @@ export class StatusChangeGeneralEventsAutomationService { .subscribe(async ({ status, statusMessage, sleepMode }) => { const oldStatus = this.vrcUser?.status; const oldStatusMessage = this.vrcUser?.statusDescription; - await this.vrchat.setStatus(status, statusMessage); - if (await this.notifications.notificationTypeEnabled('AUTO_UPDATED_VRC_STATUS')) { - await this.notifications.send( - this.translate.instant('notifications.vrcStatusChanged.content', { - newStatus: ( - (statusMessage ?? oldStatusMessage) + - ' (' + - (status ?? oldStatus) + - ')' - ).trim(), - }) - ); + const success = await this.vrchat.setStatus(status, statusMessage).catch((e) => false); + if (success) { + if (await this.notifications.notificationTypeEnabled('AUTO_UPDATED_VRC_STATUS')) { + await this.notifications.send( + this.translate.instant('notifications.vrcStatusChanged.content', { + newStatus: ( + (statusMessage ?? oldStatusMessage) + + ' (' + + (status ?? oldStatus) + + ')' + ).trim(), + }) + ); + } + this.eventLog.logEvent({ + type: 'statusChangedOnGeneralEvent', + reason: sleepMode ? 'SLEEP_MODE_ENABLED' : 'SLEEP_MODE_DISABLED', + newStatus: status, + oldStatus: oldStatus, + newStatusMessage: statusMessage, + oldStatusMessage: oldStatusMessage, + } as EventLogStatusChangedOnGeneralEvent); } - this.eventLog.logEvent({ - type: 'statusChangedOnGeneralEvent', - reason: sleepMode ? 'SLEEP_MODE_ENABLED' : 'SLEEP_MODE_DISABLED', - newStatus: status, - oldStatus: oldStatus, - newStatusMessage: statusMessage, - oldStatusMessage: oldStatusMessage, - } as EventLogStatusChangedOnGeneralEvent); }); } diff --git a/src-ui/app/services/vrchat.service.ts b/src-ui/app/services/vrchat.service.ts index 78b1592d..145611a6 100644 --- a/src-ui/app/services/vrchat.service.ts +++ b/src-ui/app/services/vrchat.service.ts @@ -237,7 +237,7 @@ export class VRChatService { info(`[VRChat] Logged in: ${this._user.value?.displayName}`); } - async setStatus(status: UserStatus | null, statusMessage: string | null): Promise { + async setStatus(status: UserStatus | null, statusMessage: string | null): Promise { // Throw if we don't have a current user const userId = this._user.value?.id; if (!userId) { @@ -247,10 +247,11 @@ export class VRChatService { // Sanitize status message if needed statusMessage = statusMessage === null ? null : statusMessage.replace(/\s+/g, ' ').trim().slice(0, 32); - // Don't do anything if the status is not changing - if (status && this._user.value?.status === status) return; - // Don't do anything if the status message is not changing - if (statusMessage && this._user.value?.statusDescription === statusMessage) return; + const statusChange = status && this._user.value?.status !== status; + const statusMessageChange = + statusMessage && this._user.value?.statusDescription !== statusMessage; + // Don't do anything if there would be no changes + if (!statusChange && !statusMessageChange) return false; // Log status change if (status && statusMessage) { info(`[VRChat] Changing status to '${statusMessage}' ('${status}')`); @@ -258,10 +259,7 @@ export class VRChatService { info(`[VRChat] Changing status to '${status}'`); } else if (statusMessage) { info(`[VRChat] Changing status message to '${statusMessage}'`); - } else { - return; } - // Send status change request try { const body: Record = {}; @@ -283,7 +281,9 @@ export class VRChatService { if (!result.result?.ok) throw result.result; } catch (e) { error(`[VRChat] Failed to update status: ${JSON.stringify(e)}`); + return false; } + return true; } public showLoginModal(autoLogin = false) {