diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java index 00eca9a4..87fb24f1 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java @@ -371,6 +371,6 @@ public class AccountSession{ } public Instance getInstanceInfo(){ - return AccountSessionManager.getInstance().getInstanceInfo(domain); + return AccountSessionManager.getInstance().getInstanceInfo(domain, token); } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java index 729276d7..2f357c53 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java @@ -107,13 +107,13 @@ public class AccountSessionManager{ private AccountSessionManager(){ prefs=MastodonApp.context.getSharedPreferences("account_manager", Context.MODE_PRIVATE); runWithDatabase(db->{ - HashSet domains=new HashSet<>(); + HashMap domains=new HashMap<>(); try(Cursor cursor=db.query("accounts", null, null, null, null, null, null)){ ContentValues values=new ContentValues(); while(cursor.moveToNext()){ DatabaseUtils.cursorRowToContentValues(cursor, values); AccountSession session=new AccountSession(values); - domains.add(session.domain.toLowerCase()); + domains.put(session.domain.toLowerCase(), session.token); sessions.put(session.getID(), session); } } @@ -135,7 +135,7 @@ public class AccountSessionManager{ session.toContentValues(values); db.insertWithOnConflict("accounts", null, values, SQLiteDatabase.CONFLICT_REPLACE); }); - updateInstanceEmojis(instance, instance.getDomain()); + updateInstanceEmojis(instance, instance.getDomain(), token); if(PushSubscriptionManager.arePushNotificationsAvailable()){ session.getPushSubscriptionManager().registerAccountForPush(null); } @@ -272,9 +272,9 @@ public class AccountSessionManager{ public void maybeUpdateLocalInfo(){ long now=System.currentTimeMillis(); - HashSet domains=new HashSet<>(); + HashMap domains=new HashMap<>(); for(AccountSession session:sessions.values()){ - domains.add(session.domain.toLowerCase()); + domains.put(session.domain.toLowerCase(), session.token); if(now-session.infoLastUpdated>24L*3600_000L){ updateSessionLocalInfo(session); } @@ -287,12 +287,12 @@ public class AccountSessionManager{ } } - private void maybeUpdateInstanceInfo(Set domains){ + private void maybeUpdateInstanceInfo(HashMap domains){ long now=System.currentTimeMillis(); - for(String domain:domains){ + for(String domain:domains.keySet()){ Long lastUpdated=instancesLastUpdated.get(domain); if(lastUpdated==null || now-lastUpdated>24L*3600_000L){ - updateInstanceInfo(domain); + updateInstanceInfo(domain, domains.get(domain)); } } } @@ -346,13 +346,13 @@ public class AccountSessionManager{ .exec(session.getID()); } - public void updateInstanceInfo(String domain){ + public void updateInstanceInfo(String domain, Token token){ loadInstanceInfo(domain, new Callback<>(){ @Override public void onSuccess(Instance instance){ instances.put(domain, instance); runOnDbThread(db->insertInstanceIntoDatabase(db, domain, instance, null, 0)); - updateInstanceEmojis(instance, domain); + updateInstanceEmojis(instance, domain, token); } @Override @@ -362,7 +362,7 @@ public class AccountSessionManager{ }); } - private void updateInstanceEmojis(Instance instance, String domain){ + private void updateInstanceEmojis(Instance instance, String domain, Token token){ new GetCustomEmojis() .setCallback(new Callback<>(){ @Override @@ -379,11 +379,11 @@ public class AccountSessionManager{ } }) - .execNoAuth(domain); + .exec(domain, token); } - private void readInstanceInfo(SQLiteDatabase db, Set domains){ - for(String domain : domains){ + private void readInstanceInfo(SQLiteDatabase db, HashMap domains){ + for(String domain : domains.keySet()){ final int maxEmojiLength=500000; try(Cursor cursor=db.rawQuery("SELECT domain, instance_obj, substr(emojis,1,?) AS emojis, length(emojis) AS emoji_length, last_updated, version FROM instances WHERE `domain` = ?", new String[]{String.valueOf(maxEmojiLength) , domain})) { @@ -446,7 +446,7 @@ public class AccountSessionManager{ return r==null ? Collections.emptyList() : r; } - public Instance getInstanceInfo(String domain){ + public Instance getInstanceInfo(String domain, Token token){ Instance i=instances.get(domain); if(i!=null) return i; @@ -456,7 +456,7 @@ public class AccountSessionManager{ InstanceV1 fake=new InstanceV1(); fake.uri=fake.title=domain; fake.description=fake.version=fake.email=""; - updateInstanceInfo(domain); + updateInstanceInfo(domain, token); return fake; } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java index ce5eb9b6..1b778407 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java @@ -191,7 +191,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements ComposeE self=session.self; instanceDomain=session.domain; customEmojis=AccountSessionManager.getInstance().getCustomEmojis(instanceDomain); - instance=AccountSessionManager.getInstance().getInstanceInfo(instanceDomain); + instance=AccountSessionManager.getInstance().getInstanceInfo(instanceDomain, session.token); if(getArguments().containsKey("editStatus")){ editingStatus=Parcels.unwrap(getArguments().getParcelable("editStatus")); } @@ -200,7 +200,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements ComposeE return; } if(customEmojis.isEmpty()){ - AccountSessionManager.getInstance().updateInstanceInfo(instanceDomain); + AccountSessionManager.getInstance().updateInstanceInfo(instanceDomain, session.token); } if(instance.maxTootChars>0) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/AccountActivationFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/AccountActivationFragment.java index d8e819b0..d899a156 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/AccountActivationFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/AccountActivationFragment.java @@ -176,7 +176,7 @@ public class AccountActivationFragment extends ToolbarFragment{ currentRequest=null; AccountSessionManager mgr=AccountSessionManager.getInstance(); AccountSession session=mgr.getAccount(accountID); - Instance instance=mgr.getInstanceInfo(session.domain); + Instance instance=mgr.getInstanceInfo(session.domain, session.token); mgr.removeAccount(accountID); mgr.addAccount(instance, session.token, result, session.app, null); String newID=mgr.getLastActiveAccountID(); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportReasonChoiceFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportReasonChoiceFragment.java index 661e5330..40c6b4c2 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportReasonChoiceFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportReasonChoiceFragment.java @@ -17,6 +17,7 @@ import com.squareup.otto.Subscribe; import org.joinmastodon.android.E; import org.joinmastodon.android.R; +import org.joinmastodon.android.api.session.AccountSession; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.events.FinishReportFragmentsEvent; import org.joinmastodon.android.fragments.StatusListFragment; @@ -94,7 +95,8 @@ public class ReportReasonChoiceFragment extends StatusListFragment{ items.add(new ChoiceItem(getString(R.string.report_reason_personal), getString(R.string.report_reason_personal_subtitle), ReportReason.PERSONAL.name())); items.add(new ChoiceItem(getString(R.string.report_reason_spam), getString(R.string.report_reason_spam_subtitle), ReportReason.SPAM.name())); - Instance inst=AccountSessionManager.getInstance().getInstanceInfo(AccountSessionManager.getInstance().getAccount(accountID).domain); + AccountSession session=AccountSessionManager.getInstance().getAccount(accountID); + Instance inst=AccountSessionManager.getInstance().getInstanceInfo(session.domain, session.token); if(inst!=null && inst.rules!=null && !inst.rules.isEmpty()){ items.add(new ChoiceItem(getString(R.string.report_reason_violation), getString(R.string.report_reason_violation_subtitle), ReportReason.VIOLATION.name())); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportRuleChoiceFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportRuleChoiceFragment.java index f88e4fb2..0f8c89bc 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportRuleChoiceFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportRuleChoiceFragment.java @@ -6,6 +6,7 @@ import android.view.View; import com.squareup.otto.Subscribe; import org.joinmastodon.android.R; +import org.joinmastodon.android.api.session.AccountSession; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.events.FinishReportFragmentsEvent; import org.joinmastodon.android.model.Instance; @@ -22,7 +23,8 @@ public class ReportRuleChoiceFragment extends BaseReportChoiceFragment{ @Override protected void populateItems(){ isMultipleChoice=true; - Instance inst=AccountSessionManager.getInstance().getInstanceInfo(AccountSessionManager.getInstance().getAccount(accountID).domain); + AccountSession session=AccountSessionManager.getInstance().getAccount(accountID); + Instance inst=AccountSessionManager.getInstance().getInstanceInfo(session.domain, session.token); if(inst!=null && inst.rules!=null){ for(Instance.Rule rule:inst.rules){ items.add(new ChoiceItem(rule.text, null, rule.id)); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerAboutFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerAboutFragment.java index 58887ca7..c14b5825 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerAboutFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerAboutFragment.java @@ -24,6 +24,7 @@ import android.widget.Toast; import org.joinmastodon.android.R; import org.joinmastodon.android.api.MastodonAPIController; import org.joinmastodon.android.api.requests.instance.GetInstanceExtendedDescription; +import org.joinmastodon.android.api.session.AccountSession; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.model.Instance; import org.joinmastodon.android.model.viewmodel.AccountViewModel; @@ -60,7 +61,8 @@ public class SettingsServerAboutFragment extends LoaderFragment{ public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); accountID=getArguments().getString("account"); - instance=AccountSessionManager.getInstance().getInstanceInfo(AccountSessionManager.get(accountID).domain); + AccountSession session=AccountSessionManager.get(accountID); + instance=AccountSessionManager.getInstance().getInstanceInfo(session.domain, session.token); loadData(); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerRulesFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerRulesFragment.java index 198fca6a..6a4a573e 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerRulesFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerRulesFragment.java @@ -5,6 +5,7 @@ import android.view.LayoutInflater; import android.view.View; import org.joinmastodon.android.R; +import org.joinmastodon.android.api.session.AccountSession; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.fragments.MastodonRecyclerFragment; import org.joinmastodon.android.model.Instance; @@ -23,7 +24,8 @@ public class SettingsServerRulesFragment extends MastodonRecyclerFragment