Procházet zdrojové kódy

integrated sampleData + chatViewController from MessageKit-sample

Bastian van de Wetering před 7 roky
rodič
revize
41d64e24eb

+ 4 - 0
deltachat-ios.xcodeproj/project.pbxproj

@@ -64,6 +64,7 @@
 		AE0D26FD1FB1FE88002FAFCE /* ChatListController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE0D26FC1FB1FE88002FAFCE /* ChatListController.swift */; };
 		AEACE2DD1FB323CA00DCDD78 /* ChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2DC1FB323CA00DCDD78 /* ChatViewController.swift */; };
 		AEACE2DF1FB3246400DCDD78 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2DE1FB3246400DCDD78 /* Message.swift */; };
+		AEACE2E11FB3271700DCDD78 /* SampleData.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2E01FB3271700DCDD78 /* SampleData.swift */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -204,6 +205,7 @@
 		AE0D26FC1FB1FE88002FAFCE /* ChatListController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatListController.swift; sourceTree = "<group>"; };
 		AEACE2DC1FB323CA00DCDD78 /* ChatViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatViewController.swift; sourceTree = "<group>"; };
 		AEACE2DE1FB3246400DCDD78 /* Message.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = "<group>"; };
+		AEACE2E01FB3271700DCDD78 /* SampleData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleData.swift; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -341,6 +343,7 @@
 				7A451D931FB1B1DB00177250 /* wrapper.h */,
 				AE0D26FC1FB1FE88002FAFCE /* ChatListController.swift */,
 				AEACE2DC1FB323CA00DCDD78 /* ChatViewController.swift */,
+				AEACE2E01FB3271700DCDD78 /* SampleData.swift */,
 			);
 			path = "deltachat-ios";
 			sourceTree = "<group>";
@@ -615,6 +618,7 @@
 				7A9FB5431FB08557001FEA36 /* mrloginparam.c in Sources */,
 				7A9FB5501FB08557001FEA36 /* mrpoortext.c in Sources */,
 				7A7923751FB0A2C800BC2DE5 /* validate.c in Sources */,
+				AEACE2E11FB3271700DCDD78 /* SampleData.swift in Sources */,
 				7A9FB5551FB08557001FEA36 /* mrstock.c in Sources */,
 				7A9FB53B1FB08557001FEA36 /* mrchatlist.c in Sources */,
 				AE0D26FD1FB1FE88002FAFCE /* ChatListController.swift in Sources */,

+ 351 - 12
deltachat-ios/ChatViewController.swift

@@ -7,29 +7,368 @@
 //
 
 import UIKit
+import MessageKit
+import MapKit
 
-class ChatViewController: UIViewController {
+class ChatViewController: MessagesViewController {
 
+    var messageList: [Message] = [] {
+        didSet {
+            DispatchQueue.main.async {
+                self.messagesCollectionView.reloadData()
+            }
+        }
+    }
+    
     override func viewDidLoad() {
         super.viewDidLoad()
+        
+        DispatchQueue.global(qos: .userInitiated).async {
+            SampleData.shared.getMessages(count: 10) { messages in
+                DispatchQueue.main.async {
+                    self.messageList = messages
+                }
+            }
+        }
+        
+        messagesCollectionView.messagesDataSource = self
+        messagesCollectionView.messagesLayoutDelegate = self
+        messagesCollectionView.messagesDisplayDelegate = self
+        messagesCollectionView.messageCellDelegate = self
+        messageInputBar.delegate = self
+        messageInputBar.sendButton.tintColor = UIColor(red: 69/255, green: 193/255, blue: 89/255, alpha: 1)
+        scrollsToBottomOnFirstLayout = true //default false
+        scrollsToBottomOnKeybordBeginsEditing = true // default false
+        
+        navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "ic_keyboard"),
+                                                            style: .plain,
+                                                            target: self,
+                                                            action: #selector(handleKeyboardButton))
+    }
+    
+    @objc func handleKeyboardButton() {
+        
+        messageInputBar.inputTextView.resignFirstResponder()
+        let actionSheetController = UIAlertController(title: "Change Keyboard Style", message: nil, preferredStyle: .actionSheet)
+        let actions = [
+            UIAlertAction(title: "Slack", style: .default, handler: { _ in
+                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1, execute: {
+                    self.slack()
+                })
+            }),
+            UIAlertAction(title: "iMessage", style: .default, handler: { _ in
+                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1, execute: {
+                    self.iMessage()
+                })
+            }),
+            UIAlertAction(title: "Default", style: .default, handler: { _ in
+                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1, execute: {
+                    self.defaultStyle()
+                })
+            }),
+            UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
+        ]
+        actions.forEach { actionSheetController.addAction($0) }
+        actionSheetController.view.tintColor = UIColor(red: 69/255, green: 193/255, blue: 89/255, alpha: 1)
+        present(actionSheetController, animated: true, completion: nil)
+    }
+    
+    // MARK: - Keyboard Style
+    
+    func slack() {
+        defaultStyle()
+        messageInputBar.isTranslucent = false
+        messageInputBar.inputTextView.backgroundColor = .clear
+        messageInputBar.inputTextView.layer.borderWidth = 0
+        let items = [
+            makeButton(named: "ic_camera").onTextViewDidChange { button, textView in
+                button.isEnabled = textView.text.isEmpty
+            },
+            makeButton(named: "ic_at").onSelected {
+                $0.tintColor = UIColor(red: 69/255, green: 193/255, blue: 89/255, alpha: 1)
+                print("@ Selected")
+            },
+            makeButton(named: "ic_hashtag").onSelected {
+                $0.tintColor = UIColor(red: 69/255, green: 193/255, blue: 89/255, alpha: 1)
+                print("# Selected")
+            },
+            .flexibleSpace,
+            makeButton(named: "ic_library").onTextViewDidChange { button, textView in
+                button.tintColor = UIColor(red: 69/255, green: 193/255, blue: 89/255, alpha: 1)
+                button.isEnabled = textView.text.isEmpty
+            },
+            messageInputBar.sendButton
+                .configure {
+                    $0.layer.cornerRadius = 8
+                    $0.layer.borderWidth = 1.5
+                    $0.layer.borderColor = $0.titleColor(for: .disabled)?.cgColor
+                    $0.setTitleColor(.white, for: .normal)
+                    $0.setTitleColor(.white, for: .highlighted)
+                    $0.setSize(CGSize(width: 52, height: 30), animated: true)
+                }.onDisabled {
+                    $0.layer.borderColor = $0.titleColor(for: .disabled)?.cgColor
+                    $0.backgroundColor = .white
+                }.onEnabled {
+                    $0.backgroundColor = UIColor(red: 69/255, green: 193/255, blue: 89/255, alpha: 1)
+                    $0.layer.borderColor = UIColor.clear.cgColor
+                }.onSelected {
+                    // We use a transform becuase changing the size would cause the other views to relayout
+                    $0.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
+                }.onDeselected {
+                    $0.transform = CGAffineTransform.identity
+            }
+        ]
+        items.forEach { $0.tintColor = .lightGray }
+        
+        // We can change the container insets if we want
+        messageInputBar.inputTextView.textContainerInset = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0)
+        messageInputBar.inputTextView.placeholderLabelInsets = UIEdgeInsets(top: 8, left: 5, bottom: 8, right: 5)
+        
+        // Since we moved the send button to the bottom stack lets set the right stack width to 0
+        messageInputBar.setRightStackViewWidthConstant(to: 0, animated: true)
+        
+        // Finally set the items
+        messageInputBar.setStackViewItems(items, forStack: .bottom, animated: true)
+    }
+    
+    func iMessage() {
+        defaultStyle()
+        messageInputBar.isTranslucent = false
+        messageInputBar.separatorLine.isHidden = true
+        messageInputBar.inputTextView.backgroundColor = UIColor(red: 245/255, green: 245/255, blue: 245/255, alpha: 1)
+        messageInputBar.inputTextView.placeholderTextColor = UIColor(red: 0.6, green: 0.6, blue: 0.6, alpha: 1)
+        messageInputBar.inputTextView.textContainerInset = UIEdgeInsets(top: 8, left: 16, bottom: 8, right: 36)
+        messageInputBar.inputTextView.placeholderLabelInsets = UIEdgeInsets(top: 8, left: 20, bottom: 8, right: 36)
+        messageInputBar.inputTextView.layer.borderColor = UIColor(red: 200/255, green: 200/255, blue: 200/255, alpha: 1).cgColor
+        messageInputBar.inputTextView.layer.borderWidth = 1.0
+        messageInputBar.inputTextView.layer.cornerRadius = 16.0
+        messageInputBar.inputTextView.layer.masksToBounds = true
+        messageInputBar.inputTextView.scrollIndicatorInsets = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0)
+        messageInputBar.setRightStackViewWidthConstant(to: 36, animated: true)
+        messageInputBar.setStackViewItems([messageInputBar.sendButton], forStack: .right, animated: true)
+        messageInputBar.sendButton.imageView?.backgroundColor = UIColor(red: 69/255, green: 193/255, blue: 89/255, alpha: 1)
+        messageInputBar.sendButton.contentEdgeInsets = UIEdgeInsets(top: 2, left: 2, bottom: 2, right: 2)
+        messageInputBar.sendButton.setSize(CGSize(width: 36, height: 36), animated: true)
+        messageInputBar.sendButton.image = #imageLiteral(resourceName: "ic_up")
+        messageInputBar.sendButton.title = nil
+        messageInputBar.sendButton.imageView?.layer.cornerRadius = 16
+        messageInputBar.sendButton.backgroundColor = .clear
+        messageInputBar.textViewPadding.right = -38
+    }
+    
+    func defaultStyle() {
+        let newMessageInputBar = MessageInputBar()
+        newMessageInputBar.sendButton.tintColor = UIColor(red: 69/255, green: 193/255, blue: 89/255, alpha: 1)
+        newMessageInputBar.delegate = self
+        messageInputBar = newMessageInputBar
+        reloadInputViews()
+    }
+    
+    // MARK: - Helpers
+    
+    func makeButton(named: String) -> InputBarButtonItem {
+        return InputBarButtonItem()
+            .configure {
+                $0.spacing = .fixed(10)
+                $0.image = UIImage(named: named)?.withRenderingMode(.alwaysTemplate)
+                $0.setSize(CGSize(width: 30, height: 30), animated: true)
+            }.onSelected {
+                $0.tintColor = UIColor(red: 69/255, green: 193/255, blue: 89/255, alpha: 1)
+            }.onDeselected {
+                $0.tintColor = UIColor.lightGray
+            }.onTouchUpInside { _ in
+                print("Item Tapped")
+        }
+    }
+}
+
+// MARK: - MessagesDataSource
 
-        // Do any additional setup after loading the view.
+extension ChatViewController: MessagesDataSource {
+    
+    func currentSender() -> Sender {
+        return SampleData.shared.currentSender
+    }
+    
+    func numberOfMessages(in messagesCollectionView: MessagesCollectionView) -> Int {
+        return messageList.count
+    }
+    
+    func messageForItem(at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> MessageType {
+        return messageList[indexPath.section]
+    }
+    
+    func avatar(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> Avatar {
+        return SampleData.shared.getAvatarFor(sender: message.sender)
     }
+    
+    func cellTopLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? {
+        let name = message.sender.displayName
+        return NSAttributedString(string: name, attributes: [NSAttributedStringKey.font: UIFont.preferredFont(forTextStyle: .caption1)])
+    }
+    
+    func cellBottomLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? {
+        let formatter = DateFormatter()
+        formatter.dateStyle = .medium
+        let dateString = formatter.string(from: message.sentDate)
+        return NSAttributedString(string: dateString, attributes: [NSAttributedStringKey.font: UIFont.preferredFont(forTextStyle: .caption2)])
+    }
+    
+}
 
-    override func didReceiveMemoryWarning() {
-        super.didReceiveMemoryWarning()
-        // Dispose of any resources that can be recreated.
+// MARK: - MessagesDisplayDelegate
+
+extension ChatViewController: MessagesDisplayDelegate, TextMessageDisplayDelegate {
+    
+    func backgroundColor(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> UIColor {
+        return isFromCurrentSender(message: message) ? UIColor(red: 69/255, green: 193/255, blue: 89/255, alpha: 1) : UIColor(red: 230/255, green: 230/255, blue: 230/255, alpha: 1)
+    }
+    
+    func textColor(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> UIColor {
+        return isFromCurrentSender(message: message) ? .white : .darkText
+    }
+    
+    func messageStyle(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> MessageStyle {
+        let corner: MessageStyle.TailCorner = isFromCurrentSender(message: message) ? .bottomRight : .bottomLeft
+        return .bubbleTail(corner, .curved)
+        //        let configurationClosure = { (view: MessageContainerView) in}
+        //        return .custom(configurationClosure)
     }
     
+}
 
-    /*
-    // MARK: - Navigation
+// MARK: - MessagesLayoutDelegate
 
-    // In a storyboard-based application, you will often want to do a little preparation before navigation
-    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
-        // Get the new view controller using segue.destinationViewController.
-        // Pass the selected object to the new view controller.
+extension ChatViewController: MessagesLayoutDelegate {
+    
+    func messagePadding(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> UIEdgeInsets {
+        if isFromCurrentSender(message: message) {
+            return UIEdgeInsets(top: 0, left: 30, bottom: 0, right: 4)
+        } else {
+            return UIEdgeInsets(top: 0, left: 4, bottom: 0, right: 30)
+        }
+    }
+    
+    func cellTopLabelAlignment(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> LabelAlignment {
+        if isFromCurrentSender(message: message) {
+            return .messageTrailing(UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 10))
+        } else {
+            return .messageLeading(UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0))
+        }
+    }
+    
+    func cellBottomLabelAlignment(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> LabelAlignment {
+        if isFromCurrentSender(message: message) {
+            return .messageLeading(UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0))
+        } else {
+            return .messageTrailing(UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 10))
+        }
     }
-    */
+    
+    func avatarAlignment(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> AvatarAlignment {
+        return .messageBottom
+    }
+    
+    func footerViewSize(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGSize {
+        
+        return CGSize(width: messagesCollectionView.bounds.width, height: 10)
+    }
+    
+}
+
+// MARK: - LocationMessageLayoutDelegate
+
+extension ChatViewController: LocationMessageLayoutDelegate {
+    
+    func heightForLocation(message: MessageType, at indexPath: IndexPath, with maxWidth: CGFloat, in messagesCollectionView: MessagesCollectionView) -> CGFloat {
+        return 200
+    }
+    
+}
+
+// MARK: - MediaMessageLayoutDelegate
+
+extension ChatViewController: MediaMessageLayoutDelegate {}
+
+// MARK: - MessageCellDelegate
+
+extension ChatViewController: MessageCellDelegate {
+    
+    func didTapAvatar<T>(in cell: MessageCollectionViewCell<T>) {
+        print("Avatar tapped")
+    }
+    
+    func didTapMessage<T>(in cell: MessageCollectionViewCell<T>) {
+        print("Message tapped")
+    }
+    
+    func didTapTopLabel<T>(in cell: MessageCollectionViewCell<T>) {
+        print("Top label tapped")
+    }
+    
+    func didTapBottomLabel<T>(in cell: MessageCollectionViewCell<T>) {
+        print("Bottom label tapped")
+    }
+    
+}
+
+// MARK: - MessageLabelDelegate
+
+extension ChatViewController: MessageLabelDelegate {
+    
+    func didSelectAddress(_ addressComponents: [String : String]) {
+        print("Address Selected: \(addressComponents)")
+    }
+    
+    func didSelectDate(_ date: Date) {
+        print("Date Selected: \(date)")
+    }
+    
+    func didSelectPhoneNumber(_ phoneNumber: String) {
+        print("Phone Number Selected: \(phoneNumber)")
+    }
+    
+    func didSelectURL(_ url: URL) {
+        print("URL Selected: \(url)")
+    }
+    
+}
+
+// MARK: - LocationMessageDisplayDelegate
+
+extension ChatViewController: LocationMessageDisplayDelegate {
+    
+    func annotationViewForLocation(message: MessageType, at indexPath: IndexPath, in messageCollectionView: MessagesCollectionView) -> MKAnnotationView? {
+        let annotationView = MKAnnotationView(annotation: nil, reuseIdentifier: nil)
+        let pinImage = #imageLiteral(resourceName: "ic_block_36pt").withRenderingMode(.alwaysTemplate)
+        annotationView.image = pinImage
+        annotationView.centerOffset = CGPoint(x: 0, y: -pinImage.size.height / 2)
+        return annotationView
+    }
+    
+    func animationBlockForLocation(message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> ((UIImageView) -> Void)? {
+        return { view in
+            view.layer.transform = CATransform3DMakeScale(0, 0, 0)
+            view.alpha = 0.0
+            UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0, options: [], animations: {
+                view.layer.transform = CATransform3DIdentity
+                view.alpha = 1.0
+            }, completion: nil)
+        }
+    }
+    
+}
+
+// MARK: - MessageInputBarDelegate
+
+extension ChatViewController: MessageInputBarDelegate {
+    
+    func messageInputBar(_ inputBar: MessageInputBar, didPressSendButtonWith text: String) {
+        messageList.append(Message(text: text, sender: currentSender(), messageId: UUID().uuidString, date: Date()))
+        inputBar.inputTextView.text = String()
+        messagesCollectionView.reloadData()
+        messagesCollectionView.scrollToBottom()
+    }
+
 
 }

+ 28 - 0
deltachat-ios/Message.swift

@@ -8,6 +8,9 @@
 
 import Foundation
 import MessageKit
+import CoreLocation
+
+
 
 struct Message: MessageType {
     
@@ -23,4 +26,29 @@ struct Message: MessageType {
         self.sentDate = date
     }
     
+    init(text: String, sender: Sender, messageId: String, date: Date) {
+        self.init(data: .text(text), sender: sender, messageId: messageId, date: date)
+    }
+    
+    init(attributedText: NSAttributedString, sender: Sender, messageId: String, date: Date) {
+        self.init(data: .attributedText(attributedText), sender: sender, messageId: messageId, date: date)
+    }
+    
+    init(image: UIImage, sender: Sender, messageId: String, date: Date) {
+        self.init(data: .photo(image), sender: sender, messageId: messageId, date: date)
+    }
+    
+    init(thumbnail: UIImage, sender: Sender, messageId: String, date: Date) {
+        let url = URL(fileURLWithPath: "")
+        self.init(data: .video(file: url, thumbnail: thumbnail), sender: sender, messageId: messageId, date: date)
+    }
+    
+    init(location: CLLocation, sender: Sender, messageId: String, date: Date) {
+        self.init(data: .location(location), sender: sender, messageId: messageId, date: date)
+    }
+    
+    init(emoji: String, sender: Sender, messageId: String, date: Date) {
+        self.init(data: .emoji(emoji), sender: sender, messageId: messageId, date: date)
+    }
+    
 }

+ 201 - 0
deltachat-ios/SampleData.swift

@@ -0,0 +1,201 @@
+/*
+ MIT License
+ 
+ Copyright (c) 2017 MessageKit
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+ */
+
+import MessageKit
+import CoreLocation
+
+final class SampleData {
+    
+    static let shared = SampleData()
+    
+    private init() {}
+    
+    let messageTextValues = [
+        "Ok",
+        "k",
+        "lol",
+        "1-800-555-0000",
+        "One Infinite Loop Cupertino, CA 95014 This is some extra text that should not be detected.",
+        "This is an example of the date detector 11/11/2017. April 1st is April Fools Day. Next Friday is not Friday the 13th.",
+        "https://github.com/SD10",
+        "Check out this awesome UI library for Chat",
+        "My favorite things in life don’t cost any money. It’s really clear that the most precious resource we all have is time.",
+        """
+            You know, this iPhone, as a matter of fact, the engine in here is made in America.
+            And not only are the engines in here made in America, but engines are made in America and are exported.
+            The glass on this phone is made in Kentucky. And so we've been working for years on doing more and more in the United States.
+            """,
+        """
+            Remembering that I'll be dead soon is the most important tool I've ever encountered to help me make the big choices in life.
+            Because almost everything - all external expectations, all pride, all fear of embarrassment or failure -
+            these things just fall away in the face of death, leaving only what is truly important.
+            """,
+        "I think if you do something and it turns out pretty good, then you should go do something else wonderful, not dwell on it for too long. Just figure out what’s next.",
+        "Price is rarely the most important thing. A cheap product might sell some units. Somebody gets it home and they feel great when they pay the money, but then they get it home and use it and the joy is gone."
+    ]
+    
+    let dan = Sender(id: "123456", displayName: "Dan Leonard")
+    let steven = Sender(id: "654321", displayName: "Steven")
+    let jobs = Sender(id: "000001", displayName: "Steve Jobs")
+    let cook = Sender(id: "656361", displayName: "Tim Cook")
+    
+    lazy var senders = [dan, steven, jobs, cook]
+    
+    var currentSender: Sender {
+        return steven
+    }
+    
+    let messageImages: [UIImage] = [#imageLiteral(resourceName: "ic_block_36pt")]
+    
+    var now = Date()
+    
+    let messageTypes = ["Text", "Text", "Text", "AttributedText", "Photo", "Video", "Location", "Emoji"]
+    
+    let attributes = ["Font1", "Font2", "Font3", "Font4", "Color", "Combo"]
+    
+    let locations: [CLLocation] = [
+        CLLocation(latitude: 37.3118, longitude: -122.0312),
+        CLLocation(latitude: 33.6318, longitude: -100.0386),
+        CLLocation(latitude: 29.3358, longitude: -108.8311),
+        CLLocation(latitude: 39.3218, longitude: -127.4312),
+        CLLocation(latitude: 35.3218, longitude: -127.4314),
+        CLLocation(latitude: 39.3218, longitude: -113.3317)
+    ]
+    
+    let emojis = [
+        "👍",
+        "👋",
+        "👋👋👋",
+        "😱😱",
+        "🎈",
+        "🇧🇷"
+    ]
+    
+    func attributedString(with text: String) -> NSAttributedString {
+        let nsString = NSString(string: text)
+        var mutableAttributedString = NSMutableAttributedString(string: text)
+        let randomAttribute = Int(arc4random_uniform(UInt32(attributes.count)))
+        let range = NSRange(location: 0, length: nsString.length)
+        
+        switch attributes[randomAttribute] {
+        case "Font1":
+            mutableAttributedString.addAttribute(NSAttributedStringKey.font, value: UIFont.preferredFont(forTextStyle: .body), range: range)
+        case "Font2":
+            mutableAttributedString.addAttributes([NSAttributedStringKey.font: UIFont.monospacedDigitSystemFont(ofSize: UIFont.systemFontSize, weight: UIFont.Weight.bold)], range: range)
+        case "Font3":
+            mutableAttributedString.addAttributes([NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)], range: range)
+        case "Font4":
+            mutableAttributedString.addAttributes([NSAttributedStringKey.font: UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)], range: range)
+        case "Color":
+            mutableAttributedString.addAttributes([NSAttributedStringKey.foregroundColor: UIColor.red], range: range)
+        case "Combo":
+            let msg9String = "Use .attributedText() to add bold, italic, colored text and more..."
+            let msg9Text = NSString(string: msg9String)
+            let msg9AttributedText = NSMutableAttributedString(string: String(msg9Text))
+            
+            msg9AttributedText.addAttribute(NSAttributedStringKey.font, value: UIFont.preferredFont(forTextStyle: .body), range: NSRange(location: 0, length: msg9Text.length))
+            msg9AttributedText.addAttributes([NSAttributedStringKey.font: UIFont.monospacedDigitSystemFont(ofSize: UIFont.systemFontSize, weight: UIFont.Weight.bold)], range: msg9Text.range(of: ".attributedText()"))
+            msg9AttributedText.addAttributes([NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)], range: msg9Text.range(of: "bold"))
+            msg9AttributedText.addAttributes([NSAttributedStringKey.font: UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)], range: msg9Text.range(of: "italic"))
+            msg9AttributedText.addAttributes([NSAttributedStringKey.foregroundColor: UIColor.red], range: msg9Text.range(of: "colored"))
+            mutableAttributedString = msg9AttributedText
+        default:
+            fatalError("Unrecognized attribute for mock message")
+        }
+        
+        return NSAttributedString(attributedString: mutableAttributedString)
+    }
+    
+    func dateAddingRandomTime() -> Date {
+        let randomNumber = Int(arc4random_uniform(UInt32(10)))
+        if randomNumber % 2 == 0 {
+            let date = Calendar.current.date(byAdding: .hour, value: randomNumber, to: now)!
+            now = date
+            return date
+        } else {
+            let randomMinute = Int(arc4random_uniform(UInt32(59)))
+            let date = Calendar.current.date(byAdding: .minute, value: randomMinute, to: now)!
+            now = date
+            return date
+        }
+    }
+    
+    func randomMessage() -> Message {
+        
+        let randomNumberSender = Int(arc4random_uniform(UInt32(senders.count)))
+        let randomNumberText = Int(arc4random_uniform(UInt32(messageTextValues.count)))
+        let randomNumberImage = Int(arc4random_uniform(UInt32(messageImages.count)))
+        let randomMessageType = Int(arc4random_uniform(UInt32(messageTypes.count)))
+        let randomNumberLocation = Int(arc4random_uniform(UInt32(locations.count)))
+        let randomNumberEmoji = Int(arc4random_uniform(UInt32(emojis.count)))
+        let uniqueID = NSUUID().uuidString
+        let sender = senders[randomNumberSender]
+        let date = dateAddingRandomTime()
+        
+        switch messageTypes[randomMessageType] {
+        case "Text":
+            return Message(text: messageTextValues[randomNumberText], sender: sender, messageId: uniqueID, date: date)
+        case "AttributedText":
+            let attributedText = attributedString(with: messageTextValues[randomNumberText])
+            return Message(attributedText: attributedText, sender: senders[randomNumberSender], messageId: uniqueID, date: date)
+        case "Photo":
+            let image = messageImages[randomNumberImage]
+            return Message(image: image, sender: sender, messageId: uniqueID, date: date)
+        case "Video":
+            let image = messageImages[randomNumberImage]
+            return Message(thumbnail: image, sender: sender, messageId: uniqueID, date: date)
+        case "Location":
+            return Message(location: locations[randomNumberLocation], sender: sender, messageId: uniqueID, date: date)
+        case "Emoji":
+            return Message(emoji: emojis[randomNumberEmoji], sender: sender, messageId: uniqueID, date: date)
+        default:
+            fatalError("Unrecognized mock message type")
+        }
+    }
+    
+    func getMessages(count: Int, completion: ([Message]) -> Void) {
+        var messages: [Message] = []
+        for _ in 0..<count {
+            messages.append(randomMessage())
+        }
+        completion(messages)
+    }
+    
+    func getAvatarFor(sender: Sender) -> Avatar {
+        switch sender {
+        case dan:
+            return Avatar(image: #imageLiteral(resourceName: "ic_people_36pt").withRenderingMode(.alwaysTemplate), initals: "DL")
+        case steven:
+            return Avatar(initals: "S")
+        case jobs:
+            return Avatar(image: #imageLiteral(resourceName: "ic_people_36pt").withRenderingMode(.alwaysTemplate), initals: "SJ")
+        case cook:
+            return Avatar(image: #imageLiteral(resourceName: "ic_people_36pt").withRenderingMode(.alwaysTemplate))
+        default:
+            return Avatar()
+        }
+    }
+    
+}
+