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 { UserNotificationService, NotificationSoundDefinition } from '../../../services/user-notification.service';
import { ServiceWorkerService } from '../../../services/service-worker.service';
import { ContentWarningPolicy } from '../../../states/settings.state';
import { ContentWarningPolicy, ContentWarningPolicyEnum } from '../../../states/settings.state';
@Component({
selector: 'app-settings',
@ -118,19 +118,19 @@ export class SettingsComponent implements OnInit {
}
if(addCw){
cwPolicySettings.addCwOnContent = addCw.split(';').map(x => x.trim());
cwPolicySettings.addCwOnContent = addCw.split(';').map(x => x.trim().toLowerCase());
} else {
cwPolicySettings.addCwOnContent = settings.contentWarningPolicy.addCwOnContent;
}
if(removeCw){
cwPolicySettings.removeCwOnContent = removeCw.split(';').map(x => x.trim());
cwPolicySettings.removeCwOnContent = removeCw.split(';').map(x => x.trim().toLowerCase());
} else {
cwPolicySettings.removeCwOnContent = settings.contentWarningPolicy.removeCwOnContent;
}
if(hide){
cwPolicySettings.hideCompletlyContent = hide.split(';').map(x => x.trim());
cwPolicySettings.hideCompletlyContent = hide.split(';').map(x => x.trim().toLowerCase());
} else {
cwPolicySettings.hideCompletlyContent = settings.contentWarningPolicy.hideCompletlyContent;
}
@ -210,14 +210,7 @@ export class SettingsComponent implements OnInit {
}
}
enum ColumnShortcut {
Ctrl = 1,
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 { StatusWrapper } from '../../../models/common.model';
import { EmojiConverter, EmojiTypeEnum } from '../../../tools/emoji.tools';
import { ContentWarningPolicyEnum } from '../../../states/settings.state';
import { stat } from 'fs';
@Component({
selector: "app-status",
@ -95,12 +97,33 @@ export class StatusComponent implements OnInit {
}
private checkContentWarning(status: Status) {
if (status.sensitive || status.spoiler_text) {
this.isContentWarned = true;
this.contentWarningText = this.emojiConverter.applyEmojis(this.displayedStatus.emojis, status.spoiler_text, EmojiTypeEnum.medium);
let cwPolicy = this.toolsService.getSettings().contentWarningPolicy;
let splittedContent = (status.content + ' ' + status.spoiler_text).toLowerCase().split(' ');
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 {
this.isContentWarned = false;
this.appActionBar.showContent();
@ -167,7 +190,7 @@ export class StatusComponent implements OnInit {
}
textSelected(): boolean {
if(this.isSelected) return false;
if (this.isSelected) return false;
const status = this._statusWrapper.status;
const accountInfo = this._statusWrapper.provider;

View File

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