Skip to content

Commit

Permalink
Merge branch 'release/0.3.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
RealBonus committed Apr 1, 2018
2 parents 149a489 + 63b600f commit 21de2e2
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Adamant/Assets/l18n/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
3 changes: 3 additions & 0 deletions Adamant/Assets/l18n/ru.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
/* Unknown internal error */
"ApiService.InternalError.UnknownError" = "Неизвестная ошибка";

/* ChatList: outgoing message preview format, like 'You: %@' */
"ChatListPage.SentMessageFormat" = "Вы: %@";

/* ChatList: scene title */
"ChatListPage.Title" = "Чаты";

Expand Down
11 changes: 10 additions & 1 deletion Adamant/CoreData/Chatroom+CoreDataClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Adamant/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>0.3.6</string>
<key>CFBundleVersion</key>
<string>22</string>
<string>23</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSCameraUsageDescription</key>
Expand Down
6 changes: 3 additions & 3 deletions Adamant/Services/DataProviders/AdamantChatsProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ extension AdamantChatsProvider {
func getChatroomsController() -> NSFetchedResultsController<Chatroom> {
let request: NSFetchRequest<Chatroom> = 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)

Expand All @@ -394,7 +394,7 @@ extension AdamantChatsProvider {
let request: NSFetchRequest<ChatTransaction> = 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
Expand All @@ -404,7 +404,7 @@ extension AdamantChatsProvider {
let request = NSFetchRequest<ChatTransaction>(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)

Expand Down
9 changes: 6 additions & 3 deletions Adamant/Services/DataProviders/AdamantTransfersProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,17 @@ extension AdamantTransfersProvider {
// MARK: Controllers
func transfersController() -> NSFetchedResultsController<TransferTransaction> {
let request = NSFetchRequest<TransferTransaction>(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
}

func transfersController(for account: CoreDataAccount) -> NSFetchedResultsController<TransferTransaction> {
let request = NSFetchRequest<TransferTransaction>(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)
Expand All @@ -197,7 +199,8 @@ extension AdamantTransfersProvider {
func unreadTransfersController() -> NSFetchedResultsController<TransferTransaction> {
let request = NSFetchRequest<TransferTransaction>(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
Expand Down
24 changes: 21 additions & 3 deletions Adamant/Stories/Chats/ChatListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 21de2e2

Please sign in to comment.