mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-23 15:03:16 +00:00
core, ui: report preference (#5620)
* core: report preference * fix tests * ios: disable reports toggle until 6.4 * android, desktop: reports preference * ui: section * boolean
This commit is contained in:
1 parent
ff35643533
commit
205ced1c1d
19 files changed
+177
-54
No files matched your search
+16
-12
@@ -1225,18 +1225,7 @@ data class Chat(
|
||||
|
||||
fun groupFeatureEnabled(feature: GroupFeature): Boolean =
|
||||
if (chatInfo is ChatInfo.Group) {
|
||||
val groupInfo = chatInfo.groupInfo
|
||||
val p = groupInfo.fullGroupPreferences
|
||||
when (feature) {
|
||||
GroupFeature.TimedMessages -> p.timedMessages.on
|
||||
GroupFeature.DirectMessages -> p.directMessages.on(groupInfo.membership)
|
||||
GroupFeature.FullDelete -> p.fullDelete.on
|
||||
GroupFeature.Reactions -> p.reactions.on
|
||||
GroupFeature.Voice -> p.voice.on(groupInfo.membership)
|
||||
GroupFeature.Files -> p.files.on(groupInfo.membership)
|
||||
GroupFeature.SimplexLinks -> p.simplexLinks.on(groupInfo.membership)
|
||||
GroupFeature.History -> p.history.on
|
||||
}
|
||||
chatInfo.groupInfo.groupFeatureEnabled(feature)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
@@ -1780,6 +1769,21 @@ data class GroupInfo (
|
||||
val canModerate: Boolean
|
||||
get() = membership.memberRole >= GroupMemberRole.Moderator && membership.memberActive
|
||||
|
||||
fun groupFeatureEnabled(feature: GroupFeature): Boolean {
|
||||
val p = fullGroupPreferences
|
||||
return when (feature) {
|
||||
GroupFeature.TimedMessages -> p.timedMessages.on
|
||||
GroupFeature.DirectMessages -> p.directMessages.on(membership)
|
||||
GroupFeature.FullDelete -> p.fullDelete.on
|
||||
GroupFeature.Reactions -> p.reactions.on
|
||||
GroupFeature.Voice -> p.voice.on(membership)
|
||||
GroupFeature.Files -> p.files.on(membership)
|
||||
GroupFeature.SimplexLinks -> p.simplexLinks.on(membership)
|
||||
GroupFeature.Reports -> p.reports.on
|
||||
GroupFeature.History -> p.history.on
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val sampleData = GroupInfo(
|
||||
groupId = 1,
|
||||
|
||||
+19
-1
@@ -5160,6 +5160,7 @@ enum class GroupFeature: Feature {
|
||||
@SerialName("voice") Voice,
|
||||
@SerialName("files") Files,
|
||||
@SerialName("simplexLinks") SimplexLinks,
|
||||
@SerialName("reports") Reports,
|
||||
@SerialName("history") History;
|
||||
|
||||
override val hasParam: Boolean get() = when(this) {
|
||||
@@ -5176,6 +5177,7 @@ enum class GroupFeature: Feature {
|
||||
Voice -> true
|
||||
Files -> true
|
||||
SimplexLinks -> true
|
||||
Reports -> false
|
||||
History -> false
|
||||
}
|
||||
|
||||
@@ -5188,6 +5190,7 @@ enum class GroupFeature: Feature {
|
||||
Voice -> generalGetString(MR.strings.voice_messages)
|
||||
Files -> generalGetString(MR.strings.files_and_media)
|
||||
SimplexLinks -> generalGetString(MR.strings.simplex_links)
|
||||
Reports -> generalGetString(MR.strings.group_reports_member_reports)
|
||||
History -> generalGetString(MR.strings.recent_history)
|
||||
}
|
||||
|
||||
@@ -5200,6 +5203,7 @@ enum class GroupFeature: Feature {
|
||||
Voice -> painterResource(MR.images.ic_keyboard_voice)
|
||||
Files -> painterResource(MR.images.ic_draft)
|
||||
SimplexLinks -> painterResource(MR.images.ic_link)
|
||||
Reports -> painterResource(MR.images.ic_flag)
|
||||
History -> painterResource(MR.images.ic_schedule)
|
||||
}
|
||||
|
||||
@@ -5212,6 +5216,7 @@ enum class GroupFeature: Feature {
|
||||
Voice -> painterResource(MR.images.ic_keyboard_voice_filled)
|
||||
Files -> painterResource(MR.images.ic_draft_filled)
|
||||
SimplexLinks -> painterResource(MR.images.ic_link)
|
||||
Reports -> painterResource(MR.images.ic_flag_filled)
|
||||
History -> painterResource(MR.images.ic_schedule_filled)
|
||||
}
|
||||
|
||||
@@ -5246,6 +5251,10 @@ enum class GroupFeature: Feature {
|
||||
GroupFeatureEnabled.ON -> generalGetString(MR.strings.allow_to_send_simplex_links)
|
||||
GroupFeatureEnabled.OFF -> generalGetString(MR.strings.prohibit_sending_simplex_links)
|
||||
}
|
||||
Reports -> when(enabled) {
|
||||
GroupFeatureEnabled.ON -> generalGetString(MR.strings.enable_sending_member_reports)
|
||||
GroupFeatureEnabled.OFF -> generalGetString(MR.strings.disable_sending_member_reports)
|
||||
}
|
||||
History -> when(enabled) {
|
||||
GroupFeatureEnabled.ON -> generalGetString(MR.strings.enable_sending_recent_history)
|
||||
GroupFeatureEnabled.OFF -> generalGetString(MR.strings.disable_sending_recent_history)
|
||||
@@ -5281,6 +5290,10 @@ enum class GroupFeature: Feature {
|
||||
GroupFeatureEnabled.ON -> generalGetString(MR.strings.group_members_can_send_simplex_links)
|
||||
GroupFeatureEnabled.OFF -> generalGetString(MR.strings.simplex_links_are_prohibited_in_group)
|
||||
}
|
||||
Reports -> when(enabled) {
|
||||
GroupFeatureEnabled.ON -> generalGetString(MR.strings.group_members_can_send_reports)
|
||||
GroupFeatureEnabled.OFF -> generalGetString(MR.strings.member_reports_are_prohibited)
|
||||
}
|
||||
History -> when(enabled) {
|
||||
GroupFeatureEnabled.ON -> generalGetString(MR.strings.recent_history_is_sent_to_new_members)
|
||||
GroupFeatureEnabled.OFF -> generalGetString(MR.strings.recent_history_is_not_sent_to_new_members)
|
||||
@@ -5400,6 +5413,7 @@ data class FullGroupPreferences(
|
||||
val voice: RoleGroupPreference,
|
||||
val files: RoleGroupPreference,
|
||||
val simplexLinks: RoleGroupPreference,
|
||||
val reports: GroupPreference,
|
||||
val history: GroupPreference,
|
||||
) {
|
||||
fun toGroupPreferences(): GroupPreferences =
|
||||
@@ -5411,7 +5425,8 @@ data class FullGroupPreferences(
|
||||
voice = voice,
|
||||
files = files,
|
||||
simplexLinks = simplexLinks,
|
||||
history = history
|
||||
reports = reports,
|
||||
history = history,
|
||||
)
|
||||
|
||||
companion object {
|
||||
@@ -5423,6 +5438,7 @@ data class FullGroupPreferences(
|
||||
voice = RoleGroupPreference(GroupFeatureEnabled.ON, role = null),
|
||||
files = RoleGroupPreference(GroupFeatureEnabled.ON, role = null),
|
||||
simplexLinks = RoleGroupPreference(GroupFeatureEnabled.ON, role = null),
|
||||
reports = GroupPreference(GroupFeatureEnabled.ON),
|
||||
history = GroupPreference(GroupFeatureEnabled.ON),
|
||||
)
|
||||
}
|
||||
@@ -5437,6 +5453,7 @@ data class GroupPreferences(
|
||||
val voice: RoleGroupPreference? = null,
|
||||
val files: RoleGroupPreference? = null,
|
||||
val simplexLinks: RoleGroupPreference? = null,
|
||||
val reports: GroupPreference? = null,
|
||||
val history: GroupPreference? = null,
|
||||
) {
|
||||
companion object {
|
||||
@@ -5448,6 +5465,7 @@ data class GroupPreferences(
|
||||
voice = RoleGroupPreference(GroupFeatureEnabled.ON, role = null),
|
||||
files = RoleGroupPreference(GroupFeatureEnabled.ON, role = null),
|
||||
simplexLinks = RoleGroupPreference(GroupFeatureEnabled.ON, role = null),
|
||||
reports = GroupPreference(GroupFeatureEnabled.ON),
|
||||
history = GroupPreference(GroupFeatureEnabled.ON),
|
||||
)
|
||||
}
|
||||
|
||||
+6
@@ -132,6 +132,11 @@ private fun GroupPreferencesLayout(
|
||||
applyPrefs(preferences.copy(simplexLinks = RoleGroupPreference(enable = enable, role)))
|
||||
}
|
||||
|
||||
SectionDividerSpaced(true, maxBottomPadding = false)
|
||||
val enableReports = remember(preferences) { mutableStateOf(preferences.reports.enable) }
|
||||
FeatureSection(GroupFeature.Reports, enableReports, null, groupInfo, preferences, onTTLUpdated) { enable, _ ->
|
||||
applyPrefs(preferences.copy(reports = GroupPreference(enable = enable)))
|
||||
}
|
||||
SectionDividerSpaced(true, maxBottomPadding = false)
|
||||
val enableHistory = remember(preferences) { mutableStateOf(preferences.history.enable) }
|
||||
FeatureSection(GroupFeature.History, enableHistory, null, groupInfo, preferences, onTTLUpdated) { enable, _ ->
|
||||
@@ -169,6 +174,7 @@ private fun FeatureSection(
|
||||
feature.text,
|
||||
icon,
|
||||
iconTint,
|
||||
disabled = feature == GroupFeature.Reports, // remove in 6.4
|
||||
checked = enableFeature.value == GroupFeatureEnabled.ON,
|
||||
) { checked ->
|
||||
onSelected(if (checked) GroupFeatureEnabled.ON else GroupFeatureEnabled.OFF, enableForRole?.value)
|
||||
|
||||
+1
-1
@@ -400,7 +400,7 @@ fun ChatItemView(
|
||||
val groupInfo = cItem.memberToModerate(cInfo)?.first
|
||||
if (groupInfo != null) {
|
||||
ModerateItemAction(cItem, questionText = moderateMessageQuestionText(cInfo.featureEnabled(ChatFeature.FullDelete), 1), showMenu, deleteMessage)
|
||||
} else if (cItem.meta.itemDeleted == null && cInfo is ChatInfo.Group && cInfo.groupInfo.membership.memberRole == GroupMemberRole.Member && !live) {
|
||||
} else if (cItem.meta.itemDeleted == null && cInfo is ChatInfo.Group && cInfo.groupInfo.groupFeatureEnabled(GroupFeature.Reports) && cInfo.groupInfo.membership.memberRole == GroupMemberRole.Member && !live) {
|
||||
ReportItemAction(cItem, composeState, showMenu)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2064,6 +2064,8 @@
|
||||
<string name="prohibit_sending_simplex_links">Prohibit sending SimpleX links</string>
|
||||
<string name="enable_sending_recent_history">Send up to 100 last messages to new members.</string>
|
||||
<string name="disable_sending_recent_history">Do not send history to new members.</string>
|
||||
<string name="enable_sending_member_reports">Allow to report messsages to moderators.</string>
|
||||
<string name="disable_sending_member_reports">Prohibit reporting messages to moderators.</string>
|
||||
<string name="group_members_can_send_disappearing">Members can send disappearing messages.</string>
|
||||
<string name="disappearing_messages_are_prohibited">Disappearing messages are prohibited.</string>
|
||||
<string name="group_members_can_send_dms">Members can send direct messages.</string>
|
||||
@@ -2082,6 +2084,8 @@
|
||||
<string name="simplex_links_are_prohibited_in_group">SimpleX links are prohibited.</string>
|
||||
<string name="recent_history_is_sent_to_new_members">Up to 100 last messages are sent to new members.</string>
|
||||
<string name="recent_history_is_not_sent_to_new_members">History is not sent to new members.</string>
|
||||
<string name="group_members_can_send_reports">Members can report messsages to moderators.</string>
|
||||
<string name="member_reports_are_prohibited">Reporting messages is prohibited in this group.</string>
|
||||
<string name="delete_after">Delete after</string>
|
||||
<string name="ttl_sec">%d sec</string>
|
||||
<string name="ttl_s">%ds</string>
|
||||
|
||||
Reference in new issue
Block a user