Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

Commit

Permalink
Avoid applying CW detection to "title" of notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
eramdam committed Jan 5, 2022
1 parent 2da43e5 commit 16ad905
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/features/contentWarnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@ import './contentWarnings.css';

import {onChirpAdded} from '../services/chirpHandler';
import {makeBTDModule, makeBtdUuidSelector} from '../types/btdCommonTypes';
import {TwitterActionEnum} from '../types/tweetdeckTypes';
import {extractContentWarnings} from './contentWarningsHelpers';

const contentWarningsIgnoreList = [
TwitterActionEnum.FAVORITE,
TwitterActionEnum.FAVORITED_MEDIA,
TwitterActionEnum.FAVORITED_MENTION,
TwitterActionEnum.FAVORITED_RETWEET,
TwitterActionEnum.RETWEETED_MEDIA,
TwitterActionEnum.RETWEETED_MENTION,
TwitterActionEnum.RETWEETED_RETWEET,
TwitterActionEnum.RETWEET,
];

export const contentWarnings = makeBTDModule(({TD, settings}) => {
if (!settings.detectContentWarnings) {
return;
Expand All @@ -20,7 +32,25 @@ export const contentWarnings = makeBTDModule(({TD, settings}) => {
return;
}

const matches = extractContentWarnings(payload.chirp.text);
// if (
// payload.chirpExtra.action &&
// contentWarningsIgnoreList.includes(payload.chirpExtra.action)
// ) {
// return;
// }

const isNotificationAboutTweet =
payload.chirpExtra.action && contentWarningsIgnoreList.includes(payload.chirpExtra.action);
const textToMatchAgainst =
isNotificationAboutTweet && payload.chirp.targetTweet
? payload.chirp.targetTweet.text
: payload.chirp.text;
const htmlTextToMatchAgainst =
isNotificationAboutTweet && payload.chirp.targetTweet
? payload.chirp.targetTweet.htmlText
: payload.chirp.htmlText;

const matches = extractContentWarnings(textToMatchAgainst);

if (!matches) {
return;
Expand Down Expand Up @@ -49,7 +79,7 @@ export const contentWarnings = makeBTDModule(({TD, settings}) => {

const tweetText = document.createElement('p');
tweetText.classList.add('tweet-text', 'js-tweet-text', 'with-linebreaks');
tweetText.innerHTML = payload.chirp.htmlText
tweetText.innerHTML = htmlTextToMatchAgainst
.replace(TD.util.escape(warningBlock), '')
.replace(/^\n/, '');
details.appendChild(tweetText);
Expand Down

0 comments on commit 16ad905

Please sign in to comment.