From a0d994ac59e334868963263231b4c1a066840d5f Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Thu, 3 Aug 2023 17:14:03 +0100 Subject: [PATCH 1/3] Merge pull request #11365 from matrix-org/andybalaam/revert-to-presence-api Revert "Switch to updating presence via /sync calls instead of PUT /presence" (cherry picked from commit bbab65a4cdcc51b65a6def388cf46b682e4914cc) --- src/Presence.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Presence.ts b/src/Presence.ts index 9ec8fa0aa1..a8ba8b40c4 100644 --- a/src/Presence.ts +++ b/src/Presence.ts @@ -17,7 +17,6 @@ limitations under the License. */ import { logger } from "matrix-js-sdk/src/logger"; -import { SetPresence } from "matrix-js-sdk/src/sync"; import { MatrixClientPeg } from "./MatrixClientPeg"; import dis from "./dispatcher/dispatcher"; @@ -27,10 +26,16 @@ import { ActionPayload } from "./dispatcher/payloads"; // Time in ms after that a user is considered as unavailable/away const UNAVAILABLE_TIME_MS = 3 * 60 * 1000; // 3 mins +enum State { + Online = "online", + Offline = "offline", + Unavailable = "unavailable", +} + class Presence { private unavailableTimer: Timer | null = null; private dispatcherRef: string | null = null; - private state: SetPresence | null = null; + private state: State | null = null; /** * Start listening the user activity to evaluate his presence state. @@ -43,7 +48,7 @@ class Presence { while (this.unavailableTimer) { try { await this.unavailableTimer.finished(); - this.setState(SetPresence.Unavailable); + this.setState(State.Unavailable); } catch (e) { /* aborted, stop got called */ } @@ -68,13 +73,13 @@ class Presence { * Get the current presence state. * @returns {string} the presence state (see PRESENCE enum) */ - public getState(): SetPresence | null { + public getState(): State | null { return this.state; } private onAction = (payload: ActionPayload): void => { if (payload.action === "user_activity") { - this.setState(SetPresence.Online); + this.setState(State.Online); this.unavailableTimer?.restart(); } }; @@ -84,7 +89,7 @@ class Presence { * If the state has changed, the homeserver will be notified. * @param {string} newState the new presence state (see PRESENCE enum) */ - private async setState(newState: SetPresence): Promise { + private async setState(newState: State): Promise { if (newState === this.state) { return; } @@ -97,7 +102,7 @@ class Presence { } try { - await MatrixClientPeg.safeGet().setSyncPresence(this.state); + await MatrixClientPeg.safeGet().setPresence({ presence: this.state }); logger.info("Presence:", newState); } catch (err) { logger.error("Failed to set presence:", err); From 50a22632ab8ec17e43d20b28cfe8fb6d10ec0370 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Fri, 4 Aug 2023 09:24:41 +0100 Subject: [PATCH 2/3] Prepare changelog for v3.77.1 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8ff4896c7..048f188382 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +Changes in [3.77.1](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.77.1) (2023-08-04) +===================================================================================================== + +## 🐛 Bug Fixes + * Revert to using the /presence API for presence ([\#11366](https://github.com/matrix-org/matrix-react-sdk/pull/11366)) + Changes in [3.77.0](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.77.0) (2023-08-01) ===================================================================================================== From fd537cc5f74f74694d1a9fd47c14e3a56a2e310e Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Fri, 4 Aug 2023 09:24:44 +0100 Subject: [PATCH 3/3] v3.77.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e7b700d689..454b120f1d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matrix-react-sdk", - "version": "3.77.0", + "version": "3.77.1", "description": "SDK for matrix.org using React", "author": "matrix.org", "repository": {