Skip to content

Commit

Permalink
Merge pull request #1625 from shadow-dot-cat/castaway/1564_messagelis…
Browse files Browse the repository at this point in the history
…t_speed_fun

fix(maillist): Ensure we only switch to index data after its loaded
  • Loading branch information
castaway authored Dec 4, 2024
2 parents 603cb9e + d010fae commit 11997c1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 35 deletions.
18 changes: 10 additions & 8 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 @@ -370,8 +370,11 @@ export class AppComponent implements OnInit, AfterViewInit, CanvasTableSelectLis

this.messagelistservice.messagesInViewSubject.subscribe(res => {
this.messagelist = res;
if (!this.showingSearchResults && !this.showingWebSocketSearchResults
&& res) {
if (
(
(!this.showingSearchResults && !this.showingWebSocketSearchResults)
|| this.messagelistservice.unindexedFolders.includes(this.selectedFolder)
) && res) {
this.setMessageDisplay('messagelist', this.messagelist);
if (this.jumpToFragment && res.length > 0) {
this.selectMessageFromFragment(this.fragment);
Expand Down Expand Up @@ -410,7 +413,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 +423,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 +999,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 All @@ -1007,10 +1011,8 @@ export class AppComponent implements OnInit, AfterViewInit, CanvasTableSelectLis
public childRouteActivated(yes: boolean): void {
this.hasChildRouterOutlet = yes;
if (yes) {
// Don't highlight a folder if we're not viewing one
this.selectedFolder = null;
} else {
// reset the default Folder
this.selectedFolder = 'Inbox';
}
}

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 @@ -447,8 +447,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 @@ -204,8 +204,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 @@ -1022,7 +1022,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 @@ -1032,7 +1033,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 @@ -1044,6 +1047,7 @@ ctx.addEventListener('message', ({ data }) => {
console.error(e);
}
}) ]);
}
} else if (data['action'] === PostMessageAction.setCurrentFolder) {
searchIndexService.currentFolder = data['folder'];
}
Expand Down
47 changes: 25 additions & 22 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 @@ -262,8 +267,8 @@ export class SearchService {
this.indexReloadedSubject.subscribe(() => {
// console.log('searchservice updating folderCounts');
// we're sending both "indexUpdated", and "updateMessageListService"
this.messagelistservice.refreshFolderCounts();
// this.messagelistservice.refreshFolderList();
// this.messagelistservice.refreshFolderCounts();
this.messagelistservice.refreshFolderList();
});

this.messagelistservice.folderListSubject
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 11997c1

Please sign in to comment.