@@ -8,6 +8,7 @@
9import UIKit
9import UIKit
10import TinyConstraints
10import TinyConstraints
12protocol UpdatableGroup:class {
13protocol UpdatableGroup:class {
13 func updateGroup(with group: Model.Group)
14 func updateGroup(with group: Model.Group)
@@ -46,7 +47,6 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
47 var cellData: [PostCellData] = [] {
48 var cellData: [PostCellData] = [] {
50 tableView.reloadData()
50 tableView.reloadData()
@@ -63,10 +63,12 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
63 tabBarController?.tabBar.isHidden = true
63 tabBarController?.tabBar.isHidden = true
64 navigationItem.largeTitleDisplayMode = .never
64 navigationItem.largeTitleDisplayMode = .never
66+ tableView.keyboardDismissMode = .onDrag
67+ tableView.separatorStyle = .none
66 tableView.register(DialogCell.self, forCellReuseIdentifier: cellId)
68 tableView.register(DialogCell.self, forCellReuseIdentifier: cellId)
67 tableView.transform = CGAffineTransform(scaleX: 1, y: -1)
69 tableView.transform = CGAffineTransform(scaleX: 1, y: -1)
68 tableView.contentInsetAdjustmentBehavior = .never
70 tableView.contentInsetAdjustmentBehavior = .never
69− tableView.contentOffset = CGPoint(x: 0, y: -30)
71+ tableView.contentOffset = CGPoint(x: 0, y: 30)
71 if let groupChat = groupChat {
73 if let groupChat = groupChat {
72 setTitleForGroup(groupChat: groupChat)
74 setTitleForGroup(groupChat: groupChat)
@@ -77,15 +79,33 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
78 var messageSendView: UIView = {
80 var messageSendView: UIView = {
79 let view = UIView()
81 let view = UIView()
80− view.backgroundColor = .red
82+ view.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
81 return view
83 return view
84− var messageTextView: UITextView = {
86+ var messageTextView: UITextView =
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
96+ let layoutManager = NSLayoutManager()
98+ // Assign the `UITextView`'s `NSLayoutManager` to the `NSTextStorage` subclass
99+ //textStorage.addLayoutManager(textView.layoutManager)
100+ textStorage.addLayoutManager(layoutManager)
102+ let textContainer = NSTextContainer()
103+ layoutManager.addTextContainer(textContainer)
85− let textView = UITextView()
105+ let textView = UITextView(frame: CGRect.zero, textContainer: textContainer)
86 textView.isEditable = true
106 textView.isEditable = true
87 textView.isScrollEnabled = true
107 textView.isScrollEnabled = true
88− textView.backgroundColor = .green
108+ textView.backgroundColor = .white
89 return textView
109 return textView
@@ -101,7 +121,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
102 var destination: Model.MessageDestination?
122 var destination: Model.MessageDestination?
104− if let group = groupChat{
124+ if let group = groupChat {
105 destination = Model.MessageDestination.groupChatDestination(group.group.id)
125 destination = Model.MessageDestination.groupChatDestination(group.group.id)
106 } else if let user = userChat {
126 } else if let user = userChat {
107 destination = Model.MessageDestination.userChatDestination(user.user)
127 destination = Model.MessageDestination.userChatDestination(user.user)
@@ -111,10 +131,17 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
112 Model.sendMessage(message: Model.SendMessage(body: Model.Attachments(markdown: messageTextView.text), destination: destination)) { [unowned self] in
132 Model.sendMessage(message: Model.SendMessage(body: Model.Attachments(markdown: messageTextView.text), destination: destination)) { [unowned self] in
113 self.getMessages(for: self.dialog!)
133 self.getMessages(for: self.dialog!)
134+ self.messageTextView.text = ""
139+ var lineView: UIView = {
141+ view.backgroundColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1)
118 var bottomConstraint: NSLayoutConstraint!
145 var bottomConstraint: NSLayoutConstraint!
120 func setConstraints(){
147 func setConstraints(){
@@ -123,17 +150,21 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
124 messageSendView.addSubview(messageTextView)
151 messageSendView.addSubview(messageTextView)
125 messageSendView.addSubview(sendButton)
152 messageSendView.addSubview(sendButton)
153+ messageSendView.addSubview(lineView)
127 messageSendView.edgesToSuperview(excluding: [.top,.bottom])
155 messageSendView.edgesToSuperview(excluding: [.top,.bottom])
129 bottomConstraint = NSLayoutConstraint(item: messageSendView, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1, constant: 0)
157 bottomConstraint = NSLayoutConstraint(item: messageSendView, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1, constant: 0)
130 view.addConstraint(bottomConstraint)
158 view.addConstraint(bottomConstraint)
132− messageSendView.height(40)
160+ messageSendView.height(60)
134 sendButton.edgesToSuperview(excluding: .left)
162 sendButton.edgesToSuperview(excluding: .left)
135 sendButton.width(60)
163 sendButton.width(60)
165+ lineView.edgesToSuperview(excluding: .bottom)
166+ lineView.height(0.5)
137 messageTextView.edgesToSuperview(excluding: .right)
168 messageTextView.edgesToSuperview(excluding: .right)
138 messageTextView.rightToLeft(of: sendButton)
169 messageTextView.rightToLeft(of: sendButton)
@@ -167,11 +198,11 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
169 func setTitleForChat(userChat: Model.UserChat){
200 func setTitleForChat(userChat: Model.UserChat){
170− navigationItem.title = "🌌 \(users![userChat.user]!.fullName())"
201+ navigationItem.title = "👤 \(users![userChat.user]!.fullName())"
173 func setTitleForGroup(groupChat: Model.GroupChat){
204 func setTitleForGroup(groupChat: Model.GroupChat){
174− navigationItem.title = "🌌 \(groupChat.group.id) \(groupChat.group.name)"
205+ navigationItem.title = "\(groupChat.group.name)"
175 navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Info", style: .plain, target: self, action: #selector(moveToInfoVC))
206 navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Info", style: .plain, target: self, action: #selector(moveToInfoVC))
@@ -215,6 +246,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
217 func getMessages(for dialog: Model.Dialog){
248 func getMessages(for dialog: Model.Dialog){
218 switch dialog {
250 switch dialog {
219 case .groupChat(let groupChat):
251 case .groupChat(let groupChat):
220 Model.getMessagesFor(typeOfChat: Model.Dialog.groupChat(groupChat), chat: groupChat.group.id)
252 Model.getMessagesFor(typeOfChat: Model.Dialog.groupChat(groupChat), chat: groupChat.group.id)
@@ -235,10 +267,12 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
236 //In cellForRowAtIndexPath
268 //In cellForRowAtIndexPath
237 cell.transform = CGAffineTransform(scaleX: 1, y: -1)
269 cell.transform = CGAffineTransform(scaleX: 1, y: -1)
270+ cell.selectionStyle = .none
239 if let author = currentMessagesInChat?[indexPath.row].author, let user = users?[author]
273 if let author = currentMessagesInChat?[indexPath.row].author, let user = users?[author]
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)!)
244 return cell
278 return cell