-
();
private readonly signatureProviders = new Set();
- constructor(
- private readonly notificationService: NotificationService,
- private readonly translocoService: TranslocoService,
- private readonly proofRepository: ProofRepository,
- private readonly imageStore: ImageStore
- ) {}
+ constructor(private readonly imageStore: ImageStore) {}
async run(assets: Assets) {
- return this.notificationService.notifyOnGoing(
- defer(() => this._run(assets)),
- this.translocoService.translate('storingAssets'),
- this.translocoService.translate('message.storingAssets'),
- true
- );
- }
-
- private async _run(assets: Assets) {
const truth = await this.collectTruth(assets);
const signatures = await this.signTargets({ assets, truth });
return Proof.from(this.imageStore, assets, truth, signatures);
diff --git a/src/app/shared/services/database/table/capacitor-filesystem-table/capacitor-filesystem-table.ts b/src/app/shared/services/database/table/capacitor-filesystem-table/capacitor-filesystem-table.ts
index 28974eb63..2cfc17057 100644
--- a/src/app/shared/services/database/table/capacitor-filesystem-table/capacitor-filesystem-table.ts
+++ b/src/app/shared/services/database/table/capacitor-filesystem-table/capacitor-filesystem-table.ts
@@ -136,14 +136,16 @@ export class CapacitorFilesystemTable implements Table {
}
async update(newTuple: T, comparator: (x: T, y: T) => boolean) {
- const afterDeletion = differenceWith(
- this.tuples$.value,
- [newTuple],
- comparator
- );
- this.tuples$.next(afterDeletion.concat(newTuple));
- await this.dumpJson();
- return newTuple;
+ return this.mutex.runExclusive(async () => {
+ const afterDeletion = differenceWith(
+ this.tuples$.value,
+ [newTuple],
+ comparator
+ );
+ this.tuples$.next(afterDeletion.concat(newTuple));
+ await this.dumpJson();
+ return newTuple;
+ });
}
private assertTuplesExist(tuples: T[], comparator: (x: T, y: T) => boolean) {
diff --git a/src/app/shared/services/dia-backend/asset/dia-backend-asset-repository.service.ts b/src/app/shared/services/dia-backend/asset/dia-backend-asset-repository.service.ts
index 1f1a7409c..cdee561ad 100644
--- a/src/app/shared/services/dia-backend/asset/dia-backend-asset-repository.service.ts
+++ b/src/app/shared/services/dia-backend/asset/dia-backend-asset-repository.service.ts
@@ -68,15 +68,7 @@ export class DiaBackendAssetRepository {
);
}
- async add(proof: Proof) {
- return this.notificationService.notifyOnGoing(
- this.createAsset$(proof),
- this.translocoService.translate('registeringProof'),
- this.translocoService.translate('message.registeringProof')
- );
- }
-
- private createAsset$(proof: Proof) {
+ add$(proof: Proof) {
return forkJoin([
defer(() => this.authService.getAuthHeaders()),
defer(() => buildFormDataToCreateAsset(proof)),
diff --git a/src/app/shared/services/notification/notification-item.spec.ts b/src/app/shared/services/notification/notification-item.spec.ts
index f85141473..97f498bc2 100644
--- a/src/app/shared/services/notification/notification-item.spec.ts
+++ b/src/app/shared/services/notification/notification-item.spec.ts
@@ -3,7 +3,6 @@
import { TestBed } from '@angular/core/testing';
import { LocalNotificationsPlugin, Plugins } from '@capacitor/core';
import { TranslocoService } from '@ngneat/transloco';
-import { of, throwError } from 'rxjs';
import { LOCAL_NOTIFICATIONS_PLUGIN } from '../../../shared/core/capacitor-plugins/capacitor-plugins.module';
import { SharedTestingModule } from '../../../shared/shared-testing.module';
import { NotificationItem } from './notification-item';
@@ -35,47 +34,6 @@ describe('NotificationItem', () => {
NotificationItem
);
});
-
- it('should be able to notify error', async () => {
- spyOn(console, 'error');
- expect(await item.error(SAMPLE_ERROR)).toBeInstanceOf(Error);
- });
-
- it('should be able to cancel itself', async () => {
- spyOn(console, 'log');
- expect(await item.cancel()).toBeInstanceOf(NotificationItem);
- });
-
- it('should be able to notify with on going action and cancel automatically', async () => {
- spyOn(console, 'info');
- spyOn(localNotificationsPlugin, 'cancel').and.resolveTo();
- const expected = 2;
- const result = await item.notifyOnGoing(
- of(1, expected),
- SAMPLE_TITLE,
- SAMPLE_MESSAGE
- );
- expect(localNotificationsPlugin.cancel).toHaveBeenCalled();
- expect(result).toEqual(expected);
- });
-
- it('should return an Error and do not cancel automatically when throw during on going action', async () => {
- const expected = SAMPLE_ERROR;
- spyOn(console, 'info');
- spyOn(localNotificationsPlugin, 'cancel').and.resolveTo();
- spyOn(item, 'error').and.resolveTo(expected);
- try {
- await item.notifyOnGoing(
- throwError(expected),
- SAMPLE_TITLE,
- SAMPLE_MESSAGE
- );
- } catch (err) {
- expect(err).toEqual(expected);
- }
- expect(localNotificationsPlugin.cancel).not.toHaveBeenCalled();
- expect(item.error).toHaveBeenCalled();
- });
});
const SAMPLE_TITLE = 'SAMPLE_TITLE';
diff --git a/src/app/shared/services/notification/notification-item.ts b/src/app/shared/services/notification/notification-item.ts
index 8f54c4b1d..0f6773c10 100644
--- a/src/app/shared/services/notification/notification-item.ts
+++ b/src/app/shared/services/notification/notification-item.ts
@@ -1,8 +1,6 @@
import { Inject } from '@angular/core';
import { LocalNotification, LocalNotificationsPlugin } from '@capacitor/core';
import { TranslocoService } from '@ngneat/transloco';
-import { Observable } from 'rxjs';
-import { last } from 'rxjs/operators';
import { LOCAL_NOTIFICATIONS_PLUGIN } from '../../../shared/core/capacitor-plugins/capacitor-plugins.module';
export class NotificationItem {
@@ -18,51 +16,6 @@ export class NotificationItem {
return this.schedule({ id: this.id, title, body });
}
- async error(error: Error) {
- console.error(error);
- await this.schedule({
- id: this.id,
- title: this.translocoService.translate('unknownError'),
- body: JSON.stringify(error),
- ongoing: false,
- });
- return error;
- }
-
- async cancel() {
- this.localNotificationsPlugin.cancel({
- notifications: [{ id: String(this.id) }],
- });
- return this;
- }
-
- async notifyOnGoing(
- action$: Observable,
- title: string,
- body: string,
- swipable = false
- ) {
- console.info(`${title}: ${body}`);
- const notification = await this.schedule({
- id: this.id,
- title,
- body,
- ongoing: !swipable,
- });
- return new Promise((resolve, reject) => {
- action$.pipe(last()).subscribe({
- next(value) {
- notification.cancel();
- resolve(value);
- },
- error(err) {
- notification.error(err);
- reject(err);
- },
- });
- });
- }
-
private async schedule(options: LocalNotification) {
await this.localNotificationsPlugin.schedule({
notifications: [options],
diff --git a/src/app/shared/services/notification/notification.service.spec.ts b/src/app/shared/services/notification/notification.service.spec.ts
index e7c203582..aa449502b 100644
--- a/src/app/shared/services/notification/notification.service.spec.ts
+++ b/src/app/shared/services/notification/notification.service.spec.ts
@@ -2,7 +2,6 @@
import { TestBed } from '@angular/core/testing';
import { LocalNotificationsPlugin, Plugins } from '@capacitor/core';
-import { of, throwError } from 'rxjs';
import { LOCAL_NOTIFICATIONS_PLUGIN } from '../../../shared/core/capacitor-plugins/capacitor-plugins.module';
import { SharedTestingModule } from '../../../shared/shared-testing.module';
import { NotificationItem } from './notification-item';
@@ -36,41 +35,6 @@ describe('NotificationService', () => {
NotificationItem
);
});
-
- it('should be able to notify error', async () => {
- spyOn(console, 'error');
- expect(await service.error(SAMPLE_ERROR)).toBeInstanceOf(Error);
- });
-
- it('should be able to notify with on going action and cancel automatically', async () => {
- spyOn(console, 'info');
- spyOn(localNotificationsPlugin, 'cancel').and.resolveTo();
- const expected = 2;
- const result = await service.notifyOnGoing(
- of(1, expected),
- SAMPLE_TITLE,
- SAMPLE_MESSAGE
- );
- expect(localNotificationsPlugin.cancel).toHaveBeenCalled();
- expect(result).toEqual(expected);
- });
-
- it('should return an Error and do not cancel automatically when throw during on going action', async () => {
- spyOn(console, 'info');
- spyOn(console, 'error');
- const expected = SAMPLE_ERROR;
- spyOn(localNotificationsPlugin, 'cancel').and.resolveTo();
- try {
- await service.notifyOnGoing(
- throwError(expected),
- SAMPLE_TITLE,
- SAMPLE_MESSAGE
- );
- } catch (err) {
- expect(err).toEqual(expected);
- }
- expect(localNotificationsPlugin.cancel).not.toHaveBeenCalled();
- });
});
const SAMPLE_TITLE = 'SAMPLE_TITLE';
diff --git a/src/app/shared/services/notification/notification.service.ts b/src/app/shared/services/notification/notification.service.ts
index 40a356040..d569e0fe0 100644
--- a/src/app/shared/services/notification/notification.service.ts
+++ b/src/app/shared/services/notification/notification.service.ts
@@ -1,7 +1,6 @@
import { Inject, Injectable } from '@angular/core';
import { LocalNotificationsPlugin } from '@capacitor/core';
import { TranslocoService } from '@ngneat/transloco';
-import { Observable } from 'rxjs';
import { LOCAL_NOTIFICATIONS_PLUGIN } from '../../../shared/core/capacitor-plugins/capacitor-plugins.module';
import { NotificationItem } from './notification-item';
@@ -37,22 +36,4 @@ export class NotificationService {
async notify(title: string, body: string) {
return this.createNotification().notify(title, body);
}
-
- async error(error: Error) {
- return this.createNotification().error(error);
- }
-
- async notifyOnGoing(
- action$: Observable,
- title: string,
- body: string,
- swipable = false
- ) {
- return this.createNotification().notifyOnGoing(
- action$,
- title,
- body,
- swipable
- );
- }
}
diff --git a/src/assets/i18n/en-us.json b/src/assets/i18n/en-us.json
index e29a4bb96..5a66d2681 100644
--- a/src/assets/i18n/en-us.json
+++ b/src/assets/i18n/en-us.json
@@ -23,8 +23,6 @@
"emptyInbox": "Empty Inbox",
"editCaption": "Edit Caption",
"selectAPublisher": "Select a Publisher",
- "registeringProof": "Registering Asset",
- "storingAssets": "Storing Capture",
"about": "About",
"version": "Version",
"informationProvider": "Information Provider",
@@ -97,8 +95,6 @@
"accountNotActivated": "This account has not been activated yet.",
"ifYouNotReceiveEmail": "If you haven't received the verification email in 10 minutes, you can click the button below to resend the verification email.",
"tooManyRetries": "You have entered the invalid email or password too many times. Please try again later.",
- "storingAssets": "Collecting environment variables, signing and storing assets...",
- "registeringProof": "Registering the asset to Numbers DIA.",
"forbiddenAllNumeric": "Cannot contain only numbers.",
"isNotEmail": "Does not follow email format.",
"pleaseWait": "Please wait...",
diff --git a/src/assets/i18n/zh-tw.json b/src/assets/i18n/zh-tw.json
index ff7538d80..d5d0e4816 100644
--- a/src/assets/i18n/zh-tw.json
+++ b/src/assets/i18n/zh-tw.json
@@ -23,8 +23,6 @@
"emptyInbox": "空收件匣",
"editCaption": "編輯標題",
"selectAPublisher": "選擇發佈者",
- "registeringProof": "正在發佈拍攝",
- "storingAssets": "正在儲存拍攝",
"about": "關於",
"version": "版本",
"informationProvider": "資訊提供者",
@@ -97,8 +95,6 @@
"accountNotActivated": "此帳戶尚未啟用。",
"ifYouNotReceiveEmail": "如果您在10分鐘內仍未收到驗證電子郵件,請單擊下面的按鈕重新發送驗證電子郵件。",
"tooManyRetries": "您輸入無效的電子郵件或密碼的次數過多。請稍後再試。",
- "storingAssets": "正在蒐集環境資料、簽章並保存拍攝...",
- "registeringProof": "正在將影像資產註冊至 Numbers DIA。",
"forbiddenAllNumeric": "密碼不能只有數字。",
"isNotEmail": "電子郵件格式不符。",
"pleaseWait": "請稍候...",