diff --git a/Postbox/ChatListTable.swift b/Postbox/ChatListTable.swift index cb9bc84df2..c619e9741f 100644 --- a/Postbox/ChatListTable.swift +++ b/Postbox/ChatListTable.swift @@ -90,7 +90,7 @@ private func extractKey(_ key: ValueBoxKey) -> (groupId: PeerGroupId?, pinningIn private func readEntry(groupId: PeerGroupId?, messageHistoryTable: MessageHistoryTable, peerChatInterfaceStateTable: PeerChatInterfaceStateTable, key: ValueBoxKey, value: ReadBuffer) -> ChatListIntermediateEntry { let (keyGroupId, pinningIndex, messageIndex, type) = extractKey(key) assert(groupId == keyGroupId) - + //preconditionFailure() let index = ChatListIndex(pinningIndex: pinningIndex, messageIndex: messageIndex) if type == ChatListEntryType.message.rawValue { var message: IntermediateMessage? diff --git a/Postbox/MessageOfInterestHolesView.swift b/Postbox/MessageOfInterestHolesView.swift index 5edfe3ac08..4fb254bde7 100644 --- a/Postbox/MessageOfInterestHolesView.swift +++ b/Postbox/MessageOfInterestHolesView.swift @@ -526,10 +526,13 @@ final class MutableMessageOfInterestHolesView: MutablePostboxView { var i = referenceIndex var j = referenceIndex + 1 + let lowerI = max(0, referenceIndex - 50) + let upperJ = min(referenceIndex + 50, self.entries.count) + switch self.location { case let .group(groupId): - while i >= 0 || j < self.entries.count { - if j < self.entries.count { + while i >= lowerI || j < upperJ { + if j < upperJ { if let hole = self.entries[j].hole { switch anchorLocation { case let .index(index): @@ -552,7 +555,7 @@ final class MutableMessageOfInterestHolesView: MutablePostboxView { } } - if i >= 0 { + if i >= lowerI { if let hole = self.entries[i].hole { switch anchorLocation { case let .index(index): @@ -598,8 +601,8 @@ final class MutableMessageOfInterestHolesView: MutablePostboxView { case let .index(index): anchorId = index.id } - while i >= 0 || j < self.entries.count { - if j < self.entries.count { + while i >= lowerI || j < upperJ { + if j < upperJ { if let hole = self.entries[j].hole { if anchorId.id >= hole.hole.min && anchorId.id <= hole.hole.maxIndex.id.id { return MessageOfInterestHole(hole: .peer(hole.hole), direction: .AroundId(anchorId)) @@ -609,7 +612,7 @@ final class MutableMessageOfInterestHolesView: MutablePostboxView { } } - if i >= 0 { + if i >= lowerI { if let hole = self.entries[i].hole { if anchorId.id >= hole.hole.min && anchorId.id <= hole.hole.maxIndex.id.id { return MessageOfInterestHole(hole: .peer(hole.hole), direction: .AroundId(anchorId)) diff --git a/Postbox/ValueBoxKey.swift b/Postbox/ValueBoxKey.swift index a734fa5c4c..b309f6589b 100644 --- a/Postbox/ValueBoxKey.swift +++ b/Postbox/ValueBoxKey.swift @@ -24,7 +24,7 @@ public struct ValueBoxKey: Equatable, Hashable, CustomStringConvertible, Compara } public init(_ value: String) { - let data = value.data(using: .utf8, allowLossyConversion: true)! + let data = value.data(using: .utf8, allowLossyConversion: true) ?? Data() self.memory = malloc(data.count) self.length = data.count self.impl = ValueBoxKeyImpl(memory: self.memory)