add notifyListen to newMessage in contact; format
continuous-integration/drone/pr Build is pending Details

This commit is contained in:
Dan Ballard 2022-01-20 13:37:09 -05:00
parent 589bc4c36c
commit 889d398343
8 changed files with 30 additions and 49 deletions

View File

@ -146,7 +146,17 @@ class CwtchNotifier {
String? contenthash = data['ContentHash']; String? contenthash = data['ContentHash'];
var selectedConversation = appState.selectedProfile == data["ProfileOnion"] && appState.selectedConversation == identifier; var selectedConversation = appState.selectedProfile == data["ProfileOnion"] && appState.selectedConversation == identifier;
profileCN.getProfile(data["ProfileOnion"])?.contactList.newMessage(identifier, messageID, timestamp, senderHandle, senderImage, isAuto, data["Data"], contenthash, selectedConversation, ); profileCN.getProfile(data["ProfileOnion"])?.contactList.newMessage(
identifier,
messageID,
timestamp,
senderHandle,
senderImage,
isAuto,
data["Data"],
contenthash,
selectedConversation,
);
break; break;
case "PeerAcknowledgement": case "PeerAcknowledgement":
@ -188,7 +198,6 @@ class CwtchNotifier {
String? contenthash = data['ContentHash']; String? contenthash = data['ContentHash'];
var selectedConversation = appState.selectedProfile == data["ProfileOnion"] && appState.selectedConversation == identifier; var selectedConversation = appState.selectedProfile == data["ProfileOnion"] && appState.selectedConversation == identifier;
// 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) {
// TODO: There are 2 timestamps associated with a new group message - time sent and time received. // TODO: There are 2 timestamps associated with a new group message - time sent and time received.

View File

@ -68,4 +68,4 @@ class AppState extends ChangeNotifier {
} }
bool isLandscape(BuildContext c) => MediaQuery.of(c).size.width > MediaQuery.of(c).size.height; bool isLandscape(BuildContext c) => MediaQuery.of(c).size.width > MediaQuery.of(c).size.height;
} }

View File

@ -220,6 +220,7 @@ class ContactInfoState extends ChangeNotifier {
if (isOnline() == false) { if (isOnline() == false) {
status = "Authenticated"; status = "Authenticated";
} }
notifyListeners();
} }
void ackCache(int messageID) { void ackCache(int messageID) {

View File

@ -127,4 +127,4 @@ class ContactListState extends ChangeNotifier {
getContact(identifier)?.newMessage(identifier, messageID, timestamp, senderHandle, senderImage, isAuto, data, contenthash, selectedConversation); getContact(identifier)?.newMessage(identifier, messageID, timestamp, senderHandle, senderImage, isAuto, data, contenthash, selectedConversation);
updateLastMessageTime(identifier, DateTime.now()); updateLastMessageTime(identifier, DateTime.now());
} }
} }

View File

@ -74,14 +74,14 @@ Future<Message> messageHandler(BuildContext context, String profileOnion, int co
} }
// Hit cache // Hit cache
MessageInfo? messageInfo = getMessageInfoFromCache(context, profileOnion, conversationIdentifier, byIndex: byIndex, index: index, byID: byID, id: id, byHash: byHash, hash: hash); MessageInfo? messageInfo = getMessageInfoFromCache(context, profileOnion, conversationIdentifier, byIndex: byIndex, index: index, byID: byID, id: id, byHash: byHash, hash: hash);
if (messageInfo != null) { if (messageInfo != null) {
return Future.value(compileOverlay(messageInfo.metadata, messageInfo.wrapper)); return Future.value(compileOverlay(messageInfo.metadata, messageInfo.wrapper));
} }
// Fetch and Cache // Fetch and Cache
var messageInfoFuture = fetchAndCacheMessageInfo(context, profileOnion, conversationIdentifier, byIndex: byIndex, index: index, byID: byID, id: id, byHash: byHash, hash: hash); var messageInfoFuture = fetchAndCacheMessageInfo(context, profileOnion, conversationIdentifier, byIndex: byIndex, index: index, byID: byID, id: id, byHash: byHash, hash: hash);
return messageInfoFuture.then( (MessageInfo? messageInfo) { return messageInfoFuture.then((MessageInfo? messageInfo) {
if (messageInfo != null) { if (messageInfo != null) {
return compileOverlay(messageInfo.metadata, messageInfo.wrapper); return compileOverlay(messageInfo.metadata, messageInfo.wrapper);
} else { } else {
@ -91,7 +91,7 @@ Future<Message> messageHandler(BuildContext context, String profileOnion, int co
} }
MessageInfo? getMessageInfoFromCache(BuildContext context, String profileOnion, int conversationIdentifier, MessageInfo? getMessageInfoFromCache(BuildContext context, String profileOnion, int conversationIdentifier,
{bool byIndex = false, int? index, bool byID = false, int? id, bool byHash = false, String? hash}) { {bool byIndex = false, int? index, bool byID = false, int? id, bool byHash = false, String? hash}) {
// Hit cache // Hit cache
try { try {
var cache = Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(conversationIdentifier)?.messageCache; var cache = Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(conversationIdentifier)?.messageCache;
@ -116,26 +116,17 @@ MessageInfo? getMessageInfoFromCache(BuildContext context, String profileOnion,
} }
Future<MessageInfo?> fetchAndCacheMessageInfo(BuildContext context, String profileOnion, int conversationIdentifier, Future<MessageInfo?> fetchAndCacheMessageInfo(BuildContext context, String profileOnion, int conversationIdentifier,
{bool byIndex = false, int? index, bool byID = false, int? id, bool byHash = false, String? hash}) { {bool byIndex = false, int? index, bool byID = false, int? id, bool byHash = false, String? hash}) {
// Load and cache // Load and cache
try { try {
Future<dynamic> rawMessageEnvelopeFuture; Future<dynamic> rawMessageEnvelopeFuture;
if (byID) { if (byID) {
rawMessageEnvelopeFuture = Provider rawMessageEnvelopeFuture = Provider.of<FlwtchState>(context, listen: false).cwtch.GetMessageByID(profileOnion, conversationIdentifier, id!);
.of<FlwtchState>(context, listen: false)
.cwtch
.GetMessageByID(profileOnion, conversationIdentifier, id!);
} else if (byHash) { } else if (byHash) {
rawMessageEnvelopeFuture = Provider rawMessageEnvelopeFuture = Provider.of<FlwtchState>(context, listen: false).cwtch.GetMessageByContentHash(profileOnion, conversationIdentifier, hash!);
.of<FlwtchState>(context, listen: false)
.cwtch
.GetMessageByContentHash(profileOnion, conversationIdentifier, hash!);
} else { } else {
rawMessageEnvelopeFuture = Provider rawMessageEnvelopeFuture = Provider.of<FlwtchState>(context, listen: false).cwtch.GetMessage(profileOnion, conversationIdentifier, index!);
.of<FlwtchState>(context, listen: false)
.cwtch
.GetMessage(profileOnion, conversationIdentifier, index!);
} }
return rawMessageEnvelopeFuture.then((dynamic rawMessageEnvelope) { return rawMessageEnvelopeFuture.then((dynamic rawMessageEnvelope) {
@ -153,12 +144,7 @@ Future<MessageInfo?> fetchAndCacheMessageInfo(BuildContext context, String profi
if (messageWrapper['Message'] == null || messageWrapper['Message'] == '' || messageWrapper['Message'] == '{}') { if (messageWrapper['Message'] == null || messageWrapper['Message'] == '' || messageWrapper['Message'] == '{}') {
return Future.delayed(Duration(seconds: 2), () { return Future.delayed(Duration(seconds: 2), () {
print("Tail recursive call to messageHandler called. This should be a rare event. If you see multiples of this log over a short period of time please log it as a bug."); print("Tail recursive call to messageHandler called. This should be a rare event. If you see multiples of this log over a short period of time please log it as a bug.");
return fetchAndCacheMessageInfo(context, profileOnion, conversationIdentifier, byIndex: byIndex, return fetchAndCacheMessageInfo(context, profileOnion, conversationIdentifier, byIndex: byIndex, index: index, byID: byID, id: id, byHash: byHash, hash: hash).then((value) => value);
index: index,
byID: byID,
id: id,
byHash: byHash,
hash: hash).then((value) => value);
}); });
} }
@ -173,25 +159,10 @@ Future<MessageInfo?> fetchAndCacheMessageInfo(BuildContext context, String profi
var signature = messageWrapper['Signature']; var signature = messageWrapper['Signature'];
var contenthash = messageWrapper['ContentHash']; var contenthash = messageWrapper['ContentHash'];
var localIndex = messageWrapper['LocalIndex']; var localIndex = messageWrapper['LocalIndex'];
var metadata = MessageMetadata( var metadata = MessageMetadata(profileOnion, conversationIdentifier, messageID, timestamp, senderHandle, senderImage, signature, attributes, ackd, error, false);
profileOnion,
conversationIdentifier,
messageID,
timestamp,
senderHandle,
senderImage,
signature,
attributes,
ackd,
error,
false);
var messageInfo = new MessageInfo(metadata, messageWrapper['Message']); var messageInfo = new MessageInfo(metadata, messageWrapper['Message']);
var cache = Provider var cache = Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(conversationIdentifier)?.messageCache;
.of<ProfileInfoState>(context, listen: false)
.contactList
.getContact(conversationIdentifier)
?.messageCache;
if (cache != null) { if (cache != null) {
if (byID) { if (byID) {

View File

@ -26,6 +26,7 @@ class MessageCache {
} }
return cache[cacheByIndex[index]]; return cache[cacheByIndex[index]];
} }
MessageInfo? getByContentHash(String contenthash) => cache[cacheByHash[contenthash]]; MessageInfo? getByContentHash(String contenthash) => cache[cacheByHash[contenthash]];
void addNew(String profileOnion, int conversation, int messageID, DateTime timestamp, String senderHandle, String senderImage, bool isAuto, String data, String? contenthash) { void addNew(String profileOnion, int conversation, int messageID, DateTime timestamp, String senderHandle, String senderImage, bool isAuto, String data, String? contenthash) {
@ -54,4 +55,4 @@ class MessageCache {
void ackCache(int messageID) { void ackCache(int messageID) {
cache[messageID]?.metadata.ackd = true; cache[messageID]?.metadata.ackd = true;
} }
} }

View File

@ -59,8 +59,7 @@ class QuotedMessage extends Message {
return ChangeNotifierProvider.value( return ChangeNotifierProvider.value(
value: this.metadata, value: this.metadata,
builder: (bcontext, child) { builder: (bcontext, child) {
return MessageRow( return MessageRow(QuotedMessageBubble(message["body"], messageHandler(bcontext, metadata.profileOnion, metadata.conversationIdentifier, byHash: true, hash: message["quotedHash"])),
QuotedMessageBubble(message["body"], messageHandler(bcontext, metadata.profileOnion, metadata.conversationIdentifier, byHash: true, hash: message["quotedHash"])),
key: key); key: key);
}); });
} catch (e) { } catch (e) {

View File

@ -284,8 +284,8 @@ class _MessageViewState extends State<MessageView> {
var children; var children;
if (Provider.of<AppState>(context).selectedConversation != null && Provider.of<AppState>(context).selectedIndex != null) { if (Provider.of<AppState>(context).selectedConversation != null && Provider.of<AppState>(context).selectedIndex != null) {
var quoted = FutureBuilder( var quoted = FutureBuilder(
future: future: messageHandler(context, Provider.of<AppState>(context).selectedProfile!, Provider.of<AppState>(context).selectedConversation!,
messageHandler(context, Provider.of<AppState>(context).selectedProfile!, Provider.of<AppState>(context).selectedConversation!, id: Provider.of<AppState>(context).selectedIndex!, byID: true), id: Provider.of<AppState>(context).selectedIndex!, byID: true),
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.hasData) { if (snapshot.hasData) {
var message = snapshot.data! as Message; var message = snapshot.data! as Message;