Added Nextcloud base
This commit is contained in:
101
lib/screen/pages/talk/chatList.dart
Normal file
101
lib/screen/pages/talk/chatList.dart
Normal file
@ -0,0 +1,101 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomResponse.dart';
|
||||
import 'package:marianum_mobile/data/chatList/chatListProps.dart';
|
||||
import 'package:marianum_mobile/widget/loadingPacket.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'chatView.dart';
|
||||
|
||||
class ChatList extends StatefulWidget {
|
||||
const ChatList({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ChatList> createState() => _ChatListState();
|
||||
}
|
||||
|
||||
class _ChatListState extends State<ChatList> {
|
||||
late String username;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
SharedPreferences.getInstance().then((value) => {
|
||||
username = value.getString("username")!
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
Provider.of<ChatListProps>(context, listen: false).run();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return Consumer<ChatListProps>(
|
||||
builder: (context, data, child) {
|
||||
|
||||
if(data.primaryLoading()) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
List<ListTile> chats = List<ListTile>.empty(growable: true);
|
||||
|
||||
for (var chatRoom in data.getRoomsResponse.sortByLastActivity()) {
|
||||
|
||||
CircleAvatar _circleAvatar = CircleAvatar(
|
||||
foregroundImage: chatRoom.type == GetRoomResponseObjectConversationType.oneToOne ? Image.network("https://cloud.marianum-fulda.de/avatar/${chatRoom.name}/128").image : null,
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
child: chatRoom.type == GetRoomResponseObjectConversationType.group ? const Icon(Icons.group) : const Icon(Icons.person),
|
||||
);
|
||||
|
||||
chats.add(ListTile(
|
||||
title: Text(chatRoom.displayName),
|
||||
subtitle: Text("${Jiffy.unixFromSecondsSinceEpoch(chatRoom.lastMessage.timestamp).fromNow()}: ${chatRoom.lastMessage.message.replaceAll("\n", " ")}", 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,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
leading: _circleAvatar,
|
||||
onTap: () async {
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (context) {
|
||||
return ChatView(
|
||||
user: chatRoom,
|
||||
selfId: username,
|
||||
avatar: _circleAvatar,
|
||||
);
|
||||
}));
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
return ListView(children: chats);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user