mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
[WIP] Monoforums
This commit is contained in:
@@ -220,6 +220,7 @@ public final class ChatMessageItemImpl: ChatMessageItem, CustomStringConvertible
|
||||
public let additionalContent: ChatMessageItemAdditionalContent?
|
||||
|
||||
let dateHeader: ChatMessageDateHeader
|
||||
let topicHeader: ChatMessageDateHeader?
|
||||
let avatarHeader: ChatMessageAvatarHeader?
|
||||
|
||||
public let headers: [ListViewItemHeader]
|
||||
@@ -286,6 +287,8 @@ public final class ChatMessageItemImpl: ChatMessageItem, CustomStringConvertible
|
||||
var displayAuthorInfo: Bool
|
||||
|
||||
let messagePeerId: PeerId = chatLocation.peerId ?? content.firstMessage.id.peerId
|
||||
var headerSeparableThreadId: Int64?
|
||||
var headerDisplayPeer: ChatMessageDateHeader.PeerData?
|
||||
|
||||
do {
|
||||
let peerId = messagePeerId
|
||||
@@ -320,6 +323,12 @@ public final class ChatMessageItemImpl: ChatMessageItem, CustomStringConvertible
|
||||
if let channel = content.firstMessage.peers[content.firstMessage.id.peerId] as? TelegramChannel, channel.isMonoForum {
|
||||
if case .replyThread = chatLocation {
|
||||
displayAuthorInfo = false
|
||||
} else {
|
||||
headerSeparableThreadId = content.firstMessage.threadId
|
||||
|
||||
if let threadId = content.firstMessage.threadId, let peer = content.firstMessage.peers[EnginePeer.Id(threadId)] {
|
||||
headerDisplayPeer = ChatMessageDateHeader.PeerData(peer: EnginePeer(peer))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -332,7 +341,7 @@ public final class ChatMessageItemImpl: ChatMessageItem, CustomStringConvertible
|
||||
isScheduledMessages = true
|
||||
}
|
||||
|
||||
self.dateHeader = ChatMessageDateHeader(timestamp: content.index.timestamp, scheduled: isScheduledMessages, presentationData: presentationData, controllerInteraction: controllerInteraction, context: context, action: { timestamp, alreadyThere in
|
||||
self.dateHeader = ChatMessageDateHeader(timestamp: content.index.timestamp, separableThreadId: nil, scheduled: isScheduledMessages, displayPeer: nil, presentationData: presentationData, controllerInteraction: controllerInteraction, context: context, action: { timestamp, alreadyThere in
|
||||
var calendar = NSCalendar.current
|
||||
calendar.timeZone = TimeZone(abbreviation: "UTC")!
|
||||
let date = Date(timeIntervalSince1970: TimeInterval(timestamp))
|
||||
@@ -343,6 +352,14 @@ public final class ChatMessageItemImpl: ChatMessageItem, CustomStringConvertible
|
||||
}
|
||||
})
|
||||
|
||||
if let headerSeparableThreadId, let headerDisplayPeer {
|
||||
self.topicHeader = ChatMessageDateHeader(timestamp: content.index.timestamp, separableThreadId: headerSeparableThreadId, scheduled: false, displayPeer: headerDisplayPeer, presentationData: presentationData, controllerInteraction: controllerInteraction, context: context, action: { _, _ in
|
||||
controllerInteraction.updateChatLocationThread(headerSeparableThreadId)
|
||||
})
|
||||
} else {
|
||||
self.topicHeader = nil
|
||||
}
|
||||
|
||||
if displayAuthorInfo {
|
||||
let message = content.firstMessage
|
||||
var hasActionMedia = false
|
||||
@@ -395,6 +412,9 @@ public final class ChatMessageItemImpl: ChatMessageItem, CustomStringConvertible
|
||||
var headers: [ListViewItemHeader] = []
|
||||
if !self.disableDate {
|
||||
headers.append(self.dateHeader)
|
||||
if let topicHeader = self.topicHeader {
|
||||
headers.append(topicHeader)
|
||||
}
|
||||
}
|
||||
if case .messageOptions = associatedData.subject {
|
||||
headers = []
|
||||
@@ -499,7 +519,7 @@ public final class ChatMessageItemImpl: ChatMessageItem, CustomStringConvertible
|
||||
}
|
||||
}
|
||||
|
||||
let (layout, apply) = nodeLayout(self, params, top, bottom, dateAtBottom && !disableDate)
|
||||
let (layout, apply) = nodeLayout(self, params, top, bottom, disableDate ? ChatMessageHeaderSpec(hasDate: false, hasTopic: false) : dateAtBottom)
|
||||
|
||||
node.contentSize = layout.contentSize
|
||||
node.insets = layout.insets
|
||||
@@ -526,7 +546,7 @@ public final class ChatMessageItemImpl: ChatMessageItem, CustomStringConvertible
|
||||
}
|
||||
}
|
||||
|
||||
public func mergedWithItems(top: ListViewItem?, bottom: ListViewItem?, isRotated: Bool) -> (top: ChatMessageMerge, bottom: ChatMessageMerge, dateAtBottom: Bool) {
|
||||
public func mergedWithItems(top: ListViewItem?, bottom: ListViewItem?, isRotated: Bool) -> (top: ChatMessageMerge, bottom: ChatMessageMerge, dateAtBottom: ChatMessageHeaderSpec) {
|
||||
var top = top
|
||||
var bottom = bottom
|
||||
if !isRotated {
|
||||
@@ -537,7 +557,7 @@ public final class ChatMessageItemImpl: ChatMessageItem, CustomStringConvertible
|
||||
|
||||
var mergedTop: ChatMessageMerge = .none
|
||||
var mergedBottom: ChatMessageMerge = .none
|
||||
var dateAtBottom = false
|
||||
var dateAtBottom = ChatMessageHeaderSpec(hasDate: false, hasTopic: false)
|
||||
if let top = top as? ChatMessageItemImpl {
|
||||
if top.dateHeader.id != self.dateHeader.id {
|
||||
mergedBottom = .none
|
||||
@@ -548,20 +568,35 @@ public final class ChatMessageItemImpl: ChatMessageItem, CustomStringConvertible
|
||||
if let bottom = bottom as? ChatMessageItemImpl {
|
||||
if bottom.dateHeader.id != self.dateHeader.id {
|
||||
mergedTop = .none
|
||||
dateAtBottom = true
|
||||
} else {
|
||||
dateAtBottom.hasDate = true
|
||||
}
|
||||
if let topicHeader = self.topicHeader, bottom.topicHeader?.id != topicHeader.id {
|
||||
mergedTop = .none
|
||||
dateAtBottom.hasTopic = true
|
||||
}
|
||||
|
||||
if !(dateAtBottom.hasDate || dateAtBottom.hasTopic) {
|
||||
mergedTop = messagesShouldBeMerged(accountPeerId: self.context.account.peerId, bottom.message, message)
|
||||
}
|
||||
} else if let bottom = bottom as? ChatUnreadItem {
|
||||
if bottom.header.id != self.dateHeader.id {
|
||||
dateAtBottom = true
|
||||
dateAtBottom.hasDate = true
|
||||
}
|
||||
if self.topicHeader != nil {
|
||||
dateAtBottom.hasTopic = true
|
||||
}
|
||||
} else if let bottom = bottom as? ChatReplyCountItem {
|
||||
if bottom.header.id != self.dateHeader.id {
|
||||
dateAtBottom = true
|
||||
dateAtBottom.hasDate = true
|
||||
}
|
||||
if self.topicHeader != nil {
|
||||
dateAtBottom.hasTopic = true
|
||||
}
|
||||
} else {
|
||||
dateAtBottom = true
|
||||
dateAtBottom.hasDate = true
|
||||
if self.topicHeader != nil {
|
||||
dateAtBottom.hasTopic = true
|
||||
}
|
||||
}
|
||||
|
||||
return (mergedTop, mergedBottom, dateAtBottom)
|
||||
@@ -589,7 +624,7 @@ public final class ChatMessageItemImpl: ChatMessageItem, CustomStringConvertible
|
||||
}
|
||||
}
|
||||
|
||||
let (layout, apply) = nodeLayout(self, params, top, bottom, dateAtBottom && !disableDate)
|
||||
let (layout, apply) = nodeLayout(self, params, top, bottom, disableDate ? ChatMessageHeaderSpec(hasDate: false, hasTopic: false) : dateAtBottom)
|
||||
Queue.mainQueue().async {
|
||||
completion(layout, { info in
|
||||
apply(animation, info, false)
|
||||
|
||||
Reference in New Issue
Block a user