156 lines
5.0 KiB
Dart
156 lines
5.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import '../../../../api/marianumcloud/talk/actions/talk_actions.dart';
|
|
import '../../../../api/marianumcloud/talk/get_participants/get_participants_cache.dart';
|
|
import '../../../../api/marianumcloud/talk/get_participants/get_participants_response.dart';
|
|
import '../../../../api/marianumcloud/talk/room/get_room_response.dart';
|
|
import '../../../../state/app/modules/chat_list/bloc/chat_list_bloc.dart';
|
|
import '../../../../widget/async_action_button.dart';
|
|
import '../../../../widget/confirm_dialog.dart';
|
|
import '../../../../widget/large_profile_picture_view.dart';
|
|
import '../../../../widget/loading_spinner.dart';
|
|
import '../../../../widget/user_avatar.dart';
|
|
import '../talk_navigator.dart';
|
|
import 'participants_list_view.dart';
|
|
|
|
class ChatInfo extends StatefulWidget {
|
|
final GetRoomResponseObject room;
|
|
const ChatInfo(this.room, {super.key});
|
|
|
|
@override
|
|
State<ChatInfo> createState() => _ChatInfoState();
|
|
}
|
|
|
|
class _ChatInfoState extends State<ChatInfo> {
|
|
GetParticipantsResponse? participants;
|
|
late bool _isFavorite;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_isFavorite = widget.room.isFavorite;
|
|
GetParticipantsCache(
|
|
chatToken: widget.room.token,
|
|
onUpdate: (GetParticipantsResponse data) {
|
|
setState(() {
|
|
participants = data;
|
|
});
|
|
},
|
|
);
|
|
}
|
|
|
|
void _refreshList() => context.read<ChatListBloc>().refresh();
|
|
|
|
Future<void> _toggleFavorite() async {
|
|
final next = !_isFavorite;
|
|
await SetFavorite(widget.room.token, next).run();
|
|
if (!mounted) return;
|
|
setState(() => _isFavorite = next);
|
|
_refreshList();
|
|
}
|
|
|
|
Future<void> _confirmLeave() async {
|
|
final closed = await showDialog<bool>(
|
|
context: context,
|
|
builder: (_) => ConfirmDialog(
|
|
title: 'Talk-Chat verlassen',
|
|
content: 'Du benötigst ggf. eine Einladung um erneut beizutreten.',
|
|
confirmButton: 'Verlassen',
|
|
onConfirmAsync: () async {
|
|
await LeaveRoom(widget.room.token).run();
|
|
if (mounted) _refreshList();
|
|
},
|
|
),
|
|
);
|
|
if (closed == true && mounted) Navigator.of(context).pop();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
var isGroup =
|
|
widget.room.type != GetRoomResponseObjectConversationType.oneToOne;
|
|
return Scaffold(
|
|
appBar: AppBar(title: Text(widget.room.displayName)),
|
|
body: ListView(
|
|
children: [
|
|
const SizedBox(height: 30),
|
|
Center(
|
|
child: GestureDetector(
|
|
child: UserAvatar(
|
|
id: isGroup ? widget.room.token : widget.room.name,
|
|
isGroup: isGroup,
|
|
size: 80,
|
|
),
|
|
onTap: () => TalkNavigator.pushSplitView(
|
|
context,
|
|
LargeProfilePictureView(
|
|
id: isGroup ? widget.room.token : widget.room.name,
|
|
isGroup: isGroup,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 30),
|
|
Text(
|
|
widget.room.displayName,
|
|
textAlign: TextAlign.center,
|
|
style: const TextStyle(fontSize: 30),
|
|
),
|
|
if (!isGroup)
|
|
Text(widget.room.name, textAlign: TextAlign.center),
|
|
const SizedBox(height: 10),
|
|
if (isGroup)
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
|
child: Text(
|
|
widget.room.description,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
const SizedBox(height: 30),
|
|
if (participants == null)
|
|
const Center(child: LoadingSpinner())
|
|
else
|
|
ListTile(
|
|
leading: const Icon(Icons.supervised_user_circle),
|
|
title: Text('${participants!.data.length} Mitglieder'),
|
|
trailing: const Icon(Icons.arrow_right),
|
|
onTap: () => TalkNavigator.pushSplitView(
|
|
context,
|
|
ParticipantsListView(
|
|
participants!,
|
|
showDirectMessageAction: isGroup,
|
|
),
|
|
),
|
|
),
|
|
if (_isFavorite)
|
|
AsyncListTile(
|
|
leading: const Icon(Icons.stars_outlined),
|
|
title: const Text('Von Favoriten entfernen'),
|
|
onPressed: _toggleFavorite,
|
|
)
|
|
else
|
|
AsyncListTile(
|
|
leading: const Icon(Icons.star_outline),
|
|
title: const Text('Zu Favoriten hinzufügen'),
|
|
onPressed: _toggleFavorite,
|
|
),
|
|
const Divider(),
|
|
ListTile(
|
|
leading: Icon(
|
|
Icons.delete_outline,
|
|
color: Theme.of(context).colorScheme.error,
|
|
),
|
|
title: Text(
|
|
'Talk-Chat verlassen',
|
|
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
|
),
|
|
onTap: _confirmLeave,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|