Skip to content

Commit

Permalink
Merge pull request #89 from swakwork/dev
Browse files Browse the repository at this point in the history
fix(Twitter): fix Tweet Info related patches in/from 10.58
  • Loading branch information
crimera authored Sep 19, 2024
2 parents 638226a + 9ac003b commit a5bbe78
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,62 @@


import com.twitter.api.model.json.core.JsonApiTweet;
import com.twitter.model.json.core.JsonTweetQuickPromoteEligibility;
import app.revanced.integrations.twitter.Pref;
import app.revanced.integrations.twitter.settings.SettingsStatus;
import java.lang.reflect.Field;

public class TweetInfo {
private static final boolean hideCommNotes,hidePromoteBtn,forceTranslate;
private static String commNotesFieldName, promoteBtnFieldName, translateFieldName;

static {
hideCommNotes = (Pref.hideCommNotes() && SettingsStatus.hideCommunityNote);;
hidePromoteBtn = (Pref.hidePromoteBtn() && SettingsStatus.hidePromoteButton);;
forceTranslate = (Pref.enableForceTranslate() && SettingsStatus.forceTranslate);;
hideCommNotes = (Pref.hideCommNotes() && SettingsStatus.hideCommunityNote);
hidePromoteBtn = (Pref.hidePromoteBtn() && SettingsStatus.hidePromoteButton);
forceTranslate = (Pref.enableForceTranslate() && SettingsStatus.forceTranslate);
commNotesFieldName = "";
promoteBtnFieldName = "";
translateFieldName = "";

}

private static void loader(Class jsonApiTweetCls){
commNotesFieldName = "";
promoteBtnFieldName = "";
translateFieldName = "";

Field[] fields = jsonApiTweetCls.getDeclaredFields();
for(Field field : fields){
if (field.getType() == boolean.class) {
if(commNotesFieldName.length()==0){
commNotesFieldName = field.getName();
continue;
}
translateFieldName = field.getName();
continue;
}
if (field.getType() == JsonTweetQuickPromoteEligibility.class) {
promoteBtnFieldName = field.getName();
}
}
}
public static JsonApiTweet checkEntry(JsonApiTweet jsonApiTweet) {
try {
Class jsonApiTweetCls = jsonApiTweet.getClass();
if( commNotesFieldName.length()==0 || promoteBtnFieldName.length()==0 || translateFieldName.length()==0 ){
loader(jsonApiTweetCls);
}
if(hideCommNotes){
Field f = jsonApiTweetCls.getDeclaredField("e0");
Field f = jsonApiTweetCls.getDeclaredField(commNotesFieldName);
f.set(jsonApiTweet,null);
}
if(hidePromoteBtn){
Field f = jsonApiTweetCls.getDeclaredField("q0");
Field f = jsonApiTweetCls.getDeclaredField(promoteBtnFieldName);
f.set(jsonApiTweet,null);
}
if(forceTranslate){
jsonApiTweet.r0 = true;
Field f = jsonApiTweetCls.getDeclaredField(translateFieldName);
f.set(jsonApiTweet,true);
}

} catch (Exception unused) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.twitter.model.json.core;

public class JsonTweetQuickPromoteEligibility {
}

0 comments on commit a5bbe78

Please sign in to comment.