@@ -8,6 +8,7 @@
88
99import UIKit
1010import TinyConstraints
11+import Marklight
1112
1213protocol UpdatableGroup:class {
1314 func updateGroup(with group: Model.Group)
@@ -46,7 +47,6 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
4647
4748 var cellData: [PostCellData] = [] {
4849 didSet {
49− print(cellData)
5050 tableView.reloadData()
5151 }
5252 }
@@ -63,10 +63,12 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
6363 tabBarController?.tabBar.isHidden = true
6464 navigationItem.largeTitleDisplayMode = .never
6565
66+ tableView.keyboardDismissMode = .onDrag
67+ tableView.separatorStyle = .none
6668 tableView.register(DialogCell.self, forCellReuseIdentifier: cellId)
6769 tableView.transform = CGAffineTransform(scaleX: 1, y: -1)
6870 tableView.contentInsetAdjustmentBehavior = .never
69− tableView.contentOffset = CGPoint(x: 0, y: -30)
71+ tableView.contentOffset = CGPoint(x: 0, y: 30)
7072
7173 if let groupChat = groupChat {
7274 setTitleForGroup(groupChat: groupChat)
@@ -77,15 +79,33 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
7779
7880 var messageSendView: UIView = {
7981 let view = UIView()
80− view.backgroundColor = .red
82+ view.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
8183 return view
8284 }()
8385
84− var messageTextView: UITextView = {
85− let textView = UITextView()
86+ var messageTextView: UITextView =
87+ {
88+ let textStorage = MarklightTextStorage()
89+ textStorage.marklightTextProcessor.codeColor = UIColor.orange
90+ textStorage.marklightTextProcessor.quoteColor = UIColor.darkGray
91+ textStorage.marklightTextProcessor.syntaxColor = UIColor.blue
92+ textStorage.marklightTextProcessor.codeFontName = "Courier"
93+ textStorage.marklightTextProcessor.fontTextStyle = UIFont.TextStyle.subheadline.rawValue
94+ textStorage.marklightTextProcessor.hideSyntax = false
95+
96+ let layoutManager = NSLayoutManager()
97+
98+ // Assign the `UITextView`'s `NSLayoutManager` to the `NSTextStorage` subclass
99+ //textStorage.addLayoutManager(textView.layoutManager)
100+ textStorage.addLayoutManager(layoutManager)
101+
102+ let textContainer = NSTextContainer()
103+ layoutManager.addTextContainer(textContainer)
104+
105+ let textView = UITextView(frame: CGRect.zero, textContainer: textContainer)
86106 textView.isEditable = true
87107 textView.isScrollEnabled = true
88− textView.backgroundColor = .green
108+ textView.backgroundColor = .white
89109 return textView
90110 }()
91111
@@ -101,7 +121,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
101121 {
102122 var destination: Model.MessageDestination?
103123
104− if let group = groupChat{
124+ if let group = groupChat {
105125 destination = Model.MessageDestination.groupChatDestination(group.group.id)
106126 } else if let user = userChat {
107127 destination = Model.MessageDestination.userChatDestination(user.user)
@@ -111,10 +131,17 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
111131 {
112132 Model.sendMessage(message: Model.SendMessage(body: Model.Attachments(markdown: messageTextView.text), destination: destination)) { [unowned self] in
113133 self.getMessages(for: self.dialog!)
134+ self.messageTextView.text = ""
114135 }
115136 }
116137 }
117138
139+ var lineView: UIView = {
140+ let view = UIView()
141+ view.backgroundColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1)
142+ return view
143+ }()
144+
118145 var bottomConstraint: NSLayoutConstraint!
119146
120147 func setConstraints(){
@@ -123,17 +150,21 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
123150
124151 messageSendView.addSubview(messageTextView)
125152 messageSendView.addSubview(sendButton)
153+ messageSendView.addSubview(lineView)
126154
127155 messageSendView.edgesToSuperview(excluding: [.top,.bottom])
128156
129157 bottomConstraint = NSLayoutConstraint(item: messageSendView, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1, constant: 0)
130158 view.addConstraint(bottomConstraint)
131159
132− messageSendView.height(40)
160+ messageSendView.height(60)
133161
134162 sendButton.edgesToSuperview(excluding: .left)
135163 sendButton.width(60)
136164
165+ lineView.edgesToSuperview(excluding: .bottom)
166+ lineView.height(0.5)
167+
137168 messageTextView.edgesToSuperview(excluding: .right)
138169 messageTextView.rightToLeft(of: sendButton)
139170
@@ -167,11 +198,11 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
167198 }
168199
169200 func setTitleForChat(userChat: Model.UserChat){
170− navigationItem.title = "🌌 \(users![userChat.user]!.fullName())"
201+ navigationItem.title = "👤 \(users![userChat.user]!.fullName())"
171202 }
172203
173204 func setTitleForGroup(groupChat: Model.GroupChat){
174− navigationItem.title = "🌌 \(groupChat.group.id) \(groupChat.group.name)"
205+ navigationItem.title = "\(groupChat.group.name)"
175206 navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Info", style: .plain, target: self, action: #selector(moveToInfoVC))
176207 }
177208
@@ -215,6 +246,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
215246 }
216247
217248 func getMessages(for dialog: Model.Dialog){
249+ print("Here")
218250 switch dialog {
219251 case .groupChat(let groupChat):
220252 Model.getMessagesFor(typeOfChat: Model.Dialog.groupChat(groupChat), chat: groupChat.group.id)
@@ -235,10 +267,12 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
235267
236268 //In cellForRowAtIndexPath
237269 cell.transform = CGAffineTransform(scaleX: 1, y: -1)
270+ cell.selectionStyle = .none
271+
238272
239273 if let author = currentMessagesInChat?[indexPath.row].author, let user = users?[author]
240274 {
241− cell.fill(with: cellData[indexPath.row].attributedData, byUser: user)
275+ cell.fill(with: cellData[indexPath.row].attributedData, byUser: user, when: (currentMessagesInChat?[indexPath.row].time)!)
242276 }
243277
244278 return cell