change lastMessageTime into lastMessage[receive|sent]Time. Receive for sort, and sent for display.
continuous-integration/drone/pr Build is pending Details
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Dan Ballard 2023-09-26 13:26:52 -07:00
parent 297a7e8a22
commit 19377e033f
6 changed files with 37 additions and 23 deletions

View File

@ -158,7 +158,7 @@ class CwtchNotifier {
lastMessageTime: DateTime.now(),
notificationPolicy: data["notificationPolicy"] ?? "ConversationNotificationPolicy.Default"));
profileCN.getProfile(data["ProfileOnion"])?.contactList.updateLastMessageTime(int.parse(data["ConversationID"]), DateTime.now());
profileCN.getProfile(data["ProfileOnion"])?.contactList.updateLastMessageReceivedTime(int.parse(data["ConversationID"]), DateTime.now());
}
break;
case "PeerDeleted":
@ -376,7 +376,7 @@ class CwtchNotifier {
isGroup: true,
lastMessageTime: DateTime.now()));
profileCN.getProfile(data["ProfileOnion"])?.contactList.updateLastMessageTime(identifier, DateTime.fromMillisecondsSinceEpoch(0));
profileCN.getProfile(data["ProfileOnion"])?.contactList.updateLastMessageReceivedTime(identifier, DateTime.fromMillisecondsSinceEpoch(0));
}
// request a new server update...
// NOTE: In the future this should also update the TokenManagerInfo

View File

@ -52,7 +52,8 @@ class ContactInfoState extends ChangeNotifier {
late String _savePeerHistory;
late int _unreadMessages = 0;
late int _totalMessages = 0;
late DateTime _lastMessageTime;
late DateTime _lastMessageReceivedTime; // last time we received a message, for sorting
late DateTime _lastMessageSentTime; // last time a message reported being sent, for display
late Map<String, GlobalKey<MessageRowState>> keys;
int _newMarkerMsgIndex = -1;
late MessageCache messageCache;
@ -106,7 +107,8 @@ class ContactInfoState extends ChangeNotifier {
this._totalMessages = numMessages;
this._unreadMessages = numUnread;
this._savePeerHistory = savePeerHistory;
this._lastMessageTime = lastMessageTime == null ? DateTime.fromMillisecondsSinceEpoch(0) : lastMessageTime;
this._lastMessageReceivedTime = lastMessageTime == null ? DateTime.fromMillisecondsSinceEpoch(0) : lastMessageTime;
this._lastMessageSentTime = _lastMessageReceivedTime;
this._server = server;
this._archived = archived;
this._notificationPolicy = notificationPolicyFromString(notificationPolicy);
@ -256,10 +258,21 @@ class ContactInfoState extends ChangeNotifier {
notifyListeners();
}
DateTime get lastMessageTime => this._lastMessageTime;
// This is last message received time (local) and to be used for sorting only
// for instance, group sync, we want to pop to the top, so we set to time.Now() for new messages
// but it should not be used for display
DateTime get lastMessageReceivedTime => this._lastMessageReceivedTime;
set lastMessageTime(DateTime newVal) {
this._lastMessageTime = newVal;
set lastMessageReceivedTime(DateTime newVal) {
this._lastMessageReceivedTime = newVal;
notifyListeners();
}
// This is last message sent time and is based on message reports of sent times
// this can be used to display in the contact list a last time a message was received
DateTime get lastMessageSentTime => this._lastMessageSentTime;
set lastMessageSentTime(DateTime newVal) {
this._lastMessageSentTime = newVal;
notifyListeners();
}
@ -322,7 +335,8 @@ class ContactInfoState extends ChangeNotifier {
_newMarkerMsgIndex++;
}
this._lastMessageTime = timestamp;
this._lastMessageReceivedTime = timestamp;
this._lastMessageSentTime = timestamp;
this.messageCache.addNew(profileOnion, identifier, messageID, timestamp, senderHandle, senderImage, isAuto, data, contenthash);
this.totalMessages += 1;

View File

@ -82,7 +82,7 @@ class ContactListState extends ChangeNotifier {
if (!a.isInvitation && b.isInvitation) return 1;
// special sorting for contacts with no messages in either history
if (a.lastMessageTime.millisecondsSinceEpoch == 0 && b.lastMessageTime.millisecondsSinceEpoch == 0) {
if (a.lastMessageReceivedTime.millisecondsSinceEpoch == 0 && b.lastMessageReceivedTime.millisecondsSinceEpoch == 0) {
// online contacts first
if (a.isOnline() && !b.isOnline()) return -1;
if (!a.isOnline() && b.isOnline()) return 1;
@ -90,27 +90,27 @@ class ContactListState extends ChangeNotifier {
return a.onion.toString().compareTo(b.onion.toString());
}
// finally... most recent history first
if (a.lastMessageTime.millisecondsSinceEpoch == 0) return 1;
if (b.lastMessageTime.millisecondsSinceEpoch == 0) return -1;
return b.lastMessageTime.compareTo(a.lastMessageTime);
if (a.lastMessageReceivedTime.millisecondsSinceEpoch == 0) return 1;
if (b.lastMessageReceivedTime.millisecondsSinceEpoch == 0) return -1;
return b.lastMessageReceivedTime.compareTo(a.lastMessageReceivedTime);
});
//<todo> if(changed) {
notifyListeners();
//} </todo>
}
void updateLastMessageTime(int forIdentifier, DateTime newMessageTime) {
void updateLastMessageReceivedTime(int forIdentifier, DateTime newMessageTime) {
var contact = getContact(forIdentifier);
if (contact == null) return;
// Assert that the new time is after the current last message time AND that
// new message time is before the current time.
if (newMessageTime.isAfter(contact.lastMessageTime)) {
if (newMessageTime.isAfter(contact.lastMessageReceivedTime)) {
if (newMessageTime.isBefore(DateTime.now().toLocal())) {
contact.lastMessageTime = newMessageTime;
contact.lastMessageReceivedTime = newMessageTime;
} else {
// Otherwise set the last message time to now...
contact.lastMessageTime = DateTime.now().toLocal();
contact.lastMessageReceivedTime = DateTime.now().toLocal();
}
resort();
}
@ -144,7 +144,7 @@ class ContactListState extends ChangeNotifier {
void newMessage(int identifier, int messageID, DateTime timestamp, String senderHandle, String senderImage, bool isAuto, String data, String contenthash, bool selectedConversation) {
getContact(identifier)?.newMessage(identifier, messageID, timestamp, senderHandle, senderImage, isAuto, data, contenthash, selectedConversation);
updateLastMessageTime(identifier, DateTime.now());
updateLastMessageReceivedTime(identifier, DateTime.now());
}
int cacheMemUsage() {

View File

@ -94,7 +94,7 @@ class ProfileInfoState extends ChangeNotifier {
// dummy set to invoke sort-on-load
if (this._contacts.num > 0) {
this._contacts.updateLastMessageTime(this._contacts.contacts.first.identifier, this._contacts.contacts.first.lastMessageTime);
this._contacts.updateLastMessageReceivedTime(this._contacts.contacts.first.identifier, this._contacts.contacts.first.lastMessageReceivedTime);
}
}
}
@ -246,7 +246,7 @@ class ProfileInfoState extends ChangeNotifier {
}
profileContact.totalMessages = newCount;
profileContact.unreadMessages = contact["numUnread"];
profileContact.lastMessageTime = DateTime.fromMillisecondsSinceEpoch(1000 * int.parse(contact["lastMsgTime"]));
profileContact.lastMessageReceivedTime = DateTime.fromMillisecondsSinceEpoch(1000 * int.parse(contact["lastMsgTime"]));
} else {
this._contacts.add(ContactInfoState(
this.onion,

View File

@ -40,8 +40,8 @@ class RemoteServerInfoState extends ChangeNotifier {
if (status == "Authenticated") {
// syncing, set lastPreSyncMessageTime
_groups.forEach((g) {
if (g.lastMessageTime.isAfter(lastPreSyncMessagTime)) {
lastPreSyncMessagTime = g.lastMessageTime;
if (g.lastMessageReceivedTime.isAfter(lastPreSyncMessagTime)) {
lastPreSyncMessagTime = g.lastMessageReceivedTime;
}
});
}

View File

@ -159,7 +159,7 @@ class _ContactRowState extends State<ContactRow> {
icon: Icon(Icons.block, color: Provider.of<Settings>(context).theme.mainTextColor),
onPressed: () {},
)
: Text(prettyDateString(context, widget.messageIndex == null ? contact.lastMessageTime : (this.cachedMessage?.getMetadata().timestamp ?? DateTime.now())))),
: Text(prettyDateString(context, widget.messageIndex == null ? contact.lastMessageSentTime : (this.cachedMessage?.getMetadata().timestamp ?? DateTime.now())))),
),
],
))),