mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-07 21:32:51 +00:00
Respect NSFW flag while letting authors review their uploads
This commit is contained in:
1 parent
e15aff51a4
commit
85258e27ea
10 files changed
+174
-21
No files matched your search
@@ -16,6 +16,7 @@ export class VideoCard {
|
||||
state = {},
|
||||
ensureGlobalMoreMenuHandlers,
|
||||
onRequestCloseAllMenus,
|
||||
nsfwContext = null,
|
||||
} = {}) {
|
||||
if (!doc) {
|
||||
throw new Error("VideoCard requires a document reference.");
|
||||
@@ -72,6 +73,16 @@ export class VideoCard {
|
||||
? onRequestCloseAllMenus
|
||||
: null;
|
||||
|
||||
this.nsfwContext = {
|
||||
isNsfw: Boolean(nsfwContext?.isNsfw),
|
||||
allowNsfw: nsfwContext?.allowNsfw !== false,
|
||||
viewerIsOwner: nsfwContext?.viewerIsOwner === true,
|
||||
};
|
||||
this.shouldMaskNsfwForOwner =
|
||||
this.nsfwContext.isNsfw &&
|
||||
!this.nsfwContext.allowNsfw &&
|
||||
this.nsfwContext.viewerIsOwner;
|
||||
|
||||
this.callbacks = {
|
||||
onPlay: null,
|
||||
onEdit: null,
|
||||
@@ -220,6 +231,7 @@ export class VideoCard {
|
||||
root.dataset.videoId = this.video.id;
|
||||
}
|
||||
|
||||
this.applyNsfwContext();
|
||||
this.applyPointerDataset();
|
||||
this.applyOwnerDataset();
|
||||
this.applySourceDatasets();
|
||||
@@ -340,6 +352,10 @@ export class VideoCard {
|
||||
|
||||
this.thumbnailEl = img;
|
||||
|
||||
if (this.shouldMaskNsfwForOwner) {
|
||||
img.classList.add("video-card__thumbnail--blurred");
|
||||
}
|
||||
|
||||
const markThumbnailAsLoaded = () => {
|
||||
if (!thumbnailUrl) {
|
||||
return;
|
||||
@@ -1257,6 +1273,29 @@ export class VideoCard {
|
||||
return container;
|
||||
}
|
||||
|
||||
applyNsfwContext() {
|
||||
if (!this.root) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.nsfwContext?.isNsfw) {
|
||||
if (this.root.dataset.nsfwVisibility) {
|
||||
delete this.root.dataset.nsfwVisibility;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.shouldMaskNsfwForOwner) {
|
||||
this.root.dataset.nsfwVisibility = "owner-only";
|
||||
this.root.classList.add("video-card--nsfw-owner");
|
||||
return;
|
||||
}
|
||||
|
||||
this.root.dataset.nsfwVisibility = this.nsfwContext.allowNsfw
|
||||
? "allowed"
|
||||
: "hidden";
|
||||
}
|
||||
|
||||
applyPointerDataset() {
|
||||
if (!this.root) {
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user