Added Nextcloud base

This commit is contained in:
2023-02-20 10:56:51 +01:00
parent e54ae9c2ff
commit fea36b9a6d
63 changed files with 1863 additions and 700 deletions

View 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);
},
);
}
}

View File

@ -1,164 +0,0 @@
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:marianum_mobile/widget/loadingPacket.dart';
import 'package:provider/provider.dart';
import '../../../dataOld/incommingPackets/talkContactsPacket.dart';
import '../../../widget/loadingSpinner.dart';
import 'chatView.dart';
class Talk extends StatefulWidget {
const Talk({Key? key}) : super(key: key);
@override
State<Talk> createState() => _TalkState();
}
class _TalkState extends State<Talk> {
// List<ChatData> chats = List<ChatData>.empty(growable: true);
//
// Future<List<ChatData>> getChats() async {
// var url = Uri.https("***REMOVED***:***REMOVED***@mhsl.eu", "marianum/app/middleware/chat.php");
// var response = await http.get(
// url,
// headers: (
// {
// "Accept": "application/json",
// "OCS-APIRequest": "true",
// }
// ),
// );
//
// return compute(parseChats, response.body);
// }
@override
void initState() {
Provider.of<TalkContactsPaket>(context, listen: false).invoke();
//TalkContactsAskPacket().send();
super.initState();
// Future.delayed(Duration.zero).then((context) => updateChats());
// Provider.of<AccountModel>(context, listen: false).channel.sink.add("chat");
}
void updateChats() {
// var chats = getChats();
//
// showDialog(
// context: context,
// barrierDismissible: false,
// builder: (BuildContext context) {
// return const LoadingSpinner();
// }
// );
//
// chats.then((value) =>
// setState(() {
// Navigator.pop(context);
// this.chats.clear();
// this.chats = value;
// })
// );
}
@override
Widget build(BuildContext context) {
// List<ListTile> chats = List<ListTile>.empty(growable: true);
//
// for (var element in this.chats) {
// chats.add(
// ListTile(
// leading: element.type == 1 ? CircleAvatar(
// backgroundColor: Colors.grey,
// foregroundImage: Image.network(element.avatar).image,
// ) : const Icon(Icons.group),
// title: Text(element.name),
// subtitle: Text(
// "${element.lastMessageAuthor}: ${element.lastMessage.replaceAll("\n", "")}",
// overflow: TextOverflow.ellipsis,
// ),
// onTap: () {
// Navigator.push(context, MaterialPageRoute(builder: (builder) => const ChatView()));
// },
// trailing: element.unreadMessages > 0 ? const Icon(Icons.mark_chat_unread) : Text(element.lastActivity),
// )
// );
// }
//
// return ListView(
// children: chats,
// );
return Consumer<TalkContactsPaket>(
builder: (context, data, child) {
List<ListTile> chats = List<ListTile>.empty(growable: true);
for (var element in data.contacts) {
chats.add(ListTile(
title: Text(element.name),
subtitle: Text("${element.lastTime}: ${element.lastMessage}".replaceAll("\n", " "), overflow: TextOverflow.ellipsis),
trailing: element.unreadMessages ? const Icon(Icons.new_releases_outlined) : null,
leading: CircleAvatar(
foregroundImage: element.isGroup ? null : Image.network(element.profilePicture).image,
backgroundColor: Theme.of(context).primaryColor,
foregroundColor: Colors.white,
child: element.isGroup ? const Icon(Icons.group) : const Icon(Icons.person),
),
onTap: () {
Navigator.of(context).push(MaterialPageRoute(builder: (context) {
return ChatView(
userToken: element.userToken,
);
}));
},
));
}
return LoadingPacket(packet: data, child: ListView(children: chats));
},
);
}
}
//
// List<ChatData> parseChats(String json) {
// final parsed = jsonDecode(json).cast<Map<String, dynamic>>();
// return parsed.map<ChatData>((a) => ChatData.fromJson(a)).toList();
// }
//
// class ChatData {
// final String name;
// final String lastMessage;
// final String lastMessageAuthor;
// final String avatar;
// final int type;
// final String lastActivity;
// final int unreadMessages;
//
// const ChatData({
// required this.name,
// required this.lastMessage,
// required this.lastMessageAuthor,
// required this.avatar,
// required this.type,
// required this.lastActivity,
// required this.unreadMessages,
// });
//
// factory ChatData.fromJson(Map<String, dynamic> json) {
// return ChatData(
// name: json['name'] as String,
// lastMessage: json['last_message'] as String,
// lastMessageAuthor: json['last_message_author'] as String,
// avatar: json['avatar'] as String,
// type: json['type'] as int,
// lastActivity: json['lastActivity'] as String,
// unreadMessages: json['unreadMessages'] as int,
// );
// }
// }

View File

@ -1,14 +1,18 @@
import 'dart:developer';
import 'package:bubble/bubble.dart';
import 'package:flutter/material.dart';
import 'package:marianum_mobile/widget/loadingPacket.dart';
import 'package:jiffy/jiffy.dart';
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomResponse.dart';
import 'package:marianum_mobile/data/chatList/chatProps.dart';
import 'package:provider/provider.dart';
import '../../../dataOld/incommingPackets/talkChatPacket.dart';
class ChatView extends StatefulWidget {
final String userToken;
const ChatView({Key? key, required this.userToken}) : super(key: key);
final GetRoomResponseObject user;
final String selfId;
final CircleAvatar avatar;
const ChatView({Key? key, required this.user, required this.selfId, required this.avatar}) : super(key: key);
@override
State<ChatView> createState() => _ChatViewState();
@ -16,7 +20,7 @@ class ChatView extends StatefulWidget {
class _ChatViewState extends State<ChatView> {
static const styleSystem = BubbleStyle(
color: Color.fromRGBO(212, 234, 244, 1.0),
color: Color(0xffd4eaf4),
borderWidth: 1,
elevation: 2,
margin: BubbleEdges.only(top: 15),
@ -24,79 +28,151 @@ class _ChatViewState extends State<ChatView> {
);
static const styleOther = BubbleStyle(
nip: BubbleNip.leftBottom,
nip: BubbleNip.leftTop,
color: Colors.white,
borderWidth: 1,
elevation: 2,
margin: BubbleEdges.only(top: 15, left: 10),
elevation: 1,
margin: BubbleEdges.only(top: 15, left: 10, right: 50),
alignment: Alignment.topLeft,
);
static const styleSelf = BubbleStyle(
nip: BubbleNip.rightBottom,
color: Color.fromRGBO(225, 255, 199, 1.0),
color: Color(0xffd9fdd3),
borderWidth: 1,
elevation: 2,
margin: BubbleEdges.only(top: 15, right: 10),
elevation: 1,
margin: BubbleEdges.only(top: 15, right: 10, left: 50),
alignment: Alignment.topRight,
);
final ScrollController _listController = ScrollController();
@override
void initState() {
super.initState();
Provider.of<TalkChatPacket>(context, listen: false).invoke(
data: {
"token": widget.userToken
},
indicateLoading: true,
allowNotifyListeners: false,
);
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
Provider.of<ChatProps>(context, listen: false).setQueryToken(widget.user.token);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey,
appBar: AppBar(
title: const Text("Chat mit jemandem"),
),
body: Consumer<TalkChatPacket>(
builder: (context, data, child) {
List<Bubble> messages = List<Bubble>.empty(growable: true);
return Consumer<ChatProps>(
builder: (context, data, child) {
List<Bubble> messages = List<Bubble>.empty(growable: true);
if(!data.primaryLoading()) {
String lastActor = "";
bool showMetadata = true;
data.getChatResponse.sortByTimestamp().forEach((element) {
showMetadata = element.messageType == GetRoomResponseObjectMessageType.comment;
BubbleStyle currentStyle;
if(element.messageType == GetRoomResponseObjectMessageType.comment) {
if(element.actorId == widget.selfId) {
currentStyle = styleSelf;
} else {
currentStyle = styleOther;
}
} else {
currentStyle = styleSystem;
}
data.messages.forEach((element) {
messages.add(Bubble(
style: styleSelf,
child: Text(element.content),
margin: BubbleEdges.only(bottom: element == data.getChatResponse.sortByTimestamp().last ? 20 : 0),
style: currentStyle,
child: Stack(
children: [
Visibility(
visible: showMetadata,
child: Positioned(
top: 0,
left: 0,
child: Text("${element.actorDisplayName}", style: TextStyle(fontWeight: FontWeight.bold, color: Theme.of(context).primaryColor)),
),
),
Padding(
padding: EdgeInsets.symmetric(vertical: showMetadata ? 18 : 0),
child: Text(element.message),
),
Visibility(
visible: showMetadata,
child: Positioned(
bottom: 0,
right: 0,
child: Text(
"${Jiffy.unixFromSecondsSinceEpoch(element.timestamp).yMMMMd} - ${Jiffy.unixFromSecondsSinceEpoch(element.timestamp).format("HH:mm")}",
style: TextStyle(color: Theme.of(context).disabledColor),
),
),
),
],
),
));
lastActor = element.actorId;
});
}
return LoadingPacket(packet: data, child: ListView(
children: [],
));
},
),
// ListView(
// children: [
// Bubble(
// style: styleSystem,
// child: const Text("Chat gestartet"),
// ),
// Bubble(
// style: styleOther,
// child: const Text("Hi, das ist ein Testtext"),
// ),
// Bubble(
// style: styleSelf,
// child: Text(widget.userToken),
// )
// ],
// ),
return Scaffold(
backgroundColor: const Color(0xffefeae2),
appBar: AppBar(
title: Row(
children: [
widget.avatar,
const SizedBox(width: 10),
Text(widget.user.displayName, overflow: TextOverflow.ellipsis, maxLines: 1),
],
),
),
body: Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/background/chat.png"),
scale: 1.5,
opacity: 0.5,
repeat: ImageRepeat.repeat,
colorFilter: ColorFilter.linearToSrgbGamma()
)
),
child: data.primaryLoading() ? const Center(child: CircularProgressIndicator()) : Column(
children: [
Expanded(
child: ListView(
reverse: true,
controller: _listController,
children: messages.reversed.toList(),
),
),
Container(
color: Theme.of(context).dividerColor,
padding: const EdgeInsets.all(10),
child: Row(
children: [
const Expanded(
child: TextField(
maxLines: null,
decoration: InputDecoration(
hintText: "Nachricht",
border: OutlineInputBorder(),
labelText: "",
),
),
),
IconButton(onPressed: () {}, icon: const Icon(Icons.send))
],
),
)
],
)
),
);
},
);
}
}