wind/lib/thread_model.dart

61 lines
1.8 KiB
Dart
Raw Normal View History

2022-04-18 22:23:30 +00:00
import 'package:enough_mail/enough_mail.dart';
2022-04-15 04:03:42 +00:00
import 'package:flutter/cupertino.dart';
import 'package:wind/message_item_view.dart';
import 'package:wind/nntp_client.dart';
class ThreadModel extends ChangeNotifier {
NNTPClient? client;
var commentTextController = TextEditingController(text: "");
Future<MessageItem> getPost(int number) async {
var msg = await client!.getPost(number);
2022-04-18 22:23:30 +00:00
var mi = MessageItem(
msg.getHeaderValue("Message-Id")!,
number,
msg.getHeaderValue("Subject")!,
msg.getHeaderValue("From")!,
msg.getHeaderValue("Date")!,
msg.decodeTextPlainPart()!);
2022-04-18 22:23:30 +00:00
mi.originalMessage = msg;
return mi;
}
2022-04-15 04:03:42 +00:00
Future<List<MessageItem>> getThread(int threadNumber) async {
if (client!.currentGroup == "") return [];
List<MessageItem> items = [];
var thread = await client!.getThread(threadNumber);
thread.forEach((pair) {
var messageNum = pair.item1;
var message = pair.item2;
items.add(MessageItem(
message.getHeaderValue("Message-Id")!,
messageNum,
null,
message.getHeaderValue("From")!,
message.getHeaderValue("Date")!,
message.decodeTextPlainPart()!));
});
return items;
}
2022-04-18 22:23:30 +00:00
Future<int> postMessage(MimeMessage opPost, String text) async {
var msg = MessageBuilder.buildSimpleTextMessage(
MailAddress.empty(), [], text,
subject: "Re: " + opPost.decodeSubject()!);
msg.setHeader("From", "anonymous");
msg.addHeader("In-Reply-To", opPost.getHeaderValue("Message-Id"));
msg.addHeader("References", opPost.getHeaderValue("Message-Id"));
msg.addHeader("Newsgroups", client!.currentGroup!);
return await client!.postArticle(msg);
}
2022-04-18 23:03:38 +00:00
void update() {
notifyListeners();
}
2022-04-15 04:03:42 +00:00
}