Skip to content

Commit

Permalink
Prefer favourite ciphers over last used / name
Browse files Browse the repository at this point in the history
  • Loading branch information
Badbird5907 committed Mar 1, 2024
1 parent 8d528c2 commit aa2b7c2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
});

this.loginCiphers = this.loginCiphers.sort((a, b) =>
this.cipherService.sortCiphersByLastUsedThenName(a, b),
this.cipherService.sortCiphersByFavouriteThenLastUsedThenName(a, b),
);
this.isLoading = this.loaded = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ export class VaultFilterComponent implements OnInit, OnDestroy {
this.ciphers = this.ciphers.filter(
(c) => !this.vaultFilterService.filterCipherForSelectedVault(c),
);
this.ciphers = this.ciphers.sort((a, b) =>
this.cipherService.sortCiphersByFavouriteThenLastUsedThenName(a, b),
);
return;
}
this.searchPending = true;
Expand All @@ -236,6 +239,9 @@ export class VaultFilterComponent implements OnInit, OnDestroy {
this.ciphers = this.ciphers.filter(
(c) => !this.vaultFilterService.filterCipherForSelectedVault(c),
);
this.ciphers = this.ciphers.sort((a, b) =>
this.cipherService.sortCiphersByFavouriteThenLastUsedThenName(a, b),
);
this.searchPending = false;
}, timeout);
}
Expand Down
1 change: 1 addition & 0 deletions libs/common/src/vault/abstractions/cipher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export abstract class CipherService {
deleteAttachmentWithServer: (id: string, attachmentId: string) => Promise<void>;
sortCiphersByLastUsed: (a: CipherView, b: CipherView) => number;
sortCiphersByLastUsedThenName: (a: CipherView, b: CipherView) => number;
sortCiphersByFavouriteThenLastUsedThenName: (a: CipherView, b: CipherView) => number;
getLocaleSortingFunction: () => (a: CipherView, b: CipherView) => number;
softDelete: (id: string | string[]) => Promise<any>;
softDeleteWithServer: (id: string, asAdmin?: boolean) => Promise<any>;
Expand Down
10 changes: 10 additions & 0 deletions libs/common/src/vault/services/cipher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,16 @@ export class CipherService implements CipherServiceAbstraction {
return this.getLocaleSortingFunction()(a, b);
}

sortCiphersByFavouriteThenLastUsedThenName(a: CipherView, b: CipherView): number {
if (a.favorite && !b.favorite) {
return -1;
}
if (!a.favorite && b.favorite) {
return 1;
}
return this.sortCiphersByLastUsedThenName(a, b);
}

getLocaleSortingFunction(): (a: CipherView, b: CipherView) => number {
return (a, b) => {
let aName = a.name;
Expand Down

0 comments on commit aa2b7c2

Please sign in to comment.