automatic ats! finally!

This commit is contained in:
zoe 2022-09-03 00:20:24 +02:00
parent f2405f750b
commit 7afa031ef7
2 changed files with 25 additions and 4 deletions

View File

@ -122,6 +122,11 @@ class PostModel implements Comparable {
}
}
// get instance of account that received this post
String getReceiverInstance() {
return identity.substring(identity.indexOf("@"));
}
@override
int compareTo(dynamic b) {
return id.compareTo(b.id);

View File

@ -16,6 +16,7 @@ class MakePost extends StatefulWidget {
}
class _MakePostState extends State<MakePost> {
String replyAts = "";
String accountid = global.settings!.activeIdentity;
int? maxLength;
String text = "";
@ -45,18 +46,32 @@ class _MakePostState extends State<MakePost> {
if (widget.inReplyTo != null) {
global.settings!.identities.forEach((key, value) async {
final post = await getPostFromUrl(key, widget.inReplyTo!.uri);
if (post.keys.first == 200) {
setState(() {
identitiesAvailable.addAll({key: post.values.first!.id});
});
if (mounted) {
if (post.keys.first == 200) {
setState(() {
identitiesAvailable.addAll({key: post.values.first!.id});
});
}
}
});
}
}
void addAt(String at) {
if (!at.contains("@")) {
at = "$at${widget.inReplyTo!.getReceiverInstance()} ";
}
replyAts = "$replyAts@$at ";
}
@override
void initState() {
if (widget.inReplyTo != null) {
addAt(widget.inReplyTo!.account.acct);
for (var element in widget.inReplyTo!.mentions) {
addAt(element.acct);
}
accountid = widget.inReplyTo!.identity;
identitiesAvailable.addAll({
widget.inReplyTo!.identity: widget.inReplyTo!.id,
@ -188,6 +203,7 @@ class _MakePostState extends State<MakePost> {
SizedBox(
height: MediaQuery.of(context).size.height * 0.6,
child: TextFormField(
initialValue: replyAts,
style: Theme.of(context).textTheme.bodyMedium,
maxLines: null,
expands: true,