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-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;
|
|
|
|
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;
|
|
|
|
bool isBlocked;
|
|
|
|
String status;
|
2021-01-06 23:09:58 +00:00
|
|
|
|
2021-01-07 19:38:06 +00:00
|
|
|
ContactModel({this.onion, this.nickname, this.status});
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////
|
|
|
|
/// ACN ///
|
|
|
|
/////////////
|
2021-01-06 23:09:58 +00:00
|
|
|
|
2021-01-07 19:38:06 +00:00
|
|
|
typedef acn_events_function = Pointer<Utf8> Function();
|
|
|
|
typedef ACNEventsFn = Pointer<Utf8> Function();
|
|
|
|
|
|
|
|
class AppModel {
|
2021-01-06 23:09:58 +00:00
|
|
|
final DynamicLibrary library;
|
|
|
|
AppModel({this.library});
|
|
|
|
|
|
|
|
Stream<String> contactEvents() async* {
|
|
|
|
var acnEventsC = library.lookup<NativeFunction<acn_events_function>>(
|
|
|
|
"ContactEvents");
|
2021-01-07 19:38:06 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2021-01-06 23:09:58 +00:00
|
|
|
final ContactEvents = acnEventsC.asFunction<ACNEventsFn>();
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
Pointer<Utf8> result = ContactEvents();
|
|
|
|
String event = Utf8.fromUtf8(result);
|
|
|
|
if (event != "") {
|
|
|
|
print(event);
|
|
|
|
yield event;
|
|
|
|
} else {
|
|
|
|
await Future.delayed(Duration(seconds: 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Stream<String> torStatus() async* {
|
|
|
|
var acnEventsC = library.lookup<NativeFunction<acn_events_function>>(
|
|
|
|
"ACNEvents");
|
2021-01-07 19:38:06 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2021-01-06 23:09:58 +00:00
|
|
|
final ACNEvents = acnEventsC.asFunction<ACNEventsFn>();
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
Pointer<Utf8> result = ACNEvents();
|
|
|
|
String event = Utf8.fromUtf8(result);
|
|
|
|
if (event != "") {
|
|
|
|
yield event;
|
|
|
|
} else {
|
|
|
|
await Future.delayed(Duration(seconds: 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-07 19:38:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////
|
|
|
|
/// Cwtch API ///
|
|
|
|
/////////////////////
|
|
|
|
|
|
|
|
typedef start_cwtch_function = Void Function(Pointer<Utf8> str, Int32 length);
|
|
|
|
typedef StartCwtchFn = void Function(Pointer<Utf8> dir, int len);
|
|
|
|
|
|
|
|
typedef access_cwtch_eventbus_function = Void Function();
|
|
|
|
typedef NextEventFn = void Function();
|
|
|
|
|
|
|
|
typedef get_json_blob_void_function = Pointer<Utf8> Function();
|
|
|
|
typedef GetJsonBlobVoidFn = Pointer<Utf8> Function();
|
|
|
|
|
|
|
|
typedef get_json_blob_string_function = Pointer<Utf8> Function(Pointer<Utf8> str, Int32 length);
|
|
|
|
typedef GetJsonBlobStringFn = Pointer<Utf8> Function(Pointer<Utf8> str,int len);
|
|
|
|
|
|
|
|
//func NumMessages(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int) (n C.int) {
|
|
|
|
typedef get_int_from_str_str_function = Int32 Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
|
|
|
|
typedef GetIntFromStrStrFn = int Function(Pointer<Utf8>, int, Pointer<Utf8>, int);
|
|
|
|
|
|
|
|
//func GetMessage(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, message_index C.int) *C.char {
|
|
|
|
typedef get_json_blob_from_str_str_int_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Int32);
|
|
|
|
typedef GetJsonBlobFromStrStrIntFn = Pointer<Utf8> Function(Pointer<Utf8>, int, Pointer<Utf8>, int, int);
|