comments
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
This commit is contained in:
parent
82d1bf873f
commit
4bd92d854f
|
@ -5,6 +5,10 @@ import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
import 'message.dart';
|
import 'message.dart';
|
||||||
|
|
||||||
|
// we only count up to 100 unread messages, if more than that we can't accurately resync message cache, just reset
|
||||||
|
// https://git.openprivacy.ca/cwtch.im/libcwtch-go/src/branch/trunk/utils/eventHandler.go#L210
|
||||||
|
const MaxUnreadBeforeCacheReset = 100;
|
||||||
|
|
||||||
class MessageInfo {
|
class MessageInfo {
|
||||||
late MessageMetadata metadata;
|
late MessageMetadata metadata;
|
||||||
late String wrapper;
|
late String wrapper;
|
||||||
|
@ -101,7 +105,7 @@ class MessageCache extends ChangeNotifier {
|
||||||
// if we find the last seen ID, the diff of unread count is what's unsynced
|
// if we find the last seen ID, the diff of unread count is what's unsynced
|
||||||
for(var i = 0; i < (count+1) && i < cacheByIndex.length; i++) {
|
for(var i = 0; i < (count+1) && i < cacheByIndex.length; i++) {
|
||||||
if (this.cacheByIndex[i].messageId == lastSeenId) {
|
if (this.cacheByIndex[i].messageId == lastSeenId) {
|
||||||
// we have
|
// we have found the matching lastSeenId so we can calculate the unsynced as the unread messages before it
|
||||||
this._indexUnsynced = count - i;
|
this._indexUnsynced = count - i;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
return;
|
return;
|
||||||
|
@ -149,6 +153,8 @@ class MessageCache extends ChangeNotifier {
|
||||||
void lockIndexes(int start, int end) {
|
void lockIndexes(int start, int end) {
|
||||||
for (var i = start; i < end; i++) {
|
for (var i = start; i < end; i++) {
|
||||||
this.cacheByIndex.insert(i, LocalIndexMessage(null, isLoading: true));
|
this.cacheByIndex.insert(i, LocalIndexMessage(null, isLoading: true));
|
||||||
|
// if there are unsynced messages on the index cache it means there are messages at the front, and by the logic in message/ByIndex/get() we will be loading those
|
||||||
|
// there for we can decrement the count as this will be one of them
|
||||||
if (this._indexUnsynced > 0) {
|
if (this._indexUnsynced > 0) {
|
||||||
this._indexUnsynced--;
|
this._indexUnsynced--;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import 'package:flutter/widgets.dart';
|
||||||
import 'contact.dart';
|
import 'contact.dart';
|
||||||
import 'contactlist.dart';
|
import 'contactlist.dart';
|
||||||
import 'filedownloadprogress.dart';
|
import 'filedownloadprogress.dart';
|
||||||
|
import 'messagecache.dart';
|
||||||
import 'profileservers.dart';
|
import 'profileservers.dart';
|
||||||
|
|
||||||
class ProfileInfoState extends ChangeNotifier {
|
class ProfileInfoState extends ChangeNotifier {
|
||||||
|
@ -177,11 +178,10 @@ class ProfileInfoState extends ChangeNotifier {
|
||||||
profileContact.status = contact["status"];
|
profileContact.status = contact["status"];
|
||||||
profileContact.totalMessages = contact["numMessages"];
|
profileContact.totalMessages = contact["numMessages"];
|
||||||
profileContact.unreadMessages = contact["numUnread"];
|
profileContact.unreadMessages = contact["numUnread"];
|
||||||
// we only count up to 100 unread messages, if more than that we can't accuratly resync message cache, just reset
|
|
||||||
if (contact["numUnread"] > 100 || (contact["numUnread"] > 0 && contact["lastSeenMessageId"] == -1)) {
|
if (contact["numUnread"] > MaxUnreadBeforeCacheReset || (contact["numUnread"] > 0 && contact["lastSeenMessageId"] == -1)) {
|
||||||
profileContact.messageCache.resetIndexCache();
|
profileContact.messageCache.resetIndexCache();
|
||||||
} else if (contact["numUnread"] > 0) {
|
} else if (contact["numUnread"] > 0) {
|
||||||
print("contact ${contact["name"]} with unread ${contact["numUnread"]} so addFrontIndexGap");
|
|
||||||
profileContact.messageCache.addFrontIndexGap(contact["numUnread"], contact["lastSeenMessageId"]);
|
profileContact.messageCache.addFrontIndexGap(contact["numUnread"], contact["lastSeenMessageId"]);
|
||||||
}
|
}
|
||||||
profileContact.lastMessageTime = DateTime.fromMillisecondsSinceEpoch(1000 * int.parse(contact["lastMsgTime"]));
|
profileContact.lastMessageTime = DateTime.fromMillisecondsSinceEpoch(1000 * int.parse(contact["lastMsgTime"]));
|
||||||
|
|
Loading…
Reference in New Issue