implemented favorite and leave actions for chat/rooms info view
This commit is contained in:
@@ -1,8 +1,13 @@
|
|||||||
import 'package:flutter/material.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_cache.dart';
|
||||||
import '../../../../api/marianumcloud/talk/get_participants/get_participants_response.dart';
|
import '../../../../api/marianumcloud/talk/get_participants/get_participants_response.dart';
|
||||||
import '../../../../api/marianumcloud/talk/room/get_room_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/large_profile_picture_view.dart';
|
||||||
import '../../../../widget/loading_spinner.dart';
|
import '../../../../widget/loading_spinner.dart';
|
||||||
import '../../../../widget/user_avatar.dart';
|
import '../../../../widget/user_avatar.dart';
|
||||||
@@ -19,9 +24,12 @@ class ChatInfo extends StatefulWidget {
|
|||||||
|
|
||||||
class _ChatInfoState extends State<ChatInfo> {
|
class _ChatInfoState extends State<ChatInfo> {
|
||||||
GetParticipantsResponse? participants;
|
GetParticipantsResponse? participants;
|
||||||
|
late bool _isFavorite;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_isFavorite = widget.room.isFavorite;
|
||||||
GetParticipantsCache(
|
GetParticipantsCache(
|
||||||
chatToken: widget.room.token,
|
chatToken: widget.room.token,
|
||||||
onUpdate: (GetParticipantsResponse data) {
|
onUpdate: (GetParticipantsResponse data) {
|
||||||
@@ -30,7 +38,32 @@ class _ChatInfoState extends State<ChatInfo> {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
super.initState();
|
}
|
||||||
|
|
||||||
|
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
|
@override
|
||||||
@@ -39,12 +72,11 @@ class _ChatInfoState extends State<ChatInfo> {
|
|||||||
widget.room.type != GetRoomResponseObjectConversationType.oneToOne;
|
widget.room.type != GetRoomResponseObjectConversationType.oneToOne;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(title: Text(widget.room.displayName)),
|
appBar: AppBar(title: Text(widget.room.displayName)),
|
||||||
body: Center(
|
body: ListView(
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 30),
|
const SizedBox(height: 30),
|
||||||
GestureDetector(
|
Center(
|
||||||
|
child: GestureDetector(
|
||||||
child: UserAvatar(
|
child: UserAvatar(
|
||||||
id: isGroup ? widget.room.token : widget.room.name,
|
id: isGroup ? widget.room.token : widget.room.name,
|
||||||
isGroup: isGroup,
|
isGroup: isGroup,
|
||||||
@@ -58,19 +90,28 @@ class _ChatInfoState extends State<ChatInfo> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
const SizedBox(height: 30),
|
const SizedBox(height: 30),
|
||||||
Text(
|
Text(
|
||||||
widget.room.displayName,
|
widget.room.displayName,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: const TextStyle(fontSize: 30),
|
style: const TextStyle(fontSize: 30),
|
||||||
),
|
),
|
||||||
if (!isGroup) Text(widget.room.name),
|
if (!isGroup)
|
||||||
|
Text(widget.room.name, textAlign: TextAlign.center),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
if (isGroup)
|
if (isGroup)
|
||||||
Text(widget.room.description, textAlign: TextAlign.center),
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||||
|
child: Text(
|
||||||
|
widget.room.description,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
const SizedBox(height: 30),
|
const SizedBox(height: 30),
|
||||||
if (participants == null) const LoadingSpinner(),
|
if (participants == null)
|
||||||
if (participants != null) ...[
|
const Center(child: LoadingSpinner())
|
||||||
|
else
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.supervised_user_circle),
|
leading: const Icon(Icons.supervised_user_circle),
|
||||||
title: Text('${participants!.data.length} Mitglieder'),
|
title: Text('${participants!.data.length} Mitglieder'),
|
||||||
@@ -83,9 +124,31 @@ class _ChatInfoState extends State<ChatInfo> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
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,
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user