diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index da1dd6f9..44fdc8e0 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -170,26 +170,26 @@ 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(data["GroupID"])!.totalMessages = idx + 1; + profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(data["GroupID"])!.totalMessages = idx + 1; - //if not currently open - if (appState.selectedProfile != data["ProfileOnion"] || appState.selectedConversation != data["GroupID"]) { - profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(data["GroupID"])!.unreadMessages++; - } + //if not currently open + if (appState.selectedProfile != data["ProfileOnion"] || appState.selectedConversation != data["GroupID"]) { + profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(data["GroupID"])!.unreadMessages++; + } - var timestampSent = DateTime.tryParse(data['TimestampSent'])!; - // TODO: There are 2 timestamps associated with a new group message - time sent and time received. - // Sent refers to the time a profile alleges they sent a message - // Received refers to the time we actually saw the message from the server - // These can obviously be very different for legitimate reasons. - // We also maintain a relative hash-link through PreviousMessageSignature which is the ground truth for - // order. - // In the future we will want to combine these 3 ordering mechanisms into a cohesive view of the timeline - // For now we perform some minimal checks on the sent timestamp to use to provide a useful ordering for honest contacts - // and ensure that malicious contacts in groups can only set this timestamp to a value within the range of `last seen message time` - // and `local now`. - profileCN.getProfile(data["ProfileOnion"])?.contactList.updateLastMessageTime(data["GroupID"], timestampSent.toLocal()); - notificationManager.notify("New Message From Group!"); + var timestampSent = DateTime.tryParse(data['TimestampSent'])!; + // TODO: There are 2 timestamps associated with a new group message - time sent and time received. + // Sent refers to the time a profile alleges they sent a message + // Received refers to the time we actually saw the message from the server + // These can obviously be very different for legitimate reasons. + // We also maintain a relative hash-link through PreviousMessageSignature which is the ground truth for + // order. + // In the future we will want to combine these 3 ordering mechanisms into a cohesive view of the timeline + // For now we perform some minimal checks on the sent timestamp to use to provide a useful ordering for honest contacts + // and ensure that malicious contacts in groups can only set this timestamp to a value within the range of `last seen message time` + // and `local now`. + profileCN.getProfile(data["ProfileOnion"])?.contactList.updateLastMessageTime(data["GroupID"], timestampSent.toLocal()); + notificationManager.notify("New Message From Group!"); } } else { // from me (already displayed - do not update counter) diff --git a/lib/models/messages/filemessage.dart b/lib/models/messages/filemessage.dart index fa178dd4..b0dbc421 100644 --- a/lib/models/messages/filemessage.dart +++ b/lib/models/messages/filemessage.dart @@ -20,7 +20,7 @@ class FileMessage extends Message { return ChangeNotifierProvider.value( value: this.metadata, builder: (bcontext, child) { - String idx = Provider.of(context).isGroup == true && this.metadata.signature != null ? this.metadata.signature! : this.metadata.messageIndex.toString(); + String idx = this.metadata.contactHandle + this.metadata.messageIndex.toString(); dynamic shareObj = jsonDecode(this.content); if (shareObj == null) { return MessageRow(MalformedBubble()); diff --git a/lib/models/messages/invitemessage.dart b/lib/models/messages/invitemessage.dart index 7313207f..df21e313 100644 --- a/lib/models/messages/invitemessage.dart +++ b/lib/models/messages/invitemessage.dart @@ -21,8 +21,7 @@ class InviteMessage extends Message { return ChangeNotifierProvider.value( value: this.metadata, builder: (bcontext, child) { - String idx = Provider.of(context).isGroup == true && this.metadata.signature != null ? this.metadata.signature! : this.metadata.messageIndex.toString(); - + String idx = this.metadata.contactHandle + this.metadata.messageIndex.toString(); String inviteTarget; String inviteNick; String invite = this.content; diff --git a/lib/models/messages/quotedmessage.dart b/lib/models/messages/quotedmessage.dart index 3bb85961..8bc0c905 100644 --- a/lib/models/messages/quotedmessage.dart +++ b/lib/models/messages/quotedmessage.dart @@ -94,7 +94,7 @@ class QuotedMessage extends Message { return ChangeNotifierProvider.value( value: this.metadata, builder: (bcontext, child) { - String idx = Provider.of(context).isGroup == true && this.metadata.signature != null ? this.metadata.signature! : this.metadata.messageIndex.toString(); + String idx = this.metadata.contactHandle + this.metadata.messageIndex.toString(); return MessageRow( QuotedMessageBubble(message["body"], quotedMessage.then((LocallyIndexedMessage? localIndex) { if (localIndex != null) { diff --git a/lib/models/messages/textmessage.dart b/lib/models/messages/textmessage.dart index 4f0d4906..a5782ac4 100644 --- a/lib/models/messages/textmessage.dart +++ b/lib/models/messages/textmessage.dart @@ -32,7 +32,7 @@ class TextMessage extends Message { return ChangeNotifierProvider.value( value: this.metadata, builder: (bcontext, child) { - String idx = this.metadata.messageIndex.toString(); + String idx = this.metadata.contactHandle + this.metadata.messageIndex.toString(); return MessageRow(MessageBubble(this.content), key: Provider.of(bcontext).getMessageKey(idx)); }); }