Final Ack Pass
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Sarah Jamie Lewis 2021-05-05 15:02:31 -07:00
parent a842691391
commit 04b498e3b8
3 changed files with 41 additions and 8 deletions

View File

@ -62,12 +62,23 @@ class CwtchNotifier {
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"]).totalMessages++;
profileCN.getProfile(data["ProfileOnion"]).contactList.updateLastMessageTime(data["RemotePeer"], DateTime.now());
break;
case "PeerAcknowledgement":
// We don't use these anymore, IndexedAcknowledgement is more suited to the UI front end...
break;
case "IndexedAcknowledgement":
var idx = int.parse(data["Index"]);
if (idx < 0) break;
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);
if (key == null) break;
Provider.of<MessageState>(key.currentContext, listen: false).ackd = true;
try {
var message = Provider.of<MessageState>(key.currentContext, listen: false);
if (message == null) break;
message.ackd = true;
} catch (e) {
// ignore, we received an ack for a message that hasn't loaded onto the screen yet...
// the protocol was faster than the ui....yay?
}
break;
case "NewMessageFromGroup":
if (data["ProfileOnion"] != data["RemotePeer"]) {
@ -77,7 +88,16 @@ class CwtchNotifier {
profileCN.getProfile(data["ProfileOnion"]).contactList.updateLastMessageTime(data["GroupID"], DateTime.now());
} else {
// from me (already displayed - do not update counter)
//todo: update ack - once group messages
var idx = data["Signature"];
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);
if (message == null) break;
message.ackd = true;
} catch (e) {
// ignore, we likely have an old key that has been replaced with an actual signature
}
}
break;
case "AppError":

View File

@ -233,7 +233,7 @@ class ContactInfoState extends ChangeNotifier {
int _unreadMessages = 0;
int _totalMessages = 0;
DateTime _lastMessageTime;
Map<int, GlobalKey> keys;
Map<String, GlobalKey> keys;
// todo: a nicer way to model contacts, groups and other "entities"
bool _isGroup;
@ -265,7 +265,7 @@ class ContactInfoState extends ChangeNotifier {
this._savePeerHistory = savePeerHistory;
this._lastMessageTime = lastMessageTime;
this._server = server;
keys = Map<int, GlobalKey>();
keys = Map<String, GlobalKey>();
}
get nickname => this._nickname;
@ -340,7 +340,7 @@ class ContactInfoState extends ChangeNotifier {
}
}
GlobalKey<MessageBubbleState> getMessageKey(int index) {
GlobalKey<MessageBubbleState> getMessageKey(String index) {
if (keys[index] == null) {
keys[index] = GlobalKey<MessageBubbleState>();
}
@ -356,6 +356,7 @@ class MessageState extends ChangeNotifier {
DateTime _timestamp;
String _senderOnion;
String _senderImage;
String _signature = "";
bool _ackd = false;
bool _loaded = false;
@ -374,6 +375,7 @@ class MessageState extends ChangeNotifier {
get senderOnion => this._senderOnion;
get senderImage => this._senderImage;
get loaded => this._loaded;
get signature => this._signature;
set ackd(bool newVal) {
this._ackd = newVal;
@ -397,6 +399,12 @@ class MessageState extends ChangeNotifier {
this._timestamp = DateTime.tryParse(messageWrapper['Timestamp']);
this._senderOnion = messageWrapper['PeerID'];
this._senderImage = messageWrapper['ContactImage'];
// If this is a group, store the signature
if (contactHandle.length == 32) {
this._signature = messageWrapper['Signature'];
}
this._loaded = true;
//update ackd last as it's changenotified
this._ackd = messageWrapper['Acknowledged'];

View File

@ -66,7 +66,12 @@ class _MessageListState extends State<MessageList> {
contactHandle: Provider.of<ContactInfoState>(outerContext).onion,
messageIndex: index,
),
child: MessageRow(key: Provider.of<ContactInfoState>(outerContext).getMessageKey(index)));
builder: (bcontext, child) {
String idx = Provider.of<ContactInfoState>(outerContext).isGroup == true && Provider.of<MessageState>(bcontext).signature.isEmpty == false
? Provider.of<MessageState>(bcontext).signature
: index.toString();
return MessageRow(key: Provider.of<ContactInfoState>(bcontext).getMessageKey(idx));
});
},
),
)));