|
|
|
@ -276,35 +276,44 @@ public extension SessionThread {
|
|
|
|
|
)
|
|
|
|
|
""")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: - Deletion
|
|
|
|
|
|
|
|
|
|
public extension SessionThread {
|
|
|
|
|
enum DeletionType {
|
|
|
|
|
case hideContactConversationAndDeleteContent
|
|
|
|
|
case deleteContactConversationAndContact
|
|
|
|
|
case leaveGroupAsync
|
|
|
|
|
case deleteGroupAndContent
|
|
|
|
|
case deleteCommunityAndContent
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static func deleteOrLeave(
|
|
|
|
|
_ db: Database,
|
|
|
|
|
type: SessionThread.DeletionType,
|
|
|
|
|
threadId: String,
|
|
|
|
|
threadVariant: Variant,
|
|
|
|
|
groupLeaveType: ClosedGroup.LeaveType,
|
|
|
|
|
calledFromConfigHandling: Bool
|
|
|
|
|
) throws {
|
|
|
|
|
try deleteOrLeave(
|
|
|
|
|
db,
|
|
|
|
|
type: type,
|
|
|
|
|
threadIds: [threadId],
|
|
|
|
|
threadVariant: threadVariant,
|
|
|
|
|
groupLeaveType: groupLeaveType,
|
|
|
|
|
calledFromConfigHandling: calledFromConfigHandling
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static func deleteOrLeave(
|
|
|
|
|
_ db: Database,
|
|
|
|
|
type: SessionThread.DeletionType,
|
|
|
|
|
threadIds: [String],
|
|
|
|
|
threadVariant: Variant,
|
|
|
|
|
groupLeaveType: ClosedGroup.LeaveType,
|
|
|
|
|
calledFromConfigHandling: Bool
|
|
|
|
|
) throws {
|
|
|
|
|
let currentUserPublicKey: String = getUserHexEncodedPublicKey(db)
|
|
|
|
|
let remainingThreadIds: Set<String> = threadIds.asSet().removing(currentUserPublicKey)
|
|
|
|
|
|
|
|
|
|
switch (threadVariant, groupLeaveType) {
|
|
|
|
|
case (.contact, .standard), (.contact, .silent):
|
|
|
|
|
switch type {
|
|
|
|
|
case .hideContactConversationAndDeleteContent:
|
|
|
|
|
// Clear any interactions for the deleted thread
|
|
|
|
|
_ = try Interaction
|
|
|
|
|
.filter(threadIds.contains(Interaction.Columns.threadId))
|
|
|
|
@ -334,28 +343,26 @@ public extension SessionThread {
|
|
|
|
|
SessionThread.Columns.shouldBeVisible.set(to: false)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
case (.contact, .forced):
|
|
|
|
|
case .deleteContactConversationAndContact:
|
|
|
|
|
// If this wasn't called from config handling then we need to hide the conversation
|
|
|
|
|
if !calledFromConfigHandling {
|
|
|
|
|
try LibSession
|
|
|
|
|
.remove(db, contactIds: Array(remainingThreadIds))
|
|
|
|
|
try LibSession.remove(db, contactIds: Array(remainingThreadIds))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_ = try SessionThread
|
|
|
|
|
.filter(ids: remainingThreadIds)
|
|
|
|
|
.deleteAll(db)
|
|
|
|
|
|
|
|
|
|
case (.legacyGroup, .standard), (.group, .standard):
|
|
|
|
|
case .leaveGroupAsync:
|
|
|
|
|
try threadIds.forEach { threadId in
|
|
|
|
|
try MessageSender
|
|
|
|
|
.leave(
|
|
|
|
|
db,
|
|
|
|
|
groupPublicKey: threadId,
|
|
|
|
|
deleteThread: true
|
|
|
|
|
)
|
|
|
|
|
try MessageSender.leave(
|
|
|
|
|
db,
|
|
|
|
|
groupPublicKey: threadId,
|
|
|
|
|
deleteThread: true
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case (.legacyGroup, .silent), (.legacyGroup, .forced), (.group, .forced), (.group, .silent):
|
|
|
|
|
case .deleteGroupAndContent:
|
|
|
|
|
try ClosedGroup.removeKeysAndUnsubscribe(
|
|
|
|
|
db,
|
|
|
|
|
threadIds: threadIds,
|
|
|
|
@ -363,7 +370,7 @@ public extension SessionThread {
|
|
|
|
|
calledFromConfigHandling: calledFromConfigHandling
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
case (.community, _):
|
|
|
|
|
case .deleteCommunityAndContent:
|
|
|
|
|
threadIds.forEach { threadId in
|
|
|
|
|
OpenGroupManager.shared.delete(
|
|
|
|
|
db,
|
|
|
|
@ -530,8 +537,8 @@ public extension SessionThread {
|
|
|
|
|
profile: Profile? = nil
|
|
|
|
|
) -> String {
|
|
|
|
|
switch variant {
|
|
|
|
|
case .legacyGroup, .group: return (closedGroupName ?? "Unknown Group")
|
|
|
|
|
case .community: return (openGroupName ?? "Unknown Community")
|
|
|
|
|
case .legacyGroup, .group: return (closedGroupName ?? "groupUnknown".localized())
|
|
|
|
|
case .community: return (openGroupName ?? "communityUnknown".localized())
|
|
|
|
|
case .contact:
|
|
|
|
|
guard !isNoteToSelf else { return "noteToSelf".localized() }
|
|
|
|
|
guard let profile: Profile = profile else {
|
|
|
|
|