Skip to content

Commit

Permalink
Merge branch 'main' into pr/FineFindus/922
Browse files Browse the repository at this point in the history
  • Loading branch information
sk22 committed Nov 10, 2023
2 parents 536bd11 + 2818672 commit f09bed7
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 40 deletions.
1 change: 0 additions & 1 deletion mastodon/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ android {
applicationIdSuffix '.debug'
}
githubRelease { initWith release }
playRelease { initWith release }
fdroidRelease { initWith release }
}
compileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,9 @@ public void extractPronouns() {
assertEquals("* (asterisk)", UiUtils.extractPronouns(MastodonApp.context, fakeAccount(
makeField("pronouns", "-- * (asterisk) --")
)).orElseThrow());

assertEquals("they/(she?)", UiUtils.extractPronouns(MastodonApp.context, fakeAccount(
makeField("pronouns", "they/(she?)...")
)).orElseThrow());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,13 @@ private boolean statusIsOnOwnProfile(Status s, Account profile){
}

private boolean isFilteredType(Status s){
AccountLocalPreferences localPreferences = getLocalPreferences();
return (!localPreferences.showReplies && s.inReplyToId != null)
|| (!localPreferences.showBoosts && s.reblog != null);
}

public <T> void filterStatusContainingObjects(List<T> objects, Function<T, Status> extractor, FilterContext context, Account profile){
AccountLocalPreferences localPreferences = getLocalPreferences();
if(!localPreferences.serverSideFiltersSupported) for(T obj:objects){
Status s=extractor.apply(obj);
if(s!=null && s.filtered!=null){
Expand Down Expand Up @@ -307,7 +309,7 @@ public <T> boolean filterStatusContainingObject(T object, Function<T, Status> ex
if(isFilteredType(s) && (context == FilterContext.HOME || context == FilterContext.PUBLIC))
return true;
// Even with server-side filters, clients are expected to remove statuses that match a filter that hides them
if(localPreferences.serverSideFiltersSupported){
if(getLocalPreferences().serverSideFiltersSupported){
for(FilterResult filter : s.filtered){
if(filter.filter.isActive() && filter.filter.filterAction==FilterAction.HIDE)
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.joinmastodon.android.api.session;

import static org.unifiedpush.android.connector.UnifiedPush.getDistributor;

import android.app.Activity;
import android.app.NotificationManager;
import android.content.ComponentName;
Expand Down Expand Up @@ -34,6 +36,7 @@
import org.joinmastodon.android.model.LegacyFilter;
import org.joinmastodon.android.model.Instance;
import org.joinmastodon.android.model.Token;
import org.unifiedpush.android.connector.UnifiedPush;

import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -101,6 +104,7 @@ private AccountSessionManager(){
}

public void addAccount(Instance instance, Token token, Account self, Application app, AccountActivationInfo activationInfo){
Context context = MastodonApp.context;
instances.put(instance.uri, instance);
AccountSession session=new AccountSession(token, self, app, instance.uri, activationInfo==null, activationInfo);
sessions.put(session.getID(), session);
Expand All @@ -113,7 +117,14 @@ public void addAccount(Instance instance, Token token, Account self, Application
MastodonAPIController.runInBackground(()->writeInstanceInfoFile(wrapper, instance.uri));

updateMoreInstanceInfo(instance, instance.uri);
if(PushSubscriptionManager.arePushNotificationsAvailable()){
if (!UnifiedPush.getDistributor(context).isEmpty()) {
UnifiedPush.registerApp(
context,
session.getID(),
new ArrayList<>(),
context.getPackageName()
);
} else if(PushSubscriptionManager.arePushNotificationsAvailable()){
session.getPushSubscriptionManager().registerAccountForPush(null);
}
maybeUpdateShortcuts();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,9 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat
private Rect tmpRect=new Rect();
@Override
public void getSelectorBounds(View view, Rect outRect){
boolean hasDescendant = false, hasAncestor = false, isWarning = false;
int lastIndex = -1, firstIndex = -1;
if(list!=view.getParent()) return;
boolean hasDescendant=false, hasAncestor=false, isWarning=false;
int lastIndex=-1, firstIndex=-1;
if(((UsableRecyclerView) list).isIncludeMarginsInItemHitbox()){
list.getDecoratedBoundsWithMargins(view, outRect);
}else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,15 @@ private void onUnifiedPushClick(){
return;
}

UnifiedPush.unregisterApp(
getContext(),
accountID
);

//re-register to fcm
AccountSessionManager.getInstance().getAccount(accountID).getPushSubscriptionManager().registerAccountForPush(getPushSubscription());
for (AccountSession accountSession : AccountSessionManager.getInstance().getLoggedInAccounts()) {
UnifiedPush.unregisterApp(
getContext(),
accountSession.getID()
);

//re-register to fcm
accountSession.getPushSubscriptionManager().registerAccountForPush(getPushSubscription());
}
unifiedPushItem.toggle();
rebindItem(unifiedPushItem);
}
Expand All @@ -350,12 +352,14 @@ private void showUnifiedPushRegisterDialog(List<String> distributors){
(dialog, which)->{
String userDistrib = distributors.get(which);
UnifiedPush.saveDistributor(getContext(), userDistrib);
UnifiedPush.registerApp(
getContext(),
accountID,
new ArrayList<>(),
getContext().getPackageName()
);
for (AccountSession accountSession : AccountSessionManager.getInstance().getLoggedInAccounts()){
UnifiedPush.registerApp(
getContext(),
accountSession.getID(),
new ArrayList<>(),
getContext().getPackageName()
);
}
unifiedPushItem.toggle();
rebindItem(unifiedPushItem);
}).setOnCancelListener(d->rebindItem(unifiedPushItem)).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.joinmastodon.android.api.MastodonAPIController.gsonWithoutDeserializer;

import android.text.TextUtils;
import android.util.Pair;

import org.joinmastodon.android.api.ObjectValidationException;
import org.joinmastodon.android.api.RequiredField;
Expand Down Expand Up @@ -223,10 +224,10 @@ public boolean isEligibleForTranslation(AccountSession session){
instanceInfo.v2.configuration.translation.enabled;

try {
String bottomText = BOTTOM_TEXT_PATTERN.matcher(getStrippedText()).find()
Pair<String, List<String>> decoded=BOTTOM_TEXT_PATTERN.matcher(getStrippedText()).find()
? new StatusTextEncoder(Bottom::decode).decode(getStrippedText(), BOTTOM_TEXT_PATTERN)
: null;
if(bottomText==null || bottomText.length()==0 || bottomText.equals("\u0005")) bottomText=null;
String bottomText=decoded==null || decoded.second.stream().allMatch(s->s.trim().isEmpty()) ? null : decoded.first;
if(bottomText!=null){
translation=new Translation();
translation.content=bottomText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ public void updateTranslation(boolean updateText){
String existingTransLang=existingTrans!=null ? existingTrans.detectedSourceLanguage : null;
String lang=existingTransLang!=null ? existingTransLang : item.status.getContentStatus().language;
Locale locale=lang!=null ? Locale.forLanguageTag(lang) : null;
translationButton.setText(locale!=null
? item.parentFragment.getString(R.string.translate_post, locale.getDisplayLanguage())
String displayLang=locale==null || locale.getDisplayLanguage().isBlank() ? lang : locale.getDisplayLanguage();
translationButton.setText(displayLang!=null
? item.parentFragment.getString(R.string.translate_post, displayLang)
: item.parentFragment.getString(R.string.sk_translate_post));
translationButton.setClickable(true);
translationButton.animate().alpha(1).setDuration(100).start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1683,12 +1683,14 @@ public static CharSequence generateFormattedString(String format, CharSequence..
"pronouns.page/"
};

private static final Pattern trimPronouns=Pattern.compile("[^\\w*]*([\\w*].*[\\w*]|[\\w*])\\W*");
private static final String PRONOUN_CHARS="\\w*¿¡!?";
private static final Pattern trimPronouns=
Pattern.compile("[^"+PRONOUN_CHARS+"]*(["+PRONOUN_CHARS+"].*["+PRONOUN_CHARS+"]|["+PRONOUN_CHARS+"])\\W*");
private static String extractPronounsFromField(String localizedPronouns, AccountField field) {
if(!field.name.toLowerCase().contains(localizedPronouns) &&
!field.name.toLowerCase().contains("pronouns")) return null;
String text=HtmlParser.text(field.value);
if(field.value.toLowerCase().contains("https://")){
if(text.toLowerCase().contains("https://")){
for(String pronounUrl : pronounsUrls){
int index=text.indexOf(pronounUrl);
int beginPronouns=index+pronounUrl.length();
Expand All @@ -1707,13 +1709,20 @@ private static String extractPronounsFromField(String localizedPronouns, Account
Matcher matcher=trimPronouns.matcher(text);
if(!matcher.find()) return null;
String pronouns=matcher.group(1);
// crude fix to allow for pronouns like "it(/she)"
int missingClosingParens=0;

// crude fix to allow for pronouns like "it(/she)" or "(de) sie/ihr"
int missingParens=0, missingBrackets=0;
for(char c : pronouns.toCharArray()){
if(c=='(') missingClosingParens++;
if(c==')') missingClosingParens--;
if(c=='(') missingParens++;
else if(c=='[') missingBrackets++;
else if(c==')') missingParens--;
else if(c==']') missingBrackets--;
}
pronouns+=")".repeat(Math.max(0, missingClosingParens));
if(missingParens > 0) pronouns+=")".repeat(missingParens);
else if(missingParens < 0) pronouns="(".repeat(missingParens*-1)+pronouns;
if(missingBrackets > 0) pronouns+="]".repeat(missingBrackets);
else if(missingBrackets < 0) pronouns="[".repeat(missingBrackets*-1)+pronouns;

// if ends with an un-closed custom emoji
if(pronouns.matches("^.*\\s+:[a-zA-Z_]+$")) pronouns+=':';
return pronouns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class ComposePollViewController{
30*60,
3600,
6*3600,
12*3600,
24*3600,
3*24*3600,
7*24*3600,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.joinmastodon.android.utils;

import android.text.TextUtils;

import org.joinmastodon.android.fragments.ComposeFragment;
import android.util.Pair;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -40,19 +40,22 @@ public String encode(String content) {
}

// prettiest almost-exact replica of a pretty function
public String decode(String content, Pattern regex) {
Matcher m = regex.matcher(content);
StringBuilder decodedString = new StringBuilder();
int previousEnd = 0;
public Pair<String, List<String>> decode(String content, Pattern regex) {
Matcher m=regex.matcher(content);
StringBuilder decodedString=new StringBuilder();
List<String> decodedParts=new ArrayList<>();
int previousEnd=0;
while (m.find()) {
MatchResult res = m.toMatchResult();
MatchResult res=m.toMatchResult();
// everything before the match - do not decode
decodedString.append(content.substring(previousEnd, res.start()));
previousEnd = res.end();
previousEnd=res.end();
// the match - do decode
decodedString.append(fn.apply(res.group()));
String decoded=fn.apply(res.group());
decodedParts.add(decoded);
decodedString.append(decoded);
}
decodedString.append(content.substring(previousEnd));
return decodedString.toString();
return Pair.create(decodedString.toString(), decodedParts);
}
}

0 comments on commit f09bed7

Please sign in to comment.