delete conversation cache on logout (#1037)

* delete conversation cache on logout

* use correct threading method
This commit is contained in:
Konrad Pozniak 2019-02-13 19:21:04 +01:00 committed by GitHub
parent fc95903866
commit fe1e9f4100
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -40,6 +40,7 @@ import com.keylesspalace.tusky.appstore.CacheUpdater;
import com.keylesspalace.tusky.appstore.EventHub;
import com.keylesspalace.tusky.appstore.MainTabsChangedEvent;
import com.keylesspalace.tusky.appstore.ProfileEditedEvent;
import com.keylesspalace.tusky.components.conversation.ConversationsRepository;
import com.keylesspalace.tusky.db.AccountEntity;
import com.keylesspalace.tusky.entity.Account;
import com.keylesspalace.tusky.interfaces.ActionButtonActivity;
@ -103,6 +104,8 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
public EventHub eventHub;
@Inject
public CacheUpdater cacheUpdater;
@Inject
ConversationsRepository conversationRepository;
private FloatingActionButton composeButton;
private AccountHeader headerResult;
@ -472,6 +475,7 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
NotificationHelper.deleteNotificationChannelsForAccount(accountManager.getActiveAccount(), MainActivity.this);
cacheUpdater.clearForUser(activeAccount.getId());
conversationRepository.deleteCacheForAccount(activeAccount.getId());
AccountEntity newAccount = accountManager.logActiveAccountOut();

View File

@ -11,6 +11,8 @@ import com.keylesspalace.tusky.entity.Conversation
import com.keylesspalace.tusky.network.MastodonApi
import com.keylesspalace.tusky.util.Listing
import com.keylesspalace.tusky.util.NetworkState
import io.reactivex.Single
import io.reactivex.schedulers.Schedulers
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
@ -93,6 +95,13 @@ class ConversationsRepository @Inject constructor(val mastodonApi: MastodonApi,
)
}
fun deleteCacheForAccount(accountId: Long) {
Single.fromCallable {
db.conversationDao().deleteForAccount(accountId)
}.subscribeOn(Schedulers.io())
.subscribe()
}
private fun insertResultIntoDb(accountId: Long, result: List<Conversation>?) {
result?.let { conversations ->
db.conversationDao().insert(conversations.map { it.toEntity(accountId) })