Handle events of type "m.room.server_acl" - details only in developer mode (#890)
This commit is contained in:
parent
413a55623e
commit
b99cdf7367
|
@ -72,15 +72,15 @@
|
|||
<string name="notice_room_update_by_you">You upgraded this room.</string>
|
||||
<string name="notice_direct_room_update">%s upgraded here.</string>
|
||||
<string name="notice_direct_room_update_by_you">You upgraded here.</string>
|
||||
<string name="notice_room_server_acl_set_title">%s set the server ACLs for this room:</string>
|
||||
<string name="notice_room_server_acl_set_title_by_you">You set the server ACLs for this room:</string>
|
||||
<string name="notice_room_server_acl_set_title">%s set the server ACLs for this room.</string>
|
||||
<string name="notice_room_server_acl_set_title_by_you">You set the server ACLs for this room.</string>
|
||||
<string name="notice_room_server_acl_set_banned">• Server matching %s are banned.</string>
|
||||
<string name="notice_room_server_acl_set_allowed">• Server matching %s are allowed.</string>
|
||||
<string name="notice_room_server_acl_set_ip_literals_allowed">• Server matching IP literals are allowed.</string>
|
||||
<string name="notice_room_server_acl_set_ip_literals_not_allowed">• Server matching IP literals are banned.</string>
|
||||
|
||||
<string name="notice_room_server_acl_updated_title">%s changed the server ACLs for this room:</string>
|
||||
<string name="notice_room_server_acl_updated_title_by_you">You changed the server ACLs for this room:</string>
|
||||
<string name="notice_room_server_acl_updated_title">%s changed the server ACLs for this room.</string>
|
||||
<string name="notice_room_server_acl_updated_title_by_you">You changed the server ACLs for this room.</string>
|
||||
<string name="notice_room_server_acl_updated_banned">• Server matching %s are now banned.</string>
|
||||
<string name="notice_room_server_acl_updated_was_banned">• Server matching %s were removed from the ban list.</string>
|
||||
<string name="notice_room_server_acl_updated_allowed">• Server matching %s are now allowed.</string>
|
||||
|
|
|
@ -19,6 +19,7 @@ package im.vector.app.features.home.room.detail.timeline.format
|
|||
import im.vector.app.ActiveSessionDataSource
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.features.settings.VectorPreferences
|
||||
import org.matrix.android.sdk.api.extensions.appendNl
|
||||
import org.matrix.android.sdk.api.extensions.orFalse
|
||||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
|
@ -50,9 +51,12 @@ import org.matrix.android.sdk.internal.crypto.model.event.EncryptionEventContent
|
|||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
class NoticeEventFormatter @Inject constructor(private val activeSessionDataSource: ActiveSessionDataSource,
|
||||
private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter,
|
||||
private val sp: StringProvider) {
|
||||
class NoticeEventFormatter @Inject constructor(
|
||||
private val activeSessionDataSource: ActiveSessionDataSource,
|
||||
private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter,
|
||||
private val vectorPreferences: VectorPreferences,
|
||||
private val sp: StringProvider
|
||||
) {
|
||||
|
||||
private val currentUserId: String?
|
||||
get() = activeSessionDataSource.currentValue?.orNull()?.myUserId
|
||||
|
@ -405,55 +409,58 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour
|
|||
sp.getString(R.string.notice_room_server_acl_updated_title, senderName)
|
||||
}
|
||||
})
|
||||
// Details
|
||||
if (eventContent.allowList.isEmpty()) {
|
||||
// Special case for stuck room
|
||||
append("\n")
|
||||
append(sp.getString(R.string.notice_room_server_acl_allow_is_empty))
|
||||
appendNl(sp.getString(R.string.notice_room_server_acl_allow_is_empty))
|
||||
} else if (vectorPreferences.developerMode()) {
|
||||
// Details, only in developer mode
|
||||
appendAclDetails(eventContent, prevEventContent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun StringBuilder.appendAclDetails(eventContent: RoomServerAclContent, prevEventContent: RoomServerAclContent?) {
|
||||
if (prevEventContent == null) {
|
||||
eventContent.allowList.forEach { appendNl(sp.getString(R.string.notice_room_server_acl_set_allowed, it)) }
|
||||
eventContent.denyList.forEach { appendNl(sp.getString(R.string.notice_room_server_acl_set_banned, it)) }
|
||||
if (eventContent.allowIpLiterals) {
|
||||
appendNl(sp.getString(R.string.notice_room_server_acl_set_ip_literals_allowed))
|
||||
} else {
|
||||
if (prevEventContent == null) {
|
||||
eventContent.allowList.forEach { appendNl(sp.getString(R.string.notice_room_server_acl_set_allowed, it)) }
|
||||
eventContent.denyList.forEach { appendNl(sp.getString(R.string.notice_room_server_acl_set_banned, it)) }
|
||||
if (eventContent.allowIpLiterals) {
|
||||
appendNl(sp.getString(R.string.notice_room_server_acl_set_ip_literals_allowed))
|
||||
} else {
|
||||
appendNl(sp.getString(R.string.notice_room_server_acl_set_ip_literals_not_allowed))
|
||||
}
|
||||
appendNl(sp.getString(R.string.notice_room_server_acl_set_ip_literals_not_allowed))
|
||||
}
|
||||
} else {
|
||||
// Display only diff
|
||||
var hasChanged = false
|
||||
// New allowed servers
|
||||
(eventContent.allowList - prevEventContent.allowList)
|
||||
.also { hasChanged = hasChanged || it.isNotEmpty() }
|
||||
.forEach { appendNl(sp.getString(R.string.notice_room_server_acl_updated_allowed, it)) }
|
||||
// Removed allowed servers
|
||||
(prevEventContent.allowList - eventContent.allowList)
|
||||
.also { hasChanged = hasChanged || it.isNotEmpty() }
|
||||
.forEach { appendNl(sp.getString(R.string.notice_room_server_acl_updated_was_allowed, it)) }
|
||||
// New denied servers
|
||||
(eventContent.denyList - prevEventContent.denyList)
|
||||
.also { hasChanged = hasChanged || it.isNotEmpty() }
|
||||
.forEach { appendNl(sp.getString(R.string.notice_room_server_acl_updated_banned, it)) }
|
||||
// Removed denied servers
|
||||
(prevEventContent.denyList - eventContent.denyList)
|
||||
.also { hasChanged = hasChanged || it.isNotEmpty() }
|
||||
.forEach { appendNl(sp.getString(R.string.notice_room_server_acl_updated_was_banned, it)) }
|
||||
|
||||
|
||||
if (prevEventContent.allowIpLiterals != eventContent.allowIpLiterals) {
|
||||
hasChanged = true
|
||||
if (eventContent.allowIpLiterals) {
|
||||
appendNl(sp.getString(R.string.notice_room_server_acl_updated_ip_literals_allowed))
|
||||
} else {
|
||||
// Display only diff
|
||||
var hasChanged = false
|
||||
// New allowed servers
|
||||
(eventContent.allowList - prevEventContent.allowList)
|
||||
.also { hasChanged = hasChanged || it.isNotEmpty() }
|
||||
.forEach { appendNl(sp.getString(R.string.notice_room_server_acl_updated_allowed, it)) }
|
||||
// Removed allowed servers
|
||||
(prevEventContent.allowList - eventContent.allowList)
|
||||
.also { hasChanged = hasChanged || it.isNotEmpty() }
|
||||
.forEach { appendNl(sp.getString(R.string.notice_room_server_acl_updated_was_allowed, it)) }
|
||||
// New denied servers
|
||||
(eventContent.denyList - prevEventContent.denyList)
|
||||
.also { hasChanged = hasChanged || it.isNotEmpty() }
|
||||
.forEach { appendNl(sp.getString(R.string.notice_room_server_acl_updated_banned, it)) }
|
||||
// Removed denied servers
|
||||
(prevEventContent.denyList - eventContent.denyList)
|
||||
.also { hasChanged = hasChanged || it.isNotEmpty() }
|
||||
.forEach { appendNl(sp.getString(R.string.notice_room_server_acl_updated_was_banned, it)) }
|
||||
|
||||
|
||||
if (prevEventContent.allowIpLiterals != eventContent.allowIpLiterals) {
|
||||
hasChanged = true
|
||||
if (eventContent.allowIpLiterals) {
|
||||
appendNl(sp.getString(R.string.notice_room_server_acl_updated_ip_literals_allowed))
|
||||
} else {
|
||||
appendNl(sp.getString(R.string.notice_room_server_acl_updated_ip_literals_not_allowed))
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasChanged) {
|
||||
appendNl(sp.getString(R.string.notice_room_server_acl_updated_no_change))
|
||||
}
|
||||
appendNl(sp.getString(R.string.notice_room_server_acl_updated_ip_literals_not_allowed))
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasChanged) {
|
||||
appendNl(sp.getString(R.string.notice_room_server_acl_updated_no_change))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue