mirror of https://github.com/tuskyapp/Tusky.git
Browse Source
* improve logout * fix tests * add db migration * delete wrongly committed file again * improve LogoutUsecasepull/2592/head
23 changed files with 185 additions and 91 deletions
@ -1,30 +0,0 @@
|
||||
/* Copyright 2021 Tusky Contributors |
||||
* |
||||
* This file is a part of Tusky. |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the |
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
||||
* Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not, |
||||
* see <http://www.gnu.org/licenses>. */ |
||||
|
||||
package com.keylesspalace.tusky.components.conversation |
||||
|
||||
import com.keylesspalace.tusky.db.AppDatabase |
||||
import javax.inject.Inject |
||||
import javax.inject.Singleton |
||||
|
||||
@Singleton |
||||
class ConversationsRepository @Inject constructor( |
||||
val db: AppDatabase |
||||
) { |
||||
|
||||
suspend fun deleteCacheForAccount(accountId: Long) { |
||||
db.conversationDao().deleteForAccount(accountId) |
||||
} |
||||
} |
||||
@ -0,0 +1,66 @@
|
||||
package com.keylesspalace.tusky.usecase |
||||
|
||||
import android.content.Context |
||||
import com.keylesspalace.tusky.components.drafts.DraftHelper |
||||
import com.keylesspalace.tusky.components.notifications.NotificationHelper |
||||
import com.keylesspalace.tusky.components.notifications.disableUnifiedPushNotificationsForAccount |
||||
import com.keylesspalace.tusky.db.AccountManager |
||||
import com.keylesspalace.tusky.db.AppDatabase |
||||
import com.keylesspalace.tusky.network.MastodonApi |
||||
import com.keylesspalace.tusky.util.removeShortcut |
||||
import javax.inject.Inject |
||||
|
||||
class LogoutUsecase @Inject constructor( |
||||
private val context: Context, |
||||
private val api: MastodonApi, |
||||
private val db: AppDatabase, |
||||
private val accountManager: AccountManager, |
||||
private val draftHelper: DraftHelper |
||||
) { |
||||
|
||||
/** |
||||
* Logs the current account out and clears all caches associated with it |
||||
* @return true if the user is logged in with other accounts, false if it was the only one |
||||
*/ |
||||
suspend fun logout(): Boolean { |
||||
accountManager.activeAccount?.let { activeAccount -> |
||||
|
||||
// invalidate the oauth token, if we have the client id & secret |
||||
// (could be missing if user logged in with a previous version of Tusky) |
||||
val clientId = activeAccount.clientId |
||||
val clientSecret = activeAccount.clientSecret |
||||
if (clientId != null && clientSecret != null) { |
||||
api.revokeOAuthToken( |
||||
clientId = clientId, |
||||
clientSecret = clientSecret, |
||||
token = activeAccount.accessToken |
||||
) |
||||
} |
||||
|
||||
// disable push notifications |
||||
disableUnifiedPushNotificationsForAccount(context, activeAccount) |
||||
|
||||
// disable pull notifications |
||||
if (!NotificationHelper.areNotificationsEnabled(context, accountManager)) { |
||||
NotificationHelper.disablePullNotifications(context) |
||||
} |
||||
|
||||
// clear notification channels |
||||
NotificationHelper.deleteNotificationChannelsForAccount(activeAccount, context) |
||||
|
||||
// remove account from local AccountManager |
||||
val otherAccountAvailable = accountManager.logActiveAccountOut() != null |
||||
|
||||
// clear the database - this could trigger network calls so do it last when all tokens are gone |
||||
db.timelineDao().removeAll(activeAccount.id) |
||||
db.conversationDao().deleteForAccount(activeAccount.id) |
||||
draftHelper.deleteAllDraftsAndAttachmentsForAccount(activeAccount.id) |
||||
|
||||
// remove shortcut associated with the account |
||||
removeShortcut(context, activeAccount) |
||||
|
||||
return otherAccountAvailable |
||||
} |
||||
return false |
||||
} |
||||
} |
||||
Loading…
Reference in new issue