From 1a749e857477b04f75f3316af5049d4f77e1c4bc Mon Sep 17 00:00:00 2001 From: Pavel Anokhov Date: Sun, 1 Apr 2018 11:44:49 +0300 Subject: [PATCH 1/3] Sent message preview format: "You: %@" --- .../Assets/l18n/en.lproj/Localizable.strings | 3 +++ .../Assets/l18n/ru.lproj/Localizable.strings | 3 +++ .../Chats/ChatListViewController.swift | 24 ++++++++++++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Adamant/Assets/l18n/en.lproj/Localizable.strings b/Adamant/Assets/l18n/en.lproj/Localizable.strings index e944901e4..2c76f4460 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/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: From 5de943c547165acf7660ff31b3926e9821ddad54 Mon Sep 17 00:00:00 2001 From: Pavel Anokhov Date: Sun, 1 Apr 2018 12:09:42 +0300 Subject: [PATCH 2/3] Sorting fixed. --- Adamant/CoreData/Chatroom+CoreDataClass.swift | 11 ++++++++++- .../Services/DataProviders/AdamantChatsProvider.swift | 6 +++--- .../DataProviders/AdamantTransfersProvider.swift | 9 ++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) 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/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 From 63b600f26f927d57ecb18c0eaf095abaf06a8e15 Mon Sep 17 00:00:00 2001 From: Pavel Anokhov Date: Sun, 1 Apr 2018 12:13:31 +0300 Subject: [PATCH 3/3] Build bump --- Adamant/Info.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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