[PM-18802] - Autofill Settings Nudges and Settings Badge (#14439)
* autofill nudge * remove undismiss logic * revert change to popup view cache service * move browser autofill logic to platform. cleanup * fix test * adjustments to autofill nudges * add missing provider * updates to autofill nudges * fix date logic * change autofillBrowserSettingsService isBrowserAutofillSettingOverridden to function * fix up browser autofill overridden settings logic * remove check for privacy in isBrowserAutofillSettingOverriddenpull/14464/head
parent
1edca39fa2
commit
a7efd2158e
@ -0,0 +1,31 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { BehaviorSubject, Observable } from "rxjs";
|
||||
|
||||
import { BrowserClientVendors } from "@bitwarden/common/autofill/constants";
|
||||
import { BrowserClientVendor } from "@bitwarden/common/autofill/types";
|
||||
|
||||
import { BrowserApi } from "../../platform/browser/browser-api";
|
||||
|
||||
/**
|
||||
* Service class for various Autofill-related browser API operations.
|
||||
*/
|
||||
@Injectable({
|
||||
providedIn: "root",
|
||||
})
|
||||
export class AutofillBrowserSettingsService {
|
||||
async isBrowserAutofillSettingOverridden(browserClient: BrowserClientVendor) {
|
||||
return (
|
||||
browserClient !== BrowserClientVendors.Unknown &&
|
||||
(await BrowserApi.browserAutofillSettingsOverridden())
|
||||
);
|
||||
}
|
||||
|
||||
private _defaultBrowserAutofillDisabled$ = new BehaviorSubject<boolean>(false);
|
||||
|
||||
defaultBrowserAutofillDisabled$: Observable<boolean> =
|
||||
this._defaultBrowserAutofillDisabled$.asObservable();
|
||||
|
||||
setDefaultBrowserAutofillDisabled(value: boolean) {
|
||||
this._defaultBrowserAutofillDisabled$.next(value);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
import { Injectable, inject } from "@angular/core";
|
||||
import { Observable, combineLatest, from, map, of } from "rxjs";
|
||||
import { catchError } from "rxjs/operators";
|
||||
|
||||
import { VaultProfileService } from "@bitwarden/angular/vault/services/vault-profile.service";
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
|
||||
import { DefaultSingleNudgeService } from "../default-single-nudge.service";
|
||||
import { NudgeStatus, VaultNudgeType } from "../vault-nudges.service";
|
||||
|
||||
const THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1000;
|
||||
|
||||
/**
|
||||
* Custom Nudge Service to use for the Autofill Nudge in the Vault
|
||||
*/
|
||||
@Injectable({
|
||||
providedIn: "root",
|
||||
})
|
||||
export class AutofillNudgeService extends DefaultSingleNudgeService {
|
||||
vaultProfileService = inject(VaultProfileService);
|
||||
logService = inject(LogService);
|
||||
|
||||
nudgeStatus$(_: VaultNudgeType, userId: UserId): Observable<NudgeStatus> {
|
||||
const profileDate$ = from(this.vaultProfileService.getProfileCreationDate(userId)).pipe(
|
||||
catchError(() => {
|
||||
this.logService.error("Error getting profile creation date");
|
||||
// Default to today to ensure we show the nudge
|
||||
return of(new Date());
|
||||
}),
|
||||
);
|
||||
|
||||
return combineLatest([
|
||||
profileDate$,
|
||||
this.getNudgeStatus$(VaultNudgeType.AutofillNudge, userId),
|
||||
of(Date.now() - THIRTY_DAYS_MS),
|
||||
]).pipe(
|
||||
map(([profileCreationDate, status, profileCutoff]) => {
|
||||
const profileOlderThanCutoff = profileCreationDate.getTime() < profileCutoff;
|
||||
return {
|
||||
hasBadgeDismissed: status.hasBadgeDismissed || profileOlderThanCutoff,
|
||||
hasSpotlightDismissed: status.hasSpotlightDismissed || profileOlderThanCutoff,
|
||||
};
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue