Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios

This commit is contained in:
Ilya Laktyushin
2022-10-03 18:46:31 +03:00
76 changed files with 1720 additions and 626 deletions

View File

@@ -72,11 +72,12 @@ public final class EngineChatList: Equatable {
public let readCounters: EnginePeerReadCounters?
public let isMuted: Bool
public let draft: Draft?
public let threadInfo: EngineMessageHistoryThreads.Info?
public let threadInfo: EngineMessageHistoryThread.Info?
public let renderedPeer: EngineRenderedPeer
public let presence: EnginePeer.Presence?
public let hasUnseenMentions: Bool
public let hasUnseenReactions: Bool
public let forumTopicTitle: String?
public let hasFailed: Bool
public let isContact: Bool
@@ -87,11 +88,12 @@ public final class EngineChatList: Equatable {
readCounters: EnginePeerReadCounters?,
isMuted: Bool,
draft: Draft?,
threadInfo: EngineMessageHistoryThreads.Info?,
threadInfo: EngineMessageHistoryThread.Info?,
renderedPeer: EngineRenderedPeer,
presence: EnginePeer.Presence?,
hasUnseenMentions: Bool,
hasUnseenReactions: Bool,
forumTopicTitle: String?,
hasFailed: Bool,
isContact: Bool
) {
@@ -106,6 +108,7 @@ public final class EngineChatList: Equatable {
self.presence = presence
self.hasUnseenMentions = hasUnseenMentions
self.hasUnseenReactions = hasUnseenReactions
self.forumTopicTitle = forumTopicTitle
self.hasFailed = hasFailed
self.isContact = isContact
}
@@ -144,6 +147,9 @@ public final class EngineChatList: Equatable {
if lhs.hasUnseenReactions != rhs.hasUnseenReactions {
return false
}
if lhs.forumTopicTitle != rhs.forumTopicTitle {
return false
}
if lhs.hasFailed != rhs.hasFailed {
return false
}
@@ -351,7 +357,7 @@ public extension EngineChatList.RelativePosition {
extension EngineChatList.Item {
convenience init?(_ entry: ChatListEntry) {
switch entry {
case let .MessageEntry(index, messages, readState, isRemovedFromTotalUnreadCount, embeddedState, renderedPeer, presence, tagSummaryInfo, hasFailed, isContact):
case let .MessageEntry(index, messages, readState, isRemovedFromTotalUnreadCount, embeddedState, renderedPeer, presence, tagSummaryInfo, forumTopicData, hasFailed, isContact):
var draft: EngineChatList.Draft?
if let embeddedState = embeddedState, let _ = embeddedState.overrideChatTimestamp {
if let opaqueState = _internal_decodeStoredChatInterfaceState(state: embeddedState) {
@@ -377,6 +383,11 @@ extension EngineChatList.Item {
hasUnseenReactions = (info.tagSummaryCount ?? 0) != 0// > (info.actionsSummaryCount ?? 0)
}
var forumTopicTitle: String?
if let forumTopicData = forumTopicData?.get(MessageHistoryThreadData.self) {
forumTopicTitle = forumTopicData.info.title
}
self.init(
id: .chatList(index.messageIndex.id.peerId),
index: .chatList(index),
@@ -389,6 +400,7 @@ extension EngineChatList.Item {
presence: presence.flatMap(EnginePeer.Presence.init),
hasUnseenMentions: hasUnseenMentions,
hasUnseenReactions: hasUnseenReactions,
forumTopicTitle: forumTopicTitle,
hasFailed: hasFailed,
isContact: isContact
)

View File

@@ -332,6 +332,20 @@ private class ReplyThreadHistoryContextImpl {
let account = self.account
let _ = (self.account.postbox.transaction { transaction -> (Api.InputPeer?, MessageId?, Int?) in
if var data = transaction.getMessageHistoryThreadInfo(peerId: messageId.peerId, threadId: Int64(messageId.id))?.get(MessageHistoryThreadData.self) {
if messageIndex.id.id >= data.maxIncomingReadId {
if let count = transaction.getThreadMessageCount(peerId: messageId.peerId, threadId: Int64(messageId.id), namespace: messageId.namespace, fromIdExclusive: data.maxIncomingReadId, toIndex: messageIndex) {
data.incomingUnreadCount = max(0, data.incomingUnreadCount - Int32(count))
}
data.maxKnownMessageId = max(data.maxKnownMessageId, messageIndex.id.id)
if let entry = CodableEntry(data) {
transaction.setMessageHistoryThreadInfo(peerId: messageId.peerId, threadId: Int64(messageId.id), info: entry)
}
}
}
if let message = transaction.getMessage(messageId) {
for attribute in message.attributes {
if let attribute = attribute as? SourceReferenceMessageAttribute {
@@ -574,8 +588,10 @@ func _internal_fetchChannelReplyThreadMessage(account: Account, messageId: Messa
return .fail(.generic)
}
let replyInfo = Promise<AccountViewTracker.UpdatedMessageReplyInfo?>()
replyInfo.set(.single(nil))
let replyInfo = Promise<MessageHistoryThreadData?>()
replyInfo.set(account.postbox.transaction { transaction -> MessageHistoryThreadData? in
return transaction.getMessageHistoryThreadInfo(peerId: messageId.peerId, threadId: Int64(messageId.id))?.get(MessageHistoryThreadData.self)
})
let remoteDiscussionMessageSignal: Signal<DiscussionMessage?, NoError> = account.network.request(Api.functions.messages.getDiscussionMessage(peer: inputPeer, msgId: messageId.id))
|> map(Optional.init)
@@ -664,12 +680,22 @@ func _internal_fetchChannelReplyThreadMessage(account: Account, messageId: Messa
}
let discussionMessageSignal = (replyInfo.get()
|> take(1)
|> mapToSignal { replyInfo -> Signal<DiscussionMessage?, NoError> in
guard let replyInfo = replyInfo else {
|> mapToSignal { threadData -> Signal<DiscussionMessage?, NoError> in
guard let threadData = threadData else {
return .single(nil)
}
return account.postbox.transaction { transaction -> DiscussionMessage? in
var foundDiscussionMessageId: MessageId?
return DiscussionMessage(
messageId: messageId,
channelMessageId: nil,
isChannelPost: false,
maxMessage: MessageId(peerId: messageId.peerId, namespace: messageId.namespace, id: threadData.maxKnownMessageId),
maxReadIncomingMessageId: MessageId(peerId: messageId.peerId, namespace: messageId.namespace, id: threadData.maxIncomingReadId),
maxReadOutgoingMessageId: MessageId(peerId: messageId.peerId, namespace: messageId.namespace, id: threadData.maxOutgoingReadId),
unreadCount: Int(threadData.incomingUnreadCount)
)
/*var foundDiscussionMessageId: MessageId?
transaction.scanMessageAttributes(peerId: replyInfo.commentsPeerId, namespace: Namespaces.Message.Cloud, limit: 1000, { id, attributes in
for attribute in attributes {
if let attribute = attribute as? SourceReferenceMessageAttribute {
@@ -696,7 +722,7 @@ func _internal_fetchChannelReplyThreadMessage(account: Account, messageId: Messa
maxReadIncomingMessageId: replyInfo.maxReadIncomingMessageId,
maxReadOutgoingMessageId: nil,
unreadCount: 0
)
)*/
}
})
|> mapToSignal { result -> Signal<DiscussionMessage?, NoError> in
@@ -718,12 +744,13 @@ func _internal_fetchChannelReplyThreadMessage(account: Account, messageId: Messa
let preloadedHistoryPosition: Signal<(FetchMessageHistoryHoleThreadInput, PeerId, MessageId?, Anchor, MessageId?), FetchChannelReplyThreadMessageError> = replyInfo.get()
|> take(1)
|> castError(FetchChannelReplyThreadMessageError.self)
|> mapToSignal { replyInfo -> Signal<(FetchMessageHistoryHoleThreadInput, PeerId, MessageId?, Anchor, MessageId?), FetchChannelReplyThreadMessageError> in
if let replyInfo = replyInfo {
return account.postbox.transaction { transaction -> (FetchMessageHistoryHoleThreadInput, PeerId, MessageId?, Anchor, MessageId?) in
|> mapToSignal { threadData -> Signal<(FetchMessageHistoryHoleThreadInput, PeerId, MessageId?, Anchor, MessageId?), FetchChannelReplyThreadMessageError> in
if let _ = threadData, !"".isEmpty {
return .fail(.generic)
/*return account.postbox.transaction { transaction -> (FetchMessageHistoryHoleThreadInput, PeerId, MessageId?, Anchor, MessageId?) in
var threadInput: FetchMessageHistoryHoleThreadInput = .threadFromChannel(channelMessageId: messageId)
var threadMessageId: MessageId?
transaction.scanMessageAttributes(peerId: replyInfo.commentsPeerId, namespace: Namespaces.Message.Cloud, limit: 1000, { id, attributes in
transaction.scanMessageAttributes(peerId: messageId.peerId, namespace: Namespaces.Message.Cloud, limit: 1000, { id, attributes in
for attribute in attributes {
if let attribute = attribute as? SourceReferenceMessageAttribute {
if attribute.messageId == messageId {
@@ -745,7 +772,7 @@ func _internal_fetchChannelReplyThreadMessage(account: Account, messageId: Messa
}
return (threadInput, replyInfo.commentsPeerId, threadMessageId, anchor, replyInfo.maxMessageId)
}
|> castError(FetchChannelReplyThreadMessageError.self)
|> castError(FetchChannelReplyThreadMessageError.self)*/
} else {
return discussionMessage.get()
|> take(1)
@@ -770,7 +797,10 @@ func _internal_fetchChannelReplyThreadMessage(account: Account, messageId: Messa
}
}
let preloadedHistory = preloadedHistoryPosition
let preloadedHistory: Signal<(FetchMessageHistoryHoleResult?, ChatReplyThreadMessage.Anchor), FetchChannelReplyThreadMessageError>
preloadedHistory = preloadedHistoryPosition
|> mapToSignal { peerInput, commentsPeerId, threadMessageId, anchor, maxMessageId -> Signal<(FetchMessageHistoryHoleResult?, ChatReplyThreadMessage.Anchor), FetchChannelReplyThreadMessageError> in
guard let maxMessageId = maxMessageId else {
return .single((FetchMessageHistoryHoleResult(removedIndices: IndexSet(integersIn: 1 ..< Int(Int32.max - 1)), strictRemovedIndices: IndexSet(), actualPeerId: nil, actualThreadId: nil, ids: []), .automatic))
@@ -814,7 +844,7 @@ func _internal_fetchChannelReplyThreadMessage(account: Account, messageId: Messa
anchor: inputAnchor,
namespaces: .not(Namespaces.Message.allScheduled)
)
if !testView.isLoading {
if !testView.isLoading || transaction.getMessageHistoryThreadInfo(peerId: threadMessageId.peerId, threadId: Int64(threadMessageId.id)) != nil {
let initialAnchor: ChatReplyThreadMessage.Anchor
switch anchor {
case .lowerBound: