feat: Cache and resend status message

This commit is contained in:
Christian Pauly 2021-02-27 14:25:55 +01:00
parent 36e1ac6b58
commit c8a70313b1
2 changed files with 27 additions and 0 deletions

View File

@ -97,6 +97,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
StreamSubscription<UiaRequest> onUiaRequest; StreamSubscription<UiaRequest> onUiaRequest;
StreamSubscription<html.Event> onFocusSub; StreamSubscription<html.Event> onFocusSub;
StreamSubscription<html.Event> onBlurSub; StreamSubscription<html.Event> onBlurSub;
StreamSubscription<Presence> onOwnPresence;
String _cachedPassword; String _cachedPassword;
String get cachedPassword { String get cachedPassword {
@ -311,6 +312,30 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
widget.apl.currentState.pushNamedAndRemoveAllOthers('/'); 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); onUiaRequest ??= client.onUiaRequest.stream.listen(_onUiaRequest);
if (PlatformInfos.isWeb || PlatformInfos.isLinux) { if (PlatformInfos.isWeb || PlatformInfos.isLinux) {
client.onSync.stream.first.then((s) { client.onSync.stream.first.then((s) {
@ -381,6 +406,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
onRoomKeyRequestSub?.cancel(); onRoomKeyRequestSub?.cancel();
onKeyVerificationRequestSub?.cancel(); onKeyVerificationRequestSub?.cancel();
onLoginStateChanged?.cancel(); onLoginStateChanged?.cancel();
onOwnPresence?.cancel();
onNotification?.cancel(); onNotification?.cancel();
onFocusSub?.cancel(); onFocusSub?.cancel();
onBlurSub?.cancel(); onBlurSub?.cancel();

View File

@ -17,4 +17,5 @@ abstract class SettingKeys {
'chat.fluffy.unifiedpush.registered'; 'chat.fluffy.unifiedpush.registered';
static const String unifiedPushEndpoint = 'chat.fluffy.unifiedpush.endpoint'; static const String unifiedPushEndpoint = 'chat.fluffy.unifiedpush.endpoint';
static const String notificationCurrentIds = 'chat.fluffy.notification_ids'; static const String notificationCurrentIds = 'chat.fluffy.notification_ids';
static const String ownStatusMessage = 'chat.fluffy.status_msg';
} }