Fix invite flow

This commit is contained in:
Sarah Jamie Lewis 2021-05-26 17:48:55 -07:00
parent 07f643588a
commit 4fc8831697
5 changed files with 18 additions and 17 deletions

View File

@ -49,7 +49,7 @@ class CwtchNotifier {
));
break;
case "PeerStateChange":
ContactInfoState contact = profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"]);
ContactInfoState? contact = profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"]);
if (contact != null) {
if (data["ConnectionState"] != null) {
contact.status = data["ConnectionState"];
@ -64,8 +64,8 @@ class CwtchNotifier {
break;
case "NewMessageFromPeer":
notificationManager.notify("New Message From Peer!");
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"]).unreadMessages++;
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"]).totalMessages++;
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"])!.unreadMessages++;
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"])!.totalMessages++;
profileCN.getProfile(data["ProfileOnion"]).contactList.updateLastMessageTime(data["RemotePeer"], DateTime.now());
break;
case "PeerAcknowledgement":
@ -75,7 +75,7 @@ class CwtchNotifier {
var idx = data["Index"];
// We return -1 for protocol message acks if there is no message
if (idx == "-1") break;
var key = profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"]).getMessageKey(idx);
var key = profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"])!.getMessageKey(idx);
if (key == null) break;
try {
var message = Provider.of<MessageState>(key.currentContext!, listen: false);
@ -89,13 +89,13 @@ class CwtchNotifier {
case "NewMessageFromGroup":
if (data["ProfileOnion"] != data["RemotePeer"]) {
//not from me
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["GroupID"]).unreadMessages++;
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["GroupID"]).totalMessages++;
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["GroupID"])!.unreadMessages++;
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["GroupID"])!.totalMessages++;
profileCN.getProfile(data["ProfileOnion"]).contactList.updateLastMessageTime(data["GroupID"], DateTime.now());
} else {
// from me (already displayed - do not update counter)
var idx = data["Signature"];
var key = profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["GroupID"]).getMessageKey(idx);
var key = profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["GroupID"])!.getMessageKey(idx);
if (key == null) break;
try {
var message = Provider.of<MessageState>(key.currentContext!, listen: false);
@ -109,7 +109,7 @@ class CwtchNotifier {
case "IndexedFailure":
print("IndexedFailure: $data");
var idx = data["Index"];
var key = profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"]).getMessageKey(idx);
var key = profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"])!.getMessageKey(idx);
try {
var message = Provider.of<MessageState>(key.currentContext!, listen: false);
message.error = true;
@ -121,7 +121,7 @@ class CwtchNotifier {
// from me (already displayed - do not update counter)
print("SendMessageToGroupError: $data");
var idx = data["Signature"];
var key = profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["GroupID"]).getMessageKey(idx);
var key = profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["GroupID"])!.getMessageKey(idx);
if (key == null) break;
try {
var message = Provider.of<MessageState>(key.currentContext!, listen: false);
@ -174,7 +174,7 @@ class CwtchNotifier {
break;
case "AcceptGroupInvite":
print("accept group invite: $data");
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["GroupID"]).isInvitation = false;
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["GroupID"])!.isInvitation = false;
profileCN.getProfile(data["ProfileOnion"]).contactList.updateLastMessageTime(data["GroupID"], DateTime.now());
break;
case "ServerStateChange":

View File

@ -118,9 +118,9 @@ class ContactListState extends ChangeNotifier {
List<ContactInfoState> get contacts => _contacts.sublist(0); //todo: copy?? dont want caller able to bypass changenotifier
ContactInfoState getContact(String onion) {
ContactInfoState? getContact(String onion) {
int idx = _contacts.indexWhere((element) => element.onion == onion);
return idx >= 0 ? _contacts[idx] : ContactInfoState("not found", "not found");
return idx >= 0 ? _contacts[idx] : null;
}
}

View File

@ -87,7 +87,7 @@ class _ContactRowState extends State<ContactRow> {
}
void _pushMessageView(String handle) {
Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(handle).unreadMessages = 0;
Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(handle)!.unreadMessages = 0;
var profileOnion = Provider.of<ProfileInfoState>(context, listen: false).onion;
Navigator.of(context).push(
MaterialPageRoute<void>(
@ -96,7 +96,7 @@ class _ContactRowState extends State<ContactRow> {
return MultiProvider(
providers: [
ChangeNotifierProvider.value(value: profile),
ChangeNotifierProvider.value(value: profile.contactList.getContact(handle)),
ChangeNotifierProvider.value(value: profile.contactList.getContact(handle)!),
],
builder: (context, child) => MessageView(),
);

View File

@ -37,7 +37,7 @@ class InvitationBubbleState extends State<InvitationBubble> {
var senderDisplayStr = "";
if (Provider.of<MessageState>(context).senderOnion != null) {
var contact = Provider.of<ProfileInfoState>(context).contactList.getContact(Provider.of<MessageState>(context).senderOnion);
senderDisplayStr = contact.nickname;
senderDisplayStr = contact!.nickname;
}
var wdgSender = Center(
widthFactor: 1,

View File

@ -26,10 +26,11 @@ class MessageBubbleState extends State<MessageBubble> {
prettyDate = DateFormat.yMd().add_jm().format(messageDate.toLocal());
}
// If the sender is not us, then we want to give them a nickname...
var senderDisplayStr = "";
if (Provider.of<MessageState>(context).senderOnion != null) {
if (!fromMe && Provider.of<MessageState>(context).senderOnion != null) {
var contact = Provider.of<ProfileInfoState>(context).contactList.getContact(Provider.of<MessageState>(context).senderOnion);
senderDisplayStr = contact.nickname;
senderDisplayStr = contact!.nickname;
}
var wdgSender = SelectableText(senderDisplayStr,
style: TextStyle(fontSize: 9.0, color: fromMe ? Provider.of<Settings>(context).theme.messageFromMeTextColor() : Provider.of<Settings>(context).theme.messageFromOtherTextColor()));