Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Mark as Watched in feed #3746

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/components/FeedPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

<LoadingIndicatorPage :show-content="videosStore != null" class="video-grid">
<template v-for="video in filteredVideos" :key="video.url">
<VideoItem v-if="shouldShowVideo(video)" :is-feed="true" :item="video" />
<VideoItem v-if="shouldShowVideo(video)" :is-feed="true" :item="video" @update:watched="onUpdateWatched" />
</template>
</LoadingIndicatorPage>
</template>
Expand Down Expand Up @@ -140,6 +140,15 @@ export default {
this.loadMoreVideos();
}
},
onUpdateWatched(urls = null) {
if (urls === null) {
if (this.videos.length > 0) this.updateWatched(this.videos);
return;
}

const subset = this.videos.filter(({ url }) => urls.includes(url));
if (subset.length > 0) this.updateWatched(subset);
},
shouldShowVideo(video) {
switch (this.selectedFilter.toLowerCase()) {
case "shorts":
Expand Down
48 changes: 47 additions & 1 deletion src/components/VideoItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@
>
<i class="i-fa6-solid:circle-minus" />
</button>
<button
v-if="showMarkOnWatched && isFeed"
ref="watchButton"
@click="toggleWatched(item.url.substr(-11))"
>
<i
v-if="item.watched && item.currentTime > item.duration * 0.9"
:title="$t('actions.mark_as_unwatched')"
class="i-fa6-solid:eye-slash"
/>
<i v-else :title="$t('actions.mark_as_watched')" class="i-fa6-solid:eye" />
</button>
<ConfirmModal
v-if="showConfirmRemove"
:message="$t('actions.delete_playlist_video_confirm')"
Expand Down Expand Up @@ -171,13 +183,14 @@ export default {
preferListen: { type: Boolean, default: false },
admin: { type: Boolean, default: false },
},
emits: ["remove"],
emits: ["update:watched", "remove"],
data() {
return {
showPlaylistModal: false,
showShareModal: false,
showVideo: true,
showConfirmRemove: false,
showMarkOnWatched: false,
};
},
computed: {
Expand All @@ -190,6 +203,7 @@ export default {
},
mounted() {
this.shouldShowVideo();
this.shouldShowMarkOnWatched();
},
methods: {
removeVideo() {
Expand All @@ -212,6 +226,38 @@ export default {
}
};
},
shouldShowMarkOnWatched() {
this.showMarkOnWatched = this.getPreferenceBoolean("watchHistory", false);
},
toggleWatched(videoId) {
if (window.db) {
var tx = window.db.transaction("watch_history", "readwrite");
var store = tx.objectStore("watch_history");
var instance = this;
var request = store.get(videoId);
request.onsuccess = function (event) {
var video = event.target.result;
if (video) {
video.watchedAt = Date.now();
} else {
video = {
videoId: videoId,
title: instance.item.title,
duration: instance.item.duration,
thumbnail: instance.item.thumbnail,
uploaderUrl: instance.item.uploaderUrl,
uploaderName: instance.item.uploaderName,
watchedAt: Date.now(),
};
}
video.currentTime =
instance.item.currentTime < instance.item.duration * 0.9 ? instance.item.duration : 0;
store.put(video);
instance.$emit("update:watched", [instance.item.url]);
instance.shouldShowVideo();
};
}
},
},
};
</script>
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"show_chapters": "Chapters",
"store_search_history": "Store Search History",
"hide_watched": "Hide watched videos in the feed",
"mark_as_watched": "Mark as Watched",
"mark_as_unwatched": "Mark as Unwatched",
"documentation": "Documentation",
"status_page": "Status",
"source_code": "Source code",
Expand Down
5 changes: 5 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ const mixin = {
var request = store.get(video.url.substr(-11));
request.onsuccess = function (event) {
if (event.target.result) {
if (event.target.result.currentTime == 0) {
video.watched = false;
video.currentTime = event.target.result.currentTime;
return;
}
video.watched = true;
video.currentTime = event.target.result.currentTime;
}
Expand Down
Loading