Skip to content

Commit

Permalink
feat: option to not send typing notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Jul 27, 2023
1 parent b85b85d commit 3ccb45c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
2 changes: 2 additions & 0 deletions assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@
"supportedVersions": {}
}
},
"sendTypingNotifications": "Send typing notifications",
"@sendTypingNotifications": {},
"sendOnEnter": "Send on enter",
"@sendOnEnter": {},
"badServerVersionsException": "The homeserver supports the Spec versions:\n{serverVersions}\nBut this app supports only {supportedVersions}",
Expand Down
1 change: 1 addition & 0 deletions lib/config/app_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ abstract class AppConfig {
static bool showDirectChatsInSpaces = true;
static bool separateChatTypes = false;
static bool autoplayImages = true;
static bool sendTypingNotifications = true;
static bool sendOnEnter = false;
static bool experimentalVoip = false;
static const bool hideTypingUsernames = false;
Expand Down
1 change: 1 addition & 0 deletions lib/config/setting_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ abstract class SettingKeys {
static const String autoplayImages = 'chat.fluffy.autoplay_images';
static const String sendOnEnter = 'chat.fluffy.send_on_enter';
static const String experimentalVoip = 'chat.fluffy.experimental_voip';
static const String sendTypingNotifications = 'chat.fluffy.send_typing_notifications';
}
32 changes: 19 additions & 13 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:io';

import 'package:fluffychat/config/app_config.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -1139,19 +1140,24 @@ class ChatController extends State<ChatPageWithRoom> {
}
}
}
typingCoolDown?.cancel();
typingCoolDown = Timer(const Duration(seconds: 2), () {
typingCoolDown = null;
currentlyTyping = false;
room.setTyping(false);
});
typingTimeout ??= Timer(const Duration(seconds: 30), () {
typingTimeout = null;
currentlyTyping = false;
});
if (!currentlyTyping) {
currentlyTyping = true;
room.setTyping(true, timeout: const Duration(seconds: 30).inMilliseconds);
if (AppConfig.sendTypingNotifications) {
typingCoolDown?.cancel();
typingCoolDown = Timer(const Duration(seconds: 2), () {
typingCoolDown = null;
currentlyTyping = false;
room.setTyping(false);
});
typingTimeout ??= Timer(const Duration(seconds: 30), () {
typingTimeout = null;
currentlyTyping = false;
});
if (!currentlyTyping) {
currentlyTyping = true;
room.setTyping(
true,
timeout: const Duration(seconds: 30).inMilliseconds,
);
}
}
setState(() => inputText = text);
}
Expand Down
6 changes: 6 additions & 0 deletions lib/pages/settings_chat/settings_chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ class SettingsChatView extends StatelessWidget {
defaultValue: AppConfig.autoplayImages,
),
const Divider(),
SettingsSwitchListTile.adaptive(
title: L10n.of(context)!.sendTypingNotifications,
onChanged: (b) => AppConfig.sendTypingNotifications = b,
storeKey: SettingKeys.sendTypingNotifications,
defaultValue: AppConfig.sendTypingNotifications,
),
SettingsSwitchListTile.adaptive(
title: L10n.of(context)!.sendOnEnter,
onChanged: (b) => AppConfig.sendOnEnter = b,
Expand Down
3 changes: 3 additions & 0 deletions lib/widgets/matrix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
store
.getItemBool(SettingKeys.autoplayImages, AppConfig.autoplayImages)
.then((value) => AppConfig.autoplayImages = value);
store
.getItemBool(SettingKeys.sendTypingNotifications, AppConfig.sendTypingNotifications)
.then((value) => AppConfig.sendTypingNotifications = value);
store
.getItemBool(SettingKeys.sendOnEnter, AppConfig.sendOnEnter)
.then((value) => AppConfig.sendOnEnter = value);
Expand Down

0 comments on commit 3ccb45c

Please sign in to comment.