Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix muting sign in emails - skip e2e #2859

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/snjs/lib/Application/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
'identifier',
'defaultHost',
'appVersion',
'apiVersion',
]

for (const optionName of requiredOptions) {
Expand Down
20 changes: 20 additions & 0 deletions packages/snjs/lib/Services/Api/ApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,26 @@ export class LegacyApiService
})
}

async updateSubscriptionSetting(
userUuid: UuidString,
settingName: string,
settingValue: string | null,
sensitive: boolean,
): Promise<HttpResponse<UpdateSettingResponse>> {
const params = {
name: settingName,
value: settingValue,
sensitive: sensitive,
}
return this.tokenRefreshableRequest<UpdateSettingResponse>({
verb: HttpVerb.Put,
url: joinPaths(this.host, Paths.v1.subscriptionSettings(userUuid)),
authentication: this.getSessionAccessToken(),
fallbackErrorMessage: API_MESSAGE_FAILED_UPDATE_SETTINGS,
params,
})
}

async deleteSetting(userUuid: UuidString, settingName: string): Promise<HttpResponse<DeleteSettingResponse>> {
return this.tokenRefreshableRequest<DeleteSettingResponse>({
verb: HttpVerb.Delete,
Expand Down
1 change: 1 addition & 0 deletions packages/snjs/lib/Services/Api/Paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const SettingsPaths = {
setting: (userUuid: string, settingName: string) => `/v1/users/${userUuid}/settings/${settingName}`,
subscriptionSetting: (userUuid: string, settingName: string) =>
`/v1/users/${userUuid}/subscription-settings/${settingName}`,
subscriptionSettings: (userUuid: string) => `/v1/users/${userUuid}/subscription-settings`,
}

const SubscriptionPaths = {
Expand Down
4 changes: 4 additions & 0 deletions packages/snjs/lib/Services/Settings/SNSettingsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export class SettingsService extends AbstractService implements SettingsClientIn
return this.provider.getSubscriptionSetting(name)
}

async updateSubscriptionSetting(name: SettingName, payload: string, sensitive = false) {
return this.provider.updateSetting(name, payload, sensitive)
}

async updateSetting(name: SettingName, payload: string, sensitive = false) {
return this.provider.updateSetting(name, payload, sensitive)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,12 @@ export interface SettingsServerInterface {

getSubscriptionSetting(userUuid: UuidString, settingName: string): Promise<HttpResponse<GetSettingResponse>>

updateSubscriptionSetting(
userUuid: UuidString,
settingName: string,
settingValue: string,
sensitive: boolean,
): Promise<HttpResponse<UpdateSettingResponse>>

deleteSetting(userUuid: UuidString, settingName: string): Promise<HttpResponse<DeleteSettingResponse>>
}
2 changes: 1 addition & 1 deletion packages/snjs/mocha/lib/Applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function createApplicationWithOptions({ identifier, environment, platform
defaultHost: host || Defaults.getDefaultHost(),
appVersion: Defaults.getAppVersion(),
webSocketUrl: Defaults.getDefaultWebSocketUrl(),
apiVersion: ApiVersion.V1,
apiVersion: ApiVersion.v0,
syncCallsThresholdPerMinute,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ const Email: FunctionComponent<Props> = ({ application }: Props) => {
}
}

const updateSubscriptionSetting = async (settingName: SettingName, payload: string): Promise<boolean> => {
try {
await application.settings.updateSubscriptionSetting(settingName, payload, false)
return true
} catch (e) {
application.alerts.alert(STRING_FAILED_TO_UPDATE_USER_SETTING).catch(console.error)
return false
}
}

const loadSettings = useCallback(async () => {
if (!application.sessions.getUser()) {
return
Expand Down Expand Up @@ -79,7 +89,7 @@ const Email: FunctionComponent<Props> = ({ application }: Props) => {
previousValue === MuteSignInEmailsOption.Muted ? MuteSignInEmailsOption.NotMuted : MuteSignInEmailsOption.Muted
setSignInEmailsMutedValue(newValue)

const updateResult = await updateSetting(
const updateResult = await updateSubscriptionSetting(
SettingName.create(SettingName.NAMES.MuteSignInEmails).getValue(),
newValue,
)
Expand Down
Loading