Skip to content

Commit

Permalink
Work on porting AME to ModernDeck
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeredwolf committed Jan 21, 2022
1 parent 85e4fa9 commit d41ffb1
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 57 deletions.
4 changes: 2 additions & 2 deletions common/resources/moderndeck.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion common/resources/moderndeck.js.map

Large diffs are not rendered by default.

49 changes: 3 additions & 46 deletions src/AMEMutesCatcher.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,11 @@

function getMeaningfulUser(target) {
return (
target.retweetedStatus?.user ||
target.sourceUser ||
target.user ||
target.following ||
target.owner
);
}

function serializeMuteCatch(target, filter) {
const meaningfulUser = getMeaningfulUser(target);
if (!meaningfulUser) {
console.debug(filter, target);
}

const simplifiedUser = {
avatar: meaningfulUser.profileImageURL,
id: meaningfulUser.id,
screenName: meaningfulUser.screenName,
name: meaningfulUser.name,
};

return {
filterType: filter.type,
value: filter.value,
user: simplifiedUser,
};
}

export function encodeCatchKey(muteCatch) {
return [muteCatch.filterType, muteCatch.user.id, encodeURIComponent(muteCatch.value)].join('$_$');
}

export function encodeMuteReasonKey(muteReason) {
return [muteReason.filterType, encodeURIComponent(muteReason.value)].join('$_$');
}
export function decodeMuteReasonKey(muteReasonKey) {
const [filterType, rawValue] = muteReasonKey.split('$_$');

return {
filterType: filterType,
value: decodeURIComponent(rawValue),
};
}

const BTD_MUTE_CATCHES_KEY = `btd_mute_catches`;
const MTD_MUTE_CATCHES_KEY = `mtd_ame_mute_catches`;

function safeInitialDataFromLocalStorage() {
const raw = window.localStorage.getItem(BTD_MUTE_CATCHES_KEY);
const raw = window.localStorage.getItem(MTD_MUTE_CATCHES_KEY);

try {
const parsed = JSON.parse(raw || '[]');
Expand All @@ -64,7 +21,7 @@ function safeInitialDataFromLocalStorage() {
}

window.addEventListener('beforeunload', () => {
window.localStorage.setItem(BTD_MUTE_CATCHES_KEY, JSON.stringify(muteCatches));
window.localStorage.setItem(MTD_MUTE_CATCHES_KEY, JSON.stringify(muteCatches));
});

export function formatMuteReason(muteCatch) {
Expand Down
2 changes: 1 addition & 1 deletion src/AdvancedMuteEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { getPref, setPref } from "./StoragePreferences";

/*
ModernDeck uses the BTD namespace for AME to enable interoperability between them,
and so
and so mutes will work across them whenever ModernDeck fully supports AME in the future.
*/

const AMEFilters = {
Expand Down
22 changes: 22 additions & 0 deletions src/DataSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,28 @@ export let settingsData = {
activate:{
func: opt => {
window.nftAvatarAction ? window.nftAvatarAction.actionToTake = opt : false;
if (opt !== "nothing") {
let alreadyHasFilter = false;

TD.controller.filterManager.getAll().forEach(filter => {
if (filter.type === "BTD_nft_avatar") {
alreadyHasFilter = true;
}
});

if (!alreadyHasFilter) {
TD.controller.filterManager.addFilter({
type:"BTD_nft_avatar",
name:"NFT Avatar",
description:"Filter out users with NFT avatars",
filter:function(tweet) {
return tweet.user.avatar && tweet.user.avatar.indexOf("https://nft.moderndeck.com/") === 0;
}
});
}
} else {

}
}
},
default:"nothing",
Expand Down
5 changes: 0 additions & 5 deletions src/ForceFeatureFlags.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/*
ForceFeatureFlags.js
Copyright (c) 2014-2022 dangered wolf, et al
Released under the MIT License
*/

/*
These are features that can be used to force enable tweetdeck developer features.
Code updated by @pixeldesu, DeckHackers, et al
*/
Expand Down
3 changes: 2 additions & 1 deletion src/ModernDeckInit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { FunctionPatcher } from "./FunctionPatcher.js";
import { LanguageFunctionPatcher } from "./LanguageFunctionPatcher.js";
import { UILanguagePicker } from "./UILanguagePicker.js";
import { UIThemeEditor } from "./UIThemeEditor.js";
import { setupAME } from "./AdvancedMuteEngine.js";
import { UIEmojiPanel } from "./UIEmojiPanel.js";
import { loginTextReplacer, checkIfSigninFormIsPresent } from "./UILoginController.js";
let welcomeData = _welcomeData;
Expand Down Expand Up @@ -369,7 +370,7 @@ function mtdInit() {
handleErrors(overrideFadeOut, "Caught error in overrideFadeOut");
handleErrors(processMustaches, "Caught error in processMustaches");
handleErrors(hookNFTActions, "Caught error in hookNFTActions");
handleErrors(setupAME, "Caught error in Advanced Mute Engine")
handleErrors(setupAME, "Caught error in Advanced Mute Engine");
handleErrors(loginTextReplacer, "Caught error in loginTextReplacer");
setTimeout(()=>handleErrors(loginTextReplacer, "Caught error in loginTextReplacer"),200);
setTimeout(()=>handleErrors(loginTextReplacer, "Caught error in loginTextReplacer"),500);
Expand Down
2 changes: 1 addition & 1 deletion src/buildId.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default 1470;
export default 1485;

0 comments on commit d41ffb1

Please sign in to comment.