2022-07-03 14:56:41 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-08-29 13:37:34 +00:00
|
|
|
import 'package:localization/localization.dart';
|
2022-08-29 21:16:13 +00:00
|
|
|
import 'package:loris/business_logic/instance/instance.dart';
|
|
|
|
import 'package:loris/business_logic/network_tools/get_post_from_url.dart';
|
|
|
|
import 'package:loris/business_logic/timeline/timeline.dart' as tl;
|
|
|
|
import '../business_logic/posting/posting.dart';
|
|
|
|
import '../partials/post.dart';
|
|
|
|
import 'package:loris/global.dart' as global;
|
2022-07-03 14:56:41 +00:00
|
|
|
|
2022-08-29 13:37:34 +00:00
|
|
|
class MakePost extends StatefulWidget {
|
|
|
|
const MakePost({Key? key, this.inReplyTo}) : super(key: key);
|
2022-08-29 21:16:13 +00:00
|
|
|
final tl.PostModel? inReplyTo;
|
2022-07-03 14:56:41 +00:00
|
|
|
|
|
|
|
@override
|
2022-08-29 13:37:34 +00:00
|
|
|
State<MakePost> createState() => _MakePostState();
|
2022-07-03 14:56:41 +00:00
|
|
|
}
|
|
|
|
|
2022-08-29 13:37:34 +00:00
|
|
|
class _MakePostState extends State<MakePost> {
|
2022-09-02 22:20:24 +00:00
|
|
|
String replyAts = "";
|
2022-08-29 21:16:13 +00:00
|
|
|
String accountid = global.settings!.activeIdentity;
|
|
|
|
int? maxLength;
|
|
|
|
String text = "";
|
|
|
|
String spoilerText = "";
|
|
|
|
// stores all identities and if available the post id you are replying to
|
|
|
|
Map<String, String?> identitiesAvailable = {};
|
|
|
|
tl.Visibility visibility = tl.Visibility.public;
|
|
|
|
|
|
|
|
void switchAccount(String acct) {
|
|
|
|
setState(() {
|
|
|
|
maxLength = null;
|
|
|
|
accountid = acct;
|
|
|
|
});
|
|
|
|
updateMaxChars();
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateMaxChars() async {
|
|
|
|
final info = await instanceInformationForIdentity(accountid);
|
|
|
|
if (info.keys.first == 200) {
|
|
|
|
setState(() {
|
|
|
|
maxLength = info.values.first!.configuration.statusconfig.maxChars;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateAvailableIds() async {
|
|
|
|
if (widget.inReplyTo != null) {
|
|
|
|
global.settings!.identities.forEach((key, value) async {
|
|
|
|
final post = await getPostFromUrl(key, widget.inReplyTo!.uri);
|
2022-09-02 22:20:24 +00:00
|
|
|
if (mounted) {
|
|
|
|
if (post.keys.first == 200) {
|
|
|
|
setState(() {
|
|
|
|
identitiesAvailable.addAll({key: post.values.first!.id});
|
|
|
|
});
|
|
|
|
}
|
2022-08-29 21:16:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-02 22:20:24 +00:00
|
|
|
void addAt(String at) {
|
|
|
|
if (!at.contains("@")) {
|
2022-09-02 23:01:30 +00:00
|
|
|
at = "$at${widget.inReplyTo!.getReceiverInstance()}";
|
|
|
|
}
|
|
|
|
if (global.settings!.identities.keys.contains(at)) {
|
|
|
|
return;
|
2022-09-02 22:20:24 +00:00
|
|
|
}
|
|
|
|
replyAts = "$replyAts@$at ";
|
|
|
|
}
|
|
|
|
|
2022-08-29 21:16:13 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
if (widget.inReplyTo != null) {
|
2022-09-04 14:20:42 +00:00
|
|
|
visibility = widget.inReplyTo!.visibility;
|
2022-09-02 22:20:24 +00:00
|
|
|
addAt(widget.inReplyTo!.account.acct);
|
|
|
|
for (var element in widget.inReplyTo!.mentions) {
|
|
|
|
addAt(element.acct);
|
|
|
|
}
|
|
|
|
|
2022-08-29 21:16:13 +00:00
|
|
|
accountid = widget.inReplyTo!.identity;
|
|
|
|
identitiesAvailable.addAll({
|
|
|
|
widget.inReplyTo!.identity: widget.inReplyTo!.id,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
global.settings!.identities.forEach((key, value) {
|
|
|
|
if (!identitiesAvailable.containsKey(DropdownMenuItem(
|
|
|
|
value: key,
|
|
|
|
child: Text(key),
|
|
|
|
))) {
|
|
|
|
identitiesAvailable.addAll({key: null});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-09-02 21:19:25 +00:00
|
|
|
if (widget.inReplyTo != null) {
|
|
|
|
spoilerText = widget.inReplyTo!.spoilerText;
|
|
|
|
}
|
2022-08-29 21:16:13 +00:00
|
|
|
super.initState();
|
|
|
|
updateMaxChars();
|
|
|
|
updateAvailableIds();
|
|
|
|
}
|
|
|
|
|
2022-07-03 14:56:41 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-29 21:16:13 +00:00
|
|
|
List<Widget> c = [];
|
|
|
|
if (widget.inReplyTo != null) {
|
|
|
|
c.add(
|
|
|
|
Post(
|
|
|
|
model: widget.inReplyTo!,
|
|
|
|
reblogVisible: false,
|
|
|
|
hideActionBar: true,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
List<DropdownMenuItem<String>> idDropdownItems = [];
|
|
|
|
identitiesAvailable.forEach((key, value) {
|
|
|
|
idDropdownItems.add(DropdownMenuItem(
|
|
|
|
value: key,
|
2022-09-02 21:19:25 +00:00
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(
|
|
|
|
key,
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
2022-08-29 21:16:13 +00:00
|
|
|
));
|
|
|
|
});
|
|
|
|
|
|
|
|
List<DropdownMenuItem<tl.Visibility>> visibilityDropdowns = [];
|
|
|
|
for (var value in tl.Visibility.values) {
|
|
|
|
visibilityDropdowns.add(DropdownMenuItem(
|
|
|
|
value: value,
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Icon(value.icon),
|
2022-09-02 21:19:25 +00:00
|
|
|
Text(
|
|
|
|
value.name,
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
|
|
),
|
2022-08-29 21:16:13 +00:00
|
|
|
],
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
List<Widget> actionButtons = [
|
|
|
|
maxLength == null
|
|
|
|
? const CircularProgressIndicator()
|
|
|
|
: SelectableText((maxLength! - text.length).toString()),
|
|
|
|
DropdownButtonHideUnderline(
|
|
|
|
child: DropdownButton<tl.Visibility>(
|
2022-09-02 21:19:25 +00:00
|
|
|
alignment: Alignment.center,
|
2022-08-29 21:16:13 +00:00
|
|
|
iconEnabledColor: Theme.of(context).colorScheme.onSurface,
|
|
|
|
items: visibilityDropdowns,
|
|
|
|
value: visibility,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
visibility = value ?? tl.Visibility.private;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
DropdownButtonHideUnderline(
|
|
|
|
child: DropdownButton<String>(
|
2022-09-02 21:19:25 +00:00
|
|
|
alignment: Alignment.center,
|
2022-08-29 21:16:13 +00:00
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
iconEnabledColor: Theme.of(context).colorScheme.onSurface,
|
|
|
|
items: idDropdownItems,
|
|
|
|
value: accountid,
|
|
|
|
onChanged: (value) {
|
|
|
|
switchAccount(value as String);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2022-09-05 19:29:35 +00:00
|
|
|
ElevatedButton.icon(
|
2022-08-29 21:16:13 +00:00
|
|
|
label: Text(
|
|
|
|
"send-post".i18n(),
|
|
|
|
),
|
|
|
|
// send the post!!!
|
|
|
|
onPressed: () async {
|
|
|
|
final model = MakePostModel(
|
2022-09-04 14:20:42 +00:00
|
|
|
spoilerText: spoilerText.trim(),
|
2022-08-29 21:16:13 +00:00
|
|
|
identity: accountid,
|
|
|
|
status: text,
|
|
|
|
visibility: visibility,
|
|
|
|
inReplyToId: widget.inReplyTo == null
|
|
|
|
? null
|
|
|
|
: identitiesAvailable[accountid]!,
|
|
|
|
);
|
|
|
|
model.sendPost();
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.send),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
c.addAll([
|
|
|
|
TextFormField(
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
2022-09-02 21:19:25 +00:00
|
|
|
initialValue: spoilerText,
|
2022-08-29 21:16:13 +00:00
|
|
|
decoration: InputDecoration(
|
|
|
|
prefixIcon: Icon(
|
|
|
|
Icons.warning,
|
|
|
|
color: Theme.of(context).colorScheme.onSurface,
|
|
|
|
),
|
|
|
|
labelText: "content-warning".i18n(),
|
|
|
|
),
|
|
|
|
onChanged: ((value) => setState(() {
|
|
|
|
spoilerText = value;
|
|
|
|
})),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: MediaQuery.of(context).size.height * 0.6,
|
|
|
|
child: TextFormField(
|
2022-09-02 22:20:24 +00:00
|
|
|
initialValue: replyAts,
|
2022-08-29 21:16:13 +00:00
|
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
|
|
maxLines: null,
|
|
|
|
expands: true,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
text = value;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 24,
|
|
|
|
),
|
|
|
|
Wrap(
|
|
|
|
runSpacing: 8,
|
|
|
|
spacing: 24,
|
|
|
|
direction: Axis.horizontal,
|
|
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
|
|
alignment: WrapAlignment.spaceAround,
|
|
|
|
children: actionButtons,
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
|
2022-08-29 13:37:34 +00:00
|
|
|
return SimpleDialog(
|
|
|
|
alignment: Alignment.center,
|
2022-08-29 21:16:13 +00:00
|
|
|
contentPadding: const EdgeInsets.all(24),
|
2022-08-29 13:37:34 +00:00
|
|
|
title: SelectableText(
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
widget.inReplyTo == null ? "make-post".i18n() : "make-reply".i18n(),
|
|
|
|
style: Theme.of(context).textTheme.displayMedium),
|
2022-08-29 21:16:13 +00:00
|
|
|
children: [
|
|
|
|
SingleChildScrollView(
|
|
|
|
child: Container(
|
|
|
|
width: (MediaQuery.of(context).size.width *
|
|
|
|
global.settings!.postWidth) -
|
|
|
|
56,
|
|
|
|
constraints: BoxConstraints(
|
|
|
|
maxWidth: global.settings!.maxPostWidth,
|
|
|
|
minWidth: 375,
|
|
|
|
),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: c,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2022-07-03 14:56:41 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|