Commit 09ec8d8d authored by Mark Harding's avatar Mark Harding
Browse files

(feat): implements nsfw consent to new activity components

parent 9acad129
Loading
Loading
Loading
Loading
+17 −8
Original line number Original line Diff line number Diff line
import { CookieService } from '../../../common/services/cookie.service';
import { CookieService } from '../../../common/services/cookie.service';
import { Injectable } from '@angular/core';
import { Injectable } from '@angular/core';


@Injectable()
type NsfwReason = {
export class NSFWSelectorService {
  value: number;
  cacheKey: string = '';
  label: string;
  selected: boolean;
  locked: boolean;
};


  reasons: Array<any> = [
export const NSFW_REASONS: NsfwReason[] = [
  { value: 1, label: 'Nudity', selected: false, locked: false },
  { value: 1, label: 'Nudity', selected: false, locked: false },
  { value: 2, label: 'Pornography', selected: false, locked: false },
  { value: 2, label: 'Pornography', selected: false, locked: false },
  { value: 3, label: 'Profanity', selected: false, locked: false },
  { value: 3, label: 'Profanity', selected: false, locked: false },
@@ -14,6 +17,12 @@ export class NSFWSelectorService {
  { value: 6, label: 'Other', selected: false, locked: false },
  { value: 6, label: 'Other', selected: false, locked: false },
];
];


@Injectable()
export class NSFWSelectorService {
  cacheKey: string = '';

  reasons: Array<any> = NSFW_REASONS;

  constructor(private cookieService: CookieService) {}
  constructor(private cookieService: CookieService) {}


  onInit() {}
  onInit() {}
+3 −3
Original line number Original line Diff line number Diff line
@@ -5,11 +5,11 @@
</m-activity__ownerBlock>
</m-activity__ownerBlock>


<m-activity__content
<m-activity__content
  *ngIf="service.canShowContent$ | async"
  *ngIf="service.shouldShowContent$ | async"
></m-activity__content>
></m-activity__content>


<!-- <m-activity__nsfwConsent *ngIf="service.isNsfw$ | async">
<m-activity__nsfwConsent *ngIf="service.shouldShowNsfwConsent$ | async">
</m-activity__nsfwConsent> -->
</m-activity__nsfwConsent>


<m-activity__toolbar
<m-activity__toolbar
  *ngIf="service.displayOptions.showToolbar"
  *ngIf="service.displayOptions.showToolbar"
+2 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ import { ModalsModule } from '../../modals/modals.module';
import { LegacyModule } from '../../legacy/legacy.module';
import { LegacyModule } from '../../legacy/legacy.module';
import { ActivityMenuComponent } from './menu/menu.component';
import { ActivityMenuComponent } from './menu/menu.component';
import { PostMenuModule } from '../../../common/components/post-menu/post-menu.module';
import { PostMenuModule } from '../../../common/components/post-menu/post-menu.module';
import { ActivityNsfwConsentComponent } from './nsfw-consent/nsfw-consent.component';


@NgModule({
@NgModule({
  imports: [
  imports: [
@@ -41,6 +42,7 @@ import { PostMenuModule } from '../../../common/components/post-menu/post-menu.m
    ActivityContentComponent,
    ActivityContentComponent,
    ActivityToolbarComponent,
    ActivityToolbarComponent,
    ActivityMenuComponent,
    ActivityMenuComponent,
    ActivityNsfwConsentComponent,
  ],
  ],
  providers: [],
  providers: [],
  exports: [ActivityComponent],
  exports: [ActivityComponent],
+57 −2
Original line number Original line Diff line number Diff line
import { BehaviorSubject, Observable } from 'rxjs';
import { BehaviorSubject, Observable, combineLatest } from 'rxjs';
import { MindsUser, MindsGroup } from '../../../interfaces/entities';
import { MindsUser, MindsGroup } from '../../../interfaces/entities';
import { map } from 'rxjs/operators';
import { map } from 'rxjs/operators';
import { Injectable } from '@angular/core';
import { Injectable } from '@angular/core';
@@ -31,11 +31,17 @@ export type ActivityEntity = {
  edited: boolean;
  edited: boolean;
  modal_source_url?: string;
  modal_source_url?: string;
  ephemeral?: boolean;
  ephemeral?: boolean;
  nsfw: Array<number>;
  paywall: boolean;
};
};


@Injectable()
@Injectable()
export class ActivityService {
export class ActivityService {
  entity$ = new BehaviorSubject(null);
  entity$ = new BehaviorSubject(null);

  /**
   * Resolves media posts to a single guid and url
   */
  canonicalUrl$: Observable<string> = this.entity$.pipe(
  canonicalUrl$: Observable<string> = this.entity$.pipe(
    map((entity: ActivityEntity) => {
    map((entity: ActivityEntity) => {
      if (!entity) return '';
      if (!entity) return '';
@@ -43,19 +49,68 @@ export class ActivityService {
      return `/newsfeed/${guid}`;
      return `/newsfeed/${guid}`;
    })
    })
  );
  );

  /**
   * TODO
   */
  canDelete$: Observable<boolean> = this.entity$.pipe();
  canDelete$: Observable<boolean> = this.entity$.pipe();
  canShowContent$: Observable<boolean> = this.entity$.pipe();

  /**
   * Allows for components to give nsfw consent
   */
  isNsfwConsented$: BehaviorSubject<boolean> = new BehaviorSubject(false);

  /**
   * Will be true if not consented and is nsfw
   */
  shouldShowNsfwConsent$: Observable<boolean> = combineLatest(
    this.entity$,
    this.isNsfwConsented$
  ).pipe(
    map(([entity, isConsented]: [ActivityEntity, boolean]) => {
      return entity.nsfw.length > 0 && !isConsented;
    })
  );

  /**
   * We do not render the contents if nsfw (and no consent) or
   * a paywall is in place
   */
  shouldShowContent$: Observable<boolean> = combineLatest(
    this.entity$,
    this.shouldShowNsfwConsent$
  ).pipe(
    map(([entity, shouldShowNsfwContsent]: [ActivityEntity, boolean]) => {
      return !shouldShowNsfwContsent && !entity.paywall;
    })
  );

  /**
   * TODO
   */
  isBoost$: Observable<boolean> = this.entity$.pipe();
  isBoost$: Observable<boolean> = this.entity$.pipe();

  /**
   * If the post is a remind this will emit true
   */
  isRemind$: Observable<boolean> = this.entity$.pipe(
  isRemind$: Observable<boolean> = this.entity$.pipe(
    map((entity: ActivityEntity) => {
    map((entity: ActivityEntity) => {
      return entity && !!entity.remind_object;
      return entity && !!entity.remind_object;
    })
    })
  );
  );

  /**
   * If the post has been editied this will emit true
   */
  isEdited$: Observable<boolean> = this.entity$.pipe(
  isEdited$: Observable<boolean> = this.entity$.pipe(
    map((entity: ActivityEntity) => {
    map((entity: ActivityEntity) => {
      return entity && entity.edited;
      return entity && entity.edited;
    })
    })
  );
  );

  /**
   * TODO
   */
  isUnlisted$: Observable<boolean> = this.entity$.pipe();
  isUnlisted$: Observable<boolean> = this.entity$.pipe();


  displayOptions: ActivityDisplayOptions = {
  displayOptions: ActivityDisplayOptions = {
+1 −1
Original line number Original line Diff line number Diff line
@@ -47,7 +47,7 @@ export class ActivityContentComponent {
    );
    );
  }
  }


  ngOnDestory() {
  ngOnDestroy() {
    this.entitySubscription.unsubscribe();
    this.entitySubscription.unsubscribe();
  }
  }


Loading