Skip to content

Commit

Permalink
Fix autoremove
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali committed Apr 12, 2021
1 parent 2977568 commit 766a818
Show file tree
Hide file tree
Showing 10 changed files with 2,444 additions and 2,432 deletions.
5 changes: 2 additions & 3 deletions Telegram/Telegram-iOS/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@
"PUSH_MESSAGES_1" = "%1$@|sent you a message";
"PUSH_MESSAGES_any" = "%1$@|sent you %2$d messages";
"PUSH_ALBUM" = "%1$@|sent you an album";
"PUSH_MESSAGE_DOCS" = "%1$@|sent you %2$d files";
"PUSH_MESSAGE_DOCS_1" = "%1$@|sent you a file";
"PUSH_MESSAGE_DOCS_any" = "%1$@|sent you %2$d files";
"PUSH_MESSAGE_FILES_1" = "%1$@|sent you a file";
"PUSH_MESSAGE_FILES_any" = "%1$@|sent you %2$d files";


"PUSH_CHANNEL_MESSAGE_TEXT" = "%1$@|%2$@";
Expand Down
4 changes: 2 additions & 2 deletions submodules/Postbox/Sources/GlobalMessageTagsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ final class MutableGlobalMessageTagsView: MutablePostboxView {
}

if let later = self.later {
addedEntries += postbox.messageHistoryTable.laterEntries(globalTagMask: self.globalTag, index: later.predecessor(), count: self.count).map { entry -> InternalGlobalMessageTagsEntry in
addedEntries += postbox.messageHistoryTable.laterEntries(globalTagMask: self.globalTag, index: later.globalPredecessor(), count: self.count).map { entry -> InternalGlobalMessageTagsEntry in
switch entry {
case let .message(message):
return .intermediateMessage(message)
Expand All @@ -358,7 +358,7 @@ final class MutableGlobalMessageTagsView: MutablePostboxView {
}
}
if let earlier = self.earlier {
addedEntries += postbox.messageHistoryTable.earlierEntries(globalTagMask: self.globalTag, index: earlier.successor(), count: self.count).map { entry -> InternalGlobalMessageTagsEntry in
addedEntries += postbox.messageHistoryTable.earlierEntries(globalTagMask: self.globalTag, index: earlier.globalSuccessor(), count: self.count).map { entry -> InternalGlobalMessageTagsEntry in
switch entry {
case let .message(message):
return .intermediateMessage(message)
Expand Down
26 changes: 21 additions & 5 deletions submodules/Postbox/Sources/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,24 @@ public struct MessageIndex: Comparable, Hashable {
self.timestamp = timestamp
}

public func predecessor() -> MessageIndex {
public func globalPredecessor() -> MessageIndex {
let previousPeerId = self.id.peerId.predecessor
if previousPeerId != self.id.peerId {
return MessageIndex(id: MessageId(peerId: previousPeerId, namespace: self.id.namespace, id: self.id.id), timestamp: self.timestamp)
} else if self.id.id != 0 {
return MessageIndex(id: MessageId(peerId: self.id.peerId, namespace: self.id.namespace, id: self.id.id), timestamp: self.timestamp)
return MessageIndex(id: MessageId(peerId: self.id.peerId, namespace: self.id.namespace, id: self.id.id - 1), timestamp: self.timestamp)
} else if self.id.namespace != 0 {
return MessageIndex(id: MessageId(peerId: self.id.peerId, namespace: self.id.namespace - 1, id: Int32.max - 1), timestamp: self.timestamp)
} else if self.timestamp != 0 {
return MessageIndex(id: MessageId(peerId: self.id.peerId, namespace: Int32(Int8.max) - 1, id: Int32.max - 1), timestamp: self.timestamp - 1)
} else {
return self
}
}

public func peerLocalPredecessor() -> MessageIndex {
if self.id.id != 0 {
return MessageIndex(id: MessageId(peerId: self.id.peerId, namespace: self.id.namespace, id: self.id.id - 1), timestamp: self.timestamp)
} else if self.id.namespace != 0 {
return MessageIndex(id: MessageId(peerId: self.id.peerId, namespace: self.id.namespace - 1, id: Int32.max - 1), timestamp: self.timestamp)
} else if self.timestamp != 0 {
Expand All @@ -118,14 +130,18 @@ public struct MessageIndex: Comparable, Hashable {
}
}

public func successor() -> MessageIndex {
public func globalSuccessor() -> MessageIndex {
let nextPeerId = self.id.peerId.successor
if nextPeerId != self.id.peerId {
return MessageIndex(id: MessageId(peerId: nextPeerId, namespace: self.id.namespace, id: self.id.id), timestamp: self.timestamp)
} else {
return MessageIndex(id: MessageId(peerId: self.id.peerId, namespace: self.id.namespace, id: self.id.id == Int32.max ? self.id.id : (self.id.id + 1)), timestamp: self.timestamp)
}
}

public func peerLocalSuccessor() -> MessageIndex {
return MessageIndex(id: MessageId(peerId: self.id.peerId, namespace: self.id.namespace, id: self.id.id == Int32.max ? self.id.id : (self.id.id + 1)), timestamp: self.timestamp)
}

public static func absoluteUpperBound() -> MessageIndex {
return MessageIndex(id: MessageId(peerId: PeerId.max, namespace: Int32(Int8.max), id: Int32.max), timestamp: Int32.max)
Expand Down Expand Up @@ -217,11 +233,11 @@ public struct ChatListIndex: Comparable, Hashable {
}

public var predecessor: ChatListIndex {
return ChatListIndex(pinningIndex: self.pinningIndex, messageIndex: self.messageIndex.predecessor())
return ChatListIndex(pinningIndex: self.pinningIndex, messageIndex: self.messageIndex.globalPredecessor())
}

public var successor: ChatListIndex {
return ChatListIndex(pinningIndex: self.pinningIndex, messageIndex: self.messageIndex.successor())
return ChatListIndex(pinningIndex: self.pinningIndex, messageIndex: self.messageIndex.globalSuccessor())
}
}

Expand Down
4 changes: 2 additions & 2 deletions submodules/Postbox/Sources/MessageHistoryReadStateTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ final class MessageHistoryReadStateTable: Table {
readPastTopIndex = true
}
if maxIncomingReadIndex < messageIndex || markedUnread || readPastTopIndex {
let (realDeltaCount, holes, messageIds) = incomingStatsInRange(maxIncomingReadIndex.successor(), messageIndex)
let (realDeltaCount, holes, messageIds) = incomingStatsInRange(maxIncomingReadIndex.peerLocalSuccessor(), messageIndex)
var deltaCount = realDeltaCount
if readPastTopIndex {
deltaCount = max(Int(count), deltaCount)
Expand Down Expand Up @@ -366,7 +366,7 @@ final class MessageHistoryReadStateTable: Table {
break
case let .indexBased(maxIncomingReadIndex, maxOutgoingReadIndex, count, markedUnread):
if maxOutgoingReadIndex < messageIndex {
let messageIds: [MessageId] = outgoingIndexStatsInRange(maxOutgoingReadIndex.successor(), messageIndex)
let messageIds: [MessageId] = outgoingIndexStatsInRange(maxOutgoingReadIndex.peerLocalSuccessor(), messageIndex)

self.markReadStatesAsUpdated(messageIndex.id.peerId, namespaces: states.namespaces)
states.namespaces[messageIndex.id.namespace] = .indexBased(maxIncomingReadIndex: maxIncomingReadIndex, maxOutgoingReadIndex: messageIndex, count: count, markedUnread: markedUnread)
Expand Down
4 changes: 2 additions & 2 deletions submodules/Postbox/Sources/MessageHistoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ public final class MessageHistoryView {
index = 0
for entry in entries {
if entry.index.id.peerId == peerId && entry.index.id.namespace == namespace {
maxNamespaceIndex = entry.index.predecessor()
maxNamespaceIndex = entry.index.peerLocalPredecessor()
break
}
index += 1
Expand Down Expand Up @@ -1109,7 +1109,7 @@ public final class MessageHistoryView {
index = 0
for entry in entries {
if entry.index.id.peerId == peerId && entry.index.id.namespace == namespace {
maxNamespaceIndex = entry.index.predecessor()
maxNamespaceIndex = entry.index.peerLocalPredecessor()
break
}
index += 1
Expand Down
16 changes: 8 additions & 8 deletions submodules/Postbox/Sources/MessageHistoryViewState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -468,27 +468,27 @@ private func sampleHoleRanges(input: MessageHistoryInput, orderedEntriesBySpace:
if items.higherThanAnchor.count == 0 {
clipRanges.append(MessageIndex.absoluteLowerBound() ... MessageIndex.absoluteUpperBound())
} else {
let clipIndex = items.higherThanAnchor[0].index.predecessor()
let clipIndex = items.higherThanAnchor[0].index.peerLocalPredecessor()
clipRanges.append(MessageIndex.absoluteLowerBound() ... clipIndex)
}
} else {
let clipIndex = items.lowerOrAtAnchor[0].index.predecessor()
let clipIndex = items.lowerOrAtAnchor[0].index.peerLocalPredecessor()
clipRanges.append(MessageIndex.absoluteLowerBound() ... clipIndex)
}
} else {
if i == items.lowerOrAtAnchor.count - 1 {
if items.higherThanAnchor.count == 0 {
clipRanges.append(MessageIndex.absoluteLowerBound() ... MessageIndex.absoluteUpperBound())
} else {
let clipIndex = items.higherThanAnchor[0].index.predecessor()
let clipIndex = items.higherThanAnchor[0].index.peerLocalPredecessor()
clipRanges.append(MessageIndex.absoluteLowerBound() ... clipIndex)
}
} else {
let clipIndex: MessageIndex
if indices.contains(Int(items.lowerOrAtAnchor[i + 1].index.id.id)) {
clipIndex = items.lowerOrAtAnchor[i + 1].index
} else {
clipIndex = items.lowerOrAtAnchor[i + 1].index.predecessor()
clipIndex = items.lowerOrAtAnchor[i + 1].index.peerLocalPredecessor()
}
clipRanges.append(MessageIndex.absoluteLowerBound() ... clipIndex)
}
Expand Down Expand Up @@ -536,27 +536,27 @@ private func sampleHoleRanges(input: MessageHistoryInput, orderedEntriesBySpace:
if items.lowerOrAtAnchor.count == 0 {
clipRanges.append(MessageIndex.absoluteLowerBound() ... MessageIndex.absoluteUpperBound())
} else {
let clipIndex = items.lowerOrAtAnchor[items.lowerOrAtAnchor.count - 1].index.successor()
let clipIndex = items.lowerOrAtAnchor[items.lowerOrAtAnchor.count - 1].index.peerLocalSuccessor()
clipRanges.append(clipIndex ... MessageIndex.absoluteUpperBound())
}
} else {
let clipIndex = items.higherThanAnchor[items.higherThanAnchor.count - 1].index.successor()
let clipIndex = items.higherThanAnchor[items.higherThanAnchor.count - 1].index.peerLocalSuccessor()
clipRanges.append(clipIndex ... MessageIndex.absoluteUpperBound())
}
} else {
if i == 0 {
if items.lowerOrAtAnchor.count == 0 {
clipRanges.append(MessageIndex.absoluteLowerBound() ... MessageIndex.absoluteUpperBound())
} else {
let clipIndex = items.lowerOrAtAnchor[items.lowerOrAtAnchor.count - 1].index.successor()
let clipIndex = items.lowerOrAtAnchor[items.lowerOrAtAnchor.count - 1].index.peerLocalSuccessor()
clipRanges.append(clipIndex ... MessageIndex.absoluteUpperBound())
}
} else {
let clipIndex: MessageIndex
if indices.contains(Int(items.higherThanAnchor[i - 1].index.id.id)) {
clipIndex = items.higherThanAnchor[i - 1].index
} else {
clipIndex = items.higherThanAnchor[i - 1].index.successor()
clipIndex = items.higherThanAnchor[i - 1].index.peerLocalSuccessor()
}
clipRanges.append(clipIndex ... MessageIndex.absoluteUpperBound())
}
Expand Down
2 changes: 1 addition & 1 deletion submodules/TelegramCore/Sources/Holes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ func fetchCallListHole(network: Network, postbox: Postbox, accountPeerId: PeerId

var updatedIndex: MessageIndex?
if let topIndex = topIndex {
updatedIndex = topIndex.predecessor()
updatedIndex = topIndex.globalPredecessor()
}

transaction.replaceGlobalMessageTagsHole(globalTags: [.Calls, .MissedCalls], index: holeIndex, with: updatedIndex, messages: storeMessages)
Expand Down
Loading

0 comments on commit 766a818

Please sign in to comment.