From 045e37a0d3f670a11fefa1b0fd3e3b99b6b5d65b Mon Sep 17 00:00:00 2001 From: CrissZollo Date: Sat, 20 Sep 2025 09:02:28 +0200 Subject: [PATCH] Updated so scheduled notifications does not cancel on test and are added and removed by saving to library --- src/screens/NotificationSettingsScreen.tsx | 12 +++--- src/services/catalogService.ts | 49 ++++++++++------------ 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/screens/NotificationSettingsScreen.tsx b/src/screens/NotificationSettingsScreen.tsx index fecf782ad..2708c5541 100644 --- a/src/screens/NotificationSettingsScreen.tsx +++ b/src/screens/NotificationSettingsScreen.tsx @@ -116,7 +116,7 @@ const NotificationSettingsScreen = () => { const resetAllNotifications = async () => { Alert.alert( 'Reset Notifications', - 'This will cancel all scheduled notifications. Are you sure?', + 'This will cancel all scheduled notifications, but will not remove anything from your saved library. Are you sure?', [ { text: 'Cancel', @@ -127,7 +127,11 @@ const NotificationSettingsScreen = () => { style: 'destructive', onPress: async () => { try { - await notificationService.cancelAllNotifications(); + // Cancel all notifications for all series, but do not remove from saved + const scheduledNotifications = notificationService.getScheduledNotifications?.() || []; + for (const notification of scheduledNotifications) { + await notificationService.cancelNotification(notification.id); + } Alert.alert('Success', 'All notifications have been reset'); } catch (error) { logger.error('Error resetting notifications:', error); @@ -466,10 +470,6 @@ const NotificationSettingsScreen = () => { )} - - - This will cancel all scheduled notifications. You'll need to re-enable them manually. - )} diff --git a/src/services/catalogService.ts b/src/services/catalogService.ts index 6b5a81ce4..3988513e8 100644 --- a/src/services/catalogService.ts +++ b/src/services/catalogService.ts @@ -1,4 +1,5 @@ import { stremioService, Meta, Manifest } from './stremioService'; +import { notificationService } from './notificationService'; import AsyncStorage from '@react-native-async-storage/async-storage'; import axios from 'axios'; import { TMDBService } from './tmdbService'; @@ -690,15 +691,14 @@ class CatalogService { try { this.libraryAddListeners.forEach(l => l(content)); } catch {} // Auto-setup notifications for series when added to library - // if (content.type === 'series') { - // try { - // const { notificationService } = await import('./notificationService'); - // await notificationService.updateNotificationsForSeries(content.id); - // console.log(`[CatalogService] Auto-setup notifications for series: ${content.name}`); - // } catch (error) { - // console.error(`[CatalogService] Failed to setup notifications for ${content.name}:`, error); - // } - // } + if (content.type === 'series') { + try { + await notificationService.updateNotificationsForSeries(content.id); + console.log(`[CatalogService] Auto-setup notifications for series: ${content.name}`); + } catch (error) { + console.error(`[CatalogService] Failed to setup notifications for ${content.name}:`, error); + } + } } public async removeFromLibrary(type: string, id: string): Promise { @@ -707,24 +707,21 @@ class CatalogService { this.saveLibrary(); this.notifyLibrarySubscribers(); try { this.libraryRemoveListeners.forEach(l => l(type, id)); } catch {} - + // Cancel notifications for series when removed from library - // if (type === 'series') { - // try { - // const { notificationService } = await import('./notificationService'); - // // Cancel all notifications for this series - // const scheduledNotifications = await notificationService.getScheduledNotifications(); - // const seriesToCancel = scheduledNotifications.filter(notification => notification.seriesId === id); - // - // for (const notification of seriesToCancel) { - // await notificationService.cancelNotification(notification.id); - // } - // - // console.log(`[CatalogService] Cancelled ${seriesToCancel.length} notifications for removed series: ${id}`); - // } catch (error) { - // console.error(`[CatalogService] Failed to cancel notifications for removed series ${id}:`, error); - // } - // } + if (type === 'series') { + try { + // Cancel all notifications for this series + const scheduledNotifications = notificationService.getScheduledNotifications(); + const seriesToCancel = scheduledNotifications.filter(notification => notification.seriesId === id); + for (const notification of seriesToCancel) { + await notificationService.cancelNotification(notification.id); + } + console.log(`[CatalogService] Cancelled ${seriesToCancel.length} notifications for removed series: ${id}`); + } catch (error) { + console.error(`[CatalogService] Failed to cancel notifications for removed series ${id}:`, error); + } + } } private addToRecentContent(content: StreamingContent): void {