diff --git a/Session/Conversations/Context Menu/ContextMenuVC+Action.swift b/Session/Conversations/Context Menu/ContextMenuVC+Action.swift index a66dcfef3..04e652f8f 100644 --- a/Session/Conversations/Context Menu/ContextMenuVC+Action.swift +++ b/Session/Conversations/Context Menu/ContextMenuVC+Action.swift @@ -136,8 +136,7 @@ extension ContextMenuVC { switch cellViewModel.variant { case .standardIncomingDeleted, .infoCall, .infoScreenshotNotification, .infoMediaSavedNotification, - .infoClosedGroupCreated, .infoClosedGroupUpdated, - .infoClosedGroupCurrentUserLeft, .infoClosedGroupCurrentUserLeaving, .infoClosedGroupCurrentUserErrorLeaving, + .infoClosedGroupCreated, .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, .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 980c0eb0c..a8ca98c6d 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -1694,8 +1694,7 @@ extension ConversationVC: switch cellViewModel.variant { case .standardIncomingDeleted, .infoCall, .infoScreenshotNotification, .infoMediaSavedNotification, - .infoClosedGroupCreated, .infoClosedGroupUpdated, - .infoClosedGroupCurrentUserLeft, .infoClosedGroupCurrentUserLeaving, .infoClosedGroupCurrentUserErrorLeaving, + .infoClosedGroupCreated, .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, .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 44886ba9c..1f7356bc2 100644 --- a/Session/Conversations/Message Cells/MessageCell.swift +++ b/Session/Conversations/Message Cells/MessageCell.swift @@ -70,8 +70,7 @@ public class MessageCell: UITableViewCell { case .standardOutgoing, .standardIncoming, .standardIncomingDeleted: return VisibleMessageCell.self - case .infoClosedGroupCreated, .infoClosedGroupUpdated, - .infoClosedGroupCurrentUserLeft, .infoClosedGroupCurrentUserLeaving, .infoClosedGroupCurrentUserErrorLeaving, + case .infoClosedGroupCreated, .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, .infoDisappearingMessagesUpdate, .infoScreenshotNotification, .infoMediaSavedNotification, .infoMessageRequestAccepted: return InfoMessageCell.self diff --git a/Session/Home/HomeViewModel.swift b/Session/Home/HomeViewModel.swift index 73d899a94..5466ccb72 100644 --- a/Session/Home/HomeViewModel.swift +++ b/Session/Home/HomeViewModel.swift @@ -307,15 +307,12 @@ public class HomeViewModel { case .closedGroup: try MessageSender .leave(db, groupPublicKey: threadId) - .done { + .done { _ in Storage.shared.writeAsync { db in _ = try SessionThread .filter(id: threadId) .deleteAll(db) } - } - .catch { _ in - } .retainUntilComplete() diff --git a/SessionMessagingKit/Database/Models/ControlMessageProcessRecord.swift b/SessionMessagingKit/Database/Models/ControlMessageProcessRecord.swift index 7540e35cc..c7cd38636 100644 --- a/SessionMessagingKit/Database/Models/ControlMessageProcessRecord.swift +++ b/SessionMessagingKit/Database/Models/ControlMessageProcessRecord.swift @@ -151,8 +151,7 @@ internal extension ControlMessageProcessRecord { .infoClosedGroupCreated: return nil - case .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, - .infoClosedGroupCurrentUserLeaving, .infoClosedGroupCurrentUserErrorLeaving: + case .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft: self.variant = .closedGroupControlMessage case .infoDisappearingMessagesUpdate: diff --git a/SessionMessagingKit/Database/Models/Interaction.swift b/SessionMessagingKit/Database/Models/Interaction.swift index 2dcb64a82..ad89bc463 100644 --- a/SessionMessagingKit/Database/Models/Interaction.swift +++ b/SessionMessagingKit/Database/Models/Interaction.swift @@ -73,8 +73,6 @@ public struct Interaction: Codable, Identifiable, Equatable, FetchableRecord, Mu case infoClosedGroupCreated = 1000 case infoClosedGroupUpdated case infoClosedGroupCurrentUserLeft - case infoClosedGroupCurrentUserLeaving - case infoClosedGroupCurrentUserErrorLeaving case infoDisappearingMessagesUpdate = 2000 @@ -89,7 +87,7 @@ public struct Interaction: Codable, Identifiable, Equatable, FetchableRecord, Mu public var isInfoMessage: Bool { switch self { - case .infoClosedGroupCreated, .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, .infoClosedGroupCurrentUserLeaving, .infoClosedGroupCurrentUserErrorLeaving, + case .infoClosedGroupCreated, .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, .infoDisappearingMessagesUpdate, .infoScreenshotNotification, .infoMediaSavedNotification, .infoMessageRequestAccepted, .infoCall: return true @@ -108,7 +106,7 @@ public struct Interaction: Codable, Identifiable, Equatable, FetchableRecord, Mu case .standardOutgoing, .standardIncomingDeleted: return false - case .infoClosedGroupCreated, .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, .infoClosedGroupCurrentUserLeaving, .infoClosedGroupCurrentUserErrorLeaving, + case .infoClosedGroupCreated, .infoClosedGroupUpdated, .infoClosedGroupCurrentUserLeft, .infoDisappearingMessagesUpdate, .infoScreenshotNotification, .infoMediaSavedNotification, .infoMessageRequestAccepted: return false @@ -848,8 +846,6 @@ 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_leave_error".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 e565eaca0..7456aea2c 100644 --- a/SessionMessagingKit/Sending & Receiving/Message Handling/MessageSender+ClosedGroups.swift +++ b/SessionMessagingKit/Sending & Receiving/Message Handling/MessageSender+ClosedGroups.swift @@ -478,7 +478,7 @@ extension MessageSender { /// unregisters from push notifications. /// /// The returned promise is fulfilled when the `MEMBER_LEFT` message has been sent to the group. - public static func leave(_ db: Database, groupPublicKey: String) throws -> Promise { + public static func leave(_ db: Database, groupPublicKey: String) throws -> Promise { guard let thread: SessionThread = try? SessionThread.fetchOne(db, id: groupPublicKey) else { SNLog("Can't leave nonexistent closed group.") return Promise(error: MessageSenderError.noThread) @@ -493,10 +493,8 @@ extension MessageSender { let interaction: Interaction = try Interaction( threadId: thread.id, authorId: userPublicKey, - variant: .infoClosedGroupCurrentUserLeaving, - body: ClosedGroupControlMessage.Kind - .memberLeft - .infoMessage(db, sender: userPublicKey), + variant: .infoClosedGroupCurrentUserLeft, + body: "group_you_leaving".localized(), timestampMs: SnodeAPI.currentOffsetTimestampMs() ).inserted(db) @@ -528,10 +526,19 @@ extension MessageSender { for: groupPublicKey, publicKey: userPublicKey ) + + try interaction.with( + body: ClosedGroupControlMessage.Kind + .memberLeft + .infoMessage(db, sender: userPublicKey) + ).update(db) } - interaction.with() + } - .map { _ in } + .map { _ in + return interactionId + } + // Update the group (if the admin leaves the group is disbanded) let wasAdminUser: Bool = try GroupMember