160 lines
5.8 KiB
Dart
160 lines
5.8 KiB
Dart
import 'dart:ui';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:loris/business_logic/chat/chat.dart';
|
|
import 'package:loris/business_logic/posts/posts.dart';
|
|
import 'package:loris/business_logic/timeline/timeline.dart';
|
|
import 'package:loris/global.dart' as global;
|
|
import 'package:loris/partials/post.dart';
|
|
import 'package:loris/partials/post_text_renderer.dart';
|
|
import 'package:loris/themes/themes.dart' as themes;
|
|
|
|
class Chatwindow extends StatefulWidget {
|
|
const Chatwindow({super.key, required this.model});
|
|
final ConversationModel model;
|
|
|
|
@override
|
|
State<Chatwindow> createState() => _ChatwindowState();
|
|
}
|
|
|
|
class _ChatwindowState extends State<Chatwindow> {
|
|
List<PostModel> models = [];
|
|
|
|
Future<void> loadContext(PostModel m) async {
|
|
final c = await getContextForPost(m);
|
|
if (c.key == 200 && mounted) {
|
|
setState(() {
|
|
print(c.value!.ancestors);
|
|
models = c.value!.ancestors +
|
|
[widget.model.lastStatus!] +
|
|
c.value!.descendants;
|
|
});
|
|
print(models);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
if (widget.model.lastStatus != null) loadContext(widget.model.lastStatus!);
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BackdropFilter(
|
|
filter:
|
|
ImageFilter.blur(sigmaX: 10, sigmaY: 10, tileMode: TileMode.mirror),
|
|
child: SimpleDialog(
|
|
contentPadding: const EdgeInsets.all(0),
|
|
backgroundColor: Theme.of(context).colorScheme.surface,
|
|
children: [
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).colorScheme.background,
|
|
borderRadius: const BorderRadius.all(themes.defaultRadius)),
|
|
width: global.getWidth(context),
|
|
constraints: global.getConstraints(context),
|
|
height: MediaQuery.of(context).size.height * 2 / 3,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Flexible(
|
|
child: ListView.separated(
|
|
shrinkWrap: true,
|
|
itemBuilder: (context, index) =>
|
|
DirectMessage(model: models[index]),
|
|
separatorBuilder: (context, index) => const Divider(
|
|
color: Colors.transparent,
|
|
height: themes.defaultSeperatorHeight,
|
|
),
|
|
itemCount: models.length),
|
|
),
|
|
Container(
|
|
padding: themes.defaultInsideMargins,
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).colorScheme.surface,
|
|
borderRadius: const BorderRadius.only(
|
|
bottomLeft: themes.defaultRadius,
|
|
bottomRight: themes.defaultRadius,
|
|
topLeft: Radius.circular(0),
|
|
topRight: Radius.circular(0)),
|
|
border: Border.fromBorderSide(BorderSide(
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
width: 2,
|
|
)),
|
|
),
|
|
child: TextField(
|
|
minLines: 1,
|
|
maxLines: 4,
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
expands: false,
|
|
decoration: InputDecoration(
|
|
suffix: Wrap(
|
|
direction: Axis.horizontal,
|
|
alignment: WrapAlignment.center,
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
children: [
|
|
IconButton(
|
|
onPressed: () {},
|
|
icon: const Icon(Icons.attach_file)),
|
|
IconButton(
|
|
onPressed: () {},
|
|
icon: const Icon(Icons.send),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
));
|
|
}
|
|
}
|
|
|
|
class DirectMessage extends StatefulWidget {
|
|
const DirectMessage({super.key, required this.model});
|
|
final PostModel model;
|
|
|
|
@override
|
|
State<DirectMessage> createState() => _DirectMessageState();
|
|
}
|
|
|
|
class _DirectMessageState extends State<DirectMessage> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(themes.defaultSeperatorHeight * 2),
|
|
child: Align(
|
|
alignment: (widget.model.identity ==
|
|
"${widget.model.account.acct}@${global.settings!.identities[widget.model.identity]!.instanceUrl}")
|
|
? Alignment.centerRight
|
|
: Alignment.centerLeft,
|
|
child: LayoutBuilder(builder: ((ctx, constraints) {
|
|
return Container(
|
|
constraints: BoxConstraints(maxWidth: constraints.maxWidth * 0.96),
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).colorScheme.surface,
|
|
border: Border.all(
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
width: 2,
|
|
),
|
|
borderRadius: const BorderRadius.all(themes.defaultRadius)),
|
|
padding: themes.defaultInsideMargins,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
DisplayName(account: widget.model.account),
|
|
PostTextRenderer(input: widget.model.content),
|
|
],
|
|
),
|
|
);
|
|
})),
|
|
),
|
|
);
|
|
}
|
|
}
|