diff --git a/GDproject.xcodeproj/project.pbxproj b/GDproject.xcodeproj/project.pbxproj index daa6033..ffd97b9 100644 --- a/GDproject.xcodeproj/project.pbxproj +++ b/GDproject.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 1210A0BB223940310080686D /* SimplifiedChannelsList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1210A0BA223940310080686D /* SimplifiedChannelsList.swift */; }; 121A8972226B1EAC005EE599 /* TagsSuggestionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 121A8971226B1EAC005EE599 /* TagsSuggestionController.swift */; }; 1220FF94227C41270092C6BC /* TaggsSelectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1220FF93227C41270092C6BC /* TaggsSelectionViewController.swift */; }; + 123589FD22899339002F8028 /* MessageViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123589FC22899339002F8028 /* MessageViewCell.swift */; }; 123E37A5221F1B3200F6E42A /* LogInViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123E37A4221F1B3200F6E42A /* LogInViewController.swift */; }; 123E37A7221F1DD700F6E42A /* MainController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123E37A6221F1DD700F6E42A /* MainController.swift */; }; 124CC7032221C00C009DF531 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 124CC7022221C00C009DF531 /* Model.swift */; }; @@ -108,6 +109,7 @@ 1210A0BA223940310080686D /* SimplifiedChannelsList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimplifiedChannelsList.swift; sourceTree = ""; }; 121A8971226B1EAC005EE599 /* TagsSuggestionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagsSuggestionController.swift; sourceTree = ""; }; 1220FF93227C41270092C6BC /* TaggsSelectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggsSelectionViewController.swift; sourceTree = ""; }; + 123589FC22899339002F8028 /* MessageViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageViewCell.swift; sourceTree = ""; }; 123E37A4221F1B3200F6E42A /* LogInViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogInViewController.swift; sourceTree = ""; }; 123E37A6221F1DD700F6E42A /* MainController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainController.swift; sourceTree = ""; }; 124CC7022221C00C009DF531 /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = ""; }; @@ -238,6 +240,7 @@ 129320082279C3B50035C7B3 /* PeopleToWriteViewController.swift */, 1298810C227F138C0032ACA3 /* Dialog */, 129320032279B4270035C7B3 /* MessagesViewController.swift */, + 123589FC22899339002F8028 /* MessageViewCell.swift */, ); path = Messages; sourceTree = ""; @@ -451,6 +454,7 @@ 1298810B227F13840032ACA3 /* DialogCell.swift in Sources */, 125A9A922286100800513E2A /* FacultyTableViewController.swift in Sources */, 125A9A8E2286068A00513E2A /* RegisterTableViewController.swift in Sources */, + 123589FD22899339002F8028 /* MessageViewCell.swift in Sources */, 12E36DCC22144725006FCDD7 /* PostViewCell.swift in Sources */, 123E37A5221F1B3200F6E42A /* LogInViewController.swift in Sources */, 125BD57F22171D73008A3575 /* Extentions.swift in Sources */, diff --git a/GDproject/Base.lproj/Main.storyboard b/GDproject/Base.lproj/Main.storyboard index 5e3ac13..5ed23eb 100644 --- a/GDproject/Base.lproj/Main.storyboard +++ b/GDproject/Base.lproj/Main.storyboard @@ -778,29 +778,53 @@ - - + + - + - + + + + + + + + + + + + + + + + + @@ -811,7 +835,7 @@ - + diff --git a/GDproject/Controller/ News and channels/ChannelListController.swift b/GDproject/Controller/ News and channels/ChannelListController.swift index a0701cf..b62d257 100644 --- a/GDproject/Controller/ News and channels/ChannelListController.swift +++ b/GDproject/Controller/ News and channels/ChannelListController.swift @@ -100,7 +100,7 @@ class ChannelListController: UITableViewController { @objc func addChannel() { // editing mode is on automatically - onEditingModeBegins?(Model.Channels(people: [], name: "Untitled", tags: []),IndexPath(row: 1, section: 0)) + onEditingModeBegins?(Model.Channels(people: [], name: "Untitled", id: 0, tags: []),IndexPath(row: 1, section: 0)) } static let generalChannel = Model.Channels(people: [], name: "General", id: -1, tags: []) diff --git a/GDproject/Controller/ News and channels/ChannelViewController.swift b/GDproject/Controller/ News and channels/ChannelViewController.swift index 226b103..98be2f1 100644 --- a/GDproject/Controller/ News and channels/ChannelViewController.swift +++ b/GDproject/Controller/ News and channels/ChannelViewController.swift @@ -60,8 +60,9 @@ class ChannelViewController: UITableViewController, UpdatableName, UpdatableChan super.viewWillDisappear(animated) } - guard let _ = self.navigationController?.viewControllers.lastIndex(of: self) else { - if let _ = channel?.id + guard let _ = self.navigationController?.viewControllers.lastIndex(of: self) else + { + if let id = channel?.id, id != 0 { Model.updateChannel(with: channel!) } else { diff --git a/GDproject/Controller/Messages/ChatInfoViewController.swift b/GDproject/Controller/Messages/ChatInfoViewController.swift index f2c1808..7ff813a 100644 --- a/GDproject/Controller/Messages/ChatInfoViewController.swift +++ b/GDproject/Controller/Messages/ChatInfoViewController.swift @@ -91,10 +91,12 @@ class ChatInfoViewController: UITableViewController { switch indexPath.section { case 0: cell.textLabel?.text = groupChat!.name + cell.selectionStyle = .none return cell case 1: cell.textLabel?.text = "Leave chat" cell.textLabel?.textColor = #colorLiteral(red: 1, green: 0.1491314173, blue: 0, alpha: 1) + cell.selectionStyle = .none return cell default: switch myPermissions{ @@ -104,6 +106,7 @@ class ChatInfoViewController: UITableViewController { case .ordinary: cell.textLabel?.text = name(for: users[usersArray[indexPath.row]]) } + cell.selectionStyle = .none return cell } } @@ -114,7 +117,7 @@ class ChatInfoViewController: UITableViewController { case .ordinary: cell.textLabel?.text = name(for: users[usersArray[indexPath.row]]) } - + cell.selectionStyle = .none return cell } @@ -143,9 +146,9 @@ class ChatInfoViewController: UITableViewController { func editName(for cell: UITableViewCell){ - let alert = UIAlertController(title: "Вы уверены?", message: "Название:", preferredStyle: .alert) + let alert = UIAlertController(title: "Are you sure?", message: "Title:", preferredStyle: .alert) - let action1 = UIAlertAction(title: "Oтмена", style: .cancel, handler: nil) + let action1 = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) alert.addTextField { [weak self] (tf) in tf.textColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1) @@ -194,10 +197,28 @@ class ChatInfoViewController: UITableViewController { case .admin: showUserChoiceVC() default: - break + showParticipantPage(with: usersArray[indexPath.row]) } } } + + + if indexPath.section == 2 && indexPath.row != 0 { + switch myPermissions{ + case .admin: + showParticipantPage(with: usersArray[indexPath.row-1]) + default: + showParticipantPage(with: usersArray[indexPath.row]) + } + } + } + + var onUserDiplay: ((Int)->())? + + func showParticipantPage(with user: Int?) { + if let user = user { + onUserDiplay?(user) + } } func showUserChoiceVC() diff --git a/GDproject/Controller/Messages/Dialog/DialogViewController.swift b/GDproject/Controller/Messages/Dialog/DialogViewController.swift index c0de30d..20696d8 100644 --- a/GDproject/Controller/Messages/Dialog/DialogViewController.swift +++ b/GDproject/Controller/Messages/Dialog/DialogViewController.swift @@ -223,6 +223,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat vc.delegate = self vc.users = users! + vc.onUserDiplay = onUserDisplay if let groupChat = groupChat { vc.groupChat = groupChat.group @@ -314,7 +315,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat var canBePaginated = false func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { - if indexPath.row == cellData.count - 1 && prevLast != indexPath.row && canBePaginated + if indexPath.row == cellData.count - 1 && prevLast != indexPath.row && canBePaginated && cellData.count >= 9 { print("exclusiveFrom \(currentMessagesInChat.last?.id ?? 0)") if let dialog = dialog diff --git a/GDproject/Controller/Messages/MessageViewCell.swift b/GDproject/Controller/Messages/MessageViewCell.swift new file mode 100644 index 0000000..5d180b3 --- /dev/null +++ b/GDproject/Controller/Messages/MessageViewCell.swift @@ -0,0 +1,38 @@ +// +// MessageViewCell.swift +// GDproject +// +// Created by cstore on 13/05/2019. +// Copyright © 2019 drHSE. All rights reserved. +// + +import UIKit + +class MessageViewCell: UITableViewCell { + + @IBOutlet weak var dialogName: UILabel! + + @IBOutlet weak var lastMessagePreview: UILabel! + + @IBOutlet weak var dateLabel: UILabel! + + override func awakeFromNib() { + super.awakeFromNib() + // Initialization code + } + + func fill(with dialog: Model.Dialog, user: Model.Users? = nil) + { + switch dialog { + + case .groupChat(let group): + dialogName.text = group.group.name + lastMessagePreview.text = group.lastMessage?.body.markdown + dateLabel.text = group.lastMessage?.time.getDate() + case .userChat(let userChat): + dialogName.text = "👤 \(user!.fullName())" + lastMessagePreview.text = userChat.lastMessage?.body.markdown + dateLabel.text = userChat.lastMessage?.time.getDate() + } + } +} diff --git a/GDproject/Controller/Messages/MessagesViewController.swift b/GDproject/Controller/Messages/MessagesViewController.swift index 60f7007..e07a820 100644 --- a/GDproject/Controller/Messages/MessagesViewController.swift +++ b/GDproject/Controller/Messages/MessagesViewController.swift @@ -64,18 +64,15 @@ class MessagesViewController: UITableViewController { override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: "MessagesCell", for: indexPath) + let cell = tableView.dequeueReusableCell(withIdentifier: "MessageViewCell", for: indexPath) as! MessageViewCell switch currentActiveDialogs[indexPath.row].self { - - case .groupChat(let group): - cell.textLabel?.text = group.group.name - cell.detailTextLabel?.text = group.lastMessage?.body.markdown + case .groupChat: + cell.fill(with: currentActiveDialogs[indexPath.row]) case .userChat(let userChat): - cell.textLabel?.text = "👤 \(users[userChat.user]!.fullName())" - cell.detailTextLabel?.text = userChat.lastMessage?.body.markdown + cell.fill(with: currentActiveDialogs[indexPath.row], user: users[userChat.user]) } - + return cell } diff --git a/GDproject/Controller/Messages/PeopleToWriteViewController.swift b/GDproject/Controller/Messages/PeopleToWriteViewController.swift index 84cf759..cc2ec6a 100644 --- a/GDproject/Controller/Messages/PeopleToWriteViewController.swift +++ b/GDproject/Controller/Messages/PeopleToWriteViewController.swift @@ -53,7 +53,6 @@ class PeopleToWriteViewController: UITableViewController { let cell = tableView.dequeueReusableCell(withIdentifier: "peopleToWriteCell", for: indexPath) cell.textLabel?.text = users[indexPath.row].fullName() - cell.detailTextLabel?.text = "\(users[indexPath.row].id)" return cell } diff --git a/GDproject/Controller/Profile/ProfileViewController.swift b/GDproject/Controller/Profile/ProfileViewController.swift index f5ce1cf..18dbab6 100644 --- a/GDproject/Controller/Profile/ProfileViewController.swift +++ b/GDproject/Controller/Profile/ProfileViewController.swift @@ -175,20 +175,43 @@ class ProfileViewController: UIViewController, UpdateUser if idProfile == DataStorage.standard.getUserId() { let logoutAction = UIAlertAction(title: "Log out", style: .destructive) - { [weak self] - (_) in - self?.logOut?() + { [weak self] (_) in + + if let logOut = self?.logOut { + logOut() + } else { + Model.logout() { + DataStorage.standard.setIsLoggedIn(value: false, with: 0) + (UIApplication.shared.delegate as! AppDelegate).relaunch() + } + } } let deleetAllSessionsAction = UIAlertAction(title: "Delete all sessions", style: .destructive) - { [weak self] - (_) in - self?.deleteAllSessions?() + { [weak self] _ in + + if let delete = self?.deleteAllSessions { + delete() + } else { + Model.deactivateAll() { + DataStorage.standard.setIsLoggedIn(value: false, with: 0) + (UIApplication.shared.delegate as! AppDelegate).relaunch() + } + } } let settingsAction = UIAlertAction(title: "Edit profile", style: .default) { [weak self] (_) in - self?.onSettings?() + + if let settings = self?.onSettings{ + settings() + } else { + let vc = self?.storyboard?.instantiateViewController(withIdentifier: "RegisterTableViewController") as! RegisterTableViewController + vc.delegate = self + vc.userActive = self?.user + + self?.navigationController?.pushViewController(vc, animated: true) + } } optionMenu.addAction(settingsAction)