mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Various improvements
This commit is contained in:
@@ -1496,32 +1496,61 @@ struct ChatRecentActionsEntry: Comparable, Identifiable {
|
||||
var text: String = ""
|
||||
var entities: [MessageTextEntity] = []
|
||||
|
||||
let rawText: PresentationStrings.FormattedString
|
||||
switch updatedValue {
|
||||
case .all:
|
||||
rawText = self.presentationData.strings.Channel_AdminLog_ReactionsEnabled(author.flatMap(EnginePeer.init)?.displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder) ?? "")
|
||||
case let .limited(reactions):
|
||||
let emojiString = reactions.compactMap({ reaction -> String? in
|
||||
switch reaction {
|
||||
case let .builtin(value):
|
||||
return value
|
||||
case .custom:
|
||||
return nil
|
||||
let rawText = self.presentationData.strings.Channel_AdminLog_ReactionsEnabled(author.flatMap(EnginePeer.init)?.displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder) ?? "")
|
||||
appendAttributedText(text: rawText, generateEntities: { index in
|
||||
if index == 0, let author = author {
|
||||
return [.TextMention(peerId: author.id)]
|
||||
} else if index == 1 {
|
||||
return [.Bold]
|
||||
}
|
||||
}).joined(separator: ", ")
|
||||
rawText = self.presentationData.strings.Channel_AdminLog_AllowedReactionsUpdated(author.flatMap(EnginePeer.init)?.displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder) ?? "", emojiString)
|
||||
case .empty:
|
||||
rawText = self.presentationData.strings.Channel_AdminLog_ReactionsDisabled(author.flatMap(EnginePeer.init)?.displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder) ?? "")
|
||||
}
|
||||
|
||||
appendAttributedText(text: rawText, generateEntities: { index in
|
||||
if index == 0, let author = author {
|
||||
return [.TextMention(peerId: author.id)]
|
||||
} else if index == 1 {
|
||||
return [.Bold]
|
||||
return []
|
||||
}, to: &text, entities: &entities)
|
||||
case let .limited(reactions):
|
||||
let authorTitle = author.flatMap(EnginePeer.init)?.displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder) ?? ""
|
||||
let rawText = self.presentationData.strings.Channel_AdminLog_AllowedReactionsUpdated(authorTitle, "")
|
||||
var previousIndex = 0
|
||||
let nsText = rawText.string as NSString
|
||||
for range in rawText.ranges.sorted(by: { $0.range.lowerBound < $1.range.lowerBound }) {
|
||||
if range.range.lowerBound > previousIndex {
|
||||
text.append(nsText.substring(with: NSRange(location: previousIndex, length: range.range.lowerBound - previousIndex)))
|
||||
}
|
||||
if range.index == 0 {
|
||||
if let author {
|
||||
entities.append(MessageTextEntity(range: (text as NSString).length ..< (text as NSString).length + (authorTitle as NSString).length, type: .TextMention(peerId: author.id)))
|
||||
}
|
||||
text.append(authorTitle)
|
||||
} else if range.index == 1 {
|
||||
for reaction in reactions {
|
||||
let reactionText: String
|
||||
switch reaction {
|
||||
case let .builtin(value):
|
||||
reactionText = value
|
||||
text.append(reactionText)
|
||||
case let .custom(fileId):
|
||||
reactionText = "."
|
||||
entities.append(MessageTextEntity(range: (text as NSString).length ..< (text as NSString).length + (reactionText as NSString).length, type: .CustomEmoji(stickerPack: nil, fileId: fileId)))
|
||||
text.append(reactionText)
|
||||
}
|
||||
}
|
||||
}
|
||||
previousIndex = range.range.upperBound
|
||||
}
|
||||
return []
|
||||
}, to: &text, entities: &entities)
|
||||
if nsText.length > previousIndex {
|
||||
text.append(nsText.substring(with: NSRange(location: previousIndex, length: nsText.length - previousIndex)))
|
||||
}
|
||||
case .empty:
|
||||
let rawText = self.presentationData.strings.Channel_AdminLog_ReactionsDisabled(author.flatMap(EnginePeer.init)?.displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder) ?? "")
|
||||
appendAttributedText(text: rawText, generateEntities: { index in
|
||||
if index == 0, let author = author {
|
||||
return [.TextMention(peerId: author.id)]
|
||||
} else if index == 1 {
|
||||
return [.Bold]
|
||||
}
|
||||
return []
|
||||
}, to: &text, entities: &entities)
|
||||
}
|
||||
|
||||
let action = TelegramMediaActionType.customText(text: text, entities: entities)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user