diff --git a/lib/components/matrix.dart b/lib/components/matrix.dart index 66ae88c6..af5eae8b 100644 --- a/lib/components/matrix.dart +++ b/lib/components/matrix.dart @@ -97,6 +97,7 @@ class MatrixState extends State with WidgetsBindingObserver { StreamSubscription onUiaRequest; StreamSubscription onFocusSub; StreamSubscription onBlurSub; + StreamSubscription onOwnPresence; String _cachedPassword; String get cachedPassword { @@ -311,6 +312,30 @@ class MatrixState extends State with WidgetsBindingObserver { widget.apl.currentState.pushNamedAndRemoveAllOthers('/'); } }); + + // Cache and resend status message + onOwnPresence ??= client.onPresence.stream.listen((presence) { + if (client.isLogged() && + client.userID == presence.senderId && + presence.presence?.statusMsg != null) { + Logs().v('Update status message: "${presence.presence.statusMsg}"'); + store.setItem( + SettingKeys.ownStatusMessage, presence.presence.statusMsg); + } + }); + if (client.isLogged()) { + store.getItem(SettingKeys.ownStatusMessage).then((statusMsg) { + if (statusMsg?.isNotEmpty ?? false) { + Logs().v('Send cached status message: "$statusMsg"'); + client.sendPresence( + client.userID, + PresenceType.online, + statusMsg: statusMsg, + ); + } + }); + } + onUiaRequest ??= client.onUiaRequest.stream.listen(_onUiaRequest); if (PlatformInfos.isWeb || PlatformInfos.isLinux) { client.onSync.stream.first.then((s) { @@ -381,6 +406,7 @@ class MatrixState extends State with WidgetsBindingObserver { onRoomKeyRequestSub?.cancel(); onKeyVerificationRequestSub?.cancel(); onLoginStateChanged?.cancel(); + onOwnPresence?.cancel(); onNotification?.cancel(); onFocusSub?.cancel(); onBlurSub?.cancel(); diff --git a/lib/config/setting_keys.dart b/lib/config/setting_keys.dart index 7206729c..f56da382 100644 --- a/lib/config/setting_keys.dart +++ b/lib/config/setting_keys.dart @@ -17,4 +17,5 @@ abstract class SettingKeys { 'chat.fluffy.unifiedpush.registered'; static const String unifiedPushEndpoint = 'chat.fluffy.unifiedpush.endpoint'; static const String notificationCurrentIds = 'chat.fluffy.notification_ids'; + static const String ownStatusMessage = 'chat.fluffy.status_msg'; }