Fix old APIs

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2021-05-03 16:44:13 +02:00
parent 68369873f4
commit f32b25c455
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA

View File

@ -155,19 +155,32 @@ public class ApiUtils {
}
public static Integer getApiVersion(UserEntity capabilities, String apiName, int[] versions) {
boolean checkedConversationV4 = !apiName.equals("conversation");
if (apiName.equals("conversation")) {
boolean hasApiV4 = false;
for (int version : versions) {
hasApiV4 |= version == 4;
}
if (!hasApiV4) {
Exception e = new Exception("Api call did not try conversation-v4 api");
Log.d(TAG, e.getMessage(), e);
}
}
for (int version : versions) {
checkedConversationV4 |= version == 4;
if (capabilities.hasSpreedFeatureCapability(apiName + "-v" + version)) {
if (!checkedConversationV4) {
Exception e = new Exception("Api call did not try conversation-v4 api");
Log.e(TAG, e.getMessage(), e);
}
return version;
}
// Fallback for old API versions
if (apiName.equals("conversation") && (version == 1 || version == 2)) {
if (capabilities.hasSpreedFeatureCapability(apiName + "-v2")) {
return version;
}
if (version == 1 && capabilities.hasSpreedFeatureCapability(apiName)) {
return version;
}
}
}
return null;
}