|
@@ -16,6 +16,7 @@ class ChatViewController: UITableViewController {
|
|
|
|
|
|
var msgChangedObserver: NSObjectProtocol?
|
|
|
var incomingMsgObserver: NSObjectProtocol?
|
|
|
+ var chatModifiedObserver: NSObjectProtocol?
|
|
|
var ephemeralTimerModifiedObserver: NSObjectProtocol?
|
|
|
// isDismissing indicates whether the ViewController is/was about to dismissed.
|
|
|
// The VC can be dismissed by pressing back '<' or by a swipe-to-dismiss gesture.
|
|
@@ -220,11 +221,12 @@ class ChatViewController: UITableViewController {
|
|
|
}
|
|
|
)
|
|
|
|
|
|
+ let dcChat = dcContext.getChat(chatId: chatId)
|
|
|
let config = ContextMenuProvider()
|
|
|
- if #available(iOS 13.0, *), !disableWriting {
|
|
|
+ if #available(iOS 13.0, *), dcChat.canSend {
|
|
|
let mainContextMenu = ContextMenuProvider.ContextMenuItem(submenuitems: [replyItem, forwardItem, infoItem, copyItem, deleteItem])
|
|
|
config.setMenu([mainContextMenu, selectMoreItem])
|
|
|
- } else if !disableWriting {
|
|
|
+ } else if dcChat.canSend {
|
|
|
config.setMenu([forwardItem, infoItem, copyItem, deleteItem, selectMoreItem])
|
|
|
} else {
|
|
|
config.setMenu([forwardItem, infoItem, copyItem, deleteItem])
|
|
@@ -236,7 +238,6 @@ class ChatViewController: UITableViewController {
|
|
|
/// The `BasicAudioController` controll the AVAudioPlayer state (play, pause, stop) and update audio cell UI accordingly.
|
|
|
private lazy var audioController = AudioController(dcContext: dcContext, chatId: chatId, delegate: self)
|
|
|
|
|
|
- private var disableWriting: Bool
|
|
|
var showCustomNavBar = true
|
|
|
var highlightedMsg: Int?
|
|
|
|
|
@@ -253,10 +254,8 @@ class ChatViewController: UITableViewController {
|
|
|
}()
|
|
|
|
|
|
init(dcContext: DcContext, chatId: Int, highlightedMsg: Int? = nil) {
|
|
|
- let dcChat = dcContext.getChat(chatId: chatId)
|
|
|
self.dcContext = dcContext
|
|
|
self.chatId = chatId
|
|
|
- self.disableWriting = !dcChat.canSend
|
|
|
self.highlightedMsg = highlightedMsg
|
|
|
super.init(nibName: nil, bundle: nil)
|
|
|
hidesBottomBarWhenPushed = true
|
|
@@ -267,8 +266,7 @@ class ChatViewController: UITableViewController {
|
|
|
}
|
|
|
|
|
|
override func loadView() {
|
|
|
- let inputBar = self.disableWriting && !dcContext.getChat(chatId: chatId).isContactRequest ? nil : messageInputBar
|
|
|
- self.tableView = ChatTableView(messageInputBar: inputBar)
|
|
|
+ self.tableView = ChatTableView(messageInputBar: messageInputBar)
|
|
|
self.tableView.delegate = self
|
|
|
self.tableView.dataSource = self
|
|
|
self.view = self.tableView
|
|
@@ -296,10 +294,13 @@ class ChatViewController: UITableViewController {
|
|
|
}
|
|
|
configureEmptyStateView()
|
|
|
|
|
|
- if !disableWriting {
|
|
|
+ let dcChat = dcContext.getChat(chatId: chatId)
|
|
|
+ if dcChat.canSend {
|
|
|
configureUIForWriting()
|
|
|
- } else if dcContext.getChat(chatId: chatId).isContactRequest {
|
|
|
+ } else if dcChat.isContactRequest {
|
|
|
configureContactRequestBar()
|
|
|
+ } else {
|
|
|
+ messageInputBar.isHidden = true
|
|
|
}
|
|
|
loadMessages()
|
|
|
}
|
|
@@ -473,7 +474,8 @@ class ChatViewController: UITableViewController {
|
|
|
) { [weak self] notification in
|
|
|
guard let self = self else { return }
|
|
|
if let ui = notification.userInfo {
|
|
|
- if self.disableWriting {
|
|
|
+ let dcChat = self.dcContext.getChat(chatId: self.chatId)
|
|
|
+ if !dcChat.canSend {
|
|
|
// always refresh, as we can't check currently
|
|
|
self.refreshMessages()
|
|
|
} else if let id = ui["message_id"] as? Int {
|
|
@@ -485,7 +487,7 @@ class ChatViewController: UITableViewController {
|
|
|
}
|
|
|
}
|
|
|
if self.showCustomNavBar {
|
|
|
- self.updateTitle(chat: self.dcContext.getChat(chatId: self.chatId))
|
|
|
+ self.updateTitle(chat: dcChat)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -507,6 +509,26 @@ class ChatViewController: UITableViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ chatModifiedObserver = nc.addObserver(
|
|
|
+ forName: dcNotificationChatModified,
|
|
|
+ object: nil, queue: OperationQueue.main
|
|
|
+ ) { [weak self] notification in
|
|
|
+ guard let self = self else { return }
|
|
|
+ if let ui = notification.userInfo, self.chatId == ui["chat_id"] as? Int {
|
|
|
+ let dcChat = self.dcContext.getChat(chatId: self.chatId)
|
|
|
+ if dcChat.canSend {
|
|
|
+ if self.messageInputBar.isHidden {
|
|
|
+ self.configureUIForWriting()
|
|
|
+ self.messageInputBar.isHidden = false
|
|
|
+ }
|
|
|
+ } else if !dcChat.isContactRequest {
|
|
|
+ if !self.messageInputBar.isHidden {
|
|
|
+ self.messageInputBar.isHidden = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
ephemeralTimerModifiedObserver = nc.addObserver(
|
|
|
forName: dcEphemeralTimerModified,
|
|
|
object: nil, queue: OperationQueue.main
|
|
@@ -534,6 +556,9 @@ class ChatViewController: UITableViewController {
|
|
|
if let incomingMsgObserver = self.incomingMsgObserver {
|
|
|
nc.removeObserver(incomingMsgObserver)
|
|
|
}
|
|
|
+ if let chatModifiedObserver = self.chatModifiedObserver {
|
|
|
+ nc.removeObserver(chatModifiedObserver)
|
|
|
+ }
|
|
|
if let ephemeralTimerModifiedObserver = self.ephemeralTimerModifiedObserver {
|
|
|
nc.removeObserver(ephemeralTimerModifiedObserver)
|
|
|
}
|
|
@@ -734,7 +759,8 @@ class ChatViewController: UITableViewController {
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
|
|
let message = dcContext.getMessage(id: messageIds[indexPath.row])
|
|
|
- if disableWriting || message.isInfo || message.type == DC_MSG_VIDEOCHAT_INVITATION {
|
|
|
+ let dcChat = dcContext.getChat(chatId: chatId)
|
|
|
+ if !dcChat.canSend || message.isInfo || message.type == DC_MSG_VIDEOCHAT_INVITATION {
|
|
|
return nil
|
|
|
}
|
|
|
|