Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[trello.com/c/lwOnjxPQ] Sending files indicator 🕝 in the chat list + ✏️ #714

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Adamant/Modules/ChatsList/ChatListFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ struct ChatListFactory {
dialogService: assembler.resolve(DialogService.self)!,
addressBook: assembler.resolve(AddressBookService.self)!,
avatarService: assembler.resolve(AvatarService.self)!,
walletServiceCompose: assembler.resolve(WalletServiceCompose.self)!
walletServiceCompose: assembler.resolve(WalletServiceCompose.self)!,
chatPreservation: assembler.resolve(ChatPreservationProtocol.self)!
)
}

Expand Down
65 changes: 61 additions & 4 deletions Adamant/Modules/ChatsList/ChatListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ final class ChatListViewController: KeyboardObservingViewController {
private let addressBook: AddressBookService
private let avatarService: AvatarService
private let walletServiceCompose: WalletServiceCompose
private let chatPreservation: ChatPreservationProtocol

// MARK: IBOutlet
@IBOutlet weak var tableView: UITableView!
Expand Down Expand Up @@ -142,7 +143,8 @@ final class ChatListViewController: KeyboardObservingViewController {
dialogService: DialogService,
addressBook: AddressBookService,
avatarService: AvatarService,
walletServiceCompose: WalletServiceCompose
walletServiceCompose: WalletServiceCompose,
chatPreservation: ChatPreservationProtocol
) {
self.accountService = accountService
self.chatsProvider = chatsProvider
Expand All @@ -153,6 +155,7 @@ final class ChatListViewController: KeyboardObservingViewController {
self.addressBook = addressBook
self.avatarService = avatarService
self.walletServiceCompose = walletServiceCompose
self.chatPreservation = chatPreservation

super.init(nibName: "ChatListViewController", bundle: nil)
}
Expand Down Expand Up @@ -193,7 +196,10 @@ final class ChatListViewController: KeyboardObservingViewController {
tableView.deselectRow(at: indexPath, animated: animated)
}
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
tableView.reloadData()
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

Expand Down Expand Up @@ -681,10 +687,15 @@ extension ChatListViewController {

cell.accountLabel.text = chatroom.getName(addressBookService: addressBook)
cell.hasUnreadMessages = chatroom.hasUnreadMessages

if let lastTransaction = chatroom.lastTransaction {
if let address = chatroom.partner?.address,
let preservedMessage = shortDescription(for: address) {
cell.hasUnreadMessages = chatroom.hasUnreadMessages
cell.lastMessageLabel.attributedText = preservedMessage
cell.isClockVisible = false
} else if let lastTransaction = chatroom.lastTransaction {
cell.hasUnreadMessages = lastTransaction.isUnread
cell.lastMessageLabel.attributedText = shortDescription(for: lastTransaction)
cell.isClockVisible = lastTransaction.statusEnum == .pending
} else {
cell.lastMessageLabel.text = nil
}
Expand Down Expand Up @@ -1034,7 +1045,53 @@ extension ChatListViewController {
return nil
}
}
private func shortDescription(for address: String) -> NSAttributedString? {
var descriptionParts: [NSAttributedString] = []

if chatPreservation.getReplyMessage(address: address, thenRemoveIt: false) != nil {
let replyImageAttachment = NSTextAttachment()
replyImageAttachment.image = UIImage(systemName: "arrowshape.turn.up.left")?.withTintColor(.adamant.primary)
replyImageAttachment.bounds = CGRect(x: .zero, y: -3, width: 23, height: 20)

descriptionParts.append(NSAttributedString(attachment: replyImageAttachment))
}
if let files = chatPreservation.getPreservedFiles(for: address, thenRemoveIt: false), !files.isEmpty {
let mediaCount = files.filter { $0.type.isMedia }.count
let otherCount = files.filter { !$0.type.isMedia }.count

let fileParts = [
mediaCount > 0 ? "📸" + (mediaCount >= 2 ? "\(mediaCount)" : "") : nil,
otherCount > 0 ? "📄" + (otherCount >= 2 ? "\(otherCount)" : "") : nil
].compactMap { $0 }

if !fileParts.isEmpty {
let parsedFileParts = fileParts
.map { markdownParser.parse($0).resolveLinkColor() }
.reduce(NSMutableAttributedString()) { result, part in
if !result.string.isEmpty { result.append(NSAttributedString(string: " ")) }
result.append(part)
return result
}
descriptionParts.append(parsedFileParts)
}
}

if let preservedMessage = chatPreservation.getPreservedMessageFor(address: address, thenRemoveIt: false) {
let processedMessage = MessageProcessHelper.process(preservedMessage)
descriptionParts.append(NSAttributedString(string: processedMessage))
}
let hasTextContent = descriptionParts.contains { !$0.string.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }

guard hasTextContent else { return nil }

let result = NSMutableAttributedString(string: "✏️: ")
for (index, part) in descriptionParts.enumerated() {
if index > 0 { result.append(NSAttributedString(string: " ")) }
result.append(part)
}

return result
}
private func getRawReplyPresentation(isOutgoing: Bool, text: String) -> NSMutableAttributedString {
let prefix = isOutgoing
? "\(String.adamant.chatList.sentMessagePrefix)"
Expand Down
27 changes: 25 additions & 2 deletions Adamant/Modules/ChatsList/ChatTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ final class ChatTableViewCell: UITableViewCell {
@IBOutlet weak var lastMessageLabel: UILabel!
@IBOutlet weak var dateLabel: UILabel!
@IBOutlet weak var badgeView: UIView!
@IBOutlet weak var clockView: UIImageView!
@IBOutlet weak var lastMessageLeadingAnchor: NSLayoutConstraint!

override func awakeFromNib() {
Task { @MainActor in badgeView.layer.cornerRadius = badgeView.bounds.height / 2 }
Task { @MainActor in
badgeView.layer.cornerRadius = badgeView.bounds.height / 2
clockView.contentMode = .scaleAspectFit
clockView.image = UIImage.asset(named: "status_pending")
clockView.tintColor = .adamant.secondary
}
}

var avatarImage: UIImage? {
get {
return avatarImageView.image
Expand Down Expand Up @@ -71,4 +77,21 @@ final class ChatTableViewCell: UITableViewCell {
badgeView.backgroundColor = newValue
}
}
var isClockVisible: Bool {
get {
return !clockView.isHidden
}
set {
if newValue {
clockView.isHidden = false
lastMessageLeadingAnchor.constant = 27
} else {
UIView.animate(withDuration: 0.3) {
self.clockView.isHidden = true
self.lastMessageLeadingAnchor.constant = 10
self.layoutIfNeeded()
}
}
}
}
}
24 changes: 15 additions & 9 deletions Adamant/Modules/ChatsList/ChatTableViewCell.xib
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="22155" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="23504" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22131"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23506"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -31,7 +31,7 @@
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="C7l-tD-ej1">
<rect key="frame" x="74" y="34" width="286" height="18"/>
<rect key="frame" x="91" y="34" width="269" height="18"/>
<string key="text">⬅️ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</string>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<nil key="textColor"/>
Expand All @@ -51,17 +51,26 @@
<constraint firstAttribute="height" constant="12" id="eHH-7p-pDT"/>
</constraints>
</view>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Ggk-q3-Bor">
<rect key="frame" x="74" y="37" width="12" height="12"/>
<constraints>
<constraint firstAttribute="width" secondItem="Ggk-q3-Bor" secondAttribute="height" multiplier="1:1" id="6zs-gc-OuG"/>
<constraint firstAttribute="height" constant="12" id="ogC-fN-w7X"/>
</constraints>
</imageView>
</subviews>
<constraints>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="C7l-tD-ej1" secondAttribute="bottom" constant="7" id="0SK-AT-azY"/>
<constraint firstItem="aVv-ww-kYa" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="1fI-md-PMc"/>
<constraint firstItem="SiC-bM-ZsH" firstAttribute="leading" secondItem="aVv-ww-kYa" secondAttribute="trailing" constant="10" id="6my-Hp-uyp"/>
<constraint firstItem="C7l-tD-ej1" firstAttribute="top" secondItem="SiC-bM-ZsH" secondAttribute="bottom" constant="5" id="9ey-Qv-1He"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="vtC-fH-ReF" secondAttribute="trailing" constant="12" id="9qX-Ut-vIf"/>
<constraint firstItem="C7l-tD-ej1" firstAttribute="leading" secondItem="SiC-bM-ZsH" secondAttribute="leading" id="GgP-A8-aEU"/>
<constraint firstItem="Ggk-q3-Bor" firstAttribute="leading" secondItem="aVv-ww-kYa" secondAttribute="trailing" constant="10" id="DS7-s2-oAe"/>
<constraint firstItem="C7l-tD-ej1" firstAttribute="trailing" secondItem="PP8-Tp-mvQ" secondAttribute="trailing" id="cKX-oK-8dF"/>
<constraint firstAttribute="trailing" secondItem="PP8-Tp-mvQ" secondAttribute="trailing" constant="15" id="dX6-xD-7WY"/>
<constraint firstAttribute="bottom" secondItem="PP8-Tp-mvQ" secondAttribute="bottom" constant="6" id="gB7-zA-C3o"/>
<constraint firstItem="Ggk-q3-Bor" firstAttribute="centerY" secondItem="C7l-tD-ej1" secondAttribute="centerY" id="geO-ve-dYL"/>
<constraint firstItem="C7l-tD-ej1" firstAttribute="leading" secondItem="aVv-ww-kYa" secondAttribute="trailing" constant="27" id="kpB-Er-bZi"/>
<constraint firstItem="SiC-bM-ZsH" firstAttribute="centerY" secondItem="vtC-fH-ReF" secondAttribute="centerY" id="ugp-j2-sbR"/>
<constraint firstItem="aVv-ww-kYa" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="14" id="xpk-tG-FaG"/>
<constraint firstItem="SiC-bM-ZsH" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="9" id="zNL-XP-X54"/>
Expand All @@ -74,17 +83,14 @@
<outlet property="accountLabel" destination="SiC-bM-ZsH" id="HPE-pt-X6B"/>
<outlet property="avatarImageView" destination="aVv-ww-kYa" id="LHB-x4-hC2"/>
<outlet property="badgeView" destination="vtC-fH-ReF" id="lGZ-I8-Lv2"/>
<outlet property="clockView" destination="Ggk-q3-Bor" id="nrL-T9-jAA"/>
<outlet property="dateLabel" destination="PP8-Tp-mvQ" id="R6V-ec-1km"/>
<outlet property="lastMessageLabel" destination="C7l-tD-ej1" id="BrB-Hs-i7K"/>
<outlet property="lastMessageLeadingAnchor" destination="kpB-Er-bZi" id="4Hh-EW-xwa"/>
</connections>
<point key="canvasLocation" x="49.5" y="70"/>
</tableViewCell>
</objects>
<designables>
<designable name="aVv-ww-kYa">
<size key="intrinsicContentSize" width="50" height="50"/>
</designable>
</designables>
<resources>
<image name="avatar-chat-placeholder" width="50" height="50"/>
</resources>
Expand Down
4 changes: 2 additions & 2 deletions Adamant/Services/DataProviders/AdamantChatsProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ extension AdamantChatsProvider {
{
transaction.statusEnum = MessageStatus.pending
transaction.partner = context.object(with: partner.objectID) as? BaseAccount

chatroom.lastTransaction = transaction
chatroom.addToTransactions(transaction)

do {
Expand Down Expand Up @@ -1038,7 +1038,7 @@ extension AdamantChatsProvider {
transaction.partner = context.object(with: partner.objectID) as? BaseAccount

chatroom.addToTransactions(transaction)

chatroom.lastTransaction = transaction
do {
try context.save()
return transaction
Expand Down