mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
Add login launch data (#174)
* added launch time data to CipherView for autofill * removed unused code * fixed linter errors
This commit is contained in:
@@ -26,8 +26,10 @@ export abstract class CipherService {
|
|||||||
defaultMatch?: UriMatchType) => Promise<CipherView[]>;
|
defaultMatch?: UriMatchType) => Promise<CipherView[]>;
|
||||||
getAllFromApiForOrganization: (organizationId: string) => Promise<CipherView[]>;
|
getAllFromApiForOrganization: (organizationId: string) => Promise<CipherView[]>;
|
||||||
getLastUsedForUrl: (url: string) => Promise<CipherView>;
|
getLastUsedForUrl: (url: string) => Promise<CipherView>;
|
||||||
|
getLastLaunchedForUrl: (url: string) => Promise<CipherView>;
|
||||||
getNextCipherForUrl: (url: string) => Promise<CipherView>;
|
getNextCipherForUrl: (url: string) => Promise<CipherView>;
|
||||||
updateLastUsedDate: (id: string) => Promise<void>;
|
updateLastUsedDate: (id: string) => Promise<void>;
|
||||||
|
updateLastLaunchedDate: (id: string) => Promise<void>;
|
||||||
saveNeverDomain: (domain: string) => Promise<void>;
|
saveNeverDomain: (domain: string) => Promise<void>;
|
||||||
saveWithServer: (cipher: Cipher) => Promise<any>;
|
saveWithServer: (cipher: Cipher) => Promise<any>;
|
||||||
shareWithServer: (cipher: CipherView, organizationId: string, collectionIds: string[]) => Promise<any>;
|
shareWithServer: (cipher: CipherView, organizationId: string, collectionIds: string[]) => Promise<any>;
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ export class SortedCiphersCache {
|
|||||||
return this.isCached(url) ? this.sortedCiphersByUrl.get(url).getLastUsed() : null;
|
return this.isCached(url) ? this.sortedCiphersByUrl.get(url).getLastUsed() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLastLaunched(url: string) {
|
||||||
|
return this.isCached(url) ? this.sortedCiphersByUrl.get(url).getLastLaunched() : null;
|
||||||
|
}
|
||||||
|
|
||||||
getNext(url: string) {
|
getNext(url: string) {
|
||||||
this.resetTimer(url);
|
this.resetTimer(url);
|
||||||
return this.isCached(url) ? this.sortedCiphersByUrl.get(url).getNext() : null;
|
return this.isCached(url) ? this.sortedCiphersByUrl.get(url).getNext() : null;
|
||||||
@@ -52,6 +56,11 @@ class Ciphers {
|
|||||||
return this.ciphers[this.lastUsedIndex];
|
return this.ciphers[this.lastUsedIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLastLaunched() {
|
||||||
|
const sortedCiphers = this.ciphers.sort((x, y) => y.localData?.lastLaunched?.valueOf() - x.localData?.lastLaunched?.valueOf());
|
||||||
|
return sortedCiphers[0];
|
||||||
|
}
|
||||||
|
|
||||||
getNext() {
|
getNext() {
|
||||||
const nextIndex = (this.lastUsedIndex + 1) % this.ciphers.length;
|
const nextIndex = (this.lastUsedIndex + 1) % this.ciphers.length;
|
||||||
this.lastUsedIndex = nextIndex;
|
this.lastUsedIndex = nextIndex;
|
||||||
|
|||||||
@@ -445,11 +445,15 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getLastUsedForUrl(url: string): Promise<CipherView> {
|
async getLastUsedForUrl(url: string): Promise<CipherView> {
|
||||||
return this.getCipherForUrl(url, true);
|
return this.getCipherForUrl(url, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getLastLaunchedForUrl(url: string): Promise<CipherView> {
|
||||||
|
return this.getCipherForUrl(url, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getNextCipherForUrl(url: string): Promise<CipherView> {
|
async getNextCipherForUrl(url: string): Promise<CipherView> {
|
||||||
return this.getCipherForUrl(url, false);
|
return this.getCipherForUrl(url, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateLastUsedDate(id: string): Promise<void> {
|
async updateLastUsedDate(id: string): Promise<void> {
|
||||||
@@ -481,6 +485,35 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateLastLaunchedDate(id: string): Promise<void> {
|
||||||
|
let ciphersLocalData = await this.storageService.get<any>(Keys.localData);
|
||||||
|
if (!ciphersLocalData) {
|
||||||
|
ciphersLocalData = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ciphersLocalData[id]) {
|
||||||
|
ciphersLocalData[id].lastLaunched = new Date().getTime();
|
||||||
|
} else {
|
||||||
|
ciphersLocalData[id] = {
|
||||||
|
lastUsedDate: new Date().getTime(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.storageService.save(Keys.localData, ciphersLocalData);
|
||||||
|
|
||||||
|
if (this.decryptedCipherCache == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < this.decryptedCipherCache.length; i++) {
|
||||||
|
const cached = this.decryptedCipherCache[i];
|
||||||
|
if (cached.id === id) {
|
||||||
|
cached.localData = ciphersLocalData[id];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async saveNeverDomain(domain: string): Promise<void> {
|
async saveNeverDomain(domain: string): Promise<void> {
|
||||||
if (domain == null) {
|
if (domain == null) {
|
||||||
return;
|
return;
|
||||||
@@ -1009,7 +1042,7 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getCipherForUrl(url: string, lastUsed: boolean): Promise<CipherView> {
|
private async getCipherForUrl(url: string, lastUsed: boolean, lastLaunched: boolean): Promise<CipherView> {
|
||||||
if (!this.sortedCiphersCache.isCached(url)) {
|
if (!this.sortedCiphersCache.isCached(url)) {
|
||||||
const ciphers = await this.getAllDecryptedForUrl(url);
|
const ciphers = await this.getAllDecryptedForUrl(url);
|
||||||
if (!ciphers) {
|
if (!ciphers) {
|
||||||
@@ -1018,6 +1051,13 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
this.sortedCiphersCache.addCiphers(url, ciphers);
|
this.sortedCiphersCache.addCiphers(url, ciphers);
|
||||||
}
|
}
|
||||||
|
|
||||||
return lastUsed ? this.sortedCiphersCache.getLastUsed(url) : this.sortedCiphersCache.getNext(url);
|
if (lastLaunched) {
|
||||||
|
return this.sortedCiphersCache.getLastLaunched(url);
|
||||||
|
} else if (lastUsed) {
|
||||||
|
return this.sortedCiphersCache.getLastUsed(url);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return this.sortedCiphersCache.getNext(url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user