Swiftgram/TelegramUI/StringForMessageTimestampStatus.swift
2018-07-21 21:31:48 +03:00

37 lines
1.2 KiB
Swift

import Foundation
import Postbox
import TelegramCore
enum MessageTimestampStatusFormat {
case regular
case minimal
}
func stringForMessageTimestampStatus(message: Message, timeFormat: PresentationTimeFormat, strings: PresentationStrings, format: MessageTimestampStatusFormat = .regular) -> String {
var dateText = stringForMessageTimestamp(timestamp: message.timestamp, timeFormat: timeFormat)
var authorTitle: String?
if let author = message.author as? TelegramUser {
if let peer = message.peers[message.id.peerId] as? TelegramChannel, case .broadcast = peer.info {
authorTitle = author.displayTitle
}
} else {
if let peer = message.peers[message.id.peerId] as? TelegramChannel, case .broadcast = peer.info {
for attribute in message.attributes {
if let attribute = attribute as? AuthorSignatureMessageAttribute {
authorTitle = attribute.signature
break
}
}
}
}
if case .regular = format {
if let authorTitle = authorTitle, !authorTitle.isEmpty {
dateText = "\(authorTitle), \(dateText)"
}
}
return dateText
}