mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-06-04 19:01:57 +00:00
ui: group service events channel texts (#6781)
This commit is contained in:
+23
-12
@@ -1748,6 +1748,9 @@ sealed class ChatInfo: SomeChat, NamedChat {
|
||||
is Group -> groupInfo
|
||||
else -> null
|
||||
}
|
||||
|
||||
val isChannel: Boolean
|
||||
get() = groupInfo_?.useRelays == true
|
||||
}
|
||||
|
||||
@Serializable
|
||||
@@ -2891,12 +2894,14 @@ data class ChatItem (
|
||||
val id: Long get() = meta.itemId
|
||||
val timestampText: String get() = meta.timestampText
|
||||
|
||||
val text: String get() {
|
||||
val text: String get() = text(isChannel = false)
|
||||
|
||||
fun text(isChannel: Boolean): String {
|
||||
val mc = content.msgContent
|
||||
return when {
|
||||
content.text == "" && file != null && mc is MsgContent.MCVoice -> String.format(generalGetString(MR.strings.voice_message_with_duration), durationText(mc.duration))
|
||||
content.text == "" && file != null -> file.fileName
|
||||
else -> content.text
|
||||
content.text(isChannel) == "" && file != null && mc is MsgContent.MCVoice -> String.format(generalGetString(MR.strings.voice_message_with_duration), durationText(mc.duration))
|
||||
content.text(isChannel) == "" && file != null -> file.fileName
|
||||
else -> content.text(isChannel)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3754,7 +3759,9 @@ sealed class CIContent: ItemContent {
|
||||
@Serializable @SerialName("chatBanner") object ChatBanner: CIContent() { override val msgContent: MsgContent? get() = null }
|
||||
@Serializable @SerialName("invalidJSON") data class InvalidJSON(val json: String): CIContent() { override val msgContent: MsgContent? get() = null }
|
||||
|
||||
override val text: String get() = when (this) {
|
||||
override val text: String get() = text(isChannel = false)
|
||||
|
||||
fun text(isChannel: Boolean): String = when (this) {
|
||||
is SndMsgContent -> msgContent.text
|
||||
is RcvMsgContent -> msgContent.text
|
||||
is SndDeleted -> generalGetString(MR.strings.deleted_description)
|
||||
@@ -3766,8 +3773,8 @@ sealed class CIContent: ItemContent {
|
||||
is RcvGroupInvitation -> groupInvitation.text
|
||||
is SndGroupInvitation -> groupInvitation.text
|
||||
is RcvDirectEventContent -> rcvDirectEvent.text
|
||||
is RcvGroupEventContent -> rcvGroupEvent.text
|
||||
is SndGroupEventContent -> sndGroupEvent.text
|
||||
is RcvGroupEventContent -> rcvGroupEvent.text(isChannel)
|
||||
is SndGroupEventContent -> sndGroupEvent.text(isChannel)
|
||||
is RcvConnEventContent -> rcvConnEvent.text
|
||||
is SndConnEventContent -> sndConnEvent.text
|
||||
is RcvChatFeature -> featureText(feature, enabled.text, param)
|
||||
@@ -4764,7 +4771,9 @@ sealed class RcvGroupEvent() {
|
||||
@Serializable @SerialName("memberProfileUpdated") class MemberProfileUpdated(val fromProfile: Profile, val toProfile: Profile): RcvGroupEvent()
|
||||
@Serializable @SerialName("newMemberPendingReview") class NewMemberPendingReview(): RcvGroupEvent()
|
||||
|
||||
val text: String get() = when (this) {
|
||||
val text: String get() = text(isChannel = false)
|
||||
|
||||
fun text(isChannel: Boolean): String = when (this) {
|
||||
is MemberAdded -> String.format(generalGetString(MR.strings.rcv_group_event_member_added), profile.profileViewName)
|
||||
is MemberConnected -> generalGetString(MR.strings.rcv_group_event_member_connected)
|
||||
is MemberAccepted -> String.format(generalGetString(MR.strings.rcv_group_event_member_accepted), profile.profileViewName)
|
||||
@@ -4779,8 +4788,8 @@ sealed class RcvGroupEvent() {
|
||||
is UserRole -> String.format(generalGetString(MR.strings.rcv_group_event_changed_your_role), role.text)
|
||||
is MemberDeleted -> String.format(generalGetString(MR.strings.rcv_group_event_member_deleted), profile.profileViewName)
|
||||
is UserDeleted -> generalGetString(MR.strings.rcv_group_event_user_deleted)
|
||||
is GroupDeleted -> generalGetString(MR.strings.rcv_group_event_group_deleted)
|
||||
is GroupUpdated -> generalGetString(MR.strings.rcv_group_event_updated_group_profile)
|
||||
is GroupDeleted -> generalGetString(if (isChannel) MR.strings.rcv_channel_event_channel_deleted else MR.strings.rcv_group_event_group_deleted)
|
||||
is GroupUpdated -> generalGetString(if (isChannel) MR.strings.rcv_channel_event_updated_channel_profile else MR.strings.rcv_group_event_updated_group_profile)
|
||||
is InvitedViaGroupLink -> generalGetString(MR.strings.rcv_group_event_invited_via_your_group_link)
|
||||
is MemberCreatedContact -> generalGetString(MR.strings.rcv_group_event_member_created_contact)
|
||||
is MemberProfileUpdated -> profileUpdatedText(fromProfile, toProfile)
|
||||
@@ -4812,7 +4821,9 @@ sealed class SndGroupEvent() {
|
||||
@Serializable @SerialName("memberAccepted") class MemberAccepted(val groupMemberId: Long, val profile: Profile): SndGroupEvent()
|
||||
@Serializable @SerialName("userPendingReview") class UserPendingReview(): SndGroupEvent()
|
||||
|
||||
val text: String get() = when (this) {
|
||||
val text: String get() = text(isChannel = false)
|
||||
|
||||
fun text(isChannel: Boolean): String = when (this) {
|
||||
is MemberRole -> String.format(generalGetString(MR.strings.snd_group_event_changed_member_role), profile.profileViewName, role.text)
|
||||
is UserRole -> String.format(generalGetString(MR.strings.snd_group_event_changed_role_for_yourself), role.text)
|
||||
is MemberBlocked -> if (blocked) {
|
||||
@@ -4822,7 +4833,7 @@ sealed class SndGroupEvent() {
|
||||
}
|
||||
is MemberDeleted -> String.format(generalGetString(MR.strings.snd_group_event_member_deleted), profile.profileViewName)
|
||||
is UserLeft -> generalGetString(MR.strings.snd_group_event_user_left)
|
||||
is GroupUpdated -> generalGetString(MR.strings.snd_group_event_group_profile_updated)
|
||||
is GroupUpdated -> generalGetString(if (isChannel) MR.strings.snd_channel_event_channel_profile_updated else MR.strings.snd_group_event_group_profile_updated)
|
||||
is MemberAccepted -> generalGetString(MR.strings.snd_group_event_member_accepted)
|
||||
is UserPendingReview -> generalGetString(MR.strings.snd_group_event_user_pending_review)
|
||||
}
|
||||
|
||||
+4
-4
@@ -44,7 +44,7 @@ abstract class NtfManager {
|
||||
chatModel.chatId.value != cInfo.id ||
|
||||
chatModel.remoteHostId() != rhId)
|
||||
) {
|
||||
displayNotification(user = user, chatId = cInfo.id, displayName = cInfo.displayName, msgText = hideSecrets(cItem))
|
||||
displayNotification(user = user, chatId = cInfo.id, displayName = cInfo.displayName, msgText = hideSecrets(cItem, cInfo.isChannel))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ abstract class NtfManager {
|
||||
}
|
||||
}
|
||||
|
||||
private fun hideSecrets(cItem: ChatItem): String {
|
||||
private fun hideSecrets(cItem: ChatItem, isChannel: Boolean = false): String {
|
||||
val md = cItem.formattedText
|
||||
return if (md != null) {
|
||||
var res = ""
|
||||
@@ -130,9 +130,9 @@ abstract class NtfManager {
|
||||
} else {
|
||||
val mc = cItem.content.msgContent
|
||||
if (mc is MsgContent.MCReport) {
|
||||
generalGetString(MR.strings.notification_group_report).format(cItem.text.ifEmpty { mc.reason.text })
|
||||
generalGetString(MR.strings.notification_group_report).format(cItem.text(isChannel).ifEmpty { mc.reason.text })
|
||||
} else {
|
||||
cItem.text
|
||||
cItem.text(isChannel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -48,8 +48,8 @@ private val msgTailMaxHeightDp = msgTailWidthDp * 1.732f // 60deg
|
||||
|
||||
val chatEventStyle = SpanStyle(fontSize = 12.sp, fontWeight = FontWeight.Light, color = CurrentColors.value.colors.secondary)
|
||||
|
||||
fun chatEventText(ci: ChatItem): AnnotatedString =
|
||||
chatEventText(ci.content.text, ci.timestampText)
|
||||
fun chatEventText(ci: ChatItem, isChannel: Boolean = false): AnnotatedString =
|
||||
chatEventText(ci.content.text(isChannel), ci.timestampText)
|
||||
|
||||
fun chatEventText(eventText: String, ts: String): AnnotatedString =
|
||||
buildAnnotatedString {
|
||||
@@ -612,7 +612,7 @@ fun ChatItemView(
|
||||
return if (count <= 1) {
|
||||
null
|
||||
} else if (ns.isEmpty()) {
|
||||
generalGetString(MR.strings.rcv_group_events_count).format(count)
|
||||
generalGetString(if (cInfo.isChannel) MR.strings.rcv_channel_events_count else MR.strings.rcv_group_events_count).format(count)
|
||||
} else if (count > ns.size) {
|
||||
members + " " + generalGetString(MR.strings.rcv_group_and_other_events).format(count - ns.size)
|
||||
} else {
|
||||
@@ -629,9 +629,9 @@ fun ChatItemView(
|
||||
buildAnnotatedString {
|
||||
withStyle(chatEventStyle) { append(memberDisplayName) }
|
||||
append(" ")
|
||||
}.plus(chatEventText(cItem))
|
||||
}.plus(chatEventText(cItem, cInfo.isChannel))
|
||||
} else {
|
||||
chatEventText(cItem)
|
||||
chatEventText(cItem, cInfo.isChannel)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -643,7 +643,7 @@ fun ChatItemView(
|
||||
@Composable fun PendingReviewEventItemView() {
|
||||
Text(
|
||||
buildAnnotatedString {
|
||||
withStyle(chatEventStyle.copy(fontWeight = FontWeight.Bold)) { append(cItem.content.text) }
|
||||
withStyle(chatEventStyle.copy(fontWeight = FontWeight.Bold)) { append(cItem.content.text(cInfo.isChannel)) }
|
||||
},
|
||||
Modifier.padding(horizontal = 6.dp, vertical = 6.dp)
|
||||
)
|
||||
|
||||
+1
-1
@@ -241,7 +241,7 @@ fun ChatPreviewView(
|
||||
Text(previewText.first, color = previewText.second)
|
||||
} else if (ci != null && showChatPreviews) {
|
||||
val (text: CharSequence, inlineTextContent) = when {
|
||||
ci.meta.itemDeleted == null -> ci.text to null
|
||||
ci.meta.itemDeleted == null -> ci.text(chat.chatInfo.isChannel) to null
|
||||
else -> markedDeletedText(ci, chat.chatInfo) to null
|
||||
}
|
||||
val formattedText = when {
|
||||
|
||||
@@ -1707,7 +1707,9 @@
|
||||
<string name="rcv_group_event_member_deleted">removed %1$s</string>
|
||||
<string name="rcv_group_event_user_deleted">removed you</string>
|
||||
<string name="rcv_group_event_group_deleted">deleted group</string>
|
||||
<string name="rcv_channel_event_channel_deleted">deleted channel</string>
|
||||
<string name="rcv_group_event_updated_group_profile">updated group profile</string>
|
||||
<string name="rcv_channel_event_updated_channel_profile">updated channel profile</string>
|
||||
<string name="rcv_group_event_invited_via_your_group_link">invited via your group link</string>
|
||||
<string name="rcv_group_event_member_created_contact">requested connection</string>
|
||||
<string name="rcv_group_event_new_member_pending_review">New member wants to join the group.</string>
|
||||
@@ -1718,6 +1720,7 @@
|
||||
<string name="snd_group_event_member_deleted">you removed %1$s</string>
|
||||
<string name="snd_group_event_user_left">you left</string>
|
||||
<string name="snd_group_event_group_profile_updated">group profile updated</string>
|
||||
<string name="snd_channel_event_channel_profile_updated">channel profile updated</string>
|
||||
<string name="snd_group_event_member_accepted">you accepted this member</string>
|
||||
<string name="snd_group_event_user_pending_review">Please wait for group moderators to review your request to join the group.</string>
|
||||
|
||||
@@ -1726,6 +1729,7 @@
|
||||
<string name="rcv_group_event_3_members_connected">%s, %s and %s connected</string>
|
||||
<string name="rcv_group_event_n_members_connected">%s, %s and %d other members connected</string>
|
||||
<string name="rcv_group_events_count">%d group events</string>
|
||||
<string name="rcv_channel_events_count">%d channel events</string>
|
||||
<string name="rcv_group_and_other_events">and %d other events</string>
|
||||
<string name="group_members_2">%s and %s</string>
|
||||
<string name="group_members_n">%s, %s and %d members</string>
|
||||
|
||||
Reference in New Issue
Block a user