Added Chat context menu for chat 'mark as read', 'mark as unread', 'add to favorites', 'remove from favorites', 'leave conversation'
added Chat favorite badge and mark chat as read when entering it
This commit is contained in:
@ -2,13 +2,18 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/leaveRoom/leaveRoom.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/setReadMarker/setReadMarker.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/setReadMarker/setReadMarkerParams.dart';
|
||||
import 'package:persistent_bottom_nav_bar/persistent_tab_view.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../../api/marianumcloud/talk/chat/richObjectStringProcessor.dart';
|
||||
import '../../../api/marianumcloud/talk/room/getRoomResponse.dart';
|
||||
import '../../../api/marianumcloud/talk/setFavorite/setFavorite.dart';
|
||||
import '../../../model/chatList/chatListProps.dart';
|
||||
import '../../../widget/confirmDialog.dart';
|
||||
import '../../../widget/unimplementedDialog.dart';
|
||||
import 'chatView.dart';
|
||||
|
||||
@ -31,10 +36,14 @@ class _ChatListState extends State<ChatList> {
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
Provider.of<ChatListProps>(context, listen: false).run();
|
||||
_query();
|
||||
});
|
||||
}
|
||||
|
||||
void _query({bool renew = false}) {
|
||||
Provider.of<ChatListProps>(context, listen: false).run(renew: renew);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@ -60,6 +69,16 @@ class _ChatListState extends State<ChatList> {
|
||||
List<ListTile> chats = List<ListTile>.empty(growable: true);
|
||||
|
||||
for (var chatRoom in data.getRoomsResponse.sortByLastActivity()) {
|
||||
|
||||
setCurrentAsRead() {
|
||||
SetReadMarker(
|
||||
chatRoom.token,
|
||||
true,
|
||||
setReadMarkerParams: SetReadMarkerParams(
|
||||
lastReadMessage: chatRoom.lastMessage.id
|
||||
)
|
||||
).run().then((value) => _query(renew: true));
|
||||
}
|
||||
|
||||
CircleAvatar circleAvatar = CircleAvatar(
|
||||
foregroundImage: chatRoom.type == GetRoomResponseObjectConversationType.oneToOne ? Image.network("https://cloud.marianum-fulda.de/avatar/${chatRoom.name}/128").image : null,
|
||||
@ -69,45 +88,129 @@ class _ChatListState extends State<ChatList> {
|
||||
);
|
||||
|
||||
chats.add(ListTile(
|
||||
leading: Stack(
|
||||
children: [
|
||||
circleAvatar,
|
||||
Visibility(
|
||||
visible: chatRoom.isFavorite,
|
||||
child: Positioned(
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(1),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).primaryColor.withAlpha(200),
|
||||
borderRadius: BorderRadius.circular(90.0),
|
||||
),
|
||||
child: const Icon(Icons.star, color: Colors.amberAccent, size: 15),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
title: Text(chatRoom.displayName),
|
||||
subtitle: Text("${Jiffy.parseFromMillisecondsSinceEpoch(chatRoom.lastMessage.timestamp * 1000).fromNow()}: ${RichObjectStringProcessor.parseToString(chatRoom.lastMessage.message.replaceAll("\n", " "), chatRoom.lastMessage.messageParameters)}", overflow: TextOverflow.ellipsis),
|
||||
trailing: Visibility(
|
||||
visible: chatRoom.unreadMessages > 0,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(1),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).primaryColor,
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 20,
|
||||
minHeight: 20,
|
||||
),
|
||||
child: Text(
|
||||
"${chatRoom.unreadMessages}",
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 15,
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Visibility(
|
||||
visible: chatRoom.unreadMessages > 0,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(1),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).primaryColor,
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 20,
|
||||
minHeight: 20,
|
||||
),
|
||||
child: Text(
|
||||
"${chatRoom.unreadMessages}",
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 15,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
leading: circleAvatar,
|
||||
onTap: () async {
|
||||
setCurrentAsRead();
|
||||
PersistentNavBarNavigator.pushNewScreen(
|
||||
context,
|
||||
screen: ChatView(room: chatRoom, selfId: username, avatar: circleAvatar),
|
||||
withNavBar: false
|
||||
);
|
||||
},
|
||||
onLongPress: () {
|
||||
showDialog(context: context, builder: (context) => SimpleDialog(
|
||||
children: [
|
||||
Visibility(
|
||||
visible: chatRoom.unreadMessages > 0,
|
||||
replacement: ListTile(
|
||||
leading: const Icon(Icons.mark_chat_unread_outlined),
|
||||
title: const Text("Als ungelesen markieren"),
|
||||
onTap: () {
|
||||
SetReadMarker(chatRoom.token, false).run().then((value) => _query(renew: true));
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.mark_chat_read_outlined),
|
||||
title: const Text("Als gelesen markieren"),
|
||||
onTap: () {
|
||||
setCurrentAsRead();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: chatRoom.isFavorite,
|
||||
replacement: ListTile(
|
||||
leading: const Icon(Icons.star_outline),
|
||||
title: const Text("Zu favoriten hinzufügen"),
|
||||
onTap: () {
|
||||
SetFavorite(chatRoom.token, true).run().then((value) => _query(renew: true));
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.stars_outlined),
|
||||
title: const Text("Von favoriten entfernen"),
|
||||
onTap: () {
|
||||
SetFavorite(chatRoom.token, false).run().then((value) => _query(renew: true));
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.delete_outline),
|
||||
title: const Text("Konversation verlassen"),
|
||||
onTap: () {
|
||||
ConfirmDialog(
|
||||
title: "Chat verlassen",
|
||||
content: "Du benötigst ggf. eine Einladung um erneut beizutreten.",
|
||||
confirmButton: "Löschen",
|
||||
onConfirm: () {
|
||||
LeaveRoom(chatRoom.token).run().then((value) => _query(renew: true));
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
).asDialog(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
));
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
return RefreshIndicator(
|
||||
color: Theme.of(context).primaryColor,
|
||||
onRefresh: () {
|
||||
Provider.of<ChatListProps>(context, listen: false).run(renew: true);
|
||||
_query(renew: true);
|
||||
return Future.delayed(const Duration(seconds: 3));
|
||||
},
|
||||
child: ListView(children: chats),
|
||||
|
Reference in New Issue
Block a user