Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! TW-2066: Update change avatar in chat det…
Browse files Browse the repository at this point in the history
…ails
  • Loading branch information
nqhhdev committed Oct 4, 2024
1 parent 4ee58b2 commit 540ac1a
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 82 deletions.
4 changes: 2 additions & 2 deletions docs/configurations/config_web_app_for_public_platform.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ in [config.sample.json](https://github.com/linagora/twake-on-matrix/blob/main/co
"app_grid_dashboard_available": true,
"homeserver": "https://example.com/",
"platform": "platform"
"default_max_upload_avatar_size": 1000000
"default_max_upload_avatar_size_in_bytes": 1000000
}
```

Expand All @@ -44,6 +44,6 @@ in [config.sample.json](https://github.com/linagora/twake-on-matrix/blob/main/co
- `app_grid_dashboard_available`: Enable App Grid
- `homeserver`: Homeserver
- `platform`: Platform, `saas` for the case of public platform
- `default_max_upload_avatar_size`: Default max upload avatar size
- `default_max_upload_avatar_size_in_bytes`: Default max upload avatar size

If you want to disable it, please change the value or remove this from `config.sample.json`
62 changes: 4 additions & 58 deletions lib/config/app_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@ abstract class AppConfig {
static String _applicationName = 'Twake Chat';

static String get applicationName => _applicationName;

static String? _applicationWelcomeMessage;

static String? get applicationWelcomeMessage => _applicationWelcomeMessage;

static String _defaultHomeserver = 'matrix.linagora.com';

static String get defaultHomeserver => _defaultHomeserver;

static double bubbleSizeFactor = 1;

static double fontSizeFactor = 1;

static String sampleValue = 'sampleValue';
Expand All @@ -57,127 +53,76 @@ abstract class AppConfig {
static double toolbarHeight(BuildContext context) =>
responsive.isMobile(context) ? 48 : 56;
static const Color chatColor = primaryColor;

static Color colorSchemeSeed = primaryColor;

static const double messageFontSize = 17.0;

static const bool allowOtherHomeservers = true;

static const bool enableRegistration = true;

static const Color primaryColor = Color.fromARGB(255, 135, 103, 172);

static const Color primaryColorLight = Color(0xFFCCBDEA);

static const Color secondaryColor = Color(0xFF41a2bc);

static String get privacyUrl => _appPolicy;

static const String enablePushTutorial =
'https://gitlab.com/famedly/fluffychat/-/wikis/Push-Notifications-without-Google-Services';

static const String encryptionTutorial =
'https://gitlab.com/famedly/fluffychat/-/wikis/How-to-use-end-to-end-encryption-in-FluffyChat';

static const String appOpenUrlScheme = 'twake.chat';

static String _webBaseUrl = 'https://fluffychat.im/web';

static String get webBaseUrl => _webBaseUrl;

static const String sourceCodeUrl =
'https://github.com/linagora/twake-on-matrix';

static const String supportUrl =
'https://github.com/linagora/twake-on-matrix/issues';

static bool renderHtml = true;

static bool hideRedactedEvents = false;

static bool hideUnknownEvents = true;

static bool hideUnimportantStateEvents = true;

static bool showDirectChatsInSpaces = true;

static bool separateChatTypes = false;

static bool autoplayImages = true;

static bool experimentalVoip = false;

static bool appGridDashboardAvailable = true;

static const bool hideTypingUsernames = false;

static const bool hideAllStateEvents = false;

static const String inviteLinkPrefix = 'https://matrix.to/#/';

static const String deepLinkPrefix = 'im.fluffychat://chat/';

static const String schemePrefix = 'matrix:';

static const String pushNotificationsChannelId = 'twake_push';

static const String pushNotificationsChannelName = 'Twake Chat push channel';

static const String pushNotificationsChannelDescription =
'Push notifications for Twake Chat';

static String pushNotificationsAppId = Platform.isIOS
? kReleaseMode
? "app.twake.ios.chat"
: "app.twake.ios.chat.sandbox"
: "app.twake.android.chat";

static const String pushNotificationsGatewayUrl =
'https://sygnal.lin-saas.dev/_matrix/push/v1/notify';

static const String pushNotificationsPusherFormat = 'event_id_only';

static const String emojiFontName = 'Noto Emoji';

static const String emojiFontUrl =
'https://github.com/googlefonts/noto-emoji/';

static const double borderRadius = 20.0;

static const double columnWidth = 360.0;

static const int maxFetchContacts = 100000;

static const int chatRoomSearchKeywordMin = 2;

static const bool chatRoomSearchWordStrategy = false;

static const String defaultImageBlurHash = 'LEHV6nWB2yk8pyo0adR*.7kCMdnj';

static const String defaultVideoBlurHash = 'L5H2EC=PM+yV0g-mq.wG9c010J}I';

static const int thumbnailQuality = 70;

static const int blurHashSize = 32;

static const int imageQuality = 50;

static const String iOSKeychainSharingId = 'KUT463DS29.app.twake.ios.chat';

static const String iOSKeychainSharingAccount = 'app.twake.ios.chat.sessions';

static const int maxFilesSendPerDialog = 6;

static const bool supportMultipleAccountsInTheSameHomeserver = false;

static const imageCompressFormmat = CompressFormat.jpeg;

static const videoThumbnailFormat = ImageFormat.JPEG;

static String? issueId;

static int defaultMaxUploadAvtarSize = 10 * (1024 * 1024);
static int defaultMaxUploadAvtarSizeInBytes = 10 * (1024 * 1024);

static const String appGridConfigurationPath =
"configurations/app_dashboard.json";
Expand Down Expand Up @@ -294,8 +239,9 @@ abstract class AppConfig {
if (json['platform'] is String?) {
platform = json['platform'];
}
if (json['default_max_upload_avatar_size'] is int) {
defaultMaxUploadAvtarSize = json['default_max_upload_avatar_size'];
if (json['default_max_upload_avatar_size_in_bytes'] is int) {
defaultMaxUploadAvtarSizeInBytes =
json['default_max_upload_avatar_size_in_bytes'];
}
}
}
11 changes: 5 additions & 6 deletions lib/pages/chat_details/chat_details_edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ class ChatDetailsEditController extends State<ChatDetailsEdit>
) async {
final result = await FilePicker.platform.pickFiles(
type: FileType.image,
withData: false,
withReadStream: true,
);
Logs().d(
Expand All @@ -198,18 +197,15 @@ class ChatDetailsEditController extends State<ChatDetailsEdit>
Logs().d(
'ChatDetailsEditController::_getImageOnWeb(): FilePickerResult - ${matrixFile.size}',
);
if (matrixFile.size > AppConfig.defaultMaxUploadAvtarSize) {
if (matrixFile.size > AppConfig.defaultMaxUploadAvtarSizeInBytes) {
TwakeSnackBar.show(
context,
L10n.of(context)!.fileTooBig(
AppConfig.defaultMaxUploadAvtarSize.bytesToMBInt(),
AppConfig.defaultMaxUploadAvtarSizeInBytes.bytesToMBInt(),
),
);
return;
}
if (!isEditedGroupInfoNotifier.value) {
isEditedGroupInfoNotifier.toggle();
}
updateGroupAvatarNotifier.value = Right(
ChatDetailsGetAvatarInByteSuccess(
matrixFile: matrixFile,
Expand All @@ -222,6 +218,9 @@ class ChatDetailsEditController extends State<ChatDetailsEdit>
}

void updateAvatarFilePicker(MatrixFile matrixFile) {
if (!isEditedGroupInfoNotifier.value) {
isEditedGroupInfoNotifier.toggle();
}
avatarFilePicker = matrixFile;
}

Expand Down
10 changes: 5 additions & 5 deletions lib/pages/new_group/new_group_chat_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class NewGroupChatInfoController extends State<NewGroupChatInfo>
getIt.get<CreateNewGroupChatInteractor>();
final groupNameTextEditingController = TextEditingController();
final avatarAssetEntityNotifier = ValueNotifier<AssetEntity?>(null);
MatrixFile? avatarFilePickerNotifier;
final avatarFilePickerNotifier = ValueNotifier<MatrixFile?>(null);

final groupNameFocusNode = FocusNode();
StreamSubscription? createNewGroupChatInteractorStreamSubscription;
Expand Down Expand Up @@ -267,7 +267,6 @@ class NewGroupChatInfoController extends State<NewGroupChatInfo>
) async {
final result = await FilePicker.platform.pickFiles(
type: FileType.image,
withData: false,
withReadStream: true,
);
if (result == null || result.files.single.readStream == null) {
Expand All @@ -277,11 +276,11 @@ class NewGroupChatInfoController extends State<NewGroupChatInfo>
Logs().d(
'NewGroupController::_getImageOnWeb(): FilePickerResult - ${matrixFile.size}',
);
if (matrixFile.size > AppConfig.defaultMaxUploadAvtarSize) {
if (matrixFile.size > AppConfig.defaultMaxUploadAvtarSizeInBytes) {
TwakeSnackBar.show(
context,
L10n.of(context)!.fileTooBig(
AppConfig.defaultMaxUploadAvtarSize.bytesToMBInt(),
AppConfig.defaultMaxUploadAvtarSizeInBytes.bytesToMBInt(),
),
);
return;
Expand All @@ -295,7 +294,7 @@ class NewGroupChatInfoController extends State<NewGroupChatInfo>
}

void updateAvatarFilePicker(MatrixFile matrixFile) {
avatarFilePickerNotifier = matrixFile;
avatarFilePickerNotifier.value = matrixFile;
}

void showImagesPickerAction({
Expand Down Expand Up @@ -364,6 +363,7 @@ class NewGroupChatInfoController extends State<NewGroupChatInfo>
createNewGroupChatInteractorStreamSubscription?.cancel();
groupNameTextEditingController.dispose();
groupNameFocusNode.dispose();
avatarFilePickerNotifier.dispose();
}

@override
Expand Down
6 changes: 3 additions & 3 deletions lib/pages/new_group/new_group_chat_info_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class NewGroupChatInfoView extends StatelessWidget {
),
Text(
L10n.of(context)!.maxImageSize(
AppConfig.defaultMaxUploadAvtarSize.bytesToMBInt(),
AppConfig.defaultMaxUploadAvtarSizeInBytes
.bytesToMBInt(),
),
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: LinagoraRefColors.material().neutral[40],
Expand Down Expand Up @@ -297,8 +298,7 @@ class _AvatarForWebBuilder extends StatelessWidget {
builder: (context, uiState, child) =>
uiState.fold((failure) => child!, (success) {
if (success is GetAvatarInStreamUIStateSuccess) {
if (success.matrixFile != null &&
success.matrixFile?.readStream == null) {
if (success.matrixFile?.readStream == null) {
return child!;
}
return ClipOval(
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/new_group/new_group_info_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ extension NewGroupInfoControllerExtension on NewGroupChatInfoController {
}

void _handleUploadAvatarInBytes(Client client) {
if (avatarFilePickerNotifier != null) {
if (avatarFilePickerNotifier.value != null) {
uploadAvatarNewGroupChatInBytes(
matrixClient: client,
matrixFile: avatarFilePickerNotifier!,
matrixFile: avatarFilePickerNotifier.value!,
);
} else {
createNewGroup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ class SettingsProfileController extends State<SettingsProfile>
) async {
final result = await FilePicker.platform.pickFiles(
type: FileType.image,
withData: false,
withReadStream: true,
);
if (result == null || result.files.single.readStream == null) {
Expand All @@ -195,11 +194,11 @@ class SettingsProfileController extends State<SettingsProfile>
Logs().d(
'SettingsProfile::_getImageOnWeb(): AvatarWebNotifier - ${matrixFile.size}',
);
if (matrixFile.size > AppConfig.defaultMaxUploadAvtarSize) {
if (matrixFile.size > AppConfig.defaultMaxUploadAvtarSizeInBytes) {
TwakeSnackBar.show(
context,
L10n.of(context)!.fileTooBig(
AppConfig.defaultMaxUploadAvtarSize.bytesToMBInt(),
AppConfig.defaultMaxUploadAvtarSizeInBytes.bytesToMBInt(),
),
);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ class SettingsProfileViewMobile extends StatelessWidget {
}
if (success is GetAvatarInBytesUIStateSuccess &&
PlatformInfos.isWeb) {
if (success.matrixFile == null ||
success.matrixFile?.readStream == null) {
if (success.matrixFile?.readStream == null) {
return child!;
}
return ClipOval(
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/stream_image_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class StreamImageViewerState extends State<StreamImageViewer> {
Widget build(BuildContext context) {
return ValueListenableBuilder(
valueListenable: imageBytes,
builder: (context, bytes, _) {
builder: (_, bytes, __) {
if (bytes == null) {
return const Center(
child: CircularProgressIndicator(),
Expand Down

0 comments on commit 540ac1a

Please sign in to comment.