From 99445a04c4936c8c52629012e54d1a7cac8284f1 Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Mon, 11 Sep 2023 15:13:39 +0200 Subject: [PATCH] Show our reaction if any in long press menu + remove it if selected again Fix scrolling for reactionsListTableView --- .../ChatConversationTableViewSwift.swift | 39 +++++++++++------- .../Views/Fragments/SheetViewController.swift | 41 +++++++++++-------- .../Chat/Views/MultilineMessageCell.swift | 14 +++---- 3 files changed, 52 insertions(+), 42 deletions(-) diff --git a/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift b/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift index dc831b8ac..310fdadbe 100644 --- a/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift +++ b/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift @@ -384,20 +384,29 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour cell.myImageView.isHidden = true cell.optionLabel.isHidden = true - cell.myEmojiButton1.layer.cornerRadius = 10 - cell.myEmojiButton1.backgroundColor = VoipTheme.light_grey_color - cell.myEmojiButton2.layer.cornerRadius = 10 - cell.myEmojiButton2.backgroundColor = VoipTheme.light_grey_color - cell.myEmojiButton3.layer.cornerRadius = 10 - cell.myEmojiButton3.backgroundColor = VoipTheme.light_grey_color - cell.myEmojiButton4.layer.cornerRadius = 10 - cell.myEmojiButton4.backgroundColor = VoipTheme.light_grey_color - cell.myEmojiButton5.layer.cornerRadius = 10 - cell.myEmojiButton5.backgroundColor = VoipTheme.light_grey_color + switch message.ownReaction?.body { + case "❤️": + cell.myEmojiButton1.layer.cornerRadius = 10 + cell.myEmojiButton1.backgroundColor = VoipTheme.light_grey_color + case "👍": + cell.myEmojiButton2.layer.cornerRadius = 10 + cell.myEmojiButton2.backgroundColor = VoipTheme.light_grey_color + case "😂": + cell.myEmojiButton3.layer.cornerRadius = 10 + cell.myEmojiButton3.backgroundColor = VoipTheme.light_grey_color + case "😮": + cell.myEmojiButton4.layer.cornerRadius = 10 + cell.myEmojiButton4.backgroundColor = VoipTheme.light_grey_color + case "😢": + cell.myEmojiButton5.layer.cornerRadius = 10 + cell.myEmojiButton5.backgroundColor = VoipTheme.light_grey_color + default: + print("No reaction") + } cell.myEmojiButton1.onClick { do { - let messageReaction = try message.createReaction(utf8Reaction: "❤️") + let messageReaction = try message.ownReaction?.body != "❤️" ? message.createReaction(utf8Reaction: "❤️") : message.createReaction(utf8Reaction: "") messageReaction.send() self.menu!.clearSelection() self.menu?.removeFromSuperview() @@ -407,7 +416,7 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour } cell.myEmojiButton2.onClick { do { - let messageReaction = try message.createReaction(utf8Reaction: "👍") + let messageReaction = try message.ownReaction?.body != "👍" ? message.createReaction(utf8Reaction: "👍") : message.createReaction(utf8Reaction: "") messageReaction.send() self.menu!.clearSelection() self.menu?.removeFromSuperview() @@ -417,7 +426,7 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour } cell.myEmojiButton3.onClick { do { - let messageReaction = try message.createReaction(utf8Reaction: "😂") + let messageReaction = try message.ownReaction?.body != "😂" ? message.createReaction(utf8Reaction: "😂") : message.createReaction(utf8Reaction: "") messageReaction.send() self.menu!.clearSelection() self.menu?.removeFromSuperview() @@ -427,7 +436,7 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour } cell.myEmojiButton4.onClick { do { - let messageReaction = try message.createReaction(utf8Reaction: "😮") + let messageReaction = try message.ownReaction?.body != "😮" ? message.createReaction(utf8Reaction: "😮") : message.createReaction(utf8Reaction: "") messageReaction.send() self.menu!.clearSelection() self.menu?.removeFromSuperview() @@ -437,7 +446,7 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour } cell.myEmojiButton5.onClick { do { - let messageReaction = try message.createReaction(utf8Reaction: "😢") + let messageReaction = try message.ownReaction?.body != "😢" ? message.createReaction(utf8Reaction: "😢") : message.createReaction(utf8Reaction: "") messageReaction.send() self.menu!.clearSelection() self.menu?.removeFromSuperview() diff --git a/Classes/Swift/Chat/Views/Fragments/SheetViewController.swift b/Classes/Swift/Chat/Views/Fragments/SheetViewController.swift index d2a1c28e7..40bac7a1c 100644 --- a/Classes/Swift/Chat/Views/Fragments/SheetViewController.swift +++ b/Classes/Swift/Chat/Views/Fragments/SheetViewController.swift @@ -112,23 +112,29 @@ final class SheetViewController: UIViewController { func setHeaderInActiveColor(color: UIColor){ colorHeaderInActive = color } - - func setCurrentPosition(position: Int){ - currentPosition = position - let path = IndexPath(item: currentPosition, section: 0) - - DispatchQueue.main.async { - if self.tabStyle == .flexible { - self.collectionHeader.scrollToItem(at: path, at: .centeredHorizontally, animated: true) - } - - self.collectionHeader.reloadData() - } - - DispatchQueue.main.async { - self.collectionPage.scrollToItem(at: path, at: .centeredHorizontally, animated: true) - } - } + + func setCurrentPosition(position: Int){ + currentPosition = position + let path = IndexPath(item: currentPosition, section: 0) + + DispatchQueue.main.async { + if self.tabStyle == .flexible { + self.collectionHeader.scrollToItem(at: path, at: .centeredHorizontally, animated: true) + } + + self.collectionHeader.reloadData() + } + + DispatchQueue.main.async { + self.collectionPage.isPagingEnabled = false + self.collectionPage.scrollToItem( + at: path, + at: .centeredHorizontally, + animated: true + ) + self.collectionPage.isPagingEnabled = true + } + } func setStyle(style: SlidingTabStyle){ tabStyle = style @@ -337,7 +343,6 @@ class SimpleItemViewController: UIViewController, UITableViewDataSource { // ParticipantsList view.addSubview(reactionsListTableView) - //reactionsListTableView.matchParentDimmensions().done() reactionsListTableView.alignParentTop(withMargin: 10).alignParentBottom().alignParentLeft().alignParentRight().done() reactionsListTableView.dataSource = self reactionsListTableView.register(ReactionCell.self, forCellReuseIdentifier: "ReactionCell") diff --git a/Classes/Swift/Chat/Views/MultilineMessageCell.swift b/Classes/Swift/Chat/Views/MultilineMessageCell.swift index 080c4fdf8..1e48f06df 100644 --- a/Classes/Swift/Chat/Views/MultilineMessageCell.swift +++ b/Classes/Swift/Chat/Views/MultilineMessageCell.swift @@ -249,11 +249,7 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource, bubble.trailingAnchor.constraint(equalTo: contentBubble.trailingAnchor).isActive = true bubble.layer.cornerRadius = 10.0 - - - - - contentBubble.addSubview(bubbleReaction) + contentView.addSubview(bubbleReaction) bubbleReaction.translatesAutoresizingMaskIntoConstraints = false bubbleReaction.topAnchor.constraint(equalTo: bubble.bottomAnchor, constant: -10).isActive = true bubbleReaction.layer.cornerRadius = 8.0 @@ -1502,12 +1498,9 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource, stackViewReactionsItem1.isHidden = false } } - + let tap = UITapGestureRecognizer(target: self, action: #selector(self.showMyViewControllerInACustomizedSheet(_:))) bubbleReaction.addGestureRecognizer(tap) - - - } }else{ contentBubble.isHidden = true @@ -1672,6 +1665,9 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource, onNewMessageReaction: { (message: ChatMessage, messageReaction: ChatMessageReaction) -> Void in ChatConversationTableViewModel.sharedModel.reloadCollectionViewCell() }, + onReactionRemoved: { (message: ChatMessage, address: Address) -> Void in + ChatConversationTableViewModel.sharedModel.reloadCollectionViewCell() + }, onFileTransferProgressIndication: { (message: ChatMessage, content: Content, offset: Int, total: Int) -> Void in self.file_transfer_progress_indication_recv(message: message, content: content, offset: offset, total: total) },