2021-01-21 20:37:35 +00:00
|
|
|
import 'dart:convert';
|
2021-01-06 23:09:58 +00:00
|
|
|
import 'dart:ffi';
|
|
|
|
import 'package:ffi/ffi.dart';
|
|
|
|
import 'dart:async';
|
2021-01-07 19:38:06 +00:00
|
|
|
import 'dart:collection';
|
2021-01-06 23:09:58 +00:00
|
|
|
|
2021-01-12 06:21:18 +00:00
|
|
|
import 'cwtch/cwtch.dart';
|
|
|
|
|
2021-01-07 19:38:06 +00:00
|
|
|
////////////////////
|
|
|
|
/// UI State ///
|
|
|
|
////////////////////
|
2021-01-06 23:09:58 +00:00
|
|
|
|
2021-01-07 19:38:06 +00:00
|
|
|
class ProfileModel {
|
|
|
|
String onion;
|
|
|
|
String nickname;
|
|
|
|
String creationDate;
|
2021-01-21 20:37:35 +00:00
|
|
|
String imagePath;
|
2021-01-07 19:38:06 +00:00
|
|
|
HashMap<String, ContactModel> contacts;
|
|
|
|
}
|
2021-01-06 23:09:58 +00:00
|
|
|
|
2021-01-07 19:38:06 +00:00
|
|
|
class ContactModel {
|
|
|
|
String onion;
|
|
|
|
String nickname;
|
|
|
|
bool isGroup;
|
2021-01-21 20:37:35 +00:00
|
|
|
bool isInvitation;
|
2021-01-07 19:38:06 +00:00
|
|
|
bool isBlocked;
|
|
|
|
String status;
|
2021-01-21 20:37:35 +00:00
|
|
|
String imagePath;
|
2021-01-06 23:09:58 +00:00
|
|
|
|
2021-01-21 20:37:35 +00:00
|
|
|
ContactModel({this.onion, this.nickname, this.status, this.isInvitation, this.isBlocked, this.imagePath});
|
2021-01-07 19:38:06 +00:00
|
|
|
}
|
|
|
|
|
2021-01-22 07:56:30 +00:00
|
|
|
class DanMessageModel {
|
2021-01-14 23:36:09 +00:00
|
|
|
String Timestamp;
|
|
|
|
bool Acknowledged;
|
|
|
|
String Message;
|
|
|
|
}
|
|
|
|
|
2021-01-21 20:37:35 +00:00
|
|
|
class ChatMessage {
|
|
|
|
final int o;
|
|
|
|
final String d;
|
|
|
|
|
|
|
|
ChatMessage({this.o, this.d});
|
|
|
|
|
|
|
|
ChatMessage.fromJson(Map<String, dynamic> json)
|
|
|
|
: o = json['o'],
|
|
|
|
d = json['d'];
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() =>
|
|
|
|
{
|
|
|
|
'o': o,
|
|
|
|
'd': d,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-01-07 19:38:06 +00:00
|
|
|
/////////////
|
|
|
|
/// ACN ///
|
|
|
|
/////////////
|
2021-01-06 23:09:58 +00:00
|
|
|
|
2021-01-12 06:21:18 +00:00
|
|
|
|
2021-01-07 19:38:06 +00:00
|
|
|
|
|
|
|
class AppModel {
|
2021-01-12 06:21:18 +00:00
|
|
|
final Cwtch cwtch;
|
|
|
|
AppModel({this.cwtch});
|
2021-01-06 23:09:58 +00:00
|
|
|
|
|
|
|
Stream<String> contactEvents() async* {
|
|
|
|
while (true) {
|
2021-01-14 23:36:09 +00:00
|
|
|
String event = await cwtch.ContactEvents();
|
2021-01-06 23:09:58 +00:00
|
|
|
if (event != "") {
|
|
|
|
print(event);
|
|
|
|
yield event;
|
|
|
|
} else {
|
|
|
|
await Future.delayed(Duration(seconds: 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream<String> torStatus() async* {
|
|
|
|
while (true) {
|
2021-01-14 23:36:09 +00:00
|
|
|
String event = await cwtch.ACNEvents();
|
2021-01-06 23:09:58 +00:00
|
|
|
if (event != "") {
|
|
|
|
yield event;
|
|
|
|
} else {
|
|
|
|
await Future.delayed(Duration(seconds: 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-07 19:38:06 +00:00
|
|
|
}
|