restoring sendmessage yay
This commit is contained in:
parent
9448529061
commit
61b838d343
|
@ -8,11 +8,20 @@ abstract class Cwtch {
|
|||
void CreateProfile(String nick, String pass);
|
||||
// ignore: non_constant_identifier_names
|
||||
void LoadProfiles(String pass);
|
||||
|
||||
// todo: remove these
|
||||
// ignore: non_constant_identifier_names
|
||||
void SendProfileEvent(String onion, String jsonEvent);
|
||||
// ignore: non_constant_identifier_names
|
||||
void SendAppEvent(String jsonEvent);
|
||||
|
||||
// ignore: non_constant_identifier_names
|
||||
void AcceptContact(String profileOnion, String contactHandle);
|
||||
// ignore: non_constant_identifier_names
|
||||
void BlockContact(String profileOnion, String contactHandle);
|
||||
// ignore: non_constant_identifier_names
|
||||
void DebugResetContact(String profileOnion, String contactHandle);
|
||||
|
||||
// ignore: non_constant_identifier_names
|
||||
Future<String> ACNEvents();
|
||||
// ignore: non_constant_identifier_names
|
||||
|
@ -27,6 +36,8 @@ abstract class Cwtch {
|
|||
Future<String> GetMessage(String profile, String handle, int index);
|
||||
// ignore: non_constant_identifier_names
|
||||
Future<String> GetMessages(String profile, String handle, int start, int end);
|
||||
// ignore: non_constant_identifier_names
|
||||
void SendMessage(String profile, String handle, String message);
|
||||
|
||||
void dispose();
|
||||
}
|
||||
|
|
|
@ -43,11 +43,19 @@ class CwtchNotifier {
|
|||
//todo: stopgap, as lc-g is supposed to handle this
|
||||
print("PSC -> adding " + data["ProfileOnion"] + " :: " + data["RemotePeer"]);
|
||||
profileCN.getProfile(data["ProfileOnion"]).contactList.add(
|
||||
ContactInfoState(profileOnion: data["ProfileOnion"], onion: data["RemotePeer"], nickname: data["name"], status: data["ConnectionState"], isBlocked: data["authorization"] == "blocked"));
|
||||
ContactInfoState(profileOnion: data["ProfileOnion"], onion: data["RemotePeer"], nickname: data["name"], status: data["ConnectionState"], isBlocked: data["authorization"] == "blocked", isInvitation: data["authorization"] == "unknown"));
|
||||
} else {
|
||||
contact.status = data["ConnectionState"];
|
||||
if (data["authorization"] != null) {
|
||||
contact.isInvitation = data["authorization"] == "unknown";
|
||||
contact.isBlocked = data["authorization"] == "blocked";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "NewMessageFromPeer":
|
||||
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"]).unreadMessages++;
|
||||
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"]).totalMessages++;
|
||||
break;
|
||||
case "AppError":
|
||||
print("New App Error: $data");
|
||||
error.handleUpdate(data["Data"]);
|
||||
|
|
|
@ -19,6 +19,9 @@ typedef StartCwtchFn = void Function(Pointer<Utf8> dir, int len, Pointer<Utf8> t
|
|||
typedef void_from_string_string_function = Void Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
|
||||
typedef VoidFromStringStringFn = void Function(Pointer<Utf8>, int, Pointer<Utf8>, int);
|
||||
|
||||
typedef void_from_string_string_string_function = Void Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
|
||||
typedef VoidFromStringStringStringFn = void Function(Pointer<Utf8>, int, Pointer<Utf8>, int, Pointer<Utf8>, int);
|
||||
|
||||
typedef access_cwtch_eventbus_function = Void Function();
|
||||
typedef NextEventFn = void Function();
|
||||
|
||||
|
@ -249,4 +252,49 @@ class CwtchFfi implements Cwtch {
|
|||
final utf8json = json.toNativeUtf8();
|
||||
SendAppBusEvent(utf8json, utf8json.length);
|
||||
}
|
||||
|
||||
@override
|
||||
// ignore: non_constant_identifier_names
|
||||
void AcceptContact(String profileOnion, String contactHandle) {
|
||||
var acceptContact = library.lookup<NativeFunction<string_string_to_void_function>>("c_AcceptContact");
|
||||
// ignore: non_constant_identifier_names
|
||||
final AcceptContact = acceptContact.asFunction<VoidFromStringStringFn>();
|
||||
final u1 = profileOnion.toNativeUtf8();
|
||||
final u2 = contactHandle.toNativeUtf8();
|
||||
AcceptContact(u1, u1.length, u2, u2.length);
|
||||
}
|
||||
|
||||
@override
|
||||
// ignore: non_constant_identifier_names
|
||||
void BlockContact(String profileOnion, String contactHandle) {
|
||||
var blockContact = library.lookup<NativeFunction<string_string_to_void_function>>("c_BlockContact");
|
||||
// ignore: non_constant_identifier_names
|
||||
final BlockContact = blockContact.asFunction<VoidFromStringStringFn>();
|
||||
final u1 = profileOnion.toNativeUtf8();
|
||||
final u2 = contactHandle.toNativeUtf8();
|
||||
BlockContact(u1, u1.length, u2, u2.length);
|
||||
}
|
||||
|
||||
@override
|
||||
// ignore: non_constant_identifier_names
|
||||
void DebugResetContact(String profileOnion, String contactHandle) {
|
||||
var debugResetContact = library.lookup<NativeFunction<string_string_to_void_function>>("c_DebugResetContact");
|
||||
// ignore: non_constant_identifier_names
|
||||
final DebugResetContact = debugResetContact.asFunction<VoidFromStringStringFn>();
|
||||
final u1 = profileOnion.toNativeUtf8();
|
||||
final u2 = contactHandle.toNativeUtf8();
|
||||
DebugResetContact(u1, u1.length, u2, u2.length);
|
||||
}
|
||||
|
||||
@override
|
||||
// ignore: non_constant_identifier_names
|
||||
void SendMessage(String profileOnion, String contactHandle, String message) {
|
||||
var sendMessage = library.lookup<NativeFunction<void_from_string_string_string_function>>("c_SendMessage");
|
||||
// ignore: non_constant_identifier_names
|
||||
final SendMessage = sendMessage.asFunction<VoidFromStringStringStringFn>();
|
||||
final u1 = profileOnion.toNativeUtf8();
|
||||
final u2 = contactHandle.toNativeUtf8();
|
||||
final u3 = message.toNativeUtf8();
|
||||
SendMessage(u1, u1.length, u2, u2.length, u3, u3.length);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,4 +118,24 @@ class CwtchGomobile implements Cwtch {
|
|||
|
||||
@override
|
||||
void dispose() => {};
|
||||
|
||||
@override
|
||||
void AcceptContact(String profileOnion, String contactHandle) {
|
||||
cwtchPlatform.invokeMethod("AcceptContact", {"ProfileOnion": profileOnion, "handle": contactHandle});
|
||||
}
|
||||
|
||||
@override
|
||||
void BlockContact(String profileOnion, String contactHandle) {
|
||||
cwtchPlatform.invokeMethod("BlockContact", {"ProfileOnion": profileOnion, "handle": contactHandle});
|
||||
}
|
||||
|
||||
@override
|
||||
void DebugResetContact(String profileOnion, String contactHandle) {
|
||||
cwtchPlatform.invokeMethod("DebugResetContact", {"ProfileOnion": profileOnion, "handle": contactHandle});
|
||||
}
|
||||
|
||||
@override
|
||||
void SendMessage(String profileOnion, String contactHandle, String message) {
|
||||
cwtchPlatform.invokeMethod("SendMessage", {"ProfileOnion": profileOnion, "handle": contactHandle, "message": message});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -138,6 +138,7 @@ class ProfileInfoState extends ChangeNotifier {
|
|||
print("decoding " + contactsJson);
|
||||
List<dynamic> contacts = jsonDecode(contactsJson);
|
||||
this._contacts.addAll(contacts.map((contact) {
|
||||
print(contact["onion"]+" "+contact["picture"]+": "+contact["authorization"]+" -> " + (contact["authorization"] == "unknown" ? "invite" : "non-invite"));
|
||||
return ContactInfoState(
|
||||
profileOnion: this.onion,
|
||||
onion: contact["onion"],
|
||||
|
@ -145,6 +146,7 @@ class ProfileInfoState extends ChangeNotifier {
|
|||
status: contact["status"],
|
||||
imagePath: contact["picture"],
|
||||
isBlocked: contact["authorization"] == "blocked",
|
||||
isInvitation: contact["authorization"] == "unknown",
|
||||
savePeerHistory: contact["saveConversationHistory"],
|
||||
numMessages: contact["numMessages"],
|
||||
numUnread: contact["numUnread"]);
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_app/views/peersettingsview.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
@ -31,13 +33,20 @@ class _MessageViewState extends State<MessageView> {
|
|||
IconButton(icon: Icon(Icons.list), onPressed: _pushContactSettings),
|
||||
IconButton(icon: Icon(Icons.push_pin), onPressed: _pushContactSettings),
|
||||
IconButton(icon: Icon(Icons.settings), onPressed: _pushContactSettings),
|
||||
IconButton(icon: Icon(Icons.bug_report_outlined), onPressed: _debugResetContact),
|
||||
],
|
||||
),
|
||||
body: MessageList(),
|
||||
body: Padding(padding: EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 108.0), child: MessageList()),
|
||||
bottomSheet: _buildComposeBox(),
|
||||
);
|
||||
}
|
||||
|
||||
void _debugResetContact() {
|
||||
Provider.of<FlwtchState>(context, listen: false).cwtch.DebugResetContact(
|
||||
Provider.of<ContactInfoState>(context, listen: false).profileOnion,
|
||||
Provider.of<ContactInfoState>(context, listen: false).onion);
|
||||
}
|
||||
|
||||
void _pushContactSettings() {
|
||||
Navigator.of(context).push(MaterialPageRoute<void>(
|
||||
builder: (BuildContext bcontext) {
|
||||
|
@ -57,9 +66,13 @@ class _MessageViewState extends State<MessageView> {
|
|||
}
|
||||
|
||||
void _sendMessage() {
|
||||
//ChatMessage cm = new ChatMessage(o: 1, d: ctrlrCompose.value.text);
|
||||
//todo: merge: Provider.of<FlwtchState>(context).cwtch.SendMessage(widget.profile.onion, widget.conversationHandle, jsonEncode(cm));
|
||||
ChatMessage cm = new ChatMessage(o: 1, d: ctrlrCompose.value.text);
|
||||
Provider.of<FlwtchState>(context, listen:false).cwtch.SendMessage(
|
||||
Provider.of<ContactInfoState>(context, listen:false).profileOnion,
|
||||
Provider.of<ContactInfoState>(context, listen:false).onion,
|
||||
jsonEncode(cm));
|
||||
ctrlrCompose.clear();
|
||||
Provider.of<ContactInfoState>(context, listen:false).totalMessages++;
|
||||
}
|
||||
|
||||
Widget _buildComposeBox() {
|
||||
|
|
|
@ -35,10 +35,12 @@ class _ContactRowState extends State<ContactRow> {
|
|||
),
|
||||
),
|
||||
trailing: contact.isInvitation != null && contact.isInvitation
|
||||
? Column(children: <Widget>[Icon(Icons.favorite, color: Opaque.current().mainTextColor()), Icon(Icons.delete, color: Opaque.current().mainTextColor())])
|
||||
: Text("99+"), //(nb: Icons.create is a pencil and we use it for "edit", not create)
|
||||
? Wrap(direction: Axis.vertical, children: <Widget>[
|
||||
IconButton(padding: EdgeInsets.zero, iconSize: 16, icon: Icon(Icons.favorite, color: Opaque.current().mainTextColor()), onPressed: _btnApprove,),
|
||||
IconButton(padding: EdgeInsets.zero, iconSize: 16, icon: Icon(Icons.delete, color: Opaque.current().mainTextColor()), onPressed: _btnReject,)])
|
||||
: Text(contact.unreadMessages.toString()), //(nb: Icons.create is a pencil and we use it for "edit", not create)
|
||||
title: Text(
|
||||
contact.nickname,
|
||||
(contact.isInvitation ? "invite " : "non-invite ") + (contact.isBlocked ? "blokt" : "nonblokt"),//contact.nickname,
|
||||
style: Provider.of<FlwtchState>(context).biggerFont,
|
||||
),
|
||||
subtitle: Text(contact.status),
|
||||
|
@ -69,4 +71,16 @@ class _ContactRowState extends State<ContactRow> {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _btnApprove() {
|
||||
Provider.of<FlwtchState>(context, listen: false).cwtch.AcceptContact(
|
||||
Provider.of<ContactInfoState>(context, listen: false).profileOnion,
|
||||
Provider.of<ContactInfoState>(context, listen: false).onion);
|
||||
}
|
||||
|
||||
void _btnReject() {
|
||||
Provider.of<FlwtchState>(context, listen: false).cwtch.BlockContact(
|
||||
Provider.of<ContactInfoState>(context, listen: false).profileOnion,
|
||||
Provider.of<ContactInfoState>(context, listen: false).onion);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../model.dart';
|
||||
|
@ -10,9 +11,25 @@ class MessageList extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _MessageListState extends State<MessageList> {
|
||||
ScrollController ctrlr1 = ScrollController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => _scrollToBottom(true));
|
||||
}
|
||||
|
||||
void _scrollToBottom(bool force) {
|
||||
if (force || ctrlr1.position.pixels >= ctrlr1.position.maxScrollExtent - 3) {
|
||||
ctrlr1.jumpTo(ctrlr1.position.maxScrollExtent);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext outerContext) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => _scrollToBottom(false));
|
||||
return ListView.builder(
|
||||
controller: ctrlr1,
|
||||
itemCount: Provider.of<ContactInfoState>(context).totalMessages,
|
||||
itemBuilder: (context, index) {
|
||||
return MessageBubble(
|
||||
|
|
Loading…
Reference in New Issue