add null check for source object

closes sk22#460
This commit is contained in:
sk 2023-03-20 14:22:46 +01:00
parent c484477d6a
commit 6734c2b9f7
1 changed files with 14 additions and 15 deletions

View File

@ -271,6 +271,15 @@ public class AccountSessionManager{
} }
} }
private void preferencesFromSource(AccountSession session, Account account) {
if (account != null && account.source != null && session.preferences != null) {
if (account.source.privacy != null)
session.preferences.postingDefaultVisibility = account.source.privacy;
if (account.source.language != null)
session.preferences.postingDefaultLanguage = account.source.language;
}
}
private void updateSessionLocalInfo(AccountSession session){ private void updateSessionLocalInfo(AccountSession session){
new GetOwnAccount() new GetOwnAccount()
.setCallback(new Callback<>(){ .setCallback(new Callback<>(){
@ -278,19 +287,12 @@ public class AccountSessionManager{
public void onSuccess(Account result){ public void onSuccess(Account result){
session.self=result; session.self=result;
session.infoLastUpdated=System.currentTimeMillis(); session.infoLastUpdated=System.currentTimeMillis();
if(session.preferences != null && session.preferences.postingDefaultVisibility != null){ preferencesFromSource(session, result);
session.preferences.postingDefaultVisibility = result.source.privacy;
}
if(session.preferences != null && session.preferences.postingDefaultLanguage != null){
session.preferences.postingDefaultLanguage = result.source.language;
}
writeAccountsFile(); writeAccountsFile();
} }
@Override @Override
public void onError(ErrorResponse error){ public void onError(ErrorResponse error){}
}
}) })
.exec(session.getID()); .exec(session.getID());
} }
@ -300,16 +302,13 @@ public class AccountSessionManager{
@Override @Override
public void onSuccess(Preferences preferences) { public void onSuccess(Preferences preferences) {
session.preferences=preferences; session.preferences=preferences;
preferencesFromSource(session, session.self);
} }
@Override @Override
public void onError(ErrorResponse error) { public void onError(ErrorResponse error) {
Preferences preferences = new Preferences(); session.preferences = new Preferences();
if(session.self != null){ preferencesFromSource(session, session.self);
preferences.postingDefaultVisibility = session.self.source.privacy;
preferences.postingDefaultLanguage = session.self.source.language;
}
session.preferences = preferences;
} }
}).exec(session.getID()); }).exec(session.getID());
} }