Skip to content

Commit

Permalink
Merge pull request #491 from Stremio/fix/dismiss-continue-watching-it…
Browse files Browse the repository at this point in the history
…em-notification

fix: continue watching items were not dismissed
  • Loading branch information
elpiel authored Aug 10, 2023
2 parents 1178940 + 8e750a8 commit de6e58a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/models/continue_watching_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@ impl<E: Env + 'static> UpdateWithCtx<E> for ContinueWatchingPreview {
match msg {
// library has changed
Msg::Internal(Internal::LibraryChanged(true))
// LibraryItem has been updated (this message alters the `mtime` and will re-order the CW list)
| Msg::Internal(Internal::UpdateLibraryItem(_))
// notifications have been updated
| Msg::Internal(Internal::NotificationsChanged)
// or a notification has been dismissed (this will re-order the given LibraryItem based on mtime)
| Msg::Internal(Internal::DismissNotificationItem(_)) => {
| Msg::Internal(Internal::NotificationsChanged) => {
library_items_update(&mut self.library_items, &ctx.library, &ctx.notifications)
}
_ => Effects::none().unchanged(),
Expand Down
1 change: 1 addition & 0 deletions src/models/ctx/update_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub fn update_library<E: Env + 'static>(
Some(library_item) => {
let mut library_item = library_item.to_owned();
library_item.state.time_offset = 0;
library_item.state.last_watched = Some(E::now());
Effects::msg(Msg::Internal(Internal::UpdateLibraryItem(library_item)))
.join(Effects::msg(Msg::Event(Event::LibraryItemRewinded {
id: id.to_owned(),
Expand Down
15 changes: 11 additions & 4 deletions src/models/ctx/update_notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ pub fn update_notifications<E: Env + 'static>(
.join(notification_items_effects)
.unchanged()
}
Msg::Action(Action::Ctx(ActionCtx::DismissNotificationItem(id))) => {
remove_notification_item(notifications, id)
}
Msg::Action(Action::Ctx(ActionCtx::Logout)) | Msg::Internal(Internal::Logout) => {
let notification_catalogs_effects = eq_update(notification_catalogs, vec![]);
let next_notifications = NotificationsBucket::new::<E>(profile.uid(), vec![]);
Expand Down Expand Up @@ -132,10 +135,7 @@ pub fn update_notifications<E: Env + 'static>(
.join(notifications_effects)
}
Msg::Internal(Internal::DismissNotificationItem(id)) => {
match notifications.items.remove(id) {
Some(_) => Effects::msg(Msg::Internal(Internal::NotificationsChanged)).unchanged(),
_ => Effects::none().unchanged(),
}
remove_notification_item(notifications, id)
}
Msg::Internal(Internal::NotificationsChanged) => {
Effects::one(push_notifications_to_storage::<E>(notifications)).unchanged()
Expand Down Expand Up @@ -256,3 +256,10 @@ fn push_notifications_to_storage<E: Env + 'static>(notifications: &Notifications
)
.into()
}

fn remove_notification_item(notifications: &mut NotificationsBucket, id: &String) -> Effects {
match notifications.items.remove(id) {
Some(_) => Effects::msg(Msg::Internal(Internal::NotificationsChanged)).unchanged(),
_ => Effects::none().unchanged(),
}
}
3 changes: 2 additions & 1 deletion src/unit_tests/ctx/rewind_library_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn actionctx_rewindlibraryitem() {
url, method, body, ..
} if url == "https://api.strem.io/api/datastorePut"
&& method == "POST"
&& body == "{\"authKey\":\"auth_key\",\"collection\":\"libraryItem\",\"changes\":[{\"_id\":\"id\",\"name\":\"name\",\"type\":\"type\",\"poster\":null,\"posterShape\":\"poster\",\"removed\":false,\"temp\":false,\"_ctime\":\"2020-01-01T00:00:00Z\",\"_mtime\":\"2020-01-02T00:00:00Z\",\"state\":{\"lastWatched\":null,\"timeWatched\":0,\"timeOffset\":0,\"overallTimeWatched\":0,\"timesWatched\":0,\"flaggedWatched\":0,\"duration\":0,\"video_id\":null,\"watched\":null,\"lastVideoReleased\":null,\"noNotif\":false},\"behaviorHints\":{\"defaultVideoId\":null,\"featuredVideoId\":null,\"hasScheduledVideos\":false}}]}" =>
&& body == "{\"authKey\":\"auth_key\",\"collection\":\"libraryItem\",\"changes\":[{\"_id\":\"id\",\"name\":\"name\",\"type\":\"type\",\"poster\":null,\"posterShape\":\"poster\",\"removed\":false,\"temp\":false,\"_ctime\":\"2020-01-01T00:00:00Z\",\"_mtime\":\"2020-01-02T00:00:00Z\",\"state\":{\"lastWatched\":\"2020-01-02T00:00:00Z\",\"timeWatched\":0,\"timeOffset\":0,\"overallTimeWatched\":0,\"timesWatched\":0,\"flaggedWatched\":0,\"duration\":0,\"video_id\":null,\"watched\":null,\"lastVideoReleased\":null,\"noNotif\":false},\"behaviorHints\":{\"defaultVideoId\":null,\"featuredVideoId\":null,\"hasScheduledVideos\":false}}]}" =>
{
future::ok(Box::new(APIResult::Ok {
result: SuccessResponse { success: True {} },
Expand Down Expand Up @@ -58,6 +58,7 @@ fn actionctx_rewindlibraryitem() {
mtime: Utc.with_ymd_and_hms(2020, 1, 2, 0, 0, 0).unwrap(),
state: LibraryItemState {
time_offset: 0,
last_watched: Some(Utc.with_ymd_and_hms(2020, 1, 2, 0, 0, 0).unwrap()),
..LibraryItemState::default()
},
..library_item.to_owned()
Expand Down

0 comments on commit de6e58a

Please sign in to comment.