applying CW policy
This commit is contained in:
parent
b15cc6047b
commit
687148bc3a
|
@ -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
|
|
||||||
}
|
|
|
@ -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",
|
||||||
|
@ -95,11 +97,32 @@ 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;
|
||||||
|
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.isContentWarned = true;
|
||||||
this.contentWarningText = this.emojiConverter.applyEmojis(this.displayedStatus.emojis, status.spoiler_text, EmojiTypeEnum.medium);
|
this.contentWarningText = this.emojiConverter.applyEmojis(this.displayedStatus.emojis, status.spoiler_text, EmojiTypeEnum.medium);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
removeContentWarning(): boolean {
|
removeContentWarning(): boolean {
|
||||||
this.isContentWarned = false;
|
this.isContentWarned = false;
|
||||||
|
|
|
@ -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[] = [];
|
||||||
|
|
Loading…
Reference in New Issue