2018-03-02 04:48:12 +01:00
|
|
|
/*
|
2018-07-24 03:11:56 +02:00
|
|
|
This file is part of FreeTube.
|
2018-03-02 04:48:12 +01:00
|
|
|
|
2018-07-24 03:11:56 +02:00
|
|
|
FreeTube is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2018-03-02 04:48:12 +01:00
|
|
|
|
2018-07-24 03:11:56 +02:00
|
|
|
FreeTube is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2018-03-02 04:48:12 +01:00
|
|
|
|
2018-07-24 03:11:56 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with FreeTube. If not, see <http://www.gnu.org/licenses/>.
|
2018-03-02 04:48:12 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2018-07-24 03:11:56 +02:00
|
|
|
* File for all functions related specifically for channels.
|
|
|
|
*/
|
2018-03-02 04:48:12 +01:00
|
|
|
|
|
|
|
/**
|
2018-07-24 03:11:56 +02:00
|
|
|
* Display a channel page, showing latest uploads.
|
|
|
|
*
|
|
|
|
* @param {string} channelId - The channel ID to display.
|
|
|
|
*
|
|
|
|
* @return {Void}
|
|
|
|
*/
|
2018-03-02 04:48:12 +01:00
|
|
|
function goToChannel(channelId) {
|
|
|
|
|
2018-09-21 16:49:23 +02:00
|
|
|
channelView.channelId = channelId;
|
|
|
|
channelView.page = 2;
|
|
|
|
|
2018-06-25 22:04:11 +02:00
|
|
|
headerView.title = 'Latest Uploads';
|
|
|
|
hideViews();
|
|
|
|
loadingView.seen = true;
|
|
|
|
|
2018-03-13 00:37:30 +01:00
|
|
|
// Setting subButtonText here as Mustache templates are logic-less.
|
|
|
|
isSubscribed(channelId).then((subscribed) => {
|
2018-06-25 22:04:11 +02:00
|
|
|
channelView.subButtonText = (subscribed ? "UNSUBSCRIBE" : "SUBSCRIBE");
|
2018-03-02 04:48:12 +01:00
|
|
|
});
|
|
|
|
|
2018-09-19 17:01:21 +02:00
|
|
|
invidiousAPI('channels', channelId, {}, (data) => {
|
2019-05-20 20:53:14 +02:00
|
|
|
ft.log(data);
|
2018-03-02 04:48:12 +01:00
|
|
|
|
2018-06-25 22:04:11 +02:00
|
|
|
channelView.id = channelId;
|
2018-09-19 17:01:21 +02:00
|
|
|
channelView.name = data.author;
|
2019-07-13 16:10:59 +02:00
|
|
|
|
|
|
|
// Can't access url of undefined, check defined
|
|
|
|
data.authorBanners.length
|
|
|
|
? channelView.banner = data.authorBanners[0].url
|
|
|
|
: channelView.banner = undefined;
|
|
|
|
|
|
|
|
data.authorThumbnails.length >= 4
|
|
|
|
? channelView.icon = data.authorThumbnails[3].url
|
|
|
|
: channelView.icon = undefined
|
|
|
|
|
2018-09-19 17:01:21 +02:00
|
|
|
channelView.subCount = data.subCount.toLocaleString(); //toLocaleString adds commas as thousands separators
|
|
|
|
channelView.description = autolinker.link(data.description); //autolinker makes URLs clickable
|
|
|
|
|
|
|
|
channelVideosView.videoList = [];
|
|
|
|
|
2019-07-13 16:10:59 +02:00
|
|
|
const views = [
|
|
|
|
aboutView,
|
|
|
|
headerView,
|
|
|
|
historyView,
|
|
|
|
popularView,
|
|
|
|
savedView,
|
|
|
|
searchView,
|
|
|
|
settingsView,
|
|
|
|
subscriptionView
|
|
|
|
]
|
|
|
|
|
|
|
|
if (seenAll(views, false)) {
|
2018-09-19 17:01:21 +02:00
|
|
|
channelVideosView.seen = true;
|
|
|
|
channelView.seen = true;
|
|
|
|
}
|
2019-07-13 16:10:59 +02:00
|
|
|
else {
|
2018-09-19 17:01:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
loadingView.seen = false;
|
|
|
|
data.latestVideos.forEach((video) => {
|
|
|
|
displayVideo(video, 'channel');
|
2018-03-02 04:48:12 +01:00
|
|
|
});
|
2019-08-01 20:42:36 +02:00
|
|
|
|
|
|
|
if (typeof(channelView.banner) === 'undefined') {
|
|
|
|
window.setTimeout(() => {$('.channelViewBanner').get(0).height = 200;}, 50);
|
|
|
|
}
|
2018-11-09 21:22:39 +01:00
|
|
|
}, (errorData) => {
|
|
|
|
showToast(errorData.responseJSON.error);
|
|
|
|
loadingView.seen = false;
|
2018-08-03 04:18:08 +02:00
|
|
|
});
|
|
|
|
}
|
2018-09-21 16:49:23 +02:00
|
|
|
|
2018-10-16 21:59:57 +02:00
|
|
|
/**
|
|
|
|
* Grab the next list of videos from a channel.
|
|
|
|
*
|
|
|
|
* @return {Void}
|
|
|
|
*/
|
2018-09-21 16:49:23 +02:00
|
|
|
function channelNextPage() {
|
2019-07-13 16:07:48 +02:00
|
|
|
showToast('Fetching results, please wait…');
|
2018-09-21 16:49:23 +02:00
|
|
|
|
2019-07-13 16:10:59 +02:00
|
|
|
invidiousAPI('channels/videos', channelView.channelId, { 'page': channelView.page }, (data) => {
|
2019-05-20 20:53:14 +02:00
|
|
|
ft.log(data);
|
2018-09-21 16:49:23 +02:00
|
|
|
data.forEach((video) => {
|
|
|
|
displayVideo(video, 'channel');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
channelView.page = channelView.page + 1;
|
|
|
|
}
|
2019-07-13 16:10:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the status of all view objects 'seen' property.
|
|
|
|
* @param {Array} views - An array of view objects, that should have a 'seen' property
|
|
|
|
* @param {bool} expected - The expected match, confirm all seen props === expected.
|
|
|
|
* True by default.
|
|
|
|
* @returns {bool} - True if all views.seen === expected
|
|
|
|
* @example seenAll{[view1, view2], false} => bool
|
|
|
|
* @example seenAll{[view1, view2]} => bool
|
|
|
|
*/
|
|
|
|
function seenAll(views, expected = true) {
|
|
|
|
return views.every(({ seen }) => seen === expected)
|
|
|
|
}
|