delete conversation cache on logout (#1037)

* delete conversation cache on logout

* use correct threading method
main
Konrad Pozniak 6 years ago committed by GitHub
parent d03751e59c
commit 26fb9e3ccf
  1. 4
      app/src/main/java/com/keylesspalace/tusky/MainActivity.java
  2. 9
      app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationsRepository.kt

@ -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();

@ -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) })

Loading…
Cancel
Save