Added search for existing chats
This commit is contained in:
@ -1,20 +1,12 @@
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoom.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomParams.dart';
|
||||
import 'package:marianum_mobile/view/pages/talk/chatTile.dart';
|
||||
import 'package:marianum_mobile/view/pages/talk/searchChat.dart';
|
||||
import 'package:persistent_bottom_nav_bar/persistent_tab_view.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../../model/chatList/chatListProps.dart';
|
||||
import '../../../widget/confirmDialog.dart';
|
||||
import '../../../widget/unimplementedDialog.dart';
|
||||
import 'chatView.dart';
|
||||
import 'chatTile.dart';
|
||||
import 'joinChat.dart';
|
||||
import 'searchChat.dart';
|
||||
|
||||
class ChatList extends StatefulWidget {
|
||||
const ChatList({Key? key}) : super(key: key);
|
||||
@ -40,6 +32,7 @@ class _ChatListState extends State<ChatList> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ChatListProps? latestData;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
@ -48,12 +41,14 @@ class _ChatListState extends State<ChatList> {
|
||||
IconButton(
|
||||
icon: const Icon(Icons.search),
|
||||
onPressed: () async {
|
||||
showSearch(context: context, delegate: SearchChat((await GetRoom(GetRoomParams(includeStatus: true)).run()).data.toList()));
|
||||
if(latestData == null) return;
|
||||
showSearch(context: context, delegate: SearchChat(latestData!.getRoomsResponse.data.toList()));
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
heroTag: "createChat",
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
onPressed: () {
|
||||
showSearch(context: context, delegate: JoinChat());
|
||||
@ -67,8 +62,9 @@ class _ChatListState extends State<ChatList> {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
List<ChatTile> chats = List<ChatTile>.empty(growable: true);
|
||||
latestData = data;
|
||||
|
||||
List<ChatTile> chats = [];
|
||||
for (var chatRoom in data.getRoomsResponse.sortByLastActivity()) {
|
||||
chats.add(ChatTile(data: chatRoom, query: _query));
|
||||
}
|
||||
|
@ -12,8 +12,40 @@ import '../../../api/marianumcloud/talk/setReadMarker/setReadMarkerParams.dart';
|
||||
import '../../../widget/confirmDialog.dart';
|
||||
import 'chatView.dart';
|
||||
|
||||
class ChatTile {
|
||||
ListTile getTile(GetRoomResponseObject data, void Function({bool renew}) query) async {
|
||||
class ChatTile extends StatefulWidget {
|
||||
final GetRoomResponseObject data;
|
||||
final void Function({bool renew}) query;
|
||||
final bool disableContextActions;
|
||||
|
||||
const ChatTile({Key? key, required this.data, required this.query, this.disableContextActions = false}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ChatTile> createState() => _ChatTileState();
|
||||
}
|
||||
|
||||
class _ChatTileState extends State<ChatTile> {
|
||||
late String username;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
SharedPreferences.getInstance().then((value) => {
|
||||
username = value.getString("username")!
|
||||
});
|
||||
}
|
||||
|
||||
void setCurrentAsRead() {
|
||||
SetReadMarker(
|
||||
widget.data.token,
|
||||
true,
|
||||
setReadMarkerParams: SetReadMarkerParams(
|
||||
lastReadMessage: widget.data.lastMessage.id
|
||||
)
|
||||
).run().then((value) => widget.query(renew: true));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
CircleAvatar circleAvatar = CircleAvatar(
|
||||
foregroundImage: widget.data.type == GetRoomResponseObjectConversationType.oneToOne ? Image.network("https://cloud.marianum-fulda.de/avatar/${widget.data.name}/128").image : null,
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
@ -21,22 +53,12 @@ class ChatTile {
|
||||
child: widget.data.type == GetRoomResponseObjectConversationType.group ? const Icon(Icons.group) : const Icon(Icons.person),
|
||||
);
|
||||
|
||||
String username = (await SharedPreferences.getInstance()).getString("username")!;
|
||||
void setCurrentAsRead() {
|
||||
SetReadMarker(
|
||||
data.token,
|
||||
true,
|
||||
setReadMarkerParams: SetReadMarkerParams(
|
||||
lastReadMessage: data.lastMessage.id
|
||||
)
|
||||
).run().then((value) => query(renew: true));
|
||||
}
|
||||
return ListTile(
|
||||
leading: Stack(
|
||||
children: [
|
||||
circleAvatar,
|
||||
Visibility(
|
||||
visible: data.isFavorite,
|
||||
visible: widget.data.isFavorite,
|
||||
child: Positioned(
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
@ -52,13 +74,13 @@ class ChatTile {
|
||||
)
|
||||
],
|
||||
),
|
||||
title: Text(data.displayName),
|
||||
subtitle: Text("${Jiffy.parseFromMillisecondsSinceEpoch(data.lastMessage.timestamp * 1000).fromNow()}: ${RichObjectStringProcessor.parseToString(data.lastMessage.message.replaceAll("\n", " "), data.lastMessage.messageParameters)}", overflow: TextOverflow.ellipsis),
|
||||
title: Text(widget.data.displayName),
|
||||
subtitle: Text("${Jiffy.parseFromMillisecondsSinceEpoch(widget.data.lastMessage.timestamp * 1000).fromNow()}: ${RichObjectStringProcessor.parseToString(widget.data.lastMessage.message.replaceAll("\n", " "), widget.data.lastMessage.messageParameters)}", overflow: TextOverflow.ellipsis),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Visibility(
|
||||
visible: data.unreadMessages > 0,
|
||||
visible: widget.data.unreadMessages > 0,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(1),
|
||||
decoration: BoxDecoration(
|
||||
@ -70,7 +92,7 @@ class ChatTile {
|
||||
minHeight: 20,
|
||||
),
|
||||
child: Text(
|
||||
"${data.unreadMessages}",
|
||||
"${widget.data.unreadMessages}",
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 15,
|
||||
@ -85,20 +107,21 @@ class ChatTile {
|
||||
setCurrentAsRead();
|
||||
PersistentNavBarNavigator.pushNewScreen(
|
||||
context,
|
||||
screen: ChatView(room: data, selfId: username, avatar: circleAvatar),
|
||||
screen: ChatView(room: widget.data, selfId: username, avatar: circleAvatar),
|
||||
withNavBar: false
|
||||
);
|
||||
},
|
||||
onLongPress: () {
|
||||
if(widget.disableContextActions) return;
|
||||
showDialog(context: context, builder: (context) => SimpleDialog(
|
||||
children: [
|
||||
Visibility(
|
||||
visible: data.unreadMessages > 0,
|
||||
visible: widget.data.unreadMessages > 0,
|
||||
replacement: ListTile(
|
||||
leading: const Icon(Icons.mark_chat_unread_outlined),
|
||||
title: const Text("Als ungelesen markieren"),
|
||||
onTap: () {
|
||||
SetReadMarker(data.token, false).run().then((value) => query(renew: true));
|
||||
SetReadMarker(widget.data.token, false).run().then((value) => widget.query(renew: true));
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
@ -112,12 +135,12 @@ class ChatTile {
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: data.isFavorite,
|
||||
visible: widget.data.isFavorite,
|
||||
replacement: ListTile(
|
||||
leading: const Icon(Icons.star_outline),
|
||||
title: const Text("Zu favoriten hinzufügen"),
|
||||
onTap: () {
|
||||
SetFavorite(data.token, true).run().then((value) => query(renew: true));
|
||||
SetFavorite(widget.data.token, true).run().then((value) => widget.query(renew: true));
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
@ -125,7 +148,7 @@ class ChatTile {
|
||||
leading: const Icon(Icons.stars_outlined),
|
||||
title: const Text("Von favoriten entfernen"),
|
||||
onTap: () {
|
||||
SetFavorite(data.token, false).run().then((value) => query(renew: true));
|
||||
SetFavorite(widget.data.token, false).run().then((value) => widget.query(renew: true));
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
@ -139,7 +162,7 @@ class ChatTile {
|
||||
content: "Du benötigst ggf. eine Einladung um erneut beizutreten.",
|
||||
confirmButton: "Löschen",
|
||||
onConfirm: () {
|
||||
LeaveRoom(data.token).run().then((value) => query(renew: true));
|
||||
LeaveRoom(widget.data.token).run().then((value) => widget.query(renew: true));
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
).asDialog(context);
|
||||
@ -151,40 +174,3 @@ class ChatTile {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ChatTile extends StatefulWidget {
|
||||
final GetRoomResponseObject data;
|
||||
final void Function({bool renew}) query;
|
||||
|
||||
const ChatTile({Key? key, required this.data, required this.query}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ChatTile> createState() => _ChatTileState();
|
||||
}
|
||||
|
||||
class _ChatTileState extends State<ChatTile> {
|
||||
|
||||
late CircleAvatar circleAvatar;
|
||||
late String username;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
SharedPreferences.getInstance().then((value) => {
|
||||
username = value.getString("username")!
|
||||
});
|
||||
|
||||
circleAvatar = CircleAvatar(
|
||||
foregroundImage: data.type == GetRoomResponseObjectConversationType.oneToOne ? Image.network("https://cloud.marianum-fulda.de/avatar/${data.name}/128").image : null,
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
child: data.type == GetRoomResponseObjectConversationType.group ? const Icon(Icons.group) : const Icon(Icons.person),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:marianum_mobile/view/pages/talk/chatTile.dart';
|
||||
|
||||
import '../../../api/marianumcloud/talk/room/getRoomResponse.dart';
|
||||
import 'chatTile.dart';
|
||||
|
||||
class SearchChat extends SearchDelegate {
|
||||
List<GetRoomResponseObject> chats;
|
||||
@ -29,7 +29,7 @@ class SearchChat extends SearchDelegate {
|
||||
itemCount: items.length,
|
||||
itemBuilder: (context, index) {
|
||||
var item = items.elementAt(index);
|
||||
return ChatTile(data: item, query: ({bool renew = true}) {});
|
||||
return ChatTile(data: item, disableContextActions: true, query: ({bool renew = true}) {});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user