diff --git a/Adamant/Assets/l18n/en.lproj/Localizable.strings b/Adamant/Assets/l18n/en.lproj/Localizable.strings index 4549c350b..becaca584 100644 --- a/Adamant/Assets/l18n/en.lproj/Localizable.strings +++ b/Adamant/Assets/l18n/en.lproj/Localizable.strings @@ -79,6 +79,9 @@ /* Unknown internal error */ "ApiService.InternalError.UnknownError" = "Unknown error. Report a bug"; +/* ChatList: outgoing message preview format, like 'You: %@' */ +"ChatListPage.SentMessageFormat" = "You: %@"; + /* ChatList: scene title */ "ChatListPage.Title" = "Chats"; diff --git a/Adamant/Assets/l18n/ru.lproj/Localizable.strings b/Adamant/Assets/l18n/ru.lproj/Localizable.strings index 1080c7b28..61306f914 100644 --- a/Adamant/Assets/l18n/ru.lproj/Localizable.strings +++ b/Adamant/Assets/l18n/ru.lproj/Localizable.strings @@ -79,6 +79,9 @@ /* Unknown internal error */ "ApiService.InternalError.UnknownError" = "Неизвестная ошибка"; +/* ChatList: outgoing message preview format, like 'You: %@' */ +"ChatListPage.SentMessageFormat" = "Вы: %@"; + /* ChatList: scene title */ "ChatListPage.Title" = "Чаты"; diff --git a/Adamant/CoreData/Chatroom+CoreDataClass.swift b/Adamant/CoreData/Chatroom+CoreDataClass.swift index 7cbed12e6..a4379f1bb 100644 --- a/Adamant/CoreData/Chatroom+CoreDataClass.swift +++ b/Adamant/CoreData/Chatroom+CoreDataClass.swift @@ -58,8 +58,17 @@ public class Chatroom: NSManagedObject { case .orderedDescending: return false + /// Rare case of identical date, compare IDs case .orderedSame: - return lhs.height < rhs.height + guard let lid = lhs.transactionId else { + return true + } + + guard let hid = rhs.transactionId else { + return false + } + + return lid < hid } }).last { if newest != lastTransaction { diff --git a/Adamant/Info.plist b/Adamant/Info.plist index 7813b9015..a212dcbce 100644 --- a/Adamant/Info.plist +++ b/Adamant/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 0.3.6 CFBundleVersion - 22 + 23 LSRequiresIPhoneOS NSCameraUsageDescription diff --git a/Adamant/Services/DataProviders/AdamantChatsProvider.swift b/Adamant/Services/DataProviders/AdamantChatsProvider.swift index ecca3abd7..d0e3d3410 100644 --- a/Adamant/Services/DataProviders/AdamantChatsProvider.swift +++ b/Adamant/Services/DataProviders/AdamantChatsProvider.swift @@ -379,7 +379,7 @@ extension AdamantChatsProvider { func getChatroomsController() -> NSFetchedResultsController { let request: NSFetchRequest = NSFetchRequest(entityName: Chatroom.entityName) request.sortDescriptors = [NSSortDescriptor(key: "updatedAt", ascending: false), - NSSortDescriptor(key: "height", ascending: false)] + NSSortDescriptor(key: "transactionId", ascending: false)] request.predicate = NSPredicate(format: "partner!=nil") let controller = NSFetchedResultsController(fetchRequest: request, managedObjectContext: stack.container.viewContext, sectionNameKeyPath: nil, cacheName: nil) @@ -394,7 +394,7 @@ extension AdamantChatsProvider { let request: NSFetchRequest = NSFetchRequest(entityName: "ChatTransaction") request.predicate = NSPredicate(format: "chatroom = %@", chatroom) request.sortDescriptors = [NSSortDescriptor(key: "date", ascending: true), - NSSortDescriptor(key: "height", ascending: true)] + NSSortDescriptor(key: "transactionId", ascending: true)] let controller = NSFetchedResultsController(fetchRequest: request, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil) return controller @@ -404,7 +404,7 @@ extension AdamantChatsProvider { let request = NSFetchRequest(entityName: "ChatTransaction") request.predicate = NSPredicate(format: "isUnread == true") request.sortDescriptors = [NSSortDescriptor.init(key: "date", ascending: false), - NSSortDescriptor(key: "height", ascending: false)] + NSSortDescriptor(key: "transactionId", ascending: false)] let controller = NSFetchedResultsController(fetchRequest: request, managedObjectContext: stack.container.viewContext, sectionNameKeyPath: "chatroom.partner.address", cacheName: nil) diff --git a/Adamant/Services/DataProviders/AdamantTransfersProvider.swift b/Adamant/Services/DataProviders/AdamantTransfersProvider.swift index 742a6066d..9f20074a0 100644 --- a/Adamant/Services/DataProviders/AdamantTransfersProvider.swift +++ b/Adamant/Services/DataProviders/AdamantTransfersProvider.swift @@ -178,7 +178,8 @@ extension AdamantTransfersProvider { // MARK: Controllers func transfersController() -> NSFetchedResultsController { let request = NSFetchRequest(entityName: TransferTransaction.entityName) - request.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false)] + request.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false), + NSSortDescriptor(key: "transactionId", ascending: false)] let controller = NSFetchedResultsController(fetchRequest: request, managedObjectContext: stack.container.viewContext, sectionNameKeyPath: nil, cacheName: nil) return controller @@ -186,7 +187,8 @@ extension AdamantTransfersProvider { func transfersController(for account: CoreDataAccount) -> NSFetchedResultsController { let request = NSFetchRequest(entityName: TransferTransaction.entityName) - request.sortDescriptors = [NSSortDescriptor(key: "date", ascending:false)] + request.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false), + NSSortDescriptor(key: "transactionId", ascending: false)] request.predicate = NSPredicate(format: "partner = %@", account) let controller = NSFetchedResultsController(fetchRequest: request, managedObjectContext: stack.container.viewContext, sectionNameKeyPath: nil, cacheName: nil) @@ -197,7 +199,8 @@ extension AdamantTransfersProvider { func unreadTransfersController() -> NSFetchedResultsController { let request = NSFetchRequest(entityName: TransferTransaction.entityName) request.predicate = NSPredicate(format: "isUnread == true") - request.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false)] + request.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false), + NSSortDescriptor(key: "transactionId", ascending: false)] let controller = NSFetchedResultsController(fetchRequest: request, managedObjectContext: stack.container.viewContext, sectionNameKeyPath: nil, cacheName: nil) return controller diff --git a/Adamant/Stories/Chats/ChatListViewController.swift b/Adamant/Stories/Chats/ChatListViewController.swift index 25a40ecaf..4ce1c35c7 100644 --- a/Adamant/Stories/Chats/ChatListViewController.swift +++ b/Adamant/Stories/Chats/ChatListViewController.swift @@ -12,6 +12,7 @@ import CoreData extension String.adamantLocalized { struct chatList { static let title = NSLocalizedString("ChatListPage.Title", comment: "ChatList: scene title") + static let sentMessagePrefix = NSLocalizedString("ChatListPage.SentMessageFormat", comment: "ChatList: outgoing message preview format, like 'You: %@'") private init() {} } @@ -208,12 +209,29 @@ extension ChatListViewController { switch chatroom.lastTransaction { case let message as MessageTransaction: - cell.lastMessageLabel.text = message.message + guard let text = message.message else { + cell.lastMessageLabel.text = nil + break + } + + if message.isOutgoing { + cell.lastMessageLabel.text = String.localizedStringWithFormat(String.adamantLocalized.chatList.sentMessagePrefix, text) + } else { + cell.lastMessageLabel.text = text + } case let transfer as TransferTransaction: if let balance = transfer.amount { - let prefix = transfer.isOutgoing ? "⬅️" : "➡️" - cell.lastMessageLabel.text = "\(prefix) \(AdamantUtilities.format(balance: balance))" + let text: String + if transfer.isOutgoing { + text = String.localizedStringWithFormat(String.adamantLocalized.chatList.sentMessagePrefix, " ⬅️ \(AdamantUtilities.format(balance: balance))") + } else { + text = "➡️ \(AdamantUtilities.format(balance: balance))" + } + + cell.lastMessageLabel.text = text + } else { + cell.lastMessageLabel.text = nil } default: