mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-17 19:09:56 +00:00
Merge commit 'eb59174efabb75701f24c148fd492e016770f190'
This commit is contained in:
commit
6de107d9c3
@ -39,7 +39,9 @@ public final class Database {
|
||||
}
|
||||
}
|
||||
|
||||
deinit { sqlite3_close(self.handle) } // sqlite3_close_v2 in Yosemite/iOS 8?
|
||||
deinit {
|
||||
sqlite3_close(self.handle)
|
||||
} // sqlite3_close_v2 in Yosemite/iOS 8?
|
||||
|
||||
public func execute(_ SQL: String) -> Bool {
|
||||
let res = sqlite3_exec(self.handle, SQL, nil, nil, nil)
|
||||
|
@ -443,7 +443,7 @@ public struct MessageForwardInfo: Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
public protocol MessageAttribute: PostboxCoding {
|
||||
public protocol MessageAttribute: class, PostboxCoding {
|
||||
var associatedPeerIds: [PeerId] { get }
|
||||
var associatedMessageIds: [MessageId] { get }
|
||||
}
|
||||
|
@ -146,6 +146,10 @@ final class MessageHistoryIndexTable: Table {
|
||||
operations.append(.Update(previousIndex, message))
|
||||
case let .InsertMessage(insertMessage) where insertMessage.index == message.index:
|
||||
break
|
||||
case let .InsertExistingMessage(insertMessage) where insertMessage.index == message.index:
|
||||
operations.removeAll()
|
||||
operations.append(.Remove(index: previousIndex))
|
||||
operations.append(.Update(insertMessage.index, message))
|
||||
default:
|
||||
operations.append(operation)
|
||||
}
|
||||
|
@ -377,6 +377,21 @@ final class MutableMessageHistoryView {
|
||||
}
|
||||
case let .loaded(loadedState):
|
||||
for operationSet in operations {
|
||||
var addCount = 0
|
||||
var removeCount = 0
|
||||
for operation in operationSet {
|
||||
switch operation {
|
||||
case .InsertMessage:
|
||||
addCount += 1
|
||||
case .Remove:
|
||||
removeCount += 1
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
if addCount == 2 && removeCount == 2 {
|
||||
assert(true)
|
||||
}
|
||||
for operation in operationSet {
|
||||
switch operation {
|
||||
case let .InsertMessage(message):
|
||||
|
@ -973,6 +973,7 @@ public func openPostbox(basePath: String, seedConfiguration: SeedConfiguration,
|
||||
subscriber.putNext(.upgrading(progress))
|
||||
})
|
||||
if let updatedPath = updatedPath {
|
||||
valueBox.internalClose()
|
||||
let _ = try? FileManager.default.removeItem(atPath: basePath + "/db")
|
||||
let _ = try? FileManager.default.moveItem(atPath: updatedPath, toPath: basePath + "/db")
|
||||
valueBox = SqliteValueBox(basePath: basePath + "/db", queue: queue, encryptionParameters: encryptionParameters, upgradeProgress: { progress in
|
||||
|
@ -8,22 +8,9 @@ import SwiftSignalKit
|
||||
|
||||
func postboxUpgrade_21to22(queue: Queue, basePath: String, valueBox: ValueBox, encryptionParameters: ValueBoxEncryptionParameters, progress: (Float) -> Void) -> String? {
|
||||
postboxLog("Upgrade 21->22 started")
|
||||
if encryptionParameters.forceEncryptionIfNoSet {
|
||||
let exportPath = "\(basePath)/version22"
|
||||
let _ = try? FileManager.default.removeItem(atPath: exportPath)
|
||||
valueBox.exportEncrypted(to: exportPath, encryptionParameters: encryptionParameters)
|
||||
|
||||
let updatedValueBox = SqliteValueBox(basePath: exportPath, queue: queue, encryptionParameters: encryptionParameters, upgradeProgress: progress)
|
||||
let metadataTable = MetadataTable(valueBox: updatedValueBox, table: MetadataTable.tableSpec(0))
|
||||
updatedValueBox.begin()
|
||||
metadataTable.setUserVersion(22)
|
||||
updatedValueBox.commit()
|
||||
return exportPath
|
||||
} else {
|
||||
valueBox.begin()
|
||||
let metadataTable = MetadataTable(valueBox: valueBox, table: MetadataTable.tableSpec(0))
|
||||
metadataTable.setUserVersion(22)
|
||||
valueBox.commit()
|
||||
return nil
|
||||
}
|
||||
valueBox.begin()
|
||||
let metadataTable = MetadataTable(valueBox: valueBox, table: MetadataTable.tableSpec(0))
|
||||
metadataTable.setUserVersion(22)
|
||||
valueBox.commit()
|
||||
return nil
|
||||
}
|
||||
|
@ -212,6 +212,10 @@ public final class SqliteValueBox: ValueBox {
|
||||
checkpoints.dispose()
|
||||
}
|
||||
|
||||
func internalClose() {
|
||||
self.database = nil
|
||||
}
|
||||
|
||||
private func openDatabase(encryptionParameters: ValueBoxEncryptionParameters?, upgradeProgress: (Float) -> Void) -> Database {
|
||||
precondition(self.queue.isCurrent())
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user