android: profile updated chat items (#3700)

This commit is contained in:
spaced4ndy 2024-01-18 15:43:26 +04:00 committed by GitHub
parent 2884ad9fde
commit 3c7e37ee9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 69 additions and 3 deletions

View File

@ -1645,8 +1645,26 @@ data class ChatItem (
val encryptedFile: Boolean? = if (file?.fileSource == null) null else file.fileSource.cryptoArgs != null val encryptedFile: Boolean? = if (file?.fileSource == null) null else file.fileSource.cryptoArgs != null
val memberDisplayName: String? get() = val memberDisplayName: String? get() =
if (chatDir is CIDirection.GroupRcv) chatDir.groupMember.chatViewName when (chatDir) {
else null is CIDirection.GroupRcv -> when (content) {
is CIContent.RcvGroupEventContent -> when (val event = content.rcvGroupEvent) {
is RcvGroupEvent.MemberProfileUpdated -> {
val to = event.toProfile
val from = event.fromProfile
when {
to.displayName != from.displayName || to.fullName != from.fullName -> null
else -> chatDir.groupMember.chatViewName
}
}
else -> chatDir.groupMember.chatViewName
}
else -> chatDir.groupMember.chatViewName
}
else -> null
}
val isDeletedContent: Boolean get() = val isDeletedContent: Boolean get() =
when (content) { when (content) {
@ -1719,7 +1737,10 @@ data class ChatItem (
is CIContent.RcvDecryptionError -> showNtfDir is CIContent.RcvDecryptionError -> showNtfDir
is CIContent.RcvGroupInvitation -> showNtfDir is CIContent.RcvGroupInvitation -> showNtfDir
is CIContent.SndGroupInvitation -> showNtfDir is CIContent.SndGroupInvitation -> showNtfDir
is CIContent.RcvDirectEventContent -> false is CIContent.RcvDirectEventContent -> when (content.rcvDirectEvent) {
is RcvDirectEvent.ContactDeleted -> false
is RcvDirectEvent.ProfileUpdated -> true
}
is CIContent.RcvGroupEventContent -> when (content.rcvGroupEvent) { is CIContent.RcvGroupEventContent -> when (content.rcvGroupEvent) {
is RcvGroupEvent.MemberAdded -> false is RcvGroupEvent.MemberAdded -> false
is RcvGroupEvent.MemberConnected -> false is RcvGroupEvent.MemberConnected -> false
@ -1732,6 +1753,7 @@ data class ChatItem (
is RcvGroupEvent.GroupUpdated -> false is RcvGroupEvent.GroupUpdated -> false
is RcvGroupEvent.InvitedViaGroupLink -> false is RcvGroupEvent.InvitedViaGroupLink -> false
is RcvGroupEvent.MemberCreatedContact -> false is RcvGroupEvent.MemberCreatedContact -> false
is RcvGroupEvent.MemberProfileUpdated -> false
} }
is CIContent.SndGroupEventContent -> showNtfDir is CIContent.SndGroupEventContent -> showNtfDir
is CIContent.RcvConnEventContent -> false is CIContent.RcvConnEventContent -> false
@ -2835,10 +2857,30 @@ sealed class MsgErrorType() {
@Serializable @Serializable
sealed class RcvDirectEvent() { sealed class RcvDirectEvent() {
@Serializable @SerialName("contactDeleted") class ContactDeleted(): RcvDirectEvent() @Serializable @SerialName("contactDeleted") class ContactDeleted(): RcvDirectEvent()
@Serializable @SerialName("profileUpdated") class ProfileUpdated(val fromProfile: Profile, val toProfile: Profile): RcvDirectEvent()
val text: String get() = when (this) { val text: String get() = when (this) {
is ContactDeleted -> generalGetString(MR.strings.rcv_direct_event_contact_deleted) is ContactDeleted -> generalGetString(MR.strings.rcv_direct_event_contact_deleted)
is ProfileUpdated -> profileUpdatedText(fromProfile, toProfile)
} }
private fun profileUpdatedText(from: Profile, to: Profile): String =
when {
to.displayName != from.displayName || to.fullName != from.fullName ->
generalGetString(MR.strings.profile_update_event_contact_name_changed).format(from.profileViewName, to.profileViewName)
to.image != from.image -> when (to.image) {
null -> generalGetString(MR.strings.profile_update_event_removed_picture)
else -> generalGetString(MR.strings.profile_update_event_set_new_picture)
}
to.contactLink != from.contactLink -> when (to.contactLink) {
null -> generalGetString(MR.strings.profile_update_event_removed_address)
else -> generalGetString(MR.strings.profile_update_event_set_new_address)
}
// shouldn't happen if backend correctly creates item; UI should be synchronized with backend
else -> generalGetString(MR.strings.profile_update_event_updated_profile)
}
} }
@Serializable @Serializable
@ -2854,6 +2896,7 @@ sealed class RcvGroupEvent() {
@Serializable @SerialName("groupUpdated") class GroupUpdated(val groupProfile: GroupProfile): RcvGroupEvent() @Serializable @SerialName("groupUpdated") class GroupUpdated(val groupProfile: GroupProfile): RcvGroupEvent()
@Serializable @SerialName("invitedViaGroupLink") class InvitedViaGroupLink(): RcvGroupEvent() @Serializable @SerialName("invitedViaGroupLink") class InvitedViaGroupLink(): RcvGroupEvent()
@Serializable @SerialName("memberCreatedContact") class MemberCreatedContact(): RcvGroupEvent() @Serializable @SerialName("memberCreatedContact") class MemberCreatedContact(): RcvGroupEvent()
@Serializable @SerialName("memberProfileUpdated") class MemberProfileUpdated(val fromProfile: Profile, val toProfile: Profile): RcvGroupEvent()
val text: String get() = when (this) { val text: String get() = when (this) {
is MemberAdded -> String.format(generalGetString(MR.strings.rcv_group_event_member_added), profile.profileViewName) is MemberAdded -> String.format(generalGetString(MR.strings.rcv_group_event_member_added), profile.profileViewName)
@ -2867,7 +2910,21 @@ sealed class RcvGroupEvent() {
is GroupUpdated -> generalGetString(MR.strings.rcv_group_event_updated_group_profile) is GroupUpdated -> generalGetString(MR.strings.rcv_group_event_updated_group_profile)
is InvitedViaGroupLink -> generalGetString(MR.strings.rcv_group_event_invited_via_your_group_link) 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 MemberCreatedContact -> generalGetString(MR.strings.rcv_group_event_member_created_contact)
is MemberProfileUpdated -> profileUpdatedText(fromProfile, toProfile)
} }
private fun profileUpdatedText(from: Profile, to: Profile): String =
when {
to.displayName != from.displayName || to.fullName != from.fullName ->
generalGetString(MR.strings.profile_update_event_member_name_changed).format(from.profileViewName, to.profileViewName)
to.image != from.image -> when (to.image) {
null -> generalGetString(MR.strings.profile_update_event_removed_picture)
else -> generalGetString(MR.strings.profile_update_event_set_new_picture)
}
// shouldn't happen if backend correctly creates item; UI should be synchronized with backend
else -> generalGetString(MR.strings.profile_update_event_updated_profile)
}
} }
@Serializable @Serializable

View File

@ -1193,6 +1193,15 @@
<string name="rcv_group_event_open_chat">Open</string> <string name="rcv_group_event_open_chat">Open</string>
<!-- Profile update event chat items -->
<string name="profile_update_event_contact_name_changed">contact %1$s changed to %2$s</string>
<string name="profile_update_event_removed_picture">removed profile picture</string>
<string name="profile_update_event_set_new_picture">set new profile picture</string>
<string name="profile_update_event_removed_address">removed contact address</string>
<string name="profile_update_event_set_new_address">set new contact address</string>
<string name="profile_update_event_updated_profile">updated profile</string>
<string name="profile_update_event_member_name_changed">member %1$s changed to %2$s</string>
<!-- Conn event chat items --> <!-- Conn event chat items -->
<string name="rcv_conn_event_switch_queue_phase_completed">changed address for you</string> <string name="rcv_conn_event_switch_queue_phase_completed">changed address for you</string>
<string name="rcv_conn_event_switch_queue_phase_changing">changing address…</string> <string name="rcv_conn_event_switch_queue_phase_changing">changing address…</string>