211 lines
5.1 KiB
Dart
211 lines
5.1 KiB
Dart
//data structures
|
|
|
|
import 'dart:typed_data';
|
|
|
|
class GetThreadResponse {
|
|
final int id;
|
|
final List<String> messages;
|
|
final String subject;
|
|
final DateTime date;
|
|
final String from_name;
|
|
final String from_address;
|
|
final List<MailAddress> to;
|
|
|
|
GetThreadResponse({
|
|
required this.id,
|
|
required this.messages,
|
|
required this.subject,
|
|
required this.date,
|
|
required this.from_name,
|
|
required this.from_address,
|
|
required this.to,
|
|
});
|
|
factory GetThreadResponse.fromJson(Map<String, dynamic> json) {
|
|
var toList = json['to'] as List<dynamic>;
|
|
|
|
return GetThreadResponse(
|
|
id: json['id'],
|
|
messages: List<String>.from(json['messages']),
|
|
subject: json['subject'],
|
|
date: DateTime.parse(json['date']),
|
|
from_name: json['from_name'],
|
|
from_address: json['from_address'],
|
|
to: toList.map((i) => MailAddress.fromJson(i)).toList(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class MailAddress {
|
|
final String? name;
|
|
final String address;
|
|
MailAddress({this.name, required this.address});
|
|
|
|
factory MailAddress.fromJson(Map<String, dynamic> json) {
|
|
return MailAddress(
|
|
name: json['name'],
|
|
address: json['address'],
|
|
);
|
|
}
|
|
|
|
@override
|
|
String toString() {
|
|
// TODO: implement toString
|
|
return '${name} <${address}>';
|
|
}
|
|
}
|
|
|
|
// //old data structure
|
|
class SerializableMessage {
|
|
final String name;
|
|
final String from;
|
|
final List<MailAddress> to;
|
|
final List<MailAddress> cc;
|
|
final String hash;
|
|
|
|
final String subject;
|
|
final String date;
|
|
final int uid;
|
|
final String list;
|
|
final String id;
|
|
final String in_reply_to;
|
|
|
|
SerializableMessage({
|
|
required this.name,
|
|
required this.from,
|
|
required this.to,
|
|
required this.cc,
|
|
required this.hash,
|
|
required this.subject,
|
|
required this.date,
|
|
required this.uid,
|
|
required this.list, //email list???
|
|
required this.id,
|
|
required this.in_reply_to,
|
|
});
|
|
|
|
factory SerializableMessage.fromJson(Map<String, dynamic> json) {
|
|
var toList = json['to'] as List;
|
|
var ccList = json['cc'] as List;
|
|
|
|
return SerializableMessage(
|
|
name: json['name'],
|
|
from: json['from'],
|
|
// to: json['name', 'address']
|
|
to: toList.map((i) => MailAddress.fromJson(i)).toList(),
|
|
cc: ccList.map((i) => MailAddress.fromJson(i)).toList(),
|
|
// path: json['path'],
|
|
hash: json['hash'],
|
|
subject: json['subject'],
|
|
date: json['date'],
|
|
uid: json['uid'],
|
|
list: json['list'],
|
|
id: json['id'],
|
|
in_reply_to: json['in_reply_to'],
|
|
);
|
|
}
|
|
}
|
|
|
|
class AttachmentInfo {
|
|
final String name;
|
|
final int size;
|
|
final String path;
|
|
|
|
AttachmentInfo({required this.name, required this.size, required this.path});
|
|
|
|
factory AttachmentInfo.fromJson(Map<String, dynamic> json) {
|
|
return AttachmentInfo(
|
|
name: json['name'],
|
|
size: json['size'],
|
|
path: json['path'],
|
|
);
|
|
}
|
|
}
|
|
|
|
class AttachmentInfoList extends Iterable<AttachmentInfo> {
|
|
final List<AttachmentInfo> _attachments;
|
|
|
|
AttachmentInfoList(this._attachments);
|
|
|
|
factory AttachmentInfoList.fromJsonList(List<Map<String, dynamic>> jsonList) {
|
|
return AttachmentInfoList(
|
|
jsonList.map((json) => AttachmentInfo.fromJson(json)).toList());
|
|
}
|
|
|
|
@override
|
|
Iterator<AttachmentInfo> get iterator => _attachments.iterator;
|
|
|
|
@override
|
|
String toString() => _attachments.toString();
|
|
}
|
|
|
|
class AttachmentResponse {
|
|
final name;
|
|
final Uint8List data;
|
|
AttachmentResponse({required this.name, required this.data});
|
|
|
|
factory AttachmentResponse.fromJson(Map<String, dynamic> json) {
|
|
return AttachmentResponse(
|
|
name: json["name"],
|
|
data: Uint8List.fromList(List<int>.from(json["data"])));
|
|
}
|
|
}
|
|
|
|
class AugmentTree {
|
|
List<AugmentTree> children = [];
|
|
|
|
String data = '';
|
|
AugmentTree? parent;
|
|
String ogTag = '';
|
|
String numbering = '';
|
|
|
|
void setData(String data) {
|
|
this.data = data;
|
|
}
|
|
|
|
static String _intToLetter(int index) {
|
|
return String.fromCharCode('a'.runes.first + index);
|
|
}
|
|
|
|
void addNumbering({String prefix = ''}) {
|
|
//if called in root, numbers them all
|
|
for (int i = 0; i < children.length; i++) {
|
|
final child = children[i];
|
|
String childNumbering;
|
|
bool parentIsLettered = prefix.contains(RegExp(r'[a-z]'));
|
|
if (prefix.isEmpty) {
|
|
parentIsLettered = false;
|
|
} else {
|
|
parentIsLettered = prefix.runes.last >= 'a'.runes.first &&
|
|
prefix.runes.last <= 'z'.runes.first;
|
|
}
|
|
|
|
if (prefix.isEmpty) {
|
|
// Top-level children (direct children of the original root being numbered) get 1, 2, 3...
|
|
childNumbering = (i + 1).toString();
|
|
} else if (parentIsLettered) {
|
|
// Deeper children get '1a', '1b', '2a', '2b', etc.
|
|
childNumbering = '$prefix${i + 1}';
|
|
} else {
|
|
childNumbering = '$prefix${_intToLetter(i)}';
|
|
}
|
|
|
|
child.numbering = childNumbering;
|
|
|
|
// Recursively call for children
|
|
child.addNumbering(prefix: childNumbering);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
class MarkdownParsed{
|
|
final String text;
|
|
MarkdownParsed({required this.text});
|
|
factory MarkdownParsed.fromJson(Map<String, String> json){
|
|
return MarkdownParsed(
|
|
text: json['md'] ?? '',
|
|
);
|
|
}
|
|
}
|
|
|