git.iko.soy/dashared/GDproject
on master help sign in
Added userChats
1a8769eDarya Rednikina
GDproject/Base.lproj/Main.storyboard+3
@@ -90,6 +90,9 @@
90 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="yir-N6-Q6f">
90 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="yir-N6-Q6f">
91 <rect key="frame" x="246" y="0.0" width="97" height="30"/>
91 <rect key="frame" x="246" y="0.0" width="97" height="30"/>
92 <state key="normal" title="New message"/>
92 <state key="normal" title="New message"/>
93+ <connections>
94+ <action selector="sendMessage:" destination="R4D-Ao-uvG" eventType="touchUpInside" id="tQc-5f-SU3"/>
95+ </connections>
93 </button>
96 </button>
94 </subviews>
97 </subviews>
95 </stackView>
98 </stackView>
GDproject/Controller/ News and channels/FullPostController.swift+1
@@ -102,6 +102,7 @@ class FullPostController: UITableViewController {
102 cell.onUserDisplay = { [weak self] (id) in
102 cell.onUserDisplay = { [weak self] (id) in
103 let vc = self?.storyboard!.instantiateViewController(withIdentifier: profileViewController) as! ProfileViewController
103 let vc = self?.storyboard!.instantiateViewController(withIdentifier: profileViewController) as! ProfileViewController
104 vc.idProfile = id
104 vc.idProfile = id
105+
105 self?.navigationController?.pushViewController(vc, animated: true)
106 self?.navigationController?.pushViewController(vc, animated: true)
106 }
107 }
107 default:
108 default:
GDproject/Controller/ News and channels/NewsController.swift+1−5
@@ -121,11 +121,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, UpdateableWi
121 }
121 }
122 }
122 }
123 default:
123 default:
124− if let anonChannel = anonymousChannel {
124+ break
125− news.dataSourse = anonChannel.posts
126− news.dictionary = anonChannel.users
127− changedChannelName?("Anonymous")
128− }
129 }
125 }
130
126
131 }
127 }
GDproject/Controller/Coordinators/MessagesCoordinator.swift+31−9
@@ -36,24 +36,46 @@ class MessagesCoordinator: BaseCoordinator {
36 newVC.whatToDoWithSelection = { [weak newVC, weak self] in
36 newVC.whatToDoWithSelection = { [weak newVC, weak self] in
37 newVC?.navigationController?.popViewController(animated: true)
37 newVC?.navigationController?.popViewController(animated: true)
38
38
39+ // detect is it a user or group dialog
40+ let count = $0.count
41+ if count == 1 {
42+
43+ let user = $0.first!.key
44+ let createdDialog = Model.Dialog.userChat(Model.UserChat(user: user))
45+
46+ let vc = DialogViewController()
47+ vc.users = Model.Channels.fullPeopleDict
48+ vc.dialog = createdDialog
49+ self?.navigationController?.pushViewController(vc, animated: true)
50+
51+ } else {
39− var group = Model.Group(users: $0, name: "Untitled", id: 0)
52+ var group = Model.Group(users: $0, name: "Untitled", id: 0)
40− Model.createGroupChat(from: group, completion:
53+ Model.createGroupChat(from: group, completion: { [weak self] id in
41− { [weak self] id in
54+
42−
43− let newVC1 = DialogViewController()
55+ let newVC1 = DialogViewController()
44− group.id = id
56+ group.id = id
45− newVC1.dialog = Model.Dialog.groupChat(Model.GroupChat(group: group))
57+ newVC1.dialog = Model.Dialog.groupChat(Model.GroupChat(group: group))
46− self?.navigationController?.pushViewController(newVC1, animated: true)
58+ self?.navigationController?.pushViewController(newVC1, animated: true)
47− })
59+ })
60+ }
48 }
61 }
49
62
50 vc?.navigationController?.pushViewController(newVC, animated: true)
63 vc?.navigationController?.pushViewController(newVC, animated: true)
51 }
64 }
52
65
53 vc.onDialogDisplay = { [weak vc] in
66 vc.onDialogDisplay = { [weak vc] in
67+
54 let newVC = DialogViewController()
68 let newVC = DialogViewController()
55 newVC.dialog = $0.dialog
69 newVC.dialog = $0.dialog
56 newVC.users = $0.users
70 newVC.users = $0.users
71+ newVC.onUserDisplay = { [weak self] id in
72+
73+ let vc = self?.storyboard.instantiateViewController(withIdentifier: profileViewController) as! ProfileViewController
74+ vc.idProfile = id
75+ self?.navigationController!.pushViewController(vc, animated: true)
76+
77+ }
78+
57 vc?.navigationController?.pushViewController(newVC, animated: true)
79 vc?.navigationController?.pushViewController(newVC, animated: true)
58 }
80 }
59
81
GDproject/Controller/Messages/ChatInfoViewController.swift+6−1
@@ -190,7 +190,12 @@ class ChatInfoViewController: UITableViewController {
190 self?.navigationController?.popViewController(animated: true)
190 self?.navigationController?.popViewController(animated: true)
191 }
191 }
192 default:
192 default:
193+ switch myPermissions{
194+ case .admin:
193− showUserChoiceVC()
195+ showUserChoiceVC()
196+ default:
197+ break
198+ }
194 }
199 }
195 }
200 }
196 }
201 }
GDproject/Controller/Messages/Dialog/DialogCell.swift+7−4
@@ -16,14 +16,14 @@ class DialogCell: UITableViewCell {
16 let button = UIButton()
16 let button = UIButton()
17 button.setTitleColor(.black, for: .normal)
17 button.setTitleColor(.black, for: .normal)
18 button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16)
18 button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16)
19− button.addTarget(self, action: #selector(displayProfile), for: .touchUpInside)
20 button.contentHorizontalAlignment = UIControl.ContentHorizontalAlignment.left
19 button.contentHorizontalAlignment = UIControl.ContentHorizontalAlignment.left
21 return button
20 return button
22 }()
21 }()
23
22
24 @objc func displayProfile()
23 @objc func displayProfile()
25 {
24 {
26− if let id = self.user?.id{
25+ if let id = self.user?.id {
26+ print("diplay")
27 onUserDisplay?(id)
27 onUserDisplay?(id)
28 }
28 }
29 }
29 }
@@ -80,6 +80,8 @@ class DialogCell: UITableViewCell {
80 // important
80 // important
81 contentView.subviews.forEach({ $0.removeFromSuperview() })
81 contentView.subviews.forEach({ $0.removeFromSuperview() })
82
82
83+ nameLabel.addTarget(self, action: #selector(displayProfile), for: .touchUpInside)
84+
83 self.user = byUser
85 self.user = byUser
84 textView = createTextView(with: markdownText, true)
86 textView = createTextView(with: markdownText, true)
85 textView.layer.cornerRadius = 10
87 textView.layer.cornerRadius = 10
@@ -110,7 +112,7 @@ class DialogCell: UITableViewCell {
110
112
111 textView.backgroundColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
113 textView.backgroundColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
112 textView.textColor = .white
114 textView.textColor = .white
113− timeLabel.edgesToSuperview(excluding: .top, insets: .right(70) + .left(4))
115+ timeLabel.edgesToSuperview(excluding: .top, insets: .right(70) + .left(8))
114 timeLabel.topToBottom(of: textView, offset: 4)
116 timeLabel.topToBottom(of: textView, offset: 4)
115 timeLabel.textAlignment = .left
117 timeLabel.textAlignment = .left
116 }
118 }
@@ -120,8 +122,9 @@ class DialogCell: UITableViewCell {
120 textView.edgesToSuperview(excluding: .left, insets: .right(8) + .bottom(20) + .top(4))
122 textView.edgesToSuperview(excluding: .left, insets: .right(8) + .bottom(20) + .top(4))
121 textView.backgroundColor = UIColor(red:0.08, green:0.49, blue:0.98, alpha:1.0)
123 textView.backgroundColor = UIColor(red:0.08, green:0.49, blue:0.98, alpha:1.0)
122 textView.textColor = .white
124 textView.textColor = .white
123− timeLabel.edgesToSuperview(excluding: .top, insets: .left(70) + .right(4))
125+ timeLabel.edgesToSuperview(excluding: .top, insets: .left(70) + .right(8))
124 timeLabel.topToBottom(of: textView, offset: 4)
126 timeLabel.topToBottom(of: textView, offset: 4)
127+ timeLabel.textAlignment = .right
125 }
128 }
126}
129}
127
130
GDproject/Controller/Messages/Dialog/DialogViewController.swift+42−16
@@ -16,6 +16,7 @@ protocol UpdatableGroup:class {
16
16
17class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegate, UITableViewDataSource
17class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegate, UITableViewDataSource
18{
18{
19+ var onUserDisplay: ((Int)->())?
19
20
20 var tableView: UITableView = UITableView()
21 var tableView: UITableView = UITableView()
21
22
@@ -47,6 +48,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
47
48
48 var cellData: [PostCellData] = [] {
49 var cellData: [PostCellData] = [] {
49 didSet {
50 didSet {
51+ prevLast = cellData.count - 1
50 tableView.reloadData()
52 tableView.reloadData()
51 }
53 }
52 }
54 }
@@ -198,7 +200,14 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
198 }
200 }
199
201
200 func setTitleForChat(userChat: Model.UserChat){
202 func setTitleForChat(userChat: Model.UserChat){
201− navigationItem.title = "👤 \(users![userChat.user]!.fullName())"
203+ navigationItem.title = "\(users![userChat.user]!.fullName())"
204+ navigationItem.rightBarButtonItem = UIBarButtonItem(title: "👤", style: .plain, target: self, action: #selector(showPersonPage))
205+ }
206+
207+ @objc func showPersonPage(){
208+ if let id = userChat?.user{
209+ onUserDisplay?(id)
210+ }
202 }
211 }
203
212
204 func setTitleForGroup(groupChat: Model.GroupChat){
213 func setTitleForGroup(groupChat: Model.GroupChat){
@@ -206,6 +215,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
206 navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Info", style: .plain, target: self, action: #selector(moveToInfoVC))
215 navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Info", style: .plain, target: self, action: #selector(moveToInfoVC))
207 }
216 }
208
217
218+ // onInfoShow
209 @objc func moveToInfoVC(){
219 @objc func moveToInfoVC(){
210 let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: chatInfoViewController) as! ChatInfoViewController
220 let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: chatInfoViewController) as! ChatInfoViewController
211
221
@@ -219,11 +229,10 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
219 navigationController?.pushViewController(vc, animated: true)
229 navigationController?.pushViewController(vc, animated: true)
220 }
230 }
221
231
222− var currentMessagesInChat: [Model.LastMessage]? {
232+ var currentMessagesInChat: [Model.LastMessage] = [] {
223− didSet {
233+ didSet
224− if let currentMessagesInChat = currentMessagesInChat {
234+ {
225− cellData = currentMessagesInChat.map { PostCellData(attributedData: PostCellData.create(with: [$0.body])) }
235+ cellData = currentMessagesInChat.map { PostCellData(attributedData: PostCellData.create(with: [$0.body])) }
226− }
227 }
236 }
228 }
237 }
229
238
@@ -245,18 +254,18 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
245 }
254 }
246 }
255 }
247
256
248− func getMessages(for dialog: Model.Dialog){
257+ func getMessages(for dialog: Model.Dialog, starting from: Int? = nil)
249− print("Here")
258+ {
250 switch dialog {
259 switch dialog {
251 case .groupChat(let groupChat):
260 case .groupChat(let groupChat):
252− Model.getMessagesFor(typeOfChat: Model.Dialog.groupChat(groupChat), chat: groupChat.group.id)
261+ Model.getMessagesFor(typeOfChat: Model.Dialog.groupChat(groupChat), chat: groupChat.group.id, exclusiveFrom: from)
253− { [unowned self] in
262+ { [weak self] in
254− self.currentMessagesInChat = $0
263+ self?.currentMessagesInChat = $0
255 }
264 }
256 case .userChat(let userChat):
265 case .userChat(let userChat):
257− Model.getMessagesFor(typeOfChat: Model.Dialog.userChat(userChat), chat: userChat.user)
266+ Model.getMessagesFor(typeOfChat: Model.Dialog.userChat(userChat), chat: userChat.user, exclusiveFrom: from)
258− { [unowned self] in
267+ { [weak self] in
259− self.currentMessagesInChat = $0
268+ self?.currentMessagesInChat = $0
260 }
269 }
261 }
270 }
262 }
271 }
@@ -270,13 +279,30 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
270 cell.selectionStyle = .none
279 cell.selectionStyle = .none
271
280
272
281
273− if let author = currentMessagesInChat?[indexPath.row].author, let user = users?[author]
282+ if let user = users?[currentMessagesInChat[indexPath.row].author]
274 {
283 {
275− cell.fill(with: cellData[indexPath.row].attributedData, byUser: user, when: (currentMessagesInChat?[indexPath.row].time)!)
284+ cell.fill(with: cellData[indexPath.row].attributedData, byUser: user, when: currentMessagesInChat[indexPath.row].time)
285+
286+ cell.onUserDisplay = onUserDisplay
276 }
287 }
277
288
278 return cell
289 return cell
279 }
290 }
291+
292+ var prevLast = -1
293+ func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
294+ {
295+ // pagination
296+// if indexPath.row == cellData.count - 1 && prevLast != indexPath.row
297+// {
298+// if let dialog = dialog
299+// {
300+// getMessages(for: dialog, starting: prevLast)
301+// }
302+//
303+// prevLast = indexPath.row
304+// }
305+ }
280}
306}
281
307
282
308
GDproject/Controller/Messages/MessagesViewController.swift+1−1
@@ -73,7 +73,7 @@ class MessagesViewController: UITableViewController {
73 cell.detailTextLabel?.text = group.lastMessage!.body.markdown
73 cell.detailTextLabel?.text = group.lastMessage!.body.markdown
74 case .userChat(let userChat):
74 case .userChat(let userChat):
75 cell.textLabel?.text = "👤 \(users[userChat.user]!.fullName())"
75 cell.textLabel?.text = "👤 \(users[userChat.user]!.fullName())"
76− cell.detailTextLabel?.text = userChat.lastMessage.body.markdown
76+ cell.detailTextLabel?.text = userChat.lastMessage!.body.markdown
77 }
77 }
78
78
79 return cell
79 return cell
GDproject/Controller/Profile/ProfileViewController.swift+13
@@ -34,6 +34,18 @@ class ProfileViewController: UIViewController
34
34
35 var onSettings: (()->())?
35 var onSettings: (()->())?
36
36
37+ @IBAction func sendMessage(_ sender: UIButton)
38+ {
39+ if let userId = idProfile
40+ {
41+ let createdDialog = Model.Dialog.userChat(Model.UserChat(user: userId))
42+ let vc = DialogViewController()
43+ vc.users = Model.Channels.fullPeopleDict
44+ vc.dialog = createdDialog
45+ self.navigationController?.pushViewController(vc, animated: true)
46+ }
47+ }
48+
37 var onChannelsListToAddAPerson: ((Model.Users)->())?
49 var onChannelsListToAddAPerson: ((Model.Users)->())?
38
50
39 var protoDictionary: [Int: UIImage] = [9: #imageLiteral(resourceName: "9"), 5051: #imageLiteral(resourceName: "5051"), 69: #imageLiteral(resourceName: "69"), 42: #imageLiteral(resourceName: "42")]
51 var protoDictionary: [Int: UIImage] = [9: #imageLiteral(resourceName: "9"), 5051: #imageLiteral(resourceName: "5051"), 69: #imageLiteral(resourceName: "69"), 42: #imageLiteral(resourceName: "42")]
@@ -110,6 +122,7 @@ class ProfileViewController: UIViewController
110 }
122 }
111
123
112 override func viewWillAppear(_ animated: Bool) {
124 override func viewWillAppear(_ animated: Bool) {
125+ tabBarController?.tabBar.isHidden = false
113
126
114 if idProfile == nil {
127 if idProfile == nil {
115 idProfile = DataStorage.standard.getUserId()
128 idProfile = DataStorage.standard.getUserId()
GDproject/Simple model/Model.swift+6−1
@@ -622,7 +622,12 @@ class Model{
622
622
623 struct UserChat: Codable {
623 struct UserChat: Codable {
624 var user: Int
624 var user: Int
625− var lastMessage: LastMessage
625+ var lastMessage: LastMessage?
626+
627+ init(user: Int, lastMessage: LastMessage? = nil) {
628+ self.user = user
629+ self.lastMessage = lastMessage
630+ }
626 }
631 }
627
632
628 struct Group: Codable {
633 struct Group: Codable {