Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/fix-presence-reset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: patch
---

Fix presence status resetting to "online".
7 changes: 5 additions & 2 deletions src/app/utils/presence.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MatrixClient } from 'matrix-js-sdk';
import { SetPresence } from 'matrix-js-sdk';
import { getPresenceSyncManager } from '$client/initMatrix';
import { Presence } from '../hooks/useUserPresence';

const PRESENCE_TO_SET_PRESENCE: Record<Presence, SetPresence> = {
Expand All @@ -16,8 +17,10 @@ export const setUserPresence = async (
presence: Presence,
statusMsg?: string
): Promise<void> => {
Promise.all([
mx.setSyncPresence(presenceToSetPresence(presence)),
const setPresence = presenceToSetPresence(presence);
getPresenceSyncManager(mx)?.setDesiredPresence(setPresence);
await Promise.all([
mx.setSyncPresence(setPresence),
mx.setPresence({
presence,
status_msg: statusMsg,
Expand Down
17 changes: 15 additions & 2 deletions src/client/presenceSync.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import type { CryptoBackend, IDeviceLists, IToDeviceEvent, MatrixClient } from '$types/matrix-sdk';
import { ClientEvent, Filter, Method, processToDeviceMessages, User } from '$types/matrix-sdk';
import {
ClientEvent,
Filter,
Method,
processToDeviceMessages,
SetPresence,
User,
} from '$types/matrix-sdk';
import { createDebugLogger } from '$utils/debugLogger';

const debugLog = createDebugLogger('presenceSync');
Expand All @@ -19,6 +26,8 @@ export class PresenceSyncManager {

private enabled = true;

private desiredSetPresence = SetPresence.Online;

private activeRequest: Promise<void> | null = null;

private abortController: AbortController | undefined;
Expand Down Expand Up @@ -49,6 +58,10 @@ export class PresenceSyncManager {
if (!this.activeRequest && !this.disposed) this.poll();
}

public setDesiredPresence(presence: SetPresence): void {
this.desiredSetPresence = presence;
}

public start(): void {
if (this.disposed || this.activeRequest || !this.enabled) return;
this.poll();
Expand Down Expand Up @@ -135,7 +148,7 @@ export class PresenceSyncManager {
filter: filterId,
since: this.syncToken,
timeout: this.pollTimeoutMs,
set_presence: 'online',
set_presence: this.desiredSetPresence,
},
undefined,
{ abortSignal: signal }
Expand Down
Loading