fix(AccountSession): load custom emoji with auth from GTS

GoToSocial requires authentication for requesting the emoji list.

Closes https://github.com/sk22/megalodon/issues/989
This commit is contained in:
FineFindus 2024-08-31 17:17:59 +02:00
parent 01225b05f2
commit 94cca7f4ed
No known key found for this signature in database
GPG Key ID: 64873EE210FF8E6B
2 changed files with 24 additions and 3 deletions

View File

@ -399,7 +399,7 @@ public class AccountSessionManager{
}
private void updateInstanceEmojis(Instance instance, String domain){
new GetCustomEmojis()
GetCustomEmojis req=(GetCustomEmojis) new GetCustomEmojis()
.setCallback(new Callback<>(){
@Override
public void onSuccess(List<Emoji> result){
@ -419,8 +419,14 @@ public class AccountSessionManager{
wrapper.instance = instance;
MastodonAPIController.runInBackground(()->writeInstanceInfoFile(wrapper, domain));
}
})
.execNoAuth(domain);
});
if(instance.isGoToSocial()) {
// GTS requires auth for emojis
// https://github.com/superseriousbusiness/gotosocial/issues/2794
req.exec(lastActiveAccountID);
return;
}
req.execNoAuth(domain);
}
private File getInstanceInfoFile(String domain){

View File

@ -1,6 +1,7 @@
package org.joinmastodon.android.model;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import org.joinmastodon.android.api.ObjectValidationException;
@ -91,6 +92,13 @@ public class Instance extends BaseModel{
public PleromaPollLimits pollLimits;
/**
* Url to the source code of the instance.
*
* Only found on GoToSocial instances
*/
public String sourceUrl;
/** like uri, but always without scheme and trailing slash */
public transient String normalizedUri;
@ -154,6 +162,13 @@ public class Instance extends BaseModel{
return version.contains("compatible; Pixelfed");
}
/**
* @return `true` if the instance is a GoToSocial instance
*/
public boolean isGoToSocial() {
return TextUtils.equals(sourceUrl, "https://github.com/superseriousbusiness/gotosocial");
}
public boolean hasFeature(Feature feature) {
Optional<List<String>> pleromaFeatures = Optional.ofNullable(pleroma)
.map(p -> p.metadata)