mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-13 23:49:29 +01:00
fix: Set room avatar
This commit is contained in:
parent
d49d44dc80
commit
b587827589
@ -10,6 +10,7 @@ import 'package:matrix/matrix.dart';
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
|
||||
import 'package:fluffychat/pages/chat_details/chat_details_view.dart';
|
||||
import 'package:fluffychat/pages/settings/settings.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions.dart/matrix_locals.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
@ -255,10 +256,50 @@ class ChatDetailsController extends State<ChatDetails> {
|
||||
}
|
||||
|
||||
void setAvatarAction() async {
|
||||
final room = Matrix.of(context).client.getRoomById(roomId);
|
||||
final actions = [
|
||||
if (PlatformInfos.isMobile)
|
||||
SheetAction(
|
||||
key: AvatarAction.camera,
|
||||
label: L10n.of(context).openCamera,
|
||||
isDefaultAction: true,
|
||||
icon: Icons.camera_alt_outlined,
|
||||
),
|
||||
SheetAction(
|
||||
key: AvatarAction.file,
|
||||
label: L10n.of(context).openGallery,
|
||||
icon: Icons.photo_outlined,
|
||||
),
|
||||
if (room?.avatar != null)
|
||||
SheetAction(
|
||||
key: AvatarAction.remove,
|
||||
label: L10n.of(context).delete,
|
||||
isDestructiveAction: true,
|
||||
icon: Icons.delete_outlined,
|
||||
),
|
||||
];
|
||||
final action = actions.length == 1
|
||||
? actions.single
|
||||
: await showModalActionSheet<AvatarAction>(
|
||||
context: context,
|
||||
title: L10n.of(context).editRoomAvatar,
|
||||
actions: actions,
|
||||
);
|
||||
if (action == null) return;
|
||||
final matrix = Matrix.of(context);
|
||||
if (action == AvatarAction.remove) {
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => matrix.client.setAvatarUrl(matrix.client.userID, null),
|
||||
);
|
||||
return;
|
||||
}
|
||||
MatrixFile file;
|
||||
if (PlatformInfos.isMobile) {
|
||||
final result = await ImagePicker().pickImage(
|
||||
source: ImageSource.gallery,
|
||||
source: action == AvatarAction.camera
|
||||
? ImageSource.camera
|
||||
: ImageSource.gallery,
|
||||
imageQuality: 50,
|
||||
maxWidth: 1600,
|
||||
maxHeight: 1600);
|
||||
@ -268,25 +309,18 @@ class ChatDetailsController extends State<ChatDetails> {
|
||||
name: result.path,
|
||||
);
|
||||
} else {
|
||||
final result = await FilePickerCross.importFromStorage(
|
||||
type: FileTypeCross.image,
|
||||
);
|
||||
final result =
|
||||
await FilePickerCross.importFromStorage(type: FileTypeCross.image);
|
||||
if (result == null) return;
|
||||
file = MatrixFile(
|
||||
bytes: result.toUint8List(),
|
||||
name: result.fileName,
|
||||
);
|
||||
}
|
||||
final room = Matrix.of(context).client.getRoomById(roomId);
|
||||
|
||||
final success = await showFutureLoadingDialog(
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => room.setAvatar(file),
|
||||
future: () => matrix.client.setAvatar(file),
|
||||
);
|
||||
if (success.error == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(L10n.of(context).avatarHasBeenChanged)));
|
||||
}
|
||||
}
|
||||
|
||||
void requestMoreMembersAction() async {
|
||||
|
@ -37,30 +37,34 @@ class SettingsController extends State<Settings> {
|
||||
});
|
||||
|
||||
void setAvatarAction() async {
|
||||
final action = await showModalActionSheet<AvatarAction>(
|
||||
context: context,
|
||||
title: L10n.of(context).changeYourAvatar,
|
||||
actions: [
|
||||
final actions = [
|
||||
if (PlatformInfos.isMobile)
|
||||
SheetAction(
|
||||
key: AvatarAction.camera,
|
||||
label: L10n.of(context).openCamera,
|
||||
isDefaultAction: true,
|
||||
icon: Icons.camera_alt_outlined,
|
||||
),
|
||||
SheetAction(
|
||||
key: AvatarAction.file,
|
||||
label: L10n.of(context).openGallery,
|
||||
icon: Icons.photo_outlined,
|
||||
),
|
||||
if (profile?.avatarUrl != null)
|
||||
SheetAction(
|
||||
key: AvatarAction.file,
|
||||
label: L10n.of(context).openGallery,
|
||||
icon: Icons.photo_outlined,
|
||||
key: AvatarAction.remove,
|
||||
label: L10n.of(context).removeYourAvatar,
|
||||
isDestructiveAction: true,
|
||||
icon: Icons.delete_outlined,
|
||||
),
|
||||
if (profile?.avatarUrl != null)
|
||||
SheetAction(
|
||||
key: AvatarAction.remove,
|
||||
label: L10n.of(context).removeYourAvatar,
|
||||
isDestructiveAction: true,
|
||||
icon: Icons.delete_outlined,
|
||||
),
|
||||
],
|
||||
);
|
||||
];
|
||||
final action = actions.length == 1
|
||||
? actions.single
|
||||
: await showModalActionSheet<AvatarAction>(
|
||||
context: context,
|
||||
title: L10n.of(context).changeYourAvatar,
|
||||
actions: actions,
|
||||
);
|
||||
if (action == null) return;
|
||||
final matrix = Matrix.of(context);
|
||||
if (action == AvatarAction.remove) {
|
||||
|
Loading…
Reference in New Issue
Block a user