Skip to content

Commit

Permalink
Fix updating status message with same visibility
Browse files Browse the repository at this point in the history
Fix updating status message with same visibility
  • Loading branch information
Raphiiko committed Jun 23, 2024
1 parent 03b848d commit 3c92e83
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 49 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 84 in src-ui/app/services/status-automations/status-change-for-player-count-automation.service.ts

View workflow job for this annotation

GitHub Actions / build-dev-release (windows-latest)

'success' is never reassigned. Use 'const' instead
.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);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 79 in src-ui/app/services/status-automations/status-change-general-events-automation.service.ts

View workflow job for this annotation

GitHub Actions / build-dev-release (windows-latest)

'e' is defined but never used
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);
});
}

Expand Down
16 changes: 8 additions & 8 deletions src-ui/app/services/vrchat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export class VRChatService {
info(`[VRChat] Logged in: ${this._user.value?.displayName}`);
}

async setStatus(status: UserStatus | null, statusMessage: string | null): Promise<void> {
async setStatus(status: UserStatus | null, statusMessage: string | null): Promise<boolean> {
// Throw if we don't have a current user
const userId = this._user.value?.id;
if (!userId) {
Expand All @@ -247,21 +247,19 @@ 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}')`);
} else if (status) {
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<string, string> = {};
Expand All @@ -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) {
Expand Down

0 comments on commit 3c92e83

Please sign in to comment.