mirror of
https://github.com/lone-cloud/prism-android
synced 2026-06-03 11:03:10 -07:00
fix app deletion
This commit is contained in:
parent
b2ae8c3e0c
commit
3bf7227a55
4 changed files with 28 additions and 17 deletions
|
|
@ -39,6 +39,13 @@ object Distributor : UnifiedPushDistributor() {
|
|||
) = backendRegisterNewChannelId(context, packageName, channelId, title, vapid, description)
|
||||
|
||||
override fun backendUnregisterChannelId(context: Context, channelId: String) {
|
||||
val db = getDb(context)
|
||||
val app = db.listApps().find { it.connectorToken == channelId }
|
||||
if (app?.description?.startsWith("target:") == true) {
|
||||
val appName = app.title ?: app.packageName
|
||||
PrismServerClient.deleteApp(context, appName)
|
||||
}
|
||||
|
||||
MessageSender.send(
|
||||
context,
|
||||
ClientMessage.Unregister(
|
||||
|
|
|
|||
|
|
@ -82,15 +82,23 @@ class MainViewModel(
|
|||
|
||||
fun deleteSelection() {
|
||||
viewModelScope.launch {
|
||||
val state = registrationsViewModel.state
|
||||
val tokenList = state.list.filter { it.selected }.map { it.token }
|
||||
messenger?.sendIMessage(InternalOpcode.REG_DELETE, "regs" to tokenList)
|
||||
registrationsViewModel.state = RegistrationListState(
|
||||
list = state.list.filter {
|
||||
!it.selected
|
||||
},
|
||||
selectionCount = 0
|
||||
)
|
||||
Log.d(TAG, "deleteSelection called")
|
||||
application?.let { app ->
|
||||
val selectedTokens = registrationsViewModel.state.list
|
||||
.filter { it.selected }
|
||||
.map { it.token }
|
||||
|
||||
Log.d(TAG, "Deleting ${selectedTokens.size} apps: $selectedTokens")
|
||||
|
||||
selectedTokens.forEach { token ->
|
||||
val intent = android.content.Intent("org.unifiedpush.android.distributor.UNREGISTER")
|
||||
intent.setPackage(app.packageName)
|
||||
intent.putExtra("token", token)
|
||||
app.sendBroadcast(intent)
|
||||
}
|
||||
|
||||
registrationsViewModel.unselectAll()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,10 @@ fun MainAppBarOrSelection(viewModel: MainViewModel, onGoToSettings: () -> Unit)
|
|||
val registrationsState = viewModel.registrationsViewModel.state
|
||||
if (registrationsState.selectionCount > 0) {
|
||||
UnregisterBarUi(
|
||||
viewModel = viewModel.registrationsViewModel
|
||||
viewModel = viewModel.registrationsViewModel,
|
||||
onDelete = {
|
||||
viewModel.deleteSelection()
|
||||
}
|
||||
)
|
||||
} else {
|
||||
MainAppBar(
|
||||
|
|
|
|||
|
|
@ -65,13 +65,6 @@ class PrismInternalService : InternalService() {
|
|||
override fun registrations() = object : IRegistrations {
|
||||
override fun delete(registrations: List<String>) {
|
||||
registrations.forEach { token ->
|
||||
// Prism's custom logic: delete from Prism server if it's a "target:" app
|
||||
val dbApp = db.listApps().find { it.connectorToken == token }
|
||||
if (dbApp?.description?.startsWith("target:") == true) {
|
||||
val appName = dbApp.title ?: dbApp.packageName
|
||||
PrismServerClient.deleteApp(context, appName)
|
||||
}
|
||||
|
||||
distributor.deleteApp(context, token)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue