Navigation access icon

This commit is contained in:
binwiederhier 2023-01-03 11:28:04 -05:00
parent 2f725bf80d
commit 2500ce0920
3 changed files with 57 additions and 19 deletions

View file

@ -256,25 +256,25 @@ class AccountApi {
return null;
}
console.log(`[AccountApi] Syncing account`);
const remoteAccount = await this.get();
if (remoteAccount.language) {
await i18n.changeLanguage(remoteAccount.language);
const account = await this.get();
if (account.language) {
await i18n.changeLanguage(account.language);
}
if (remoteAccount.notification) {
if (remoteAccount.notification.sound) {
await prefs.setSound(remoteAccount.notification.sound);
if (account.notification) {
if (account.notification.sound) {
await prefs.setSound(account.notification.sound);
}
if (remoteAccount.notification.delete_after) {
await prefs.setDeleteAfter(remoteAccount.notification.delete_after);
if (account.notification.delete_after) {
await prefs.setDeleteAfter(account.notification.delete_after);
}
if (remoteAccount.notification.min_priority) {
await prefs.setMinPriority(remoteAccount.notification.min_priority);
if (account.notification.min_priority) {
await prefs.setMinPriority(account.notification.min_priority);
}
}
if (remoteAccount.subscriptions) {
await subscriptionManager.syncFromRemote(remoteAccount.subscriptions);
if (account.subscriptions) {
await subscriptionManager.syncFromRemote(account.subscriptions, account.reservations);
}
return remoteAccount;
return account;
} catch (e) {
console.log(`[AccountApi] Error fetching account`, e);
if ((e instanceof UnauthorizedError)) {

View file

@ -35,7 +35,7 @@ class SubscriptionManager {
return subscription;
}
async syncFromRemote(remoteSubscriptions) {
async syncFromRemote(remoteSubscriptions, remoteReservations) {
console.log(`[SubscriptionManager] Syncing subscriptions from remote`, remoteSubscriptions);
// Add remote subscriptions
@ -43,8 +43,10 @@ class SubscriptionManager {
for (let i = 0; i < remoteSubscriptions.length; i++) {
const remote = remoteSubscriptions[i];
const local = await this.add(remote.base_url, remote.topic);
const reservation = remoteReservations?.find(r => remote.base_url === config.baseUrl && remote.topic === r.topic) || null;
await this.setRemoteId(local.id, remote.id);
await this.setDisplayName(local.id, remote.display_name);
await this.setReservation(local.id, reservation); // May be null!
remoteIds.push(remote.id);
}
@ -174,6 +176,12 @@ class SubscriptionManager {
});
}
async setReservation(subscriptionId, reservation) {
await db.subscriptions.update(subscriptionId, {
reservation: reservation
});
}
async pruneNotifications(thresholdTimestamp) {
await db.notifications
.where("time").below(thresholdTimestamp)