New Cwtch Library Integration #258

Merged
sarah merged 14 commits from cwtch-lib-integration into trunk 2021-12-10 21:02:02 +00:00
9 changed files with 35 additions and 34 deletions
Showing only changes of commit 995282fa04 - Show all commits

View File

@ -35,7 +35,7 @@ class CwtchNotifier {
}
void handleMessage(String type, dynamic data) {
EnvironmentConfig.debugLog("NewEvent $type $data");
//EnvironmentConfig.debugLog("NewEvent $type $data");
switch (type) {
sarah marked this conversation as resolved
Review

?

?
case "CwtchStarted":
appState.SetCwtchInit();
@ -144,7 +144,7 @@ class CwtchNotifier {
profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.newMarker++;
}
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++;
// We only ever see messages from authenticated peers.
@ -170,17 +170,17 @@ class CwtchNotifier {
if (key == null) break;
try {
var message = Provider.of<MessageMetadata>(key.currentContext!, listen: false);
if (message == null) break;
message.ackd = true;
// 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
// end during syncing.
if (profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(conversation)!.isOnline() == false) {
profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(conversation)!.status = "Authenticated";
}
message.ackd = true;
profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(conversation)!.ackCache(messageID);
} 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?
// ignore, most likely cause is the key got optimized out...
}
break;
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...
if (currentTotal != null && idx >= currentTotal) {
profileCN
.getProfile(data["ProfileOnion"])
?.contactList
.getContact(identifier)!
.updateMessageCache(identifier, idx, timestampSent, senderHandle, senderImage, data["Data"], data["Signature"]);
profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.updateMessageCache(identifier, idx, timestampSent, senderHandle, senderImage, data["Data"]);
profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.totalMessages++;
//if not currently open

View File

@ -687,11 +687,16 @@ class ContactInfoState extends ChangeNotifier {
return ret;
}
void updateMessageCache(int conversation, int messageID, DateTime timestamp, String senderHandle, String senderImage, String data, String signature) {
this.messageCache.insert(0, MessageCache(MessageMetadata(profileOnion, conversation, messageID, timestamp, senderHandle, senderImage, signature, {}, false, false), data));
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, "", {}, false, false), data));
}
void bumpMessageCache() {
sarah marked this conversation as resolved
Review

ideally internal. the public setter for totalMessages can call, and updateMessageCaches should internally inc totalMessages

ideally internal. the public setter for totalMessages can call, and updateMessageCaches should internally inc totalMessages
this.messageCache.insert(0, null);
}
void ackCache(int messageID) {
this.messageCache.firstWhere((element) => element?.metadata.messageID == messageID)?.metadata.ackd = true;
notifyListeners();
}
}

View File

@ -58,8 +58,8 @@ Message compileOverlay(MessageMetadata metadata, String messageData) {
}
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;
if (cache.length > index) {
var cache = Provider.of<ProfileInfoState>(context).contactList.getContact(conversationIdentifier)?.messageCache;
if (cache != null && cache.length > index) {
if (cache[index] != null) {
return Future.value(compileOverlay(cache[index]!.metadata, cache[index]!.wrapper));
}

View File

@ -35,7 +35,7 @@ class FileMessage extends Message {
return MessageRow(MalformedBubble());
}
return MessageRow(FileBubble(nameSuggestion, rootHash, nonce, fileSize));
return MessageRow(FileBubble(nameSuggestion, rootHash, nonce, fileSize), key: key);
});
}

View File

@ -37,11 +37,10 @@ class InviteMessage extends Message {
inviteTarget = jsonObj['GroupID'];
inviteNick = jsonObj['GroupName'];
} else {
return MessageRow(MalformedBubble());
return MessageRow(MalformedBubble(), key: key);
}
}
var lrt = Provider.of<ContactInfoState>(bcontext).lastMessageTime;
return MessageRow(InvitationBubble(overlay, inviteTarget, inviteNick, invite));
return MessageRow(InvitationBubble(overlay, inviteTarget, inviteNick, invite), key: key);
});
}

View File

@ -11,10 +11,9 @@ class MalformedMessage extends Message {
@override
Widget getWidget(BuildContext context, Key key) {
return ChangeNotifierProvider.value(
key: key,
value: this.metadata,
builder: (context, child) {
return MessageRow(MalformedBubble());
return MessageRow(MalformedBubble(), key: key);
});
}

View File

@ -89,15 +89,16 @@ class QuotedMessage extends Message {
});
return ChangeNotifierProvider.value(
key: key,
value: this.metadata,
builder: (bcontext, child) {
return MessageRow(QuotedMessageBubble(message["body"], quotedMessage.then((LocallyIndexedMessage? localIndex) {
if (localIndex != null) {
return messageHandler(context, metadata.profileOnion, metadata.conversationIdentifier, localIndex.index);
}
return MalformedMessage(this.metadata);
})));
return MessageRow(
QuotedMessageBubble(message["body"], quotedMessage.then((LocallyIndexedMessage? localIndex) {
if (localIndex != null) {
return messageHandler(context, metadata.profileOnion, metadata.conversationIdentifier, localIndex.index);
}
return MalformedMessage(this.metadata);
})),
key: key);
});
} catch (e) {
return MalformedMessage(this.metadata).getWidget(context, key);

View File

@ -33,13 +33,12 @@ class TextMessage extends Message {
@override
Widget getWidget(BuildContext context, Key key) {
return ChangeNotifierProvider.value(
key: key,
value: this.metadata,
builder: (bcontext, child) {
var lrt = Provider.of<ContactInfoState>(bcontext).lastMessageTime;
// var key = Provider.of<ContactInfoState>(bcontext).getMessageKey(this.metadata.conversationIdentifier, this.metadata.messageID, lrt);
return MessageRow(MessageBubble(this.content));
return MessageRow(
MessageBubble(this.content),
key: key,
);
});
}
}

View File

@ -204,7 +204,9 @@ class MessageRowState extends State<MessageRow> with SingleTickerProviderStateMi
children: widgetRow,
)))));
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]);
} else {
return mr;