Skip to content

Commit

Permalink
remove check for tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-tatar committed Nov 22, 2022
1 parent 4ea375e commit 85ef658
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions src/nora/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@andrei-tatar/nora-firebase-common';
import { FirebaseApp } from 'firebase/app';
import { getAuth } from 'firebase/auth';
import { DatabaseReference, get, getDatabase, onValue, ref, remove, set } from 'firebase/database';
import { DatabaseReference, getDatabase, onValue, ref, remove, set } from 'firebase/database';
import {
BehaviorSubject, concat, defer, merge, Observable,
of, Subject, throwError, timer
Expand Down Expand Up @@ -156,22 +156,18 @@ export class FirebaseSync {
}

async sendNotification(notification: WebpushNotification) {
if (await this.hasDeviceTokens()) {
await this.queueJob({
type: 'notify',
notification,
});
}
await this.queueJob({
type: 'notify',
notification,
});
}

async sendGoogleHomeNotification(deviceId: string, notification: ObjectDetectionNotification) {
if (await this.hasDeviceTokens()) {
await this.queueJob({
type: 'notify-home',
deviceId,
notification,
});
}
await this.queueJob({
type: 'notify-home',
deviceId,
notification,
});
}

watchForActions(identifier: string): Observable<string> {
Expand All @@ -191,12 +187,6 @@ export class FirebaseSync {
);
}

private async hasDeviceTokens() {
const tokensRef = ref(this.db, `user/${this.uid}/device_tokens`);
const tokens: string[] | null = await get(tokensRef).then(s => s.val());
return !!tokens?.length;
}

private async syncDevices(devices: Device[]) {
const syncAttributes = devices.map(({ id, attributes, name }) => ({ id, attributes, name }));
syncAttributes.sort((a, b) => a.id.localeCompare(b.id));
Expand Down

0 comments on commit 85ef658

Please sign in to comment.