Made blocking rules account specific
This commit is contained in:
@ -1074,7 +1074,7 @@ class BaresipService: Service() {
|
||||
blockedCall = true
|
||||
getString(R.string.hidden_call_blocked)
|
||||
}
|
||||
else if (isBlocked(peerUri)) {
|
||||
else if (isBlocked(ua.account.aor, peerUri)) {
|
||||
blockedCall = true
|
||||
String.format(
|
||||
getString(R.string.call_blocked),
|
||||
@ -1523,7 +1523,7 @@ class BaresipService: Service() {
|
||||
|
||||
if ((ua.account.blockUnknown && Contact.contactName(peerUri) == peerUri) ||
|
||||
(ua.account.blockHidden && peerUri.contains("anonymous")) ||
|
||||
isBlocked(peerUri)) {
|
||||
isBlocked(aor, peerUri)) {
|
||||
Log.d(TAG, "Auto-rejecting blocked message from $peerUri")
|
||||
toast(
|
||||
if (ua.account.blockHidden && peerUri.contains("anonymous"))
|
||||
@ -2176,7 +2176,7 @@ class BaresipService: Service() {
|
||||
).add()
|
||||
return
|
||||
}
|
||||
if (isBlocked(uri)) {
|
||||
if (isBlocked(ua.account.aor, uri)) {
|
||||
Log.d(TAG, "Auto-rejecting incoming PSTN call from $uri by block rule")
|
||||
telecomCall.disconnect()
|
||||
toast(
|
||||
@ -3188,9 +3188,9 @@ class BaresipService: Service() {
|
||||
var blocked = ArrayList<Blocked>()
|
||||
var blockRules = mutableListOf<BlockRule>()
|
||||
|
||||
fun isBlocked(uri: String): Boolean {
|
||||
fun isBlocked(aor: String, uri: String): Boolean {
|
||||
for (rule in blockRules)
|
||||
if (rule.matches(uri)) return true
|
||||
if ((rule.aor == aor || rule.aor == "") && rule.matches(uri)) return true
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ import java.io.File
|
||||
|
||||
@Serializable
|
||||
class BlockRule(
|
||||
val aor: String = "",
|
||||
val pattern: String
|
||||
) {
|
||||
fun matches(uri: String): Boolean {
|
||||
@ -18,8 +19,8 @@ class BlockRule(
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun exists(pattern: String): Boolean {
|
||||
return BaresipService.blockRules.any { it.pattern == pattern }
|
||||
fun exists(aor: String, pattern: String): Boolean {
|
||||
return BaresipService.blockRules.any { it.aor == aor && it.pattern == pattern }
|
||||
}
|
||||
|
||||
fun save() {
|
||||
|
||||
@ -77,7 +77,9 @@ fun NavGraphBuilder.blockingScreenRoute(navController: NavController) {
|
||||
@Composable
|
||||
fun BlockingScreen(navController: NavController, viewModel: AccountViewModel, ua: UserAgent) {
|
||||
val acc = ua.account
|
||||
var rules by remember { mutableStateOf(BaresipService.blockRules.toList()) }
|
||||
var rules by remember {
|
||||
mutableStateOf(BaresipService.blockRules.filter { it.aor == acc.aor || it.aor == "" })
|
||||
}
|
||||
|
||||
remember {
|
||||
viewModel.loadAccount(acc)
|
||||
@ -111,14 +113,14 @@ fun BlockingScreen(navController: NavController, viewModel: AccountViewModel, ua
|
||||
)
|
||||
}
|
||||
},
|
||||
bottomBar = { NewRule(onRuleAdded = { rules = BaresipService.blockRules.toList() }) },
|
||||
bottomBar = { NewRule(acc.aor, onRuleAdded = { rules = BaresipService.blockRules.filter { it.aor == acc.aor || it.aor == "" } }) },
|
||||
content = { contentPadding ->
|
||||
BlockingContent(
|
||||
contentPadding,
|
||||
viewModel,
|
||||
rules,
|
||||
acc,
|
||||
onRuleDeleted = { rules = BaresipService.blockRules.toList() }
|
||||
onRuleDeleted = { rules = BaresipService.blockRules.filter { it.aor == acc.aor || it.aor == "" } }
|
||||
)
|
||||
},
|
||||
)
|
||||
@ -294,7 +296,7 @@ fun BlockingContent(
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun NewRule(onRuleAdded: () -> Unit) {
|
||||
fun NewRule(aor: String, onRuleAdded: () -> Unit) {
|
||||
val alertTitle = remember { mutableStateOf("") }
|
||||
val alertMessage = remember { mutableStateOf("") }
|
||||
val showAlert = remember { mutableStateOf(false) }
|
||||
@ -353,8 +355,8 @@ fun NewRule(onRuleAdded: () -> Unit) {
|
||||
modifier = Modifier.offset(y = 2.dp),
|
||||
onClick = {
|
||||
if (pattern.trim().isNotEmpty()) {
|
||||
if (!BlockRule.exists(pattern.trim())) {
|
||||
BaresipService.blockRules.add(BlockRule(pattern.trim()))
|
||||
if (!BlockRule.exists(aor, pattern.trim())) {
|
||||
BaresipService.blockRules.add(BlockRule(aor, pattern.trim()))
|
||||
BlockRule.save()
|
||||
onRuleAdded()
|
||||
}
|
||||
|
||||
@ -444,8 +444,8 @@ private fun Calls(
|
||||
}
|
||||
thirdButtonText.value = ctx.getString(R.string.block)
|
||||
thirdAction.value = {
|
||||
if (!BlockRule.exists(peerUri)) {
|
||||
BaresipService.blockRules.add(BlockRule(peerUri))
|
||||
if (!BlockRule.exists(ua.account.aor, peerUri)) {
|
||||
BaresipService.blockRules.add(BlockRule(ua.account.aor, peerUri))
|
||||
BlockRule.save()
|
||||
}
|
||||
}
|
||||
|
||||
@ -376,8 +376,8 @@ private fun Chats(
|
||||
secondAction.value = { navController.navigate("contact/${message.peerUri}/new") }
|
||||
thirdButtonText.value = blockText
|
||||
thirdAction.value = {
|
||||
if (!BlockRule.exists(message.peerUri)) {
|
||||
BaresipService.blockRules.add(BlockRule(message.peerUri))
|
||||
if (!BlockRule.exists(account.aor, message.peerUri)) {
|
||||
BaresipService.blockRules.add(BlockRule(account.aor, message.peerUri))
|
||||
BlockRule.save()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user