Improve notification level storage

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2019-04-05 12:26:52 +02:00
parent b998a2f6db
commit d43c37d88b

View File

@ -21,6 +21,7 @@
package com.nextcloud.talk.utils.preferencestorage; package com.nextcloud.talk.utils.preferencestorage;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils;
import autodagger.AutoInjector; import autodagger.AutoInjector;
import com.nextcloud.talk.api.NcApi; import com.nextcloud.talk.api.NcApi;
import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.application.NextcloudTalkApplication;
@ -49,6 +50,7 @@ public class DatabaseStorageModule implements StorageModule {
private String conversationToken; private String conversationToken;
private long accountIdentifier; private long accountIdentifier;
private String messageNotificationLevel;
public DatabaseStorageModule(UserEntity conversationUser, String conversationToken) { public DatabaseStorageModule(UserEntity conversationUser, String conversationToken) {
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
@ -68,45 +70,49 @@ public class DatabaseStorageModule implements StorageModule {
arbitraryStorageUtils.storeStorageSetting(accountIdentifier, key, value, conversationToken); arbitraryStorageUtils.storeStorageSetting(accountIdentifier, key, value, conversationToken);
} else { } else {
if (conversationUser.hasSpreedCapabilityWithName("notification-levels")) { if (conversationUser.hasSpreedCapabilityWithName("notification-levels")) {
int intValue; if (!TextUtils.isEmpty(messageNotificationLevel) && !messageNotificationLevel.equals(value)) {
switch (value) { int intValue;
case "never": switch (value) {
intValue = 3; case "never":
break; intValue = 3;
case "mention": break;
intValue = 2; case "mention":
break; intValue = 2;
case "always": break;
intValue = 1; case "always":
break; intValue = 1;
default: break;
intValue = 0; default:
intValue = 0;
}
ncApi.setNotificationLevel(ApiUtils.getCredentials(conversationUser.getUsername(), conversationUser.getToken()),
ApiUtils.getUrlForSettingNotificationlevel(conversationUser.getBaseUrl(), conversationToken),
intValue)
.subscribeOn(Schedulers.newThread())
.subscribe(new Observer<GenericOverall>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(GenericOverall genericOverall) {
messageNotificationLevel = value;
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
} else {
messageNotificationLevel = value;
} }
ncApi.setNotificationLevel(ApiUtils.getCredentials(conversationUser.getUsername(), conversationUser.getToken()),
ApiUtils.getUrlForSettingNotificationlevel(conversationUser.getBaseUrl(), conversationToken),
intValue)
.subscribeOn(Schedulers.newThread())
.subscribe(new Observer<GenericOverall>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(GenericOverall genericOverall) {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
} }
} }
} }
@ -133,11 +139,15 @@ public class DatabaseStorageModule implements StorageModule {
@Override @Override
public String getString(String key, String defaultVal) { public String getString(String key, String defaultVal) {
ArbitraryStorageEntity valueFromDb = arbitraryStorageUtils.getStorageSetting(accountIdentifier, key, conversationToken); if (!key.equals("message_notification_level")) {
if (valueFromDb == null) { ArbitraryStorageEntity valueFromDb = arbitraryStorageUtils.getStorageSetting(accountIdentifier, key, conversationToken);
return defaultVal; if (valueFromDb == null) {
return defaultVal;
} else {
return valueFromDb.getValue();
}
} else { } else {
return valueFromDb.getValue(); return messageNotificationLevel;
} }
} }