Merge branch 'feature/MALINKA-774/Incorrect_messages_order' into 'develop'
Resolve MALINKA-774 "Feature//incorrect messages order" See merge request raspberry/mobile/ios!239
This commit is contained in:
+7
-53
@@ -37,6 +37,10 @@ var lastMsgs: [String: String] = [:]
|
||||
|
||||
final class CryptoChatControllerChat: MessagesViewController {
|
||||
|
||||
private enum Constants {
|
||||
static let bottomInset: CGFloat = 38
|
||||
}
|
||||
|
||||
typealias HistoryService = CryptoChat.Service.MsgsHistory
|
||||
|
||||
let username: String
|
||||
@@ -86,7 +90,6 @@ final class CryptoChatControllerChat: MessagesViewController {
|
||||
|
||||
private lazy var buttonsView: CryptoChatButtonsArrayView = {
|
||||
let buttonsView = CryptoChatButtonsArrayView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 56))
|
||||
// buttonsView.frameOrigin = CGPoint(x: 0, y: 0)
|
||||
buttonsView.qrPressed = { [weak self] in self?.showQrPopup() }
|
||||
buttonsView.transferPressed = { [weak self] in
|
||||
|
||||
@@ -117,8 +120,6 @@ final class CryptoChatControllerChat: MessagesViewController {
|
||||
|
||||
self.messagesCollectionView.register(InfoHeaderCollectionReusableView.self,
|
||||
forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader)
|
||||
|
||||
// view.addSubview(createButton)
|
||||
self.view.addSubview(self.buttonsView)
|
||||
|
||||
Network.accounts.getChatPublicKey(username, completion: { [weak self] in self?.publicKey = $0.value })
|
||||
@@ -144,7 +145,7 @@ final class CryptoChatControllerChat: MessagesViewController {
|
||||
DispatchQueue.main.async {
|
||||
self.loadedMsgsCount = min(self.messages.count, self.loadedMsgsCount + 100)
|
||||
self.messagesCollectionView.reloadData()
|
||||
self.messagesCollectionView.scrollToLastItem()
|
||||
self.messagesCollectionView.scrollFullDown()
|
||||
|
||||
historyService.markChatAsRead(username: self.username)
|
||||
}
|
||||
@@ -155,17 +156,12 @@ final class CryptoChatControllerChat: MessagesViewController {
|
||||
|
||||
navigationItem.title = self.username
|
||||
navigationItem.leftBarButtonItem = .pop(self)
|
||||
// navigationItem.rightBarButtonItem = .info {
|
||||
// Alert.hint(text: L10n.CryptoChat.Chat.infoHelpText)
|
||||
// }
|
||||
|
||||
self.messagesCollectionView.messagesDataSource = self
|
||||
self.messagesCollectionView.messagesLayoutDelegate = self
|
||||
self.messagesCollectionView.messagesDisplayDelegate = self
|
||||
|
||||
// let tap = UITapGestureRecognizer(target: self, action: #selector(CryptoChatControllerChat.dismissKeyboard))
|
||||
// messagesCollectionView.addGestureRecognizer(tap)
|
||||
self.messagesCollectionView.keyboardDismissMode = .onDrag
|
||||
self.additionalBottomInset = Constants.bottomInset
|
||||
|
||||
self.navigationController?.navigationBar.barTintColor = .white
|
||||
self.messagesCollectionView.backgroundColor = .white
|
||||
@@ -173,7 +169,7 @@ final class CryptoChatControllerChat: MessagesViewController {
|
||||
self.configureMessageCollectionView()
|
||||
self.configureMessageInputBar()
|
||||
|
||||
self.messagesCollectionView.scrollToLastItem()
|
||||
self.messagesCollectionView.scrollFullDown()
|
||||
|
||||
self.messagesCollectionView.addSubview(refreshControl)
|
||||
self.refreshControl.addTarget(self, action: #selector(loadMoreMessages), for: .valueChanged)
|
||||
@@ -294,49 +290,12 @@ final class CryptoChatControllerChat: MessagesViewController {
|
||||
self.messageInputBar.inputTextView.placeholderTextColor = Asset.textPebble.color
|
||||
self.messageInputBar.inputTextView.textColor = Asset.textGranite.color
|
||||
self.messageInputBar.inputTextView.font = Font.font(style: .regular, size: 16)
|
||||
// messageInputBar.inputTextView.layer.cornerRadius = 12.0
|
||||
// messageInputBar.inputTextView.layer.borderWidth = 1.0
|
||||
// messageInputBar.inputTextView.layer.borderColor = Asset.lightGray.color.cgColor
|
||||
// messageInputBar.separatorLine.isHidden = true
|
||||
self.messageInputBar.separatorLine.backgroundColor = Asset.marble.color
|
||||
self.messageInputBar.textViewPadding = UIEdgeInsets(top: 4, left: 0, bottom: 4, right: 0)
|
||||
self.messageInputBar.maxTextViewHeight = 140
|
||||
// messageInputBar.inputTextView.textContainerInset = UIEdgeInsets(top: 5, left: 12, bottom: 4, right: 32)
|
||||
// messageInputBar.inputTextView.placeholderLabelInsets = UIEdgeInsets(top: 5, left: 16, bottom: 4, right: 12)
|
||||
self.messageInputBar.inputTextView.placeholder = L10n.CryptoChat.Chat.emptyInputPlaceholder
|
||||
self.messageInputBar.backgroundView.backgroundColor = .white
|
||||
self.messageInputBar.inputTextView.isImagePasteEnabled = false
|
||||
|
||||
return ()
|
||||
|
||||
let items = [
|
||||
InputBarButtonItem()
|
||||
.configure {
|
||||
$0.spacing = .fixed(20)
|
||||
$0.image = Asset.chatQr.image
|
||||
$0.setSize(CGSize(width: 32, height: 32), animated: false)
|
||||
}.onSelected { [weak self] _ in
|
||||
self?.showQrPopup()
|
||||
}
|
||||
// .onDeselected {
|
||||
// $0.tintColor = UIColor.lightGray
|
||||
// }
|
||||
,
|
||||
self.messageInputBar
|
||||
.sendButton
|
||||
.configure {
|
||||
$0.spacing = .fixed(0)
|
||||
$0.image = Asset.chatSend.image
|
||||
$0.title = nil
|
||||
$0.setSize(CGSize(width: 32, height: 32), animated: false)
|
||||
}
|
||||
]
|
||||
self.messageInputBar.middleContentViewPadding.right = -46
|
||||
self.messageInputBar.setRightStackViewWidthConstant(to: 82 , animated: true)
|
||||
self.messageInputBar.setStackViewItems(items, forStack: .right, animated: true)
|
||||
self.messageInputBar.invalidateIntrinsicContentSize()
|
||||
self.reloadInputViews()
|
||||
self.messageInputBar.layoutIfNeeded()
|
||||
}
|
||||
|
||||
private func showQrPopup() {
|
||||
@@ -422,8 +381,6 @@ extension CryptoChatControllerChat: InputBarAccessoryViewDelegate {
|
||||
Network.Service.Blockchain.execute(contract: .chat, action: .chatSendDm, data: msg, privateKeys: [$0]) {
|
||||
switch $0 {
|
||||
case let .success(trxId):
|
||||
// UserDefaults.standard.setValue(<#T##value: Any?##Any?#>, forKey: "chatsReadCount")
|
||||
// AccountHistory().current?.fetchUntil(trxId: trxId)
|
||||
self.historyService.setMsgSynced(ephemPublicKey: msg.ephemPublicKey)
|
||||
case let .failure(error):
|
||||
self.dismissKeyboard()
|
||||
@@ -462,7 +419,6 @@ extension CryptoChatControllerChat: InputBarAccessoryViewDelegate {
|
||||
|
||||
self.messageInputBar.sendButton.stopAnimating()
|
||||
self.messageInputBar.inputTextView.placeholder = L10n.CryptoChat.Chat.emptyInputPlaceholder
|
||||
// self.insertMessages(components)
|
||||
self.messagesCollectionView.scrollToLastItem(animated: true)
|
||||
|
||||
self.sendMsgTo(publicKey: receiverPublicKey, msg: msg)
|
||||
@@ -471,11 +427,9 @@ extension CryptoChatControllerChat: InputBarAccessoryViewDelegate {
|
||||
|
||||
Network.accounts.getChatPublicKey(username, completion: { [weak self] in
|
||||
self?.publicKey = $0.value
|
||||
// guard let self = self else { return }
|
||||
self?.messageInputBar.sendButton.stopAnimating()
|
||||
self?.messageInputBar.inputTextView.placeholder = L10n.CryptoChat.Chat.emptyInputPlaceholder
|
||||
|
||||
// self.insertMessages(components)
|
||||
self?.messagesCollectionView.scrollToLastItem(animated: true)
|
||||
|
||||
if let receiverPublicKey = $0.value,
|
||||
|
||||
@@ -221,7 +221,7 @@ extension CryptoChat.Service {
|
||||
&& $0.account == ApplicationEnvironment.shared().current.contract(.chat)
|
||||
&& $0.name == Network.Model.Blockchain.Action.chatSendDm.rawValue
|
||||
&& $0.receiver == self.username
|
||||
&& ($0.blockTime >= lastSyncTimestamp || $0.blockTime <= firstSyncTimestamp)
|
||||
&& $0.blockTime >= lastSyncTimestamp
|
||||
}
|
||||
.sorted(by: \.accountActionId, ascending: true)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// MessagesCollectionView+Extensions.swift
|
||||
// Malinka
|
||||
//
|
||||
// Created by Nut.Tech on 01.02.2023.
|
||||
// Copyright © 2023 NUT.Tech. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import MessageKit
|
||||
|
||||
extension MessagesCollectionView {
|
||||
func scrollFullDown(animated: Bool = true) {
|
||||
DispatchQueue.main.async {
|
||||
self.performBatchUpdates(nil) { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
let contentSize = self.collectionViewLayout.collectionViewContentSize
|
||||
let bottomOffset = CGPoint(x: 0, y: contentSize.height - self.bounds.size.height + self.contentInset.bottom)
|
||||
self.setContentOffset(bottomOffset, animated: animated)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user