Various improvements

This commit is contained in:
Ilya Laktyushin
2025-06-08 18:28:49 +02:00
parent bc04d3c8e9
commit 41ae916106
60 changed files with 3715 additions and 2865 deletions

View File

@@ -1286,12 +1286,81 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
}
attributedString = addAttributesToStringWithRanges(resultString._tuple, body: bodyAttributes, argumentAttributes: attributes)
}
case .unknown:
attributedString = nil
case let .todoCompletions(completed, incompleted):
//TODO:release
let _ = completed
let _ = incompleted
var todo: TelegramMediaTodo?
for attribute in message.attributes {
if let attribute = attribute as? ReplyMessageAttribute, let message = message.associatedMessages[attribute.messageId] {
for media in message.media {
if let media = media as? TelegramMediaTodo {
todo = media
}
}
}
}
if let todo {
if message.author?.id == accountPeerId {
let resultString: PresentationStrings.FormattedString
if let completedTaskId = completed.first, let completedTask = todo.items.first(where: { $0.id == completedTaskId }) {
resultString = strings.Notification_TodoCompletedYou(completedTask.text)
} else if let incompletedTaskId = incompleted.first, let incompletedTask = todo.items.first(where: { $0.id == incompletedTaskId }) {
resultString = strings.Notification_TodoIncompletedYou(incompletedTask.text)
} else {
fatalError()
}
attributedString = addAttributesToStringWithRanges(resultString._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes])
} else {
let peerName = message.author?.compactDisplayTitle ?? ""
var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, message.author?.id)])
attributes[1] = boldAttributes
let resultString: PresentationStrings.FormattedString
if let completedTaskId = completed.first, let completedTask = todo.items.first(where: { $0.id == completedTaskId }) {
resultString = strings.Notification_TodoCompleted(peerName, completedTask.text)
} else if let incompletedTaskId = incompleted.first, let incompletedTask = todo.items.first(where: { $0.id == incompletedTaskId }) {
resultString = strings.Notification_TodoIncompleted(peerName, incompletedTask.text)
} else {
fatalError()
}
attributedString = addAttributesToStringWithRanges(resultString._tuple, body: bodyAttributes, argumentAttributes: attributes)
}
} else {
attributedString = NSAttributedString(string: ".")
}
case let .todoAppendTasks(tasks):
var todoTitle = ""
for attribute in message.attributes {
if let attribute = attribute as? ReplyMessageAttribute, let message = message.associatedMessages[attribute.messageId] {
for media in message.media {
if let todo = media as? TelegramMediaTodo {
todoTitle = todo.text
}
}
}
}
if message.author?.id == accountPeerId {
let resultString: PresentationStrings.FormattedString
if tasks.count == 1, let task = tasks.first {
resultString = strings.Notification_TodoAddedTaskYou(task.text, todoTitle)
} else {
resultString = strings.Notification_TodoAddedMultipleTasksYou(strings.Notification_TodoTasks(Int32(tasks.count)), todoTitle)
}
attributedString = addAttributesToStringWithRanges(resultString._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes, 1: boldAttributes])
} else {
let peerName = message.author?.compactDisplayTitle ?? ""
var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, message.author?.id)])
attributes[1] = boldAttributes
attributes[2] = boldAttributes
let resultString: PresentationStrings.FormattedString
if tasks.count == 1, let task = tasks.first {
resultString = strings.Notification_TodoAddedTask(peerName, task.text, todoTitle)
} else {
resultString = strings.Notification_TodoAddedMultipleTasks(peerName, strings.Notification_TodoTasks(Int32(tasks.count)), todoTitle)
}
attributedString = addAttributesToStringWithRanges(resultString._tuple, body: bodyAttributes, argumentAttributes: attributes)
}
case .unknown:
attributedString = nil
}
break