Skip to content

Commit

Permalink
bugfixes and touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
ereio committed Dec 14, 2020
1 parent 1aa2771 commit e3e9b84
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/global/storage/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Future<Map<String, Map<dynamic, dynamic>>> loadStorage(Database storage) async {
encrypted: room.encryptionEnabled,
);
printError(
'[loadMessages] ${messages[room.id].length.toString()} ${room.name} loaded',
'[loadMessages] ${messages[room.id]?.length} ${room.name} loaded',
);
}

Expand Down
3 changes: 0 additions & 3 deletions lib/store/events/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ ThunkAction<AppState> fetchMessageEvents({
"limit": limit,
});

printDebug("[fetchMessageEvents] CALLED FOR ${room.name} ${to} ${from}");
printJson(messagesJson);

// The token the pagination ends at. If dir=b this token should be used again to request even earlier events.
final String end = messagesJson['end'];

Expand Down
3 changes: 2 additions & 1 deletion lib/store/events/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ Future<List<Message>> loadMessages(
final store = StoreRef<String, String>(MESSAGES);

// TODO: properly paginate through cold storage messages instead of loading all
final eventIdsPaginated = eventIds; //.skip(offset).take(limit).toList();
final eventIdsPaginated =
eventIds ?? []; //.skip(offset).take(limit).toList();

final messagesPaginated =
await store.records(eventIdsPaginated).get(storage);
Expand Down
19 changes: 10 additions & 9 deletions lib/store/rooms/room/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class Room {
int lastUpdate = this.lastUpdate;
int namePriority = this.namePriority != 4 ? this.namePriority : 4;

var usersAdd = Map<String, User>.from(this.usersNew);
var usersAdd = Map<String, User>.from(this.usersNew ?? {});
var userIdsRemove = List<String>();

Set<String> userIds = Set<String>.from(this.userIds ?? []);
Expand Down Expand Up @@ -508,19 +508,20 @@ class Room {
* outside displaying messages
*/
Room fromMessageEvents({
List<Message> messages,
List<Message> messages = const [],
String lastHash,
String prevHash, // previously fetched hash
String nextHash,
}) {
try {
printDebug(
'[fromMessageEvents] ${this.name} ${messages.length.toString()}',
'[fromMessageEvents] ${this.name} ${messages.length}',
);

bool limited;
int lastUpdate = this.lastUpdate;
List<Message> outbox = List<Message>.from(this.outbox ?? []);
final messageIds = this.messageIds ?? [];

// Converting only message events
final hasEncrypted = messages.firstWhere(
Expand All @@ -536,11 +537,11 @@ class Room {
// limited indicates need to fetch additional data for room timelines
if (this.limited) {
// Check to see if the new messages contain those existing in cache
if (messages.isNotEmpty && this.messageIds.isNotEmpty) {
final messageKnown = this.messageIds.firstWhere(
(id) => id == messages[0].id,
orElse: () => null,
);
if (messages.isNotEmpty && messageIds.isNotEmpty) {
final messageKnown = messageIds.firstWhere(
(id) => id == messages[0].id,
orElse: () => null,
);

// Set limited to false if they now exist
limited = messageKnown != null;
Expand Down Expand Up @@ -572,7 +573,7 @@ class Room {
// save messages and unique message id updates
final messageIdsNew = Set<String>.from(messagesMap.keys);
final messagesNew = List<Message>.from(messagesMap.values);
final messageIdsAll = Set<String>.from(this.messageIds)
final messageIdsAll = Set<String>.from(this.messageIds ?? [])
..addAll(messageIdsNew);

// Save values to room
Expand Down
2 changes: 1 addition & 1 deletion lib/store/sync/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ ThunkAction<AppState> stopSyncObserver() {
ThunkAction<AppState> initialSync() {
return (Store<AppState> store) async {
// Start initial sync in background
await store.dispatch(SetSyncing(syncing: true));
await store.dispatch(fetchSync());

// Fetch All Room Ids - continue showing a sync
await store.dispatch(SetSyncing(syncing: true));
await store.dispatch(fetchDirectRooms());
await store.dispatch(fetchRooms());
await store.dispatch(SetSyncing(syncing: false));
Expand Down
8 changes: 7 additions & 1 deletion lib/views/home/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ class _Props extends Equatable {
unauthed: store.state.syncStore.unauthed,
offline: store.state.syncStore.offline,
syncing: () {
final synced = store.state.syncStore.synced;
final syncing = store.state.syncStore.syncing;
final offline = store.state.syncStore.offline;
final backgrounded = store.state.syncStore.backgrounded;
Expand All @@ -658,11 +659,16 @@ class _Props extends Equatable {
final lastAttempt = DateTime.fromMillisecondsSinceEpoch(
store.state.syncStore.lastAttempt ?? 0);

// See if the last attempted sync is older than 60 seconds
// See if the last attempted sy nc is older than 60 seconds
final isLastAttemptOld = DateTime.now()
.difference(lastAttempt)
.compareTo(Duration(seconds: 90));

// syncing for the first time
if (syncing && !synced) {
return true;
}

// syncing for the first time since going offline
if (syncing && offline) {
return true;
Expand Down

0 comments on commit e3e9b84

Please sign in to comment.