From 102b4a67ad77f396ad90088d506a1df98523f418 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Wed, 8 Mar 2023 17:00:17 +1100 Subject: [PATCH] update UI and copy for group leaving status --- .../Context Menu/ContextMenuVC+Action.swift | 3 +- .../ConversationVC+Interaction.swift | 3 +- .../Message Cells/MessageCell.swift | 3 +- Session/Home/HomeViewModel.swift | 8 ++- Session/Shared/FullConversationCell.swift | 60 ++++++++++++++----- .../Models/ControlMessageProcessRecord.swift | 2 +- .../Database/Models/Interaction.swift | 13 +++- .../MessageSender+ClosedGroups.swift | 7 +-- 8 files changed, 71 insertions(+), 28 deletions(-) diff --git a/Session/Conversations/Context Menu/ContextMenuVC+Action.swift b/Session/Conversations/Context Menu/ContextMenuVC+Action.swift index 04e652f8f..a66dcfef3 100644 --- a/Session/Conversations/Context Menu/ContextMenuVC+Action.swift +++ b/Session/Conversations/Context Menu/ContextMenuVC+Action.swift @@ -136,7 +136,8 @@ extension ContextMenuVC { switch cellViewModel.variant { case .standardIncomingDeleted, .infoCall, .infoScreenshotNotification, .infoMediaSavedNotification, - .infoClosedGroupCreated, .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, + .infoClosedGroupCreated, .infoClosedGroupUpdated, + .infoClosedGroupCurrentUserLeft, .infoClosedGroupCurrentUserLeaving, .infoClosedGroupCurrentUserErrorLeaving, .infoMessageRequestAccepted, .infoDisappearingMessagesUpdate: // Let the user delete info messages and unsent messages return [ Action.delete(cellViewModel, delegate) ] diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 037e39647..03e300e67 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -1706,7 +1706,8 @@ extension ConversationVC: switch cellViewModel.variant { case .standardIncomingDeleted, .infoCall, .infoScreenshotNotification, .infoMediaSavedNotification, - .infoClosedGroupCreated, .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, + .infoClosedGroupCreated, .infoClosedGroupUpdated, + .infoClosedGroupCurrentUserLeft, .infoClosedGroupCurrentUserLeaving, .infoClosedGroupCurrentUserErrorLeaving, .infoMessageRequestAccepted, .infoDisappearingMessagesUpdate: // Info messages and unsent messages should just trigger a local // deletion (they are created as side effects so we wouldn't be diff --git a/Session/Conversations/Message Cells/MessageCell.swift b/Session/Conversations/Message Cells/MessageCell.swift index 1f7356bc2..44886ba9c 100644 --- a/Session/Conversations/Message Cells/MessageCell.swift +++ b/Session/Conversations/Message Cells/MessageCell.swift @@ -70,7 +70,8 @@ public class MessageCell: UITableViewCell { case .standardOutgoing, .standardIncoming, .standardIncomingDeleted: return VisibleMessageCell.self - case .infoClosedGroupCreated, .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, + case .infoClosedGroupCreated, .infoClosedGroupUpdated, + .infoClosedGroupCurrentUserLeft, .infoClosedGroupCurrentUserLeaving, .infoClosedGroupCurrentUserErrorLeaving, .infoDisappearingMessagesUpdate, .infoScreenshotNotification, .infoMediaSavedNotification, .infoMessageRequestAccepted: return InfoMessageCell.self diff --git a/Session/Home/HomeViewModel.swift b/Session/Home/HomeViewModel.swift index 888af3141..9b1d7f0cc 100644 --- a/Session/Home/HomeViewModel.swift +++ b/Session/Home/HomeViewModel.swift @@ -312,7 +312,13 @@ public class HomeViewModel { if let _ = error { try Interaction .filter(id: interactionId) - .updateAll(db, Interaction.Columns.body.set(to: "group_leave_error".localized())) + .updateAll( + db, + [ + Interaction.Columns.variant.set(to: Interaction.Variant.infoClosedGroupCurrentUserErrorLeaving), + Interaction.Columns.body.set(to: "group_unable_to_leave".localized()) + ] + ) } else { _ = try SessionThread .filter(id: threadId) diff --git a/Session/Shared/FullConversationCell.swift b/Session/Shared/FullConversationCell.swift index 9ab4b39fa..0b9ce6e9f 100644 --- a/Session/Shared/FullConversationCell.swift +++ b/Session/Shared/FullConversationCell.swift @@ -384,12 +384,32 @@ public final class FullConversationCell: UITableViewCell { typingIndicatorView.stopAnimation() ThemeManager.onThemeChange(observer: snippetLabel) { [weak self, weak snippetLabel] theme, _ in - guard let textColor: UIColor = theme.color(for: .textPrimary) else { return } - - snippetLabel?.attributedText = self?.getSnippet( - cellViewModel: cellViewModel, - textColor: textColor - ) + if cellViewModel.interactionVariant == .infoClosedGroupCurrentUserLeaving { + guard let textColor: UIColor = theme.color(for: .textSecondary) else { return } + + self?.displayNameLabel.themeTextColor = .textSecondary + + snippetLabel?.attributedText = self?.getSnippet( + cellViewModel: cellViewModel, + textColor: textColor + ) + } else if cellViewModel.interactionVariant == .infoClosedGroupCurrentUserErrorLeaving { + guard let textColor: UIColor = theme.color(for: .danger) else { return } + + snippetLabel?.attributedText = self?.getSnippet( + cellViewModel: cellViewModel, + textColor: textColor + ) + } else { + guard let textColor: UIColor = theme.color(for: .textPrimary) else { return } + + self?.displayNameLabel.themeTextColor = .textPrimary + + snippetLabel?.attributedText = self?.getSnippet( + cellViewModel: cellViewModel, + textColor: textColor + ) + } } } @@ -471,7 +491,10 @@ public final class FullConversationCell: UITableViewCell { )) } - if cellViewModel.threadVariant == .closedGroup || cellViewModel.threadVariant == .openGroup { + if + (cellViewModel.threadVariant == .closedGroup || cellViewModel.threadVariant == .openGroup) && + (![Interaction.Variant.infoClosedGroupCurrentUserErrorLeaving, Interaction.Variant.infoClosedGroupCurrentUserLeaving].contains(cellViewModel.interactionVariant)) + { let authorName: String = cellViewModel.authorName(for: cellViewModel.threadVariant) result.append(NSAttributedString( @@ -480,17 +503,22 @@ public final class FullConversationCell: UITableViewCell { )) } + let previewText: String = { + if cellViewModel.interactionVariant == .infoClosedGroupCurrentUserErrorLeaving { return "group_leave_error".localized() } + return Interaction.previewText( + variant: (cellViewModel.interactionVariant ?? .standardIncoming), + body: cellViewModel.interactionBody, + threadContactDisplayName: cellViewModel.threadContactName(), + authorDisplayName: cellViewModel.authorName(for: cellViewModel.threadVariant), + attachmentDescriptionInfo: cellViewModel.interactionAttachmentDescriptionInfo, + attachmentCount: cellViewModel.interactionAttachmentCount, + isOpenGroupInvitation: (cellViewModel.interactionIsOpenGroupInvitation == true) + ) + }() + result.append(NSAttributedString( string: MentionUtilities.highlightMentionsNoAttributes( - in: Interaction.previewText( - variant: (cellViewModel.interactionVariant ?? .standardIncoming), - body: cellViewModel.interactionBody, - threadContactDisplayName: cellViewModel.threadContactName(), - authorDisplayName: cellViewModel.authorName(for: cellViewModel.threadVariant), - attachmentDescriptionInfo: cellViewModel.interactionAttachmentDescriptionInfo, - attachmentCount: cellViewModel.interactionAttachmentCount, - isOpenGroupInvitation: (cellViewModel.interactionIsOpenGroupInvitation == true) - ), + in: previewText, threadVariant: cellViewModel.threadVariant, currentUserPublicKey: cellViewModel.currentUserPublicKey, currentUserBlindedPublicKey: cellViewModel.currentUserBlindedPublicKey diff --git a/SessionMessagingKit/Database/Models/ControlMessageProcessRecord.swift b/SessionMessagingKit/Database/Models/ControlMessageProcessRecord.swift index c7cd38636..bc01ef67c 100644 --- a/SessionMessagingKit/Database/Models/ControlMessageProcessRecord.swift +++ b/SessionMessagingKit/Database/Models/ControlMessageProcessRecord.swift @@ -151,7 +151,7 @@ internal extension ControlMessageProcessRecord { .infoClosedGroupCreated: return nil - case .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft: + case .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, .infoClosedGroupCurrentUserLeaving, .infoClosedGroupCurrentUserErrorLeaving: self.variant = .closedGroupControlMessage case .infoDisappearingMessagesUpdate: diff --git a/SessionMessagingKit/Database/Models/Interaction.swift b/SessionMessagingKit/Database/Models/Interaction.swift index ad89bc463..f12b5af46 100644 --- a/SessionMessagingKit/Database/Models/Interaction.swift +++ b/SessionMessagingKit/Database/Models/Interaction.swift @@ -73,6 +73,8 @@ public struct Interaction: Codable, Identifiable, Equatable, FetchableRecord, Mu case infoClosedGroupCreated = 1000 case infoClosedGroupUpdated case infoClosedGroupCurrentUserLeft + case infoClosedGroupCurrentUserErrorLeaving + case infoClosedGroupCurrentUserLeaving case infoDisappearingMessagesUpdate = 2000 @@ -87,7 +89,8 @@ public struct Interaction: Codable, Identifiable, Equatable, FetchableRecord, Mu public var isInfoMessage: Bool { switch self { - case .infoClosedGroupCreated, .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, + case .infoClosedGroupCreated, .infoClosedGroupUpdated, + .infoClosedGroupCurrentUserLeft, .infoClosedGroupCurrentUserLeaving, .infoClosedGroupCurrentUserErrorLeaving, .infoDisappearingMessagesUpdate, .infoScreenshotNotification, .infoMediaSavedNotification, .infoMessageRequestAccepted, .infoCall: return true @@ -106,7 +109,8 @@ public struct Interaction: Codable, Identifiable, Equatable, FetchableRecord, Mu case .standardOutgoing, .standardIncomingDeleted: return false - case .infoClosedGroupCreated, .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, + case .infoClosedGroupCreated, .infoClosedGroupUpdated, + .infoClosedGroupCurrentUserLeft, .infoClosedGroupCurrentUserLeaving, .infoClosedGroupCurrentUserErrorLeaving, .infoDisappearingMessagesUpdate, .infoScreenshotNotification, .infoMediaSavedNotification, .infoMessageRequestAccepted: return false @@ -399,6 +403,7 @@ public struct Interaction: Codable, Identifiable, Equatable, FetchableRecord, Mu public extension Interaction { func with( + variant: Variant? = nil, serverHash: String? = nil, authorId: String? = nil, body: String? = nil, @@ -415,7 +420,7 @@ public extension Interaction { messageUuid: self.messageUuid, threadId: self.threadId, authorId: (authorId ?? self.authorId), - variant: self.variant, + variant: (variant ?? self.variant), body: (body ?? self.body), timestampMs: (timestampMs ?? self.timestampMs), receivedAtTimestampMs: self.receivedAtTimestampMs, @@ -846,6 +851,8 @@ public extension Interaction { case .infoClosedGroupCreated: return "GROUP_CREATED".localized() case .infoClosedGroupCurrentUserLeft: return "GROUP_YOU_LEFT".localized() + case .infoClosedGroupCurrentUserLeaving: return "group_you_leaving".localized() + case .infoClosedGroupCurrentUserErrorLeaving: return "group_unable_to_leave".localized() case .infoClosedGroupUpdated: return (body ?? "GROUP_UPDATED".localized()) case .infoMessageRequestAccepted: return (body ?? "MESSAGE_REQUESTS_ACCEPTED".localized()) diff --git a/SessionMessagingKit/Sending & Receiving/Message Handling/MessageSender+ClosedGroups.swift b/SessionMessagingKit/Sending & Receiving/Message Handling/MessageSender+ClosedGroups.swift index a083885a5..61cc4dc99 100644 --- a/SessionMessagingKit/Sending & Receiving/Message Handling/MessageSender+ClosedGroups.swift +++ b/SessionMessagingKit/Sending & Receiving/Message Handling/MessageSender+ClosedGroups.swift @@ -493,7 +493,7 @@ extension MessageSender { let interaction: Interaction = try Interaction( threadId: thread.id, authorId: userPublicKey, - variant: .infoClosedGroupCurrentUserLeft, + variant: .infoClosedGroupCurrentUserLeaving, body: "group_you_leaving".localized(), timestampMs: SnodeAPI.currentOffsetTimestampMs() ).inserted(db) @@ -530,9 +530,8 @@ extension MessageSender { ) try interaction.with( - body: ClosedGroupControlMessage.Kind - .memberLeft - .infoMessage(db, sender: userPublicKey) + variant: .infoClosedGroupCurrentUserLeft, + body: "GROUP_YOU_LEFT".localized() ).update(db) } seal.fulfill((interactionId, nil))