1
0
Fork 0
mirror of https://git.sr.ht/~cadence/cloudtube synced 2026-03-02 10:41:36 +00:00

Rework subscribing to deleted channels

This commit is contained in:
Cadence Ember 2022-01-10 14:18:45 +13:00
parent 15e3f06ad6
commit 109dcd22de
No known key found for this signature in database
GPG key ID: BC1C2C61CF521B17
12 changed files with 167 additions and 22 deletions

View file

@ -13,6 +13,16 @@ module.exports = [
const data = await fetchChannel(id, settings.instance)
const subscribed = user.isSubscribed(id)
const instanceOrigin = settings.instance
// problem with the channel? fetchChannel has collected the necessary information for us.
// we can render a skeleton page, display the message, and provide the option to unsubscribe.
if (data.error) {
const statusCode = data.missing ? 410 : 500
return render(statusCode, "pug/channel-error.pug", {settings, data, subscribed, instanceOrigin})
}
// everything is fine
// normalise info, apply watched status
if (!data.second__subCountText && data.subCount) {
data.second__subCountText = converters.subscriberCountToText(data.subCount)
@ -24,7 +34,7 @@ module.exports = [
video.watched = watchedVideos.includes(video.videoId)
})
}
return render(200, "pug/channel.pug", {settings, url, data, subscribed, instanceOrigin})
return render(200, "pug/channel.pug", {settings, data, subscribed, instanceOrigin})
}
}
]

View file

@ -26,7 +26,6 @@ module.exports = [
await fetchChannel(ucid, settings.instance)
db.prepare(
"INSERT INTO Subscriptions (token, ucid) VALUES (?, ?)"
+ " ON CONFLICT (token, ucid) DO UPDATE SET channel_missing = 0"
).run(token, ucid)
} else {
db.prepare("DELETE FROM Subscriptions WHERE token = ? AND ucid = ?").run(token, ucid)
@ -41,7 +40,6 @@ module.exports = [
}),
content: "Success, redirecting..."
}
return redirect(params.get("referrer"), 303)
} else {
return {
statusCode: 200,

View file

@ -11,12 +11,14 @@ module.exports = [
let hasSubscriptions = false
let videos = []
let channels = []
let missingChannelCount = 0
let refreshed = null
if (user.token) {
// trigger a background refresh, needed if they came back from being inactive
refresher.skipWaiting()
// get channels
channels = db.prepare(`SELECT Channels.* FROM Channels INNER JOIN Subscriptions ON Channels.ucid = Subscriptions.ucid WHERE token = ? ORDER BY name`).all(user.token)
missingChannelCount = channels.reduce((a, c) => a + c.missing, 0)
// get refreshed status
refreshed = db.prepare(`SELECT min(refreshed) as min, max(refreshed) as max, count(refreshed) as count FROM Channels INNER JOIN Subscriptions ON Channels.ucid = Subscriptions.ucid WHERE token = ?`).get(user.token)
// get watched videos
@ -37,7 +39,7 @@ module.exports = [
}
const settings = user.getSettingsOrDefaults()
const instanceOrigin = settings.instance
return render(200, "pug/subscriptions.pug", {url, settings, hasSubscriptions, videos, channels, refreshed, timeToPastText, instanceOrigin})
return render(200, "pug/subscriptions.pug", {url, settings, hasSubscriptions, videos, channels, missingChannelCount, refreshed, timeToPastText, instanceOrigin})
}
}
]