always update active account, but not others

This commit is contained in:
sk
2023-05-31 12:23:04 +02:00
parent de3a252884
commit 02f9f8c8ea
2 changed files with 29 additions and 21 deletions

View File

@@ -35,15 +35,18 @@ public class MainActivity extends FragmentStackActivity{
if(AccountSessionManager.getInstance().getLoggedInAccounts().isEmpty()){ if(AccountSessionManager.getInstance().getLoggedInAccounts().isEmpty()){
showFragmentClearingBackStack(new CustomWelcomeFragment()); showFragmentClearingBackStack(new CustomWelcomeFragment());
}else{ }else{
AccountSessionManager.getInstance().maybeUpdateLocalInfo();
AccountSession session; AccountSession session;
Bundle args=new Bundle(); Bundle args=new Bundle();
Intent intent=getIntent(); Intent intent=getIntent();
if(intent.hasExtra("fromExternalShare")) { if(intent.hasExtra("fromExternalShare")) {
AccountSessionManager.getInstance().setLastActiveAccountID(intent.getStringExtra("account")); AccountSessionManager.getInstance()
.setLastActiveAccountID(intent.getStringExtra("account"));
AccountSessionManager.getInstance().maybeUpdateLocalInfo(
AccountSessionManager.getInstance().getLastActiveAccount());
showFragmentForExternalShare(intent.getExtras()); showFragmentForExternalShare(intent.getExtras());
return; return;
} }
boolean fromNotification = intent.getBooleanExtra("fromNotification", false); boolean fromNotification = intent.getBooleanExtra("fromNotification", false);
boolean hasNotification = intent.hasExtra("notification"); boolean hasNotification = intent.hasExtra("notification");
if(fromNotification){ if(fromNotification){
@@ -57,6 +60,7 @@ public class MainActivity extends FragmentStackActivity{
}else{ }else{
session=AccountSessionManager.getInstance().getLastActiveAccount(); session=AccountSessionManager.getInstance().getLastActiveAccount();
} }
AccountSessionManager.getInstance().maybeUpdateLocalInfo(session);
args.putString("account", session.getID()); args.putString("account", session.getID());
Fragment fragment=session.activated ? new HomeFragment() : new AccountActivationFragment(); Fragment fragment=session.activated ? new HomeFragment() : new AccountActivationFragment();
fragment.setArguments(args); fragment.setArguments(args);
@@ -80,12 +84,12 @@ public class MainActivity extends FragmentStackActivity{
@Override @Override
protected void onNewIntent(Intent intent){ protected void onNewIntent(Intent intent){
super.onNewIntent(intent); super.onNewIntent(intent);
if(intent.hasExtra("fromExternalShare")) showFragmentForExternalShare(intent.getExtras()); AccountSessionManager.getInstance().maybeUpdateLocalInfo();
else if(intent.getBooleanExtra("fromNotification", false)){ if (intent.hasExtra("fromExternalShare")) showFragmentForExternalShare(intent.getExtras());
else if (intent.getBooleanExtra("fromNotification", false)) {
String accountID=intent.getStringExtra("accountID"); String accountID=intent.getStringExtra("accountID");
AccountSession accountSession;
try{ try{
accountSession=AccountSessionManager.getInstance().getAccount(accountID); AccountSessionManager.getInstance().getAccount(accountID);
}catch(IllegalStateException x){ }catch(IllegalStateException x){
return; return;
} }

View File

@@ -258,31 +258,35 @@ public class AccountSessionManager{
} }
public void maybeUpdateLocalInfo(){ public void maybeUpdateLocalInfo(){
maybeUpdateLocalInfo(null);
}
public void maybeUpdateLocalInfo(AccountSession activeSession){
long now=System.currentTimeMillis(); long now=System.currentTimeMillis();
HashSet<String> domains=new HashSet<>(); HashSet<String> domains=new HashSet<>();
for(AccountSession session:sessions.values()){ for(AccountSession session:sessions.values()){
domains.add(session.domain.toLowerCase()); domains.add(session.domain.toLowerCase());
// if(now-session.infoLastUpdated>24L*3600_000L){ if(now-session.infoLastUpdated>24L*3600_000L || session == activeSession){
updateSessionPreferences(session); updateSessionPreferences(session);
updateSessionLocalInfo(session); updateSessionLocalInfo(session);
// } }
// if(now-session.filtersLastUpdated>3600_000L){ if(now-session.filtersLastUpdated>3600_000L || session == activeSession){
updateSessionWordFilters(session); updateSessionWordFilters(session);
// } }
updateSessionMarkers(session); updateSessionMarkers(session);
} }
if(loadedInstances){ if(loadedInstances){
maybeUpdateCustomEmojis(domains); maybeUpdateCustomEmojis(domains, activeSession != null ? activeSession.domain : null);
} }
} }
private void maybeUpdateCustomEmojis(Set<String> domains){ private void maybeUpdateCustomEmojis(Set<String> domains, String activeDomain){
// long now=System.currentTimeMillis(); long now=System.currentTimeMillis();
for(String domain:domains){ for(String domain:domains){
// Long lastUpdated=instancesLastUpdated.get(domain); Long lastUpdated=instancesLastUpdated.get(domain);
// if(lastUpdated==null || now-lastUpdated>24L*3600_000L){ if(lastUpdated==null || now-lastUpdated>24L*3600_000L || domain.equals(activeDomain)){
updateInstanceInfo(domain); updateInstanceInfo(domain);
// } }
} }
} }
@@ -449,7 +453,7 @@ public class AccountSessionManager{
} }
if(!loadedInstances){ if(!loadedInstances){
loadedInstances=true; loadedInstances=true;
maybeUpdateCustomEmojis(domains); maybeUpdateCustomEmojis(domains, null);
} }
} }