This repository has been archived by the owner on Jun 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2308 from RocketChat/fix/message_draft
[FIX] Reintroduce message drafting
- Loading branch information
Showing
6 changed files
with
125 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
Rocket.Chat/Controllers/Chat/MessageViewControllerEmptyState.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// MessageViewControllerEmptyState.swift | ||
// Rocket.Chat | ||
// | ||
// Created by Matheus Cardoso on 11/12/18. | ||
// Copyright © 2018 Rocket.Chat. All rights reserved. | ||
// | ||
|
||
extension MessagesViewController { | ||
func updateEmptyState() { | ||
if subscription == nil { | ||
title = "" | ||
composerView.isHidden = true | ||
|
||
chatTitleView?.removeFromSuperview() | ||
emptyStateImageView?.removeFromSuperview() | ||
|
||
guard let theme = view.theme else { return } | ||
let themeName = ThemeManager.themes.first { $0.theme == theme }?.title | ||
|
||
let imageView = UIImageView(image: UIImage(named: "Empty State \(themeName ?? "light")")) | ||
imageView.contentMode = .scaleAspectFill | ||
imageView.clipsToBounds = true | ||
view.addSubview(imageView) | ||
|
||
emptyStateImageView = imageView | ||
|
||
updateEmptyStateFrame() | ||
} else { | ||
emptyStateImageView?.removeFromSuperview() | ||
} | ||
} | ||
|
||
func updateEmptyStateFrame() { | ||
emptyStateImageView?.frame = view.bounds | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Rocket.Chat/Controllers/Chat/MessageViewControllerSearching.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// MessageViewControllerSearching.swift | ||
// Rocket.Chat | ||
// | ||
// Created by Matheus Cardoso on 11/12/18. | ||
// Copyright © 2018 Rocket.Chat. All rights reserved. | ||
// | ||
|
||
extension MessagesViewController { | ||
func updateSearchMessagesButton() { | ||
if subscription != nil { | ||
navigationItem.rightBarButtonItem = UIBarButtonItem( | ||
barButtonSystemItem: .search, | ||
target: self, | ||
action: #selector(showSearchMessages) | ||
) | ||
} else { | ||
navigationItem.rightBarButtonItem = nil | ||
} | ||
} | ||
|
||
@objc func showSearchMessages() { | ||
guard | ||
let controller = storyboard?.instantiateViewController(withIdentifier: "MessagesList"), | ||
let messageList = controller as? MessagesListViewController | ||
else { | ||
return | ||
} | ||
|
||
messageList.data.subscription = subscription | ||
messageList.data.isSearchingMessages = true | ||
let searchMessagesNav = BaseNavigationController(rootViewController: messageList) | ||
|
||
present(searchMessagesNav, animated: true, completion: nil) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Rocket.Chat/Controllers/Chat/MessagesViewControllerDrafting.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// MessagesViewControllerDrafting.swift | ||
// Rocket.Chat | ||
// | ||
// Created by Matheus Cardoso on 11/12/18. | ||
// Copyright © 2018 Rocket.Chat. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension MessagesViewController { | ||
func startDraftMessage() { | ||
NotificationCenter.default.addObserver( | ||
self, | ||
selector: #selector(updateDraftMessage), | ||
name: UITextView.textDidChangeNotification, | ||
object: composerView.textView | ||
) | ||
|
||
recoverDraftMessage() | ||
} | ||
|
||
@objc func updateDraftMessage() { | ||
if let subscription = subscription { | ||
DraftMessageManager.update(draftMessage: composerView.textView.text, for: subscription) | ||
} | ||
} | ||
|
||
func recoverDraftMessage() { | ||
if let subscription = subscription { | ||
composerView.textView.text = DraftMessageManager.draftMessage(for: subscription) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,6 @@ extension MessagesViewController { | |
composerView.textView.text = "" | ||
|
||
stopReplying() | ||
updateDraftMessage() | ||
} | ||
} |