Fixup Acks / Message Keys
continuous-integration/drone/pr Build is pending
Details
continuous-integration/drone/pr Build is pending
Details
This commit is contained in:
parent
c9319d32d0
commit
995282fa04
|
@ -35,7 +35,7 @@ class CwtchNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleMessage(String type, dynamic data) {
|
void handleMessage(String type, dynamic data) {
|
||||||
EnvironmentConfig.debugLog("NewEvent $type $data");
|
//EnvironmentConfig.debugLog("NewEvent $type $data");
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "CwtchStarted":
|
case "CwtchStarted":
|
||||||
appState.SetCwtchInit();
|
appState.SetCwtchInit();
|
||||||
|
@ -144,7 +144,7 @@ class CwtchNotifier {
|
||||||
profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.newMarker++;
|
profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.newMarker++;
|
||||||
}
|
}
|
||||||
profileCN.getProfile(data["ProfileOnion"])?.contactList.updateLastMessageTime(identifier, DateTime.now());
|
profileCN.getProfile(data["ProfileOnion"])?.contactList.updateLastMessageTime(identifier, DateTime.now());
|
||||||
profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.updateMessageCache(identifier, messageID, timestamp, senderHandle, senderImage, data["Data"], "");
|
profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.updateMessageCache(identifier, messageID, timestamp, senderHandle, senderImage, data["Data"]);
|
||||||
profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.totalMessages++;
|
profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.totalMessages++;
|
||||||
|
|
||||||
// We only ever see messages from authenticated peers.
|
// We only ever see messages from authenticated peers.
|
||||||
|
@ -170,17 +170,17 @@ class CwtchNotifier {
|
||||||
if (key == null) break;
|
if (key == null) break;
|
||||||
try {
|
try {
|
||||||
var message = Provider.of<MessageMetadata>(key.currentContext!, listen: false);
|
var message = Provider.of<MessageMetadata>(key.currentContext!, listen: false);
|
||||||
if (message == null) break;
|
message.ackd = true;
|
||||||
|
|
||||||
// We only ever see acks from authenticated peers.
|
// We only ever see acks from authenticated peers.
|
||||||
// If the contact is marked as offline then override this - can happen when the contact is removed from the front
|
// If the contact is marked as offline then override this - can happen when the contact is removed from the front
|
||||||
// end during syncing.
|
// end during syncing.
|
||||||
if (profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(conversation)!.isOnline() == false) {
|
if (profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(conversation)!.isOnline() == false) {
|
||||||
profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(conversation)!.status = "Authenticated";
|
profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(conversation)!.status = "Authenticated";
|
||||||
}
|
}
|
||||||
message.ackd = true;
|
profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(conversation)!.ackCache(messageID);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// ignore, we received an ack for a message that hasn't loaded onto the screen yet...
|
// ignore, most likely cause is the key got optimized out...
|
||||||
// the protocol was faster than the ui....yay?
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "NewMessageFromGroup":
|
case "NewMessageFromGroup":
|
||||||
|
@ -194,11 +194,7 @@ class CwtchNotifier {
|
||||||
|
|
||||||
// Only bother to do anything if we know about the group and the provided index is greater than our current total...
|
// Only bother to do anything if we know about the group and the provided index is greater than our current total...
|
||||||
if (currentTotal != null && idx >= currentTotal) {
|
if (currentTotal != null && idx >= currentTotal) {
|
||||||
profileCN
|
profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.updateMessageCache(identifier, idx, timestampSent, senderHandle, senderImage, data["Data"]);
|
||||||
.getProfile(data["ProfileOnion"])
|
|
||||||
?.contactList
|
|
||||||
.getContact(identifier)!
|
|
||||||
.updateMessageCache(identifier, idx, timestampSent, senderHandle, senderImage, data["Data"], data["Signature"]);
|
|
||||||
profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.totalMessages++;
|
profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.totalMessages++;
|
||||||
|
|
||||||
//if not currently open
|
//if not currently open
|
||||||
|
|
|
@ -687,11 +687,16 @@ class ContactInfoState extends ChangeNotifier {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateMessageCache(int conversation, int messageID, DateTime timestamp, String senderHandle, String senderImage, String data, String signature) {
|
void updateMessageCache(int conversation, int messageID, DateTime timestamp, String senderHandle, String senderImage, String data) {
|
||||||
this.messageCache.insert(0, MessageCache(MessageMetadata(profileOnion, conversation, messageID, timestamp, senderHandle, senderImage, signature, {}, false, false), data));
|
this.messageCache.insert(0, MessageCache(MessageMetadata(profileOnion, conversation, messageID, timestamp, senderHandle, senderImage, "", {}, false, false), data));
|
||||||
}
|
}
|
||||||
|
|
||||||
void bumpMessageCache() {
|
void bumpMessageCache() {
|
||||||
this.messageCache.insert(0, null);
|
this.messageCache.insert(0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ackCache(int messageID) {
|
||||||
|
this.messageCache.firstWhere((element) => element?.metadata.messageID == messageID)?.metadata.ackd = true;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,8 +58,8 @@ Message compileOverlay(MessageMetadata metadata, String messageData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Message> messageHandler(BuildContext context, String profileOnion, int conversationIdentifier, int index, {bool byID = false}) {
|
Future<Message> messageHandler(BuildContext context, String profileOnion, int conversationIdentifier, int index, {bool byID = false}) {
|
||||||
var cache = Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(conversationIdentifier)!.messageCache;
|
var cache = Provider.of<ProfileInfoState>(context).contactList.getContact(conversationIdentifier)?.messageCache;
|
||||||
if (cache.length > index) {
|
if (cache != null && cache.length > index) {
|
||||||
if (cache[index] != null) {
|
if (cache[index] != null) {
|
||||||
return Future.value(compileOverlay(cache[index]!.metadata, cache[index]!.wrapper));
|
return Future.value(compileOverlay(cache[index]!.metadata, cache[index]!.wrapper));
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ class FileMessage extends Message {
|
||||||
return MessageRow(MalformedBubble());
|
return MessageRow(MalformedBubble());
|
||||||
}
|
}
|
||||||
|
|
||||||
return MessageRow(FileBubble(nameSuggestion, rootHash, nonce, fileSize));
|
return MessageRow(FileBubble(nameSuggestion, rootHash, nonce, fileSize), key: key);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,11 +37,10 @@ class InviteMessage extends Message {
|
||||||
inviteTarget = jsonObj['GroupID'];
|
inviteTarget = jsonObj['GroupID'];
|
||||||
inviteNick = jsonObj['GroupName'];
|
inviteNick = jsonObj['GroupName'];
|
||||||
} else {
|
} else {
|
||||||
return MessageRow(MalformedBubble());
|
return MessageRow(MalformedBubble(), key: key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var lrt = Provider.of<ContactInfoState>(bcontext).lastMessageTime;
|
return MessageRow(InvitationBubble(overlay, inviteTarget, inviteNick, invite), key: key);
|
||||||
return MessageRow(InvitationBubble(overlay, inviteTarget, inviteNick, invite));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,9 @@ class MalformedMessage extends Message {
|
||||||
@override
|
@override
|
||||||
Widget getWidget(BuildContext context, Key key) {
|
Widget getWidget(BuildContext context, Key key) {
|
||||||
return ChangeNotifierProvider.value(
|
return ChangeNotifierProvider.value(
|
||||||
key: key,
|
|
||||||
value: this.metadata,
|
value: this.metadata,
|
||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
return MessageRow(MalformedBubble());
|
return MessageRow(MalformedBubble(), key: key);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,15 +89,16 @@ class QuotedMessage extends Message {
|
||||||
});
|
});
|
||||||
|
|
||||||
return ChangeNotifierProvider.value(
|
return ChangeNotifierProvider.value(
|
||||||
key: key,
|
|
||||||
value: this.metadata,
|
value: this.metadata,
|
||||||
builder: (bcontext, child) {
|
builder: (bcontext, child) {
|
||||||
return MessageRow(QuotedMessageBubble(message["body"], quotedMessage.then((LocallyIndexedMessage? localIndex) {
|
return MessageRow(
|
||||||
if (localIndex != null) {
|
QuotedMessageBubble(message["body"], quotedMessage.then((LocallyIndexedMessage? localIndex) {
|
||||||
return messageHandler(context, metadata.profileOnion, metadata.conversationIdentifier, localIndex.index);
|
if (localIndex != null) {
|
||||||
}
|
return messageHandler(context, metadata.profileOnion, metadata.conversationIdentifier, localIndex.index);
|
||||||
return MalformedMessage(this.metadata);
|
}
|
||||||
})));
|
return MalformedMessage(this.metadata);
|
||||||
|
})),
|
||||||
|
key: key);
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return MalformedMessage(this.metadata).getWidget(context, key);
|
return MalformedMessage(this.metadata).getWidget(context, key);
|
||||||
|
|
|
@ -33,13 +33,12 @@ class TextMessage extends Message {
|
||||||
@override
|
@override
|
||||||
Widget getWidget(BuildContext context, Key key) {
|
Widget getWidget(BuildContext context, Key key) {
|
||||||
return ChangeNotifierProvider.value(
|
return ChangeNotifierProvider.value(
|
||||||
key: key,
|
|
||||||
value: this.metadata,
|
value: this.metadata,
|
||||||
builder: (bcontext, child) {
|
builder: (bcontext, child) {
|
||||||
var lrt = Provider.of<ContactInfoState>(bcontext).lastMessageTime;
|
return MessageRow(
|
||||||
// var key = Provider.of<ContactInfoState>(bcontext).getMessageKey(this.metadata.conversationIdentifier, this.metadata.messageID, lrt);
|
MessageBubble(this.content),
|
||||||
|
key: key,
|
||||||
return MessageRow(MessageBubble(this.content));
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,7 +204,9 @@ class MessageRowState extends State<MessageRow> with SingleTickerProviderStateMi
|
||||||
children: widgetRow,
|
children: widgetRow,
|
||||||
)))));
|
)))));
|
||||||
var mark = Provider.of<ContactInfoState>(context).newMarker;
|
var mark = Provider.of<ContactInfoState>(context).newMarker;
|
||||||
if (mark > 0 && Provider.of<ContactInfoState>(context).messageCache[mark]?.metadata.messageID == Provider.of<MessageMetadata>(context).messageID) {
|
if (mark > 0 &&
|
||||||
|
Provider.of<ContactInfoState>(context).messageCache.length > mark &&
|
||||||
|
Provider.of<ContactInfoState>(context).messageCache[mark]?.metadata.messageID == Provider.of<MessageMetadata>(context).messageID) {
|
||||||
return Column(crossAxisAlignment: fromMe ? CrossAxisAlignment.end : CrossAxisAlignment.start, children: [Align(alignment: Alignment.center, child: _bubbleNew()), mr]);
|
return Column(crossAxisAlignment: fromMe ? CrossAxisAlignment.end : CrossAxisAlignment.start, children: [Align(alignment: Alignment.center, child: _bubbleNew()), mr]);
|
||||||
} else {
|
} else {
|
||||||
return mr;
|
return mr;
|
||||||
|
|
Loading…
Reference in New Issue