Skip to content

Commit

Permalink
fix(maillist): Ensure we only switch to index data after its loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
castaway committed Nov 18, 2024
1 parent 100b945 commit 591f168
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 28 deletions.
7 changes: 4 additions & 3 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class AppComponent implements OnInit, AfterViewInit, CanvasTableSelectLis
entireHistoryInProgress = false;

displayedFolders = new Observable<FolderListEntry[]>();
selectedFolder = 'Inbox';
selectedFolder = '';
composeSelected: boolean;
draftsSelected: boolean;
overviewSelected: boolean;
Expand Down Expand Up @@ -410,7 +410,7 @@ export class AppComponent implements OnInit, AfterViewInit, CanvasTableSelectLis
fragment => {
if (!fragment) {
// This also runs when we load '/compose' .. but doesnt need to
this.messagelistservice.setCurrentFolder('Inbox');
this.switchToFolder('Inbox');
if (this.singlemailviewer) {
this.singlemailviewer.close();
}
Expand All @@ -420,8 +420,8 @@ export class AppComponent implements OnInit, AfterViewInit, CanvasTableSelectLis

if (fragment !== this.fragment) {
this.fragment = fragment;
this.selectMessageFromFragment(this.fragment);
if (this.canvastable.rows && this.canvastable.rows.rowCount() > 0) {
this.selectMessageFromFragment(this.fragment);
this.canvastable.jumpToOpenMessage();
} else {
this.jumpToFragment = true;
Expand Down Expand Up @@ -996,6 +996,7 @@ export class AppComponent implements OnInit, AfterViewInit, CanvasTableSelectLis

this.showingWebSocketSearchResults = false;
this.usewebsocketsearch = false;
this.showingSearchResults = true;

// don't scroll to top when redrawing after index updates
if (!this.hasChildRouterOutlet) {
Expand Down
7 changes: 5 additions & 2 deletions src/app/rmmapi/messagelist.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,11 @@ export class MessageListService {
folders.forEach((f) => this.staleFolders[f] = true);
// check if current visible folder has updates
// refresh if localsearch not activated (aka setCurrentFolder)
if (this.staleFolders[this.currentFolder]) {
this.searchservice.pipe(take(1)).subscribe(searchservice => {
if (!searchservice.localSearchActivated &&
this.staleFolders[this.currentFolder]) {
this.fetchFolderMessages();
}
}
});
}
}
10 changes: 7 additions & 3 deletions src/app/xapian/index.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ class SearchIndexService {
FS.syncfs(true, async () => {
// console.log('Worker: Loading partitions');
this.openStoredPartitions();
await this.updateIndexWithNewChanges();
ctx.postMessage({'action': PostMessageAction.indexUpdated});
await this.updateIndexWithNewChanges();
});


Expand Down Expand Up @@ -1025,7 +1025,8 @@ ctx.addEventListener('message', ({ data }) => {
if (searchIndexDocumentUpdates.length > 0 && searchIndexService.localSearchActivated) {
searchIndexService.postMessagesToXapianWorker(searchIndexDocumentUpdates);
}
} else if (data['action'] === PostMessageAction.addTermToDocument && searchIndexService.localSearchActivated) {
} else if (data['action'] === PostMessageAction.addTermToDocument) {
if (searchIndexService.localSearchActivated) {
searchIndexService.postMessagesToXapianWorker([
new SearchIndexDocumentUpdate(data['messageId'], async () => {
try {
Expand All @@ -1035,7 +1036,9 @@ ctx.addEventListener('message', ({ data }) => {
console.error(e);
}
}) ]);
} else if (data['action'] === PostMessageAction.removeTermFromDocument && searchIndexService.localSearchActivated) {
}
} else if (data['action'] === PostMessageAction.removeTermFromDocument) {
if (searchIndexService.localSearchActivated) {
searchIndexService.postMessagesToXapianWorker([
new SearchIndexDocumentUpdate(data['messageId'], async () => {
try {
Expand All @@ -1047,6 +1050,7 @@ ctx.addEventListener('message', ({ data }) => {
console.error(e);
}
}) ]);
}
} else if (data['action'] === PostMessageAction.setCurrentFolder) {
searchIndexService.currentFolder = data['folder'];
}
Expand Down
43 changes: 23 additions & 20 deletions src/app/xapian/searchservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,13 @@ export class SearchService {
).subscribe((hasLocalIndex: boolean) => {
if (!this.isExpired) {
if (hasLocalIndex) {
this.openDBOnWorker();
this.init();
this.initSubject.subscribe((opened) => {
if (opened) {
this.indexReloadedSubject.next(undefined);
this.openDBOnWorker();
}
});
} else {
// We have no local index - but still need the polling loop here
this.indexLastUpdateTime = new Date().getTime(); // Set the last update time to now since we don't have a local index
Expand Down Expand Up @@ -293,40 +298,38 @@ export class SearchService {
// but it doesn't.
this.rmmapi.messageFlagChangeSubject
.subscribe((msgFlagChange) => {
if (msgFlagChange.flaggedFlag !== null) {
if (msgFlagChange.flaggedFlag === true) {
this.indexWorker.postMessage(
if (msgFlagChange.flaggedFlag !== null) {
if (msgFlagChange.flaggedFlag === true) {
this.indexWorker.postMessage(
{'action': PostMessageAction.addTermToDocument,
'messageId': msgFlagChange.id,
'term': 'XFflagged'
});
} else {
this.indexWorker.postMessage(
});
} else {
this.indexWorker.postMessage(
{'action': PostMessageAction.removeTermFromDocument,
'messageId': msgFlagChange.id,
'term': 'XFflagged'
});
}
} else if (msgFlagChange.seenFlag !== null) {
if (msgFlagChange.seenFlag === true) {
this.indexWorker.postMessage(
}
} else if (msgFlagChange.seenFlag !== null) {
if (msgFlagChange.seenFlag === true) {
this.indexWorker.postMessage(
{'action': PostMessageAction.addTermToDocument,
'messageId': msgFlagChange.id,
'term': 'XFseen'
});
} else {
this.indexWorker.postMessage(
});
} else {
this.indexWorker.postMessage(
{'action': PostMessageAction.removeTermFromDocument,
'messageId': msgFlagChange.id,
'term': 'XFseen'
});
}
// counts and list to ensure we have uptodate data
this.messagelistservice.refreshFolderList();
} else {
console.error('Empty flag change message', msgFlagChange);
}
// console.log('Flag Change: local index');
} else {
console.error('Empty flag change message', msgFlagChange);
}
// console.log('Flag Change: local index');
});

// open for reading (for canvastable comms)
Expand Down

0 comments on commit 591f168

Please sign in to comment.