Various fixes

This commit is contained in:
Ilya Laktyushin
2025-06-09 20:46:26 +02:00
parent 9edf52ed36
commit d7634beb50
8 changed files with 87 additions and 43 deletions

View File

@@ -1297,38 +1297,47 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
}
}
}
var taskTitle = "DELETED"
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)
if let completedTaskId = completed.first, let completedTask = todo.items.first(where: { $0.id == completedTaskId }) {
taskTitle = completedTask.text
} else if let incompletedTaskId = incompleted.first, let incompletedTask = todo.items.first(where: { $0.id == incompletedTaskId }) {
taskTitle = incompletedTask.text
}
}
if taskTitle.count > 20 {
taskTitle = taskTitle.prefix(20) + ""
}
if message.author?.id == accountPeerId {
let resultString: PresentationStrings.FormattedString
if let _ = completed.first {
resultString = strings.Notification_TodoCompletedYou(taskTitle)
} else if let _ = incompleted.first {
resultString = strings.Notification_TodoIncompletedYou(taskTitle)
} else {
resultString = strings.Notification_TodoCompletedYou("")
}
attributedString = addAttributesToStringWithRanges(resultString._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes])
} else {
attributedString = NSAttributedString(string: ".")
let peerName = message.author?.compactDisplayTitle ?? ""
var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, message.author?.id)])
attributes[1] = boldAttributes
let resultString: PresentationStrings.FormattedString
if let _ = completed.first {
resultString = strings.Notification_TodoCompleted(peerName, taskTitle)
} else if let _ = incompleted.first {
resultString = strings.Notification_TodoIncompleted(peerName, taskTitle)
} else {
resultString = strings.Notification_TodoCompleted(peerName, "")
}
attributedString = addAttributesToStringWithRanges(resultString._tuple, body: bodyAttributes, argumentAttributes: attributes)
}
case let .todoAppendTasks(tasks):
var todoTitle = ""
var todoTitle = "DELETED"
for attribute in message.attributes {
if let attribute = attribute as? ReplyMessageAttribute, let message = message.associatedMessages[attribute.messageId] {
for media in message.media {
@@ -1338,10 +1347,17 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
}
}
}
if todoTitle.count > 20 {
todoTitle = todoTitle.prefix(20) + ""
}
if message.author?.id == accountPeerId {
let resultString: PresentationStrings.FormattedString
if tasks.count == 1, let task = tasks.first {
resultString = strings.Notification_TodoAddedTaskYou(task.text, todoTitle)
var taskTitle = task.text
if taskTitle.count > 20 {
taskTitle = taskTitle.prefix(20) + ""
}
resultString = strings.Notification_TodoAddedTaskYou(taskTitle, todoTitle)
} else {
resultString = strings.Notification_TodoAddedMultipleTasksYou(strings.Notification_TodoTasks(Int32(tasks.count)), todoTitle)
}
@@ -1354,7 +1370,11 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
let resultString: PresentationStrings.FormattedString
if tasks.count == 1, let task = tasks.first {
resultString = strings.Notification_TodoAddedTask(peerName, task.text, todoTitle)
var taskTitle = task.text
if taskTitle.count > 20 {
taskTitle = taskTitle.prefix(20) + ""
}
resultString = strings.Notification_TodoAddedTask(peerName, taskTitle, todoTitle)
} else {
resultString = strings.Notification_TodoAddedMultipleTasks(peerName, strings.Notification_TodoTasks(Int32(tasks.count)), todoTitle)
}