Update watched videos more often.

This commit is contained in:
FireMasterK 2021-08-22 15:52:11 +05:30
parent cadc1ac72c
commit da75f28091
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD
5 changed files with 30 additions and 28 deletions

View file

@ -47,6 +47,7 @@ export default {
activated() { activated() {
if (this.channel && !this.channel.error) document.title = this.channel.name + " - Piped"; if (this.channel && !this.channel.error) document.title = this.channel.name + " - Piped";
window.addEventListener("scroll", this.handleScroll); window.addEventListener("scroll", this.handleScroll);
if (this.channel && !this.channel.error) this.updateWatched(this.channel.relatedStreams);
}, },
deactivated() { deactivated() {
window.removeEventListener("scroll", this.handleScroll); window.removeEventListener("scroll", this.handleScroll);
@ -78,6 +79,7 @@ export default {
if (!this.channel.error) { if (!this.channel.error) {
document.title = this.channel.name + " - Piped"; document.title = this.channel.name + " - Piped";
if (this.authenticated) this.fetchSubscribedStatus(); if (this.authenticated) this.fetchSubscribedStatus();
this.updateWatched(this.channel.relatedStreams);
} }
}); });
}, },
@ -88,9 +90,9 @@ export default {
this.fetchJson(this.apiUrl() + "/nextpage/channel/" + this.channel.id, { this.fetchJson(this.apiUrl() + "/nextpage/channel/" + this.channel.id, {
nextpage: this.channel.nextpage, nextpage: this.channel.nextpage,
}).then(json => { }).then(json => {
this.channel.relatedStreams.concat(json.relatedStreams);
this.channel.nextpage = json.nextpage; this.channel.nextpage = json.nextpage;
this.loading = false; this.loading = false;
this.updateWatched(json.relatedStreams);
json.relatedStreams.map(stream => this.channel.relatedStreams.push(stream)); json.relatedStreams.map(stream => this.channel.relatedStreams.push(stream));
}); });
} }

View file

@ -46,29 +46,12 @@ export default {
mounted() { mounted() {
this.fetchFeed().then(videos => { this.fetchFeed().then(videos => {
this.videos = videos; this.videos = videos;
(async () => { this.updateWatched(this.videos);
if (window.db) {
var tx = window.db.transaction("watch_history", "readonly");
var store = tx.objectStore("watch_history");
const cursorRequest = store.openCursor();
cursorRequest.onsuccess = e => {
const cursor = e.target.result;
if (cursor) {
const video = this.videos.filter(
video => video.url.substr(-11) === cursor.value.videoId,
)[0];
if (video != null) {
video.watched = true;
}
cursor.continue();
}
};
}
})();
}); });
}, },
activated() { activated() {
document.title = "Feed - Piped"; document.title = "Feed - Piped";
if (this.videos.length > 0) this.updateWatched(this.videos);
}, },
methods: { methods: {
async fetchFeed() { async fetchFeed() {

View file

@ -50,7 +50,6 @@ export default {
}, },
methods: { methods: {
register() { register() {
console.log("authToken" + this.hashCode(this.apiUrl()));
this.fetchJson(this.apiUrl() + "/register", null, { this.fetchJson(this.apiUrl() + "/register", null, {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({

View file

@ -27,10 +27,14 @@ export default {
mounted() { mounted() {
let region = this.getPreferenceString("region", "US"); let region = this.getPreferenceString("region", "US");
this.fetchTrending(region).then(videos => (this.videos = videos)); this.fetchTrending(region).then(videos => {
this.videos = videos;
this.updateWatched(this.videos);
});
}, },
activated() { activated() {
document.title = "Trending - Piped"; document.title = "Trending - Piped";
if (this.videos.length > 0) this.updateWatched(this.videos);
}, },
methods: { methods: {
async fetchTrending(region) { async fetchTrending(region) {

View file

@ -25,7 +25,7 @@ library.add(
faHeadphones, faHeadphones,
faYoutube, faYoutube,
faRss, faRss,
faChevronLeft faChevronLeft,
); );
import("uikit/dist/css/uikit-core.css"); import("uikit/dist/css/uikit-core.css");
@ -160,11 +160,25 @@ const mixin = {
}, },
urlify(string) { urlify(string) {
const regex = /(((https?:\/\/)|(www\.))[^\s]+)/g; const regex = /(((https?:\/\/)|(www\.))[^\s]+)/g;
if (!string) return ''; if (!string) return "";
return string.replace(regex, (url) => { return string.replace(regex, url => {
return `<a class="uk-button uk-button-text" href="${url}" target="_blank">${url}</a>` return `<a class="uk-button uk-button-text" href="${url}" target="_blank">${url}</a>`;
}) });
},
async updateWatched(videos) {
if (window.db) {
var tx = window.db.transaction("watch_history", "readonly");
var store = tx.objectStore("watch_history");
videos.map(async video => {
var request = store.get(video.url.substr(-11));
request.onsuccess = function(event) {
if (event.target.result) {
video.watched = true;
} }
};
});
}
},
}, },
computed: { computed: {
backgroundColor() { backgroundColor() {