Implement actions for a thread

This commit is contained in:
ismailgulek
2021-11-25 14:55:44 +03:00
parent 5dc3198d09
commit 09fb1d0c9d
4 changed files with 77 additions and 6 deletions

View File

@@ -22,6 +22,11 @@ class ThreadViewController: RoomViewController {
private(set) var threadId: String!
private var permalink: String? {
guard let threadId = threadId else { return nil }
return MXTools.permalink(toEvent: threadId, inRoom: roomDataSource.roomId)
}
class func instantiate(withThreadId threadId: String,
configuration: RoomDisplayConfiguration) -> ThreadViewController {
let threadVC = ThreadViewController.instantiate(with: configuration)
@@ -44,4 +49,70 @@ class ThreadViewController: RoomViewController {
threadTitleView.mode = .specificThread(threadId: threadId)
}
override func onButtonPressed(_ sender: Any) {
if let sender = sender as? UIBarButtonItem, sender == navigationItem.rightBarButtonItem {
showThreadActions()
return
}
super.onButtonPressed(sender)
}
private func showThreadActions() {
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let viewInRoomAction = UIAlertAction(title: VectorL10n.roomEventActionViewInRoom,
style: .default,
handler: { [weak self] action in
guard let self = self else { return }
self.delegate?.roomViewController(self,
showRoomWithId: self.roomDataSource.roomId,
eventId: self.threadId)
})
alertController.addAction(viewInRoomAction)
let copyLinkAction = UIAlertAction(title: VectorL10n.threadCopyLinkToThread,
style: .default,
handler: { [weak self] action in
guard let self = self else { return }
self.copyPermalink()
})
alertController.addAction(copyLinkAction)
let shareAction = UIAlertAction(title: VectorL10n.roomEventActionShare,
style: .default,
handler: { [weak self] action in
guard let self = self else { return }
self.sharePermalink()
})
alertController.addAction(shareAction)
alertController.addAction(UIAlertAction(title: VectorL10n.cancel,
style: .cancel,
handler: nil))
alertController.popoverPresentationController?.barButtonItem = navigationItem.rightBarButtonItem
self.present(alertController, animated: true, completion: nil)
}
private func copyPermalink() {
guard let permalink = permalink else {
return
}
MXKPasteboardManager.shared.pasteboard.string = permalink
}
private func sharePermalink() {
guard let permalink = permalink else {
return
}
let activityVC = UIActivityViewController(activityItems: [permalink],
applicationActivities: nil)
activityVC.modalTransitionStyle = .coverVertical
activityVC.popoverPresentationController?.barButtonItem = navigationItem.rightBarButtonItem
present(activityVC, animated: true, completion: nil)
}
}