mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-29 17:29:20 +00:00
Fix Scrolling Reply Bubble Chat
This commit is contained in:
parent
5e6e302fd1
commit
1730a50a56
5 changed files with 95 additions and 48 deletions
|
|
@ -107,6 +107,31 @@ class ChatConversationTableViewModel: ControlsViewModel {
|
|||
let chatRoomEvents = chatRoom?.getHistoryRangeEvents(begin: index, end: index+1)
|
||||
return chatRoomEvents?.first?.chatMessage
|
||||
}
|
||||
|
||||
func getIndexMessage(message: ChatMessage) -> Int {
|
||||
var index = -1
|
||||
if (chatRoom == nil) {
|
||||
return index
|
||||
}
|
||||
|
||||
var indexRange = 0
|
||||
let msgId = message.messageId
|
||||
|
||||
while index == -1 {
|
||||
let chatRoomEvents = chatRoom?.getHistoryRangeEvents(begin: indexRange, end: indexRange+20)
|
||||
if chatRoomEvents?.count == 0 {
|
||||
index = -2
|
||||
}
|
||||
chatRoomEvents?.reversed().forEach({ event in
|
||||
let chat = event.chatMessage
|
||||
if (chat != nil && msgId == chat?.messageId) {
|
||||
index = indexRange ;
|
||||
}
|
||||
indexRange += 1
|
||||
})
|
||||
}
|
||||
return index
|
||||
}
|
||||
|
||||
func getNBMessages() -> Int {
|
||||
if (chatRoom == nil) {
|
||||
|
|
|
|||
|
|
@ -86,7 +86,19 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour
|
|||
override func viewDidAppear(_ animated: Bool) {
|
||||
self.collectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .top, animated: false)
|
||||
}
|
||||
|
||||
|
||||
func scrollToMessage(message: ChatMessage){
|
||||
let messageIndex = ChatConversationTableViewModel.sharedModel.getIndexMessage(message: message)
|
||||
print("ChatConversationTableViewSwift collectionview \(messageIndex)")
|
||||
|
||||
collectionView.reloadData()
|
||||
collectionView.layoutIfNeeded()
|
||||
collectionView.scrollToItem(at: IndexPath(row: messageIndex, section: 0), at: .bottom, animated: false)
|
||||
//Scroll twice because collection view doesn't have time to calculate cell size
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
|
||||
self.collectionView.scrollToItem(at: IndexPath(row: messageIndex, section: 0), at: .bottom, animated: false)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UICollectionViewDataSource -
|
||||
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||
|
|
@ -94,9 +106,11 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour
|
|||
|
||||
if let message = ChatConversationTableViewModel.sharedModel.getMessage(index: indexPath.row){
|
||||
cell.configure(message: message, isBasic: basic)
|
||||
if !cell.replyContent.isHidden {
|
||||
if (!cell.replyContent.isHidden && message.replyMessage != nil){
|
||||
cell.replyContent.onClick {
|
||||
print("ChatConversationTableViewSwift collectionview cellForItemAt click \(linphone_chat_message_get_reply_message(message.getCobject))")
|
||||
print("\n\nChatConversationTableViewSwift collectionview new")
|
||||
print("ChatConversationTableViewSwift collectionview \(indexPath.row+1)")
|
||||
self.scrollToMessage(message: message.replyMessage!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ class ChatConversationViewSwift: BackActionsNavigationView, PHPickerViewControll
|
|||
ChatConversationViewModel.sharedModel.createChatConversation()
|
||||
|
||||
topBar.backgroundColor = VoipTheme.voipToolbarBackgroundColor.get()
|
||||
//self.contentView.addSubview(tableController.tableView)
|
||||
self.contentView.addSubview(tableController.tableView)
|
||||
self.contentView.addSubview(tableControllerSwift.view)
|
||||
|
||||
// Setup Autolayout constraints
|
||||
|
|
@ -237,7 +237,7 @@ class ChatConversationViewSwift: BackActionsNavigationView, PHPickerViewControll
|
|||
tableControllerSwift.view.topAnchor.constraint(equalTo: self.contentView.topAnchor, constant: 0).isActive = true
|
||||
tableControllerSwift.view.rightAnchor.constraint(equalTo: self.contentView.rightAnchor, constant: 0).isActive = true
|
||||
|
||||
//tableController.chatRoom = ChatConversationViewModel.sharedModel.chatRoom?.getCobject
|
||||
tableController.chatRoom = ChatConversationViewModel.sharedModel.chatRoom?.getCobject
|
||||
ChatConversationTableViewModel.sharedModel.chatRoom = ChatConversationViewModel.sharedModel.chatRoom
|
||||
|
||||
refreshControl.addTarget(self, action: #selector(refreshData), for: .valueChanged)
|
||||
|
|
|
|||
|
|
@ -456,50 +456,57 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI
|
|||
contentViewBubble.minWidth(216).done()
|
||||
forwardView.isHidden = true
|
||||
replyView.isHidden = false
|
||||
replyColorContent.backgroundColor = message.replyMessage!.isOutgoing ? UIColor("A") : UIColor("D")
|
||||
|
||||
let isIcal = ICSBubbleView.isConferenceInvitationMessage(cmessage: (message.replyMessage?.getCobject)!)
|
||||
let content : String? = (isIcal ? ICSBubbleView.getSubjectFromContent(cmessage: (message.replyMessage?.getCobject)!) : ChatMessage.getSwiftObject(cObject: (message.replyMessage?.getCobject)!).utf8Text)
|
||||
let contentList = linphone_chat_message_get_contents(message.replyMessage?.getCobject)
|
||||
let fromAddress = FastAddressBook.displayName(for: message.replyMessage!.fromAddress?.getCobject)
|
||||
replyLabelTextView.text = String.localizedStringWithFormat(NSLocalizedString("%@", comment: ""), fromAddress!)
|
||||
|
||||
replyContentTextView.text = content
|
||||
replyContentForMeetingTextView.text = content
|
||||
if(isIcal){
|
||||
replyMeetingSchedule.image = UIImage(named: "voip_meeting_schedule")
|
||||
replyMeetingSchedule.isHidden = false
|
||||
replyContentForMeetingTextView.isHidden = false
|
||||
replyContentForMeetingSpacing.isHidden = false
|
||||
replyContentTextView.isHidden = true
|
||||
mediaSelectorReply.isHidden = true
|
||||
replyContentTextSpacing.isHidden = true
|
||||
}else{
|
||||
|
||||
if(message.replyMessage != nil){
|
||||
replyColorContent.backgroundColor = message.replyMessage!.isOutgoing ? UIColor("A") : UIColor("D")
|
||||
|
||||
let isIcal = ICSBubbleView.isConferenceInvitationMessage(cmessage: (message.replyMessage?.getCobject)!)
|
||||
let content : String? = (isIcal ? ICSBubbleView.getSubjectFromContent(cmessage: (message.replyMessage?.getCobject)!) : ChatMessage.getSwiftObject(cObject: (message.replyMessage?.getCobject)!).utf8Text)
|
||||
let contentList = linphone_chat_message_get_contents(message.replyMessage?.getCobject)
|
||||
let fromAddress = FastAddressBook.displayName(for: message.replyMessage!.fromAddress?.getCobject)
|
||||
replyLabelTextView.text = String.localizedStringWithFormat(NSLocalizedString("%@", comment: ""), fromAddress!)
|
||||
|
||||
replyContentTextView.text = content
|
||||
replyContentForMeetingTextView.text = content
|
||||
if(isIcal){
|
||||
replyMeetingSchedule.image = UIImage(named: "voip_meeting_schedule")
|
||||
replyMeetingSchedule.isHidden = false
|
||||
replyContentForMeetingTextView.isHidden = false
|
||||
replyContentForMeetingSpacing.isHidden = false
|
||||
replyContentTextView.isHidden = true
|
||||
mediaSelectorReply.isHidden = true
|
||||
replyContentTextSpacing.isHidden = true
|
||||
}else{
|
||||
|
||||
if(bctbx_list_size(contentList) > 1 || content == ""){
|
||||
mediaSelectorReply.isHidden = false
|
||||
replyContentTextSpacing.isHidden = true
|
||||
ChatMessage.getSwiftObject(cObject: (message.replyMessage?.getCobject)!).contents.forEach({ content in
|
||||
if(content.isFile){
|
||||
let indexPath = IndexPath(row: replyCollectionView.count, section: 0)
|
||||
replyURLCollection.append(URL(string: content.filePath)!)
|
||||
replyCollectionView.append(getImageFrom(content.getCobject, filePath: content.filePath, forReplyBubble: true)!)
|
||||
collectionViewReply.insertItems(at: [indexPath])
|
||||
}else if(content.isText){
|
||||
replyContentTextSpacing.isHidden = false
|
||||
}
|
||||
})
|
||||
|
||||
}else{
|
||||
mediaSelectorReply.isHidden = true
|
||||
}
|
||||
replyMeetingSchedule.isHidden = true
|
||||
replyContentForMeetingTextView.isHidden = true
|
||||
replyContentForMeetingSpacing.isHidden = true
|
||||
replyContentTextView.isHidden = false
|
||||
|
||||
}
|
||||
replyContentTextView.text = message.replyMessage!.contents.first?.utf8Text
|
||||
if(bctbx_list_size(contentList) > 1 || content == ""){
|
||||
mediaSelectorReply.isHidden = false
|
||||
replyContentTextSpacing.isHidden = true
|
||||
ChatMessage.getSwiftObject(cObject: (message.replyMessage?.getCobject)!).contents.forEach({ content in
|
||||
if(content.isFile){
|
||||
let indexPath = IndexPath(row: replyCollectionView.count, section: 0)
|
||||
replyURLCollection.append(URL(string: content.filePath)!)
|
||||
replyCollectionView.append(getImageFrom(content.getCobject, filePath: content.filePath, forReplyBubble: true)!)
|
||||
collectionViewReply.insertItems(at: [indexPath])
|
||||
}else if(content.isText){
|
||||
replyContentTextSpacing.isHidden = false
|
||||
}
|
||||
})
|
||||
|
||||
}else{
|
||||
mediaSelectorReply.isHidden = true
|
||||
}
|
||||
replyMeetingSchedule.isHidden = true
|
||||
replyContentForMeetingTextView.isHidden = true
|
||||
replyContentForMeetingSpacing.isHidden = true
|
||||
replyContentTextView.isHidden = false
|
||||
|
||||
}
|
||||
replyContentTextView.text = message.replyMessage!.contents.first?.utf8Text
|
||||
}else{
|
||||
replyLabelTextView.isHidden = true
|
||||
replyContentTextSpacing.isHidden = false
|
||||
replyContentTextView.text = VoipTexts.bubble_chat_reply_message_does_not_exist + " "
|
||||
}
|
||||
}else{
|
||||
NSLayoutConstraint.activate(preContentViewBubbleConstraintsHidden)
|
||||
NSLayoutConstraint.deactivate(forwardConstraints)
|
||||
|
|
|
|||
|
|
@ -168,6 +168,7 @@ import UIKit
|
|||
@objc static let operation_in_progress_wait = NSLocalizedString("Operation in progress, please wait",comment:"")
|
||||
@objc static let bubble_chat_transferred = NSLocalizedString("Transferred",comment:"")
|
||||
@objc static let bubble_chat_reply = NSLocalizedString("Answer",comment:"")
|
||||
@objc static let bubble_chat_reply_message_does_not_exist = NSLocalizedString("Original message does not exist anymore.",comment:"")
|
||||
|
||||
// FROM ANDROID END
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue