applying CW policy

This commit is contained in:
Nicolas Constant 2020-03-28 17:43:31 -04:00
parent b15cc6047b
commit 687148bc3a
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
3 changed files with 39 additions and 17 deletions

View File

@ -6,7 +6,7 @@ import { environment } from '../../../../environments/environment';
import { ToolsService } from '../../../services/tools.service'; import { ToolsService } from '../../../services/tools.service';
import { UserNotificationService, NotificationSoundDefinition } from '../../../services/user-notification.service'; import { UserNotificationService, NotificationSoundDefinition } from '../../../services/user-notification.service';
import { ServiceWorkerService } from '../../../services/service-worker.service'; import { ServiceWorkerService } from '../../../services/service-worker.service';
import { ContentWarningPolicy } from '../../../states/settings.state'; import { ContentWarningPolicy, ContentWarningPolicyEnum } from '../../../states/settings.state';
@Component({ @Component({
selector: 'app-settings', selector: 'app-settings',
@ -118,19 +118,19 @@ export class SettingsComponent implements OnInit {
} }
if(addCw){ if(addCw){
cwPolicySettings.addCwOnContent = addCw.split(';').map(x => x.trim()); cwPolicySettings.addCwOnContent = addCw.split(';').map(x => x.trim().toLowerCase());
} else { } else {
cwPolicySettings.addCwOnContent = settings.contentWarningPolicy.addCwOnContent; cwPolicySettings.addCwOnContent = settings.contentWarningPolicy.addCwOnContent;
} }
if(removeCw){ if(removeCw){
cwPolicySettings.removeCwOnContent = removeCw.split(';').map(x => x.trim()); cwPolicySettings.removeCwOnContent = removeCw.split(';').map(x => x.trim().toLowerCase());
} else { } else {
cwPolicySettings.removeCwOnContent = settings.contentWarningPolicy.removeCwOnContent; cwPolicySettings.removeCwOnContent = settings.contentWarningPolicy.removeCwOnContent;
} }
if(hide){ if(hide){
cwPolicySettings.hideCompletlyContent = hide.split(';').map(x => x.trim()); cwPolicySettings.hideCompletlyContent = hide.split(';').map(x => x.trim().toLowerCase());
} else { } else {
cwPolicySettings.hideCompletlyContent = settings.contentWarningPolicy.hideCompletlyContent; cwPolicySettings.hideCompletlyContent = settings.contentWarningPolicy.hideCompletlyContent;
} }
@ -210,14 +210,7 @@ export class SettingsComponent implements OnInit {
} }
} }
enum ColumnShortcut { enum ColumnShortcut {
Ctrl = 1, Ctrl = 1,
Win = 2 Win = 2
}
enum ContentWarningPolicyEnum {
None = 1,
HideAll = 2,
AddOnAllContent = 3
} }

View File

@ -6,6 +6,8 @@ import { OpenThreadEvent, ToolsService } from "../../../services/tools.service";
import { ActionBarComponent } from "./action-bar/action-bar.component"; import { ActionBarComponent } from "./action-bar/action-bar.component";
import { StatusWrapper } from '../../../models/common.model'; import { StatusWrapper } from '../../../models/common.model';
import { EmojiConverter, EmojiTypeEnum } from '../../../tools/emoji.tools'; import { EmojiConverter, EmojiTypeEnum } from '../../../tools/emoji.tools';
import { ContentWarningPolicyEnum } from '../../../states/settings.state';
import { stat } from 'fs';
@Component({ @Component({
selector: "app-status", selector: "app-status",
@ -50,7 +52,7 @@ export class StatusComponent implements OnInit {
private _statusWrapper: StatusWrapper; private _statusWrapper: StatusWrapper;
status: Status; status: Status;
@Input('statusWrapper') @Input('statusWrapper')
set statusWrapper(value: StatusWrapper) { set statusWrapper(value: StatusWrapper) {
this._statusWrapper = value; this._statusWrapper = value;
@ -95,12 +97,33 @@ export class StatusComponent implements OnInit {
} }
private checkContentWarning(status: Status) { private checkContentWarning(status: Status) {
if (status.sensitive || status.spoiler_text) { let cwPolicy = this.toolsService.getSettings().contentWarningPolicy;
this.isContentWarned = true; let splittedContent = (status.content + ' ' + status.spoiler_text).toLowerCase().split(' ');
this.contentWarningText = this.emojiConverter.applyEmojis(this.displayedStatus.emojis, status.spoiler_text, EmojiTypeEnum.medium);
if (cwPolicy.policy === ContentWarningPolicyEnum.None && (status.sensitive || status.spoiler_text)) {
this.setContentWarning(status);
} else if (cwPolicy.policy === ContentWarningPolicyEnum.HideAll) {
let detected = cwPolicy.addCwOnContent.filter(x => splittedContent.find(y => y == x));
if(!detected || detected.length === 0) return;
if(!status.spoiler_text){
status.spoiler_text = detected.join(' ');
}
this.setContentWarning(status);
} else if (cwPolicy.policy === ContentWarningPolicyEnum.AddOnAllContent) {
let detected = cwPolicy.removeCwOnContent.find(x => splittedContent.find(y => y == x) != null) != null;
if(!detected) {
this.setContentWarning(status);
}
} }
} }
private setContentWarning(status: Status) {
this.isContentWarned = true;
this.contentWarningText = this.emojiConverter.applyEmojis(this.displayedStatus.emojis, status.spoiler_text, EmojiTypeEnum.medium);
}
removeContentWarning(): boolean { removeContentWarning(): boolean {
this.isContentWarned = false; this.isContentWarned = false;
this.appActionBar.showContent(); this.appActionBar.showContent();
@ -167,7 +190,7 @@ export class StatusComponent implements OnInit {
} }
textSelected(): boolean { textSelected(): boolean {
if(this.isSelected) return false; if (this.isSelected) return false;
const status = this._statusWrapper.status; const status = this._statusWrapper.status;
const accountInfo = this._statusWrapper.provider; const accountInfo = this._statusWrapper.provider;

View File

@ -34,8 +34,14 @@ export class AccountSettings {
customStatusCharLength: number = 500; customStatusCharLength: number = 500;
} }
export enum ContentWarningPolicyEnum {
None = 1,
HideAll = 2,
AddOnAllContent = 3
}
export class ContentWarningPolicy { export class ContentWarningPolicy {
policy: number = 1; policy: ContentWarningPolicyEnum = ContentWarningPolicyEnum.None;
addCwOnContent: string[] = []; addCwOnContent: string[] = [];
removeCwOnContent: string[] = []; removeCwOnContent: string[] = [];
hideCompletlyContent: string[] = []; hideCompletlyContent: string[] = [];