// SPDX-FileCopyrightText: 2019-Present Christian Kußowski // SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat // // SPDX-License-Identifier: AGPL-3.0-or-later import 'package:matrix/matrix.dart'; extension ClientPresenceExtension on Client { /// Sets the own presence status message. /// /// The SDK's [Client.setPresence] only performs the HTTP request and does not /// update the local presence cache, the database or the /// [Client.onPresenceChanged] stream. As a result /// [Client.fetchCurrentPresence] keeps returning the previous status until the /// homeserver echoes it back over `/sync`. This helper updates all local /// caches after a successful request so the new status is shown immediately. Future setStatusMessage(String statusMsg) async { final userId = userID; if (userId == null) return; await setPresence(userId, PresenceType.online, statusMsg: statusMsg); final presence = CachedPresence( PresenceType.online, null, statusMsg, null, userId, ); // ignore: deprecated_member_use presences[userId] = presence; await database.storePresence(userId, presence); onPresenceChanged.add(presence); } }