mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-02-02 16:14:21 +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:vrouter/vrouter.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/pages/chat_details/chat_details_view.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/matrix_sdk_extensions.dart/matrix_locals.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
@ -255,10 +256,50 @@ class ChatDetailsController extends State<ChatDetails> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setAvatarAction() async {
|
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;
|
MatrixFile file;
|
||||||
if (PlatformInfos.isMobile) {
|
if (PlatformInfos.isMobile) {
|
||||||
final result = await ImagePicker().pickImage(
|
final result = await ImagePicker().pickImage(
|
||||||
source: ImageSource.gallery,
|
source: action == AvatarAction.camera
|
||||||
|
? ImageSource.camera
|
||||||
|
: ImageSource.gallery,
|
||||||
imageQuality: 50,
|
imageQuality: 50,
|
||||||
maxWidth: 1600,
|
maxWidth: 1600,
|
||||||
maxHeight: 1600);
|
maxHeight: 1600);
|
||||||
@ -268,25 +309,18 @@ class ChatDetailsController extends State<ChatDetails> {
|
|||||||
name: result.path,
|
name: result.path,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
final result = await FilePickerCross.importFromStorage(
|
final result =
|
||||||
type: FileTypeCross.image,
|
await FilePickerCross.importFromStorage(type: FileTypeCross.image);
|
||||||
);
|
|
||||||
if (result == null) return;
|
if (result == null) return;
|
||||||
file = MatrixFile(
|
file = MatrixFile(
|
||||||
bytes: result.toUint8List(),
|
bytes: result.toUint8List(),
|
||||||
name: result.fileName,
|
name: result.fileName,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
final room = Matrix.of(context).client.getRoomById(roomId);
|
await showFutureLoadingDialog(
|
||||||
|
|
||||||
final success = await showFutureLoadingDialog(
|
|
||||||
context: context,
|
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 {
|
void requestMoreMembersAction() async {
|
||||||
|
@ -37,10 +37,8 @@ class SettingsController extends State<Settings> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
void setAvatarAction() async {
|
void setAvatarAction() async {
|
||||||
final action = await showModalActionSheet<AvatarAction>(
|
final actions = [
|
||||||
context: context,
|
if (PlatformInfos.isMobile)
|
||||||
title: L10n.of(context).changeYourAvatar,
|
|
||||||
actions: [
|
|
||||||
SheetAction(
|
SheetAction(
|
||||||
key: AvatarAction.camera,
|
key: AvatarAction.camera,
|
||||||
label: L10n.of(context).openCamera,
|
label: L10n.of(context).openCamera,
|
||||||
@ -59,7 +57,13 @@ class SettingsController extends State<Settings> {
|
|||||||
isDestructiveAction: true,
|
isDestructiveAction: true,
|
||||||
icon: Icons.delete_outlined,
|
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;
|
if (action == null) return;
|
||||||
final matrix = Matrix.of(context);
|
final matrix = Matrix.of(context);
|
||||||
|
Loading…
Reference in New Issue
Block a user