update UI and copy for group leaving status

pull/799/head
ryanzhao 3 years ago
parent f14982ed7b
commit 102b4a67ad

@ -136,7 +136,8 @@ extension ContextMenuVC {
switch cellViewModel.variant { switch cellViewModel.variant {
case .standardIncomingDeleted, .infoCall, case .standardIncomingDeleted, .infoCall,
.infoScreenshotNotification, .infoMediaSavedNotification, .infoScreenshotNotification, .infoMediaSavedNotification,
.infoClosedGroupCreated, .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, .infoClosedGroupCreated, .infoClosedGroupUpdated,
.infoClosedGroupCurrentUserLeft, .infoClosedGroupCurrentUserLeaving, .infoClosedGroupCurrentUserErrorLeaving,
.infoMessageRequestAccepted, .infoDisappearingMessagesUpdate: .infoMessageRequestAccepted, .infoDisappearingMessagesUpdate:
// Let the user delete info messages and unsent messages // Let the user delete info messages and unsent messages
return [ Action.delete(cellViewModel, delegate) ] return [ Action.delete(cellViewModel, delegate) ]

@ -1706,7 +1706,8 @@ extension ConversationVC:
switch cellViewModel.variant { switch cellViewModel.variant {
case .standardIncomingDeleted, .infoCall, case .standardIncomingDeleted, .infoCall,
.infoScreenshotNotification, .infoMediaSavedNotification, .infoScreenshotNotification, .infoMediaSavedNotification,
.infoClosedGroupCreated, .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, .infoClosedGroupCreated, .infoClosedGroupUpdated,
.infoClosedGroupCurrentUserLeft, .infoClosedGroupCurrentUserLeaving, .infoClosedGroupCurrentUserErrorLeaving,
.infoMessageRequestAccepted, .infoDisappearingMessagesUpdate: .infoMessageRequestAccepted, .infoDisappearingMessagesUpdate:
// Info messages and unsent messages should just trigger a local // Info messages and unsent messages should just trigger a local
// deletion (they are created as side effects so we wouldn't be // deletion (they are created as side effects so we wouldn't be

@ -70,7 +70,8 @@ public class MessageCell: UITableViewCell {
case .standardOutgoing, .standardIncoming, .standardIncomingDeleted: case .standardOutgoing, .standardIncoming, .standardIncomingDeleted:
return VisibleMessageCell.self return VisibleMessageCell.self
case .infoClosedGroupCreated, .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, case .infoClosedGroupCreated, .infoClosedGroupUpdated,
.infoClosedGroupCurrentUserLeft, .infoClosedGroupCurrentUserLeaving, .infoClosedGroupCurrentUserErrorLeaving,
.infoDisappearingMessagesUpdate, .infoScreenshotNotification, .infoMediaSavedNotification, .infoDisappearingMessagesUpdate, .infoScreenshotNotification, .infoMediaSavedNotification,
.infoMessageRequestAccepted: .infoMessageRequestAccepted:
return InfoMessageCell.self return InfoMessageCell.self

@ -312,7 +312,13 @@ public class HomeViewModel {
if let _ = error { if let _ = error {
try Interaction try Interaction
.filter(id: interactionId) .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 { } else {
_ = try SessionThread _ = try SessionThread
.filter(id: threadId) .filter(id: threadId)

@ -384,12 +384,32 @@ public final class FullConversationCell: UITableViewCell {
typingIndicatorView.stopAnimation() typingIndicatorView.stopAnimation()
ThemeManager.onThemeChange(observer: snippetLabel) { [weak self, weak snippetLabel] theme, _ in ThemeManager.onThemeChange(observer: snippetLabel) { [weak self, weak snippetLabel] theme, _ in
guard let textColor: UIColor = theme.color(for: .textPrimary) else { return } if cellViewModel.interactionVariant == .infoClosedGroupCurrentUserLeaving {
guard let textColor: UIColor = theme.color(for: .textSecondary) else { return }
snippetLabel?.attributedText = self?.getSnippet(
cellViewModel: cellViewModel, self?.displayNameLabel.themeTextColor = .textSecondary
textColor: textColor
) 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) let authorName: String = cellViewModel.authorName(for: cellViewModel.threadVariant)
result.append(NSAttributedString( 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( result.append(NSAttributedString(
string: MentionUtilities.highlightMentionsNoAttributes( string: MentionUtilities.highlightMentionsNoAttributes(
in: Interaction.previewText( in: 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)
),
threadVariant: cellViewModel.threadVariant, threadVariant: cellViewModel.threadVariant,
currentUserPublicKey: cellViewModel.currentUserPublicKey, currentUserPublicKey: cellViewModel.currentUserPublicKey,
currentUserBlindedPublicKey: cellViewModel.currentUserBlindedPublicKey currentUserBlindedPublicKey: cellViewModel.currentUserBlindedPublicKey

@ -151,7 +151,7 @@ internal extension ControlMessageProcessRecord {
.infoClosedGroupCreated: .infoClosedGroupCreated:
return nil return nil
case .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft: case .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, .infoClosedGroupCurrentUserLeaving, .infoClosedGroupCurrentUserErrorLeaving:
self.variant = .closedGroupControlMessage self.variant = .closedGroupControlMessage
case .infoDisappearingMessagesUpdate: case .infoDisappearingMessagesUpdate:

@ -73,6 +73,8 @@ public struct Interaction: Codable, Identifiable, Equatable, FetchableRecord, Mu
case infoClosedGroupCreated = 1000 case infoClosedGroupCreated = 1000
case infoClosedGroupUpdated case infoClosedGroupUpdated
case infoClosedGroupCurrentUserLeft case infoClosedGroupCurrentUserLeft
case infoClosedGroupCurrentUserErrorLeaving
case infoClosedGroupCurrentUserLeaving
case infoDisappearingMessagesUpdate = 2000 case infoDisappearingMessagesUpdate = 2000
@ -87,7 +89,8 @@ public struct Interaction: Codable, Identifiable, Equatable, FetchableRecord, Mu
public var isInfoMessage: Bool { public var isInfoMessage: Bool {
switch self { switch self {
case .infoClosedGroupCreated, .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, case .infoClosedGroupCreated, .infoClosedGroupUpdated,
.infoClosedGroupCurrentUserLeft, .infoClosedGroupCurrentUserLeaving, .infoClosedGroupCurrentUserErrorLeaving,
.infoDisappearingMessagesUpdate, .infoScreenshotNotification, .infoMediaSavedNotification, .infoDisappearingMessagesUpdate, .infoScreenshotNotification, .infoMediaSavedNotification,
.infoMessageRequestAccepted, .infoCall: .infoMessageRequestAccepted, .infoCall:
return true return true
@ -106,7 +109,8 @@ public struct Interaction: Codable, Identifiable, Equatable, FetchableRecord, Mu
case .standardOutgoing, .standardIncomingDeleted: return false case .standardOutgoing, .standardIncomingDeleted: return false
case .infoClosedGroupCreated, .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, case .infoClosedGroupCreated, .infoClosedGroupUpdated,
.infoClosedGroupCurrentUserLeft, .infoClosedGroupCurrentUserLeaving, .infoClosedGroupCurrentUserErrorLeaving,
.infoDisappearingMessagesUpdate, .infoScreenshotNotification, .infoMediaSavedNotification, .infoDisappearingMessagesUpdate, .infoScreenshotNotification, .infoMediaSavedNotification,
.infoMessageRequestAccepted: .infoMessageRequestAccepted:
return false return false
@ -399,6 +403,7 @@ public struct Interaction: Codable, Identifiable, Equatable, FetchableRecord, Mu
public extension Interaction { public extension Interaction {
func with( func with(
variant: Variant? = nil,
serverHash: String? = nil, serverHash: String? = nil,
authorId: String? = nil, authorId: String? = nil,
body: String? = nil, body: String? = nil,
@ -415,7 +420,7 @@ public extension Interaction {
messageUuid: self.messageUuid, messageUuid: self.messageUuid,
threadId: self.threadId, threadId: self.threadId,
authorId: (authorId ?? self.authorId), authorId: (authorId ?? self.authorId),
variant: self.variant, variant: (variant ?? self.variant),
body: (body ?? self.body), body: (body ?? self.body),
timestampMs: (timestampMs ?? self.timestampMs), timestampMs: (timestampMs ?? self.timestampMs),
receivedAtTimestampMs: self.receivedAtTimestampMs, receivedAtTimestampMs: self.receivedAtTimestampMs,
@ -846,6 +851,8 @@ public extension Interaction {
case .infoClosedGroupCreated: return "GROUP_CREATED".localized() case .infoClosedGroupCreated: return "GROUP_CREATED".localized()
case .infoClosedGroupCurrentUserLeft: return "GROUP_YOU_LEFT".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 .infoClosedGroupUpdated: return (body ?? "GROUP_UPDATED".localized())
case .infoMessageRequestAccepted: return (body ?? "MESSAGE_REQUESTS_ACCEPTED".localized()) case .infoMessageRequestAccepted: return (body ?? "MESSAGE_REQUESTS_ACCEPTED".localized())

@ -493,7 +493,7 @@ extension MessageSender {
let interaction: Interaction = try Interaction( let interaction: Interaction = try Interaction(
threadId: thread.id, threadId: thread.id,
authorId: userPublicKey, authorId: userPublicKey,
variant: .infoClosedGroupCurrentUserLeft, variant: .infoClosedGroupCurrentUserLeaving,
body: "group_you_leaving".localized(), body: "group_you_leaving".localized(),
timestampMs: SnodeAPI.currentOffsetTimestampMs() timestampMs: SnodeAPI.currentOffsetTimestampMs()
).inserted(db) ).inserted(db)
@ -530,9 +530,8 @@ extension MessageSender {
) )
try interaction.with( try interaction.with(
body: ClosedGroupControlMessage.Kind variant: .infoClosedGroupCurrentUserLeft,
.memberLeft body: "GROUP_YOU_LEFT".localized()
.infoMessage(db, sender: userPublicKey)
).update(db) ).update(db)
} }
seal.fulfill((interactionId, nil)) seal.fulfill((interactionId, nil))

Loading…
Cancel
Save