Worked on messages: infoVC is almost perfect, CGAffineTransform is done, whole design-beauty-style is left thought..

This commit is contained in:
Darya Rednikina 2019-05-06 01:25:40 +03:00
parent 6b11f20214
commit b65cc457d4
14 changed files with 582 additions and 239 deletions

View File

@ -19,6 +19,7 @@
1261BB93227B364C003898CF /* ChannelViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1261BB92227B364C003898CF /* ChannelViewController.swift */; };
1261BB95227B3991003898CF /* AddToChannelVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1261BB94227B3991003898CF /* AddToChannelVC.swift */; };
1261BB9E227B793D003898CF /* ChatInfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1261BB9D227B793D003898CF /* ChatInfoViewController.swift */; };
12758257227F1401001F291F /* DialogViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12758256227F1401001F291F /* DialogViewController.swift */; };
1288B5CE221F1158002BE6B1 /* DataStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1288B5CD221F1158002BE6B1 /* DataStorage.swift */; };
1291BE2D2221312D009D3F23 /* ChannelsCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1291BE2C2221312C009D3F23 /* ChannelsCoordinator.swift */; };
1291BE342221569B009D3F23 /* TabbarCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1291BE332221569B009D3F23 /* TabbarCoordinator.swift */; };
@ -26,8 +27,8 @@
129320042279B4270035C7B3 /* MessagesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 129320032279B4270035C7B3 /* MessagesViewController.swift */; };
129320072279B5690035C7B3 /* MessagesCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 129320062279B5690035C7B3 /* MessagesCoordinator.swift */; };
129320092279C3B50035C7B3 /* PeopleToWriteViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 129320082279C3B50035C7B3 /* PeopleToWriteViewController.swift */; };
1293200B2279D02D0035C7B3 /* DialogViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1293200A2279D02D0035C7B3 /* DialogViewController.swift */; };
1293200D2279D7310035C7B3 /* CompletionTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1293200C2279D7310035C7B3 /* CompletionTree.swift */; };
1298810B227F13840032ACA3 /* DialogCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1298810A227F13840032ACA3 /* DialogCell.swift */; };
12BA4B9B224101A400DF93D7 /* ApplicationCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12BA4B9A224101A400DF93D7 /* ApplicationCoordinator.swift */; };
12BA4B9D224101E700DF93D7 /* BaseCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12BA4B9C224101E700DF93D7 /* BaseCoordinator.swift */; };
12BA4B9F224102B700DF93D7 /* LogInCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12BA4B9E224102B700DF93D7 /* LogInCoordinator.swift */; };
@ -113,6 +114,7 @@
1261BB92227B364C003898CF /* ChannelViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelViewController.swift; sourceTree = "<group>"; };
1261BB94227B3991003898CF /* AddToChannelVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddToChannelVC.swift; sourceTree = "<group>"; };
1261BB9D227B793D003898CF /* ChatInfoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatInfoViewController.swift; sourceTree = "<group>"; };
12758256227F1401001F291F /* DialogViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DialogViewController.swift; sourceTree = "<group>"; };
1288B5CD221F1158002BE6B1 /* DataStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataStorage.swift; sourceTree = "<group>"; };
1291BE2C2221312C009D3F23 /* ChannelsCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelsCoordinator.swift; sourceTree = "<group>"; };
1291BE332221569B009D3F23 /* TabbarCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabbarCoordinator.swift; sourceTree = "<group>"; };
@ -120,8 +122,8 @@
129320032279B4270035C7B3 /* MessagesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesViewController.swift; sourceTree = "<group>"; };
129320062279B5690035C7B3 /* MessagesCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesCoordinator.swift; sourceTree = "<group>"; };
129320082279C3B50035C7B3 /* PeopleToWriteViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PeopleToWriteViewController.swift; path = GDproject/Controller/Messages/PeopleToWriteViewController.swift; sourceTree = SOURCE_ROOT; };
1293200A2279D02D0035C7B3 /* DialogViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = DialogViewController.swift; path = GDproject/Controller/Messages/DialogViewController.swift; sourceTree = SOURCE_ROOT; };
1293200C2279D7310035C7B3 /* CompletionTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompletionTree.swift; sourceTree = "<group>"; };
1298810A227F13840032ACA3 /* DialogCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DialogCell.swift; sourceTree = "<group>"; };
12BA4B9A224101A400DF93D7 /* ApplicationCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationCoordinator.swift; sourceTree = "<group>"; };
12BA4B9C224101E700DF93D7 /* BaseCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseCoordinator.swift; sourceTree = "<group>"; };
12BA4B9E224102B700DF93D7 /* LogInCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogInCoordinator.swift; sourceTree = "<group>"; };
@ -225,12 +227,21 @@
children = (
1261BB9D227B793D003898CF /* ChatInfoViewController.swift */,
129320082279C3B50035C7B3 /* PeopleToWriteViewController.swift */,
1293200A2279D02D0035C7B3 /* DialogViewController.swift */,
1298810C227F138C0032ACA3 /* Dialog */,
129320032279B4270035C7B3 /* MessagesViewController.swift */,
);
path = Messages;
sourceTree = "<group>";
};
1298810C227F138C0032ACA3 /* Dialog */ = {
isa = PBXGroup;
children = (
12758256227F1401001F291F /* DialogViewController.swift */,
1298810A227F13840032ACA3 /* DialogCell.swift */,
);
path = Dialog;
sourceTree = "<group>";
};
12E36D8F221424EA006FCDD7 = {
isa = PBXGroup;
children = (
@ -425,10 +436,10 @@
12DB7FDF221877160096878E /* InviteViewController.swift in Sources */,
121A8972226B1EAC005EE599 /* TagsSuggestionController.swift in Sources */,
1293200D2279D7310035C7B3 /* CompletionTree.swift in Sources */,
1293200B2279D02D0035C7B3 /* DialogViewController.swift in Sources */,
12E36DCA22144635006FCDD7 /* NewPostViewController.swift in Sources */,
1261BB9E227B793D003898CF /* ChatInfoViewController.swift in Sources */,
12E36D9E221424EA006FCDD7 /* NewsController.swift in Sources */,
1298810B227F13840032ACA3 /* DialogCell.swift in Sources */,
12E36DCC22144725006FCDD7 /* PostViewCell.swift in Sources */,
123E37A5221F1B3200F6E42A /* LogInViewController.swift in Sources */,
125BD57F22171D73008A3575 /* Extentions.swift in Sources */,
@ -439,6 +450,7 @@
1291BE2D2221312D009D3F23 /* ChannelsCoordinator.swift in Sources */,
12E36DD122148122006FCDD7 /* FullPostController.swift in Sources */,
129320042279B4270035C7B3 /* MessagesViewController.swift in Sources */,
12758257227F1401001F291F /* DialogViewController.swift in Sources */,
1288B5CE221F1158002BE6B1 /* DataStorage.swift in Sources */,
12BA4B9F224102B700DF93D7 /* LogInCoordinator.swift in Sources */,
12F3D6B22241097B00A69214 /* ProfileCoordinator.swift in Sources */,

View File

@ -619,12 +619,28 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="bgd-9d-SmR">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="cell3" textLabel="8Ad-wM-No8" detailTextLabel="QHM-V8-CWk" style="IBUITableViewCellStyleSubtitle" id="bgd-9d-SmR">
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="bgd-9d-SmR" id="9W4-bO-4MN">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="8Ad-wM-No8">
<rect key="frame" x="16" y="5" width="33.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="hfhhfhh" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="QHM-V8-CWk">
<rect key="frame" x="16" y="25.5" width="44.5" height="14.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
@ -641,84 +657,31 @@
<!--Chat Info View Controller-->
<scene sceneID="1br-Xg-fR9">
<objects>
<tableViewController id="Rfd-Hp-Qqv" customClass="ChatInfoViewController" customModule="GDproject" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="Rvg-ok-cnE">
<tableViewController storyboardIdentifier="ChatInfoViewController" id="Rfd-Hp-Qqv" customClass="ChatInfoViewController" customModule="GDproject" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="Rvg-ok-cnE">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<sections>
<tableViewSection headerTitle="Title" id="EwY-Ph-im0">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="hl5-Uc-R53">
<rect key="frame" x="0.0" y="55.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="hl5-Uc-R53" id="Oy5-4e-dPI">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="cell" textLabel="EdJ-of-2FG" style="IBUITableViewCellStyleDefault" id="hl5-Uc-R53">
<rect key="frame" x="0.0" y="55.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="hl5-Uc-R53" id="Oy5-4e-dPI">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="EdJ-of-2FG">
<rect key="frame" x="16" y="0.0" width="343" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="Opportunities" id="FhP-ZG-Wz1">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" textLabel="q4L-ZD-zVb" style="IBUITableViewCellStyleDefault" id="lrc-b1-1JB">
<rect key="frame" x="0.0" y="155.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="lrc-b1-1JB" id="4YN-xu-f78">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Leave chat" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="q4L-ZD-zVb">
<rect key="frame" x="16" y="0.0" width="343" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="1" green="0.14913141730000001" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="Actions" id="oLK-Mz-9rh">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="mO7-R4-T0a" style="IBUITableViewCellStyleDefault" id="6N5-8b-glu">
<rect key="frame" x="0.0" y="255.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="6N5-8b-glu" id="pKT-jH-Ur5">
<rect key="frame" x="0.0" y="0.0" width="341" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Show participants" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="mO7-R4-T0a">
<rect key="frame" x="16" y="0.0" width="324" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" textLabel="fXd-wg-rwW" style="IBUITableViewCellStyleDefault" id="VQR-WR-KA7">
<rect key="frame" x="0.0" y="299.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="VQR-WR-KA7" id="mkm-sp-LKZ">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Add participants" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="fXd-wg-rwW">
<rect key="frame" x="16" y="0.0" width="343" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<sections/>
<connections>
<outlet property="dataSource" destination="Rfd-Hp-Qqv" id="ThC-G8-che"/>
<outlet property="delegate" destination="Rfd-Hp-Qqv" id="1WG-zg-Ahf"/>

View File

@ -65,5 +65,7 @@ let dialogViewController = "DialogViewController"
let tagsSuggestionController = "TagsSuggestionController"
let chatInfoViewController = "ChatInfoViewController"
let blueSystemColor = UIColor(red: 0, green: 137/255, blue: 249/255, alpha: 0.5)

View File

@ -53,7 +53,7 @@ class ChannelViewController: UITableViewController, UpdatableName, UpdatableChan
super.viewWillAppear(animated)
tableView.reloadData()
}
// TODO: update channel
override func viewWillDisappear(_ animated: Bool) {
defer {
@ -147,7 +147,8 @@ class ChannelViewController: UITableViewController, UpdatableName, UpdatableChan
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath)
{
if editingStyle == UITableViewCell.EditingStyle.delete {
if editingStyle == UITableViewCell.EditingStyle.delete
{
if indexPath.section == 1 {
channel?.people.remove(at: indexPath.row-1)
} else {

View File

@ -53,6 +53,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, UpdateableWi
updater.delegate = self
searchController = UISearchController(searchResultsController: updater)
navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.title = "Loading ..."
tableView.refreshControl = refreshContr
// Configure Refresh Control

View File

@ -8,7 +8,6 @@
import UIKit
import Cartography
import MarkdownKit
import TinyConstraints
class PostViewCell: UITableViewCell
@ -182,7 +181,9 @@ class PostViewCell: UITableViewCell
}
@objc func displayProfile(){
onUserDisplay?(post!.authorId)
if let id = post?.authorId {
onUserDisplay?(id)
}
}
@objc func setAnonymousChannel(on button: UIButton){

View File

@ -32,14 +32,23 @@ class MessagesCoordinator: BaseCoordinator {
vc.onUserDisplayList = { [weak vc, unowned self] in
let newVC = self.storyboard.instantiateViewController(withIdentifier: peopleToWriteVC) as! PeopleToWriteViewController
// newVC.whatToDoWithSelection = {
//
// }
vc?.navigationController?.pushViewController(newVC, animated: true)
}
vc.onDialogDisplay = { [weak vc, unowned self] _ in
vc.onDialogDisplay = { [weak vc, unowned self] in
let newVC = self.storyboard.instantiateViewController(withIdentifier: dialogVC) as! DialogViewController
//newVC.currentDialog = $0
newVC.dialog = $0.dialog
newVC.users = $0.users
vc?.navigationController?.pushViewController(newVC, animated: true)
}
navigationController?.viewControllers = [vc]
}
}

View File

@ -8,87 +8,233 @@
import UIKit
/// Class for displaying chat info
///
class ChatInfoViewController: UITableViewController {
enum PersonStatus{
case admin
case ordinary
}
weak var delegate: UpdatableGroup?
var groupChat: Model.Group? {
didSet{
if let groupChat = groupChat {
usersArray = groupChat.users.map { $0.key }
}
}
}
var usersArray: [Int] = [] {
didSet {
tableView.reloadData()
}
}
var users: [Int: Model.Users] = [:]
func canIEditThisChat() -> PersonStatus
{
let myId = UserDefaults.standard.integer(forKey: UserDefaultsKeys.id.rawValue)
if let groupChatUserPermission = groupChat?.users[myId]?.isAdmin {
return groupChatUserPermission ? .admin : .ordinary
}
return .ordinary
}
var myPermissions: PersonStatus = .ordinary
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
myPermissions = canIEditThisChat()
tableView.reloadData()
switch myPermissions {
case .admin:
navigationItem.rightBarButtonItem = self.editButtonItem
default:
return
}
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 0
return 3
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 0
switch section {
case 0:
return 1
case 1:
return 1
default:
return usersArray.count + (myPermissions == .ordinary ? 0 : 1)
}
}
/*
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
// Configure the cell...
if indexPath.row == 0 {
switch indexPath.section {
case 0:
cell.textLabel?.text = groupChat!.name
return cell
case 1:
cell.textLabel?.text = "Leave chat"
cell.textLabel?.textColor = #colorLiteral(red: 1, green: 0.1491314173, blue: 0, alpha: 1)
return cell
default:
switch myPermissions{
case .admin:
cell.textLabel?.text = "Add participants"
cell.accessoryType = .disclosureIndicator
case .ordinary:
cell.textLabel?.text = name(for: users[usersArray[indexPath.row]])
}
return cell
}
}
switch myPermissions{
case .admin:
cell.textLabel?.text = name(for: users[usersArray[indexPath.row-1]])
case .ordinary:
cell.textLabel?.text = name(for: users[usersArray[indexPath.row]])
}
return cell
}
*/
private func name(for user: Model.Users?) -> String {
return "👤 \(user!.fullName())"
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?
{
switch section {
case 0:
return "Title"
case 1:
return "Opportunities"
default:
return "Participants"
}
}
/*
// Override to support conditional editing of the table view.
func editName(for cell: UITableViewCell){
let alert = UIAlertController(title: "Вы уверены?", message: "Название:", preferredStyle: .alert)
let action1 = UIAlertAction(title: "Oтмена", style: .cancel, handler: nil)
alert.addTextField { [weak self] (tf) in
tf.textColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
tf.text = self?.groupChat?.name
}
let action2 = UIAlertAction(title: "OK", style: .default) { [unowned self] _ in
let name = alert.textFields?.first?.text
cell.textLabel?.text = name
self.groupChat?.name = name!
Model.updateGroupChat(with: self.groupChat!)
self.delegate?.updateGroup(with: self.groupChat!)
}
alert.addAction(action1)
alert.addAction(action2)
present(alert, animated: true, completion: nil)
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
guard let groupChat = groupChat else {
return
}
guard let cell = tableView.cellForRow(at: indexPath) else {
return
}
if indexPath.row == 0 {
switch indexPath.section{
case 0:
switch myPermissions{
case .admin:
editName(for: cell)
default:
break
}
case 1:
Model.leaveGroupChat(id: groupChat.id) {
[weak self] in
self?.navigationController?.popViewController(animated: true)
}
default:
showUserChoiceVC()
}
}
}
func showUserChoiceVC()
{
let vc = storyboard?.instantiateViewController(withIdentifier: peopleToWriteVC) as! PeopleToWriteViewController
vc.whatToDoWithSelection = { [weak self, weak vc] mapa in
mapa.forEach { self?.users[$0.key] = Model.Channels.fullPeopleDict[$0.key] }
mapa.forEach { self?.groupChat?.users[$0.key] = $0.value }
vc?.navigationController?.popViewController(animated: true)
}
navigationController?.pushViewController(vc, animated: true)
}
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath)
{
if editingStyle == UITableViewCell.EditingStyle.delete {
groupChat?.users[usersArray[indexPath.row-1]] = nil
}
tableView.reloadData()
}
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
if indexPath.row == 0 {
return false
}
return true
}
*/
/*
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
/// update chatInfo
override func viewWillDisappear(_ animated: Bool) {
defer {
super.viewWillDisappear(animated)
}
guard let _ = self.navigationController?.viewControllers.lastIndex(of: self) else {
switch myPermissions {
case .ordinary:
return
case .admin:
Model.updateGroupChat(with: groupChat!)
delegate?.updateGroup(with: groupChat!)
}
return
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the item to be re-orderable.
return true
}
*/
/*
// MARK: - Navigation
// 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.destination.
// Pass the selected object to the new view controller.
}
*/
}

View File

@ -0,0 +1,93 @@
//
// DialogCell.swift
// GDproject
//
// Created by cstore on 05/05/2019.
// Copyright © 2019 drHSE. All rights reserved.
//
import UIKit
import TinyConstraints
import MarkdownKit
class DialogCell: UITableViewCell {
let nameLabel: UIButton = {
let button = UIButton()
button.setTitleColor(.black, for: .normal)
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16)
button.addTarget(self, action: #selector(displayProfile), for: .touchUpInside)
button.contentHorizontalAlignment = UIControl.ContentHorizontalAlignment.left
return button
}()
@objc func displayProfile()
{
if let id = self.user?.id{
onUserDisplay?(id)
}
}
var onUserDisplay: ((Int)->())?
let fullNameLabel: UILabel = {
let label = UILabel()
label.textColor = #colorLiteral(red: 0.3333333433, green: 0.3333333433, blue: 0.3333333433, alpha: 1)
label.text = "Богомазова Вероника Львовна"
label.font = UIFont.systemFont(ofSize: 12)
return label
}()
let timeLabel: UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: 12)
label.textColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1)
return label
}()
func createTextView(with text: NSAttributedString, _ isSelectable: Bool) -> UITextView
{
let textView = UITextView()
textView.isScrollEnabled = false
textView.isEditable = false
if isSelectable {
textView.isSelectable = true
} else {
textView.isUserInteractionEnabled = false
}
textView.attributedText = text
return textView
}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?)
{
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
required init?(coder aDecoder: NSCoder)
{
fatalError("init(coder:) has not been implemented")
}
var user: Model.Users? {
didSet{
nameLabel.setTitle(user!.fullName(), for: .normal)
}
}
func fill(with markdownText: NSAttributedString, byUser: Model.Users)
{
// important
contentView.subviews.forEach({ $0.removeFromSuperview() })
self.user = byUser
let textView = createTextView(with: markdownText, true)
self.contentView.addSubview(nameLabel)
self.contentView.addSubview(textView)
nameLabel.edgesToSuperview(excluding: .bottom, insets: .top(8) + .left(8))
textView.edgesToSuperview(excluding: .top, insets: .right(8) + .left(8) + .bottom(8))
textView.topToBottom(of: nameLabel)
}
}

View File

@ -0,0 +1,145 @@
//
// DialogViewController.swift
// GDproject
//
// Created by cstore on 01/05/2019.
// Copyright © 2019 drHSE. All rights reserved.
//
import UIKit
protocol UpdatableGroup:class {
func updateGroup(with group: Model.Group)
}
class DialogViewController: UITableViewController, UpdatableGroup {
func updateGroup(with group: Model.Group){
self.groupChat?.group = group
setTitleForGroup(groupChat: groupChat!)
}
let cellId = "cell3"
var onInfoShow: (()->())?
var dialog: Model.Dialog? {
didSet{
switch dialog! {
case .groupChat(let chat):
self.groupChat = chat
case .userChat(let chat):
self.userChat = chat
}
}
}
var groupChat: Model.GroupChat?
var userChat: Model.UserChat?
var users: [Int: Model.Users]?
var groupId: Int?
var cellData: [PostCellData] = [] {
didSet {
print(cellData)
tableView.reloadData()
}
}
override func viewDidLoad() {
super.viewDidLoad()
tabBarController?.tabBar.isHidden = true
navigationItem.largeTitleDisplayMode = .never
tableView.register(DialogCell.self, forCellReuseIdentifier: cellId)
tableView.transform = CGAffineTransform(scaleX: 1, y: -1)
tableView.contentInsetAdjustmentBehavior = .never
tableView.contentOffset = CGPoint(x: 0, y: -30)
if let groupChat = groupChat {
setTitleForGroup(groupChat: groupChat)
} else if let userChat = userChat{
setTitleForChat(userChat: userChat)
}
}
func setTitleForChat(userChat: Model.UserChat){
navigationItem.title = "🌌 \(users![userChat.user]!.fullName())"
}
func setTitleForGroup(groupChat: Model.GroupChat){
navigationItem.title = "🌌 \(groupChat.group.id) \(groupChat.group.name)"
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Info", style: .plain, target: self, action: #selector(moveToInfoVC))
}
@objc func moveToInfoVC(){
let vc = storyboard?.instantiateViewController(withIdentifier: chatInfoViewController) as! ChatInfoViewController
vc.delegate = self
vc.users = users!
if let groupChat = groupChat {
vc.groupChat = groupChat.group
}
navigationController?.pushViewController(vc, animated: true)
}
var currentMessagesInChat: [Model.LastMessage]? {
didSet {
if let currentMessagesInChat = currentMessagesInChat {
cellData = currentMessagesInChat.map { PostCellData(attributedData: PostCellData.create(with: [$0.body])) }
}
}
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return cellData.count
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let dialog = dialog {
getMessages(for: dialog)
}
}
func getMessages(for dialog: Model.Dialog){
switch dialog {
case .groupChat(let groupChat):
Model.getMessagesFor(typeOfChat: Model.Dialog.groupChat(groupChat), chat: groupChat.group.id)
{ [unowned self] in
self.currentMessagesInChat = $0
}
case .userChat(let userChat):
Model.getMessagesFor(typeOfChat: Model.Dialog.userChat(userChat), chat: userChat.user)
{ [unowned self] in
self.currentMessagesInChat = $0
}
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! DialogCell
//In cellForRowAtIndexPath
cell.transform = CGAffineTransform(scaleX: 1, y: -1)
if let author = currentMessagesInChat?[indexPath.row].author, let user = users?[author]
{
cell.fill(with: cellData[indexPath.row].attributedData, byUser: user)
}
return cell
}
}

View File

@ -1,67 +0,0 @@
//
// DialogViewController.swift
// GDproject
//
// Created by cstore on 01/05/2019.
// Copyright © 2019 drHSE. All rights reserved.
//
import UIKit
class DialogViewController: UITableViewController {
var onInfoShow: (()->())?
var group: Model.Group?
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
if let id = group {
navigationItem.title = "🌌 \(id.id) \(id.name)"
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Info", style: .plain, target: self, action: #selector(moveToInfoVC))
}
}
@objc func moveToInfoVC(){
}
var currentMessagesInChat: [Model.LastMessage]? {
didSet {
tableView.reloadData()
}
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return currentMessagesInChat?.count ?? 0
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let group = group {
Model.getMessagesForGroupChat(chat: group.id) { [unowned self] in
self.currentMessagesInChat = $0
}
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.detailTextLabel?.text = currentMessagesInChat![indexPath.row].body.markdown
cell.textLabel?.text = "\(currentMessagesInChat![indexPath.row].author)"
return cell
}
}

View File

@ -12,14 +12,17 @@ class MessagesViewController: UITableViewController {
// curreent Active which can be displayed
var currentActiveDialogs: [Model.Dialog] = [] {
didSet{
didSet {
tableView.reloadData()
}
}
// curreent users
var users: [Int: Model.Users] = [:]
var onUserDisplayList: (()->())?
var onDialogDisplay: ((Model.Dialog)->())?
var onDialogDisplay: (((dialog: Model.Dialog, users: [Int:Model.Users]))->())?
let searchC = UISearchController(searchResultsController: nil)
@ -42,9 +45,10 @@ class MessagesViewController: UITableViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
tabBarController?.tabBar.isHidden = false
Model.getChatAll { [weak self] in
self?.currentActiveDialogs = $0
self?.currentActiveDialogs = $0.0
self?.users = $0.1
}
}
@ -67,7 +71,7 @@ class MessagesViewController: UITableViewController {
cell.textLabel?.text = group.group.name
cell.detailTextLabel?.text = group.lastMessage.body.markdown
case .userChat(let userChat):
cell.textLabel?.text = "\(userChat.user)"
cell.textLabel?.text = "\(users[userChat.user]!)"
cell.detailTextLabel?.text = userChat.lastMessage.body.markdown
}
@ -75,6 +79,7 @@ class MessagesViewController: UITableViewController {
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
onDialogDisplay?(currentActiveDialogs[indexPath.row])
let tuple = (currentActiveDialogs[indexPath.row],users)
onDialogDisplay?(tuple)
}
}

View File

@ -10,7 +10,8 @@ import UIKit
class PeopleToWriteViewController: UITableViewController {
// TODO: - edit button when it's used for selection
// TODO: - edit button when it's used for selection
var whatToDoWithSelection: (([Int: Model.UserPermission])->())?
let searchC = UISearchController(searchResultsController: nil)
@ -23,7 +24,9 @@ class PeopleToWriteViewController: UITableViewController {
tableView.isEditing = true
self.navigationItem.title = "People"
self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(newMessage))
self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(newMessage))
self.navigationItem.largeTitleDisplayMode = .never
self.navigationItem.searchController = searchC
self.navigationItem.hidesSearchBarWhenScrolling = false
@ -32,15 +35,12 @@ class PeopleToWriteViewController: UITableViewController {
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(true, animated: animated)
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return users.count
}
@ -62,15 +62,7 @@ class PeopleToWriteViewController: UITableViewController {
{
if chosenUsers.count != 0
{
navigationController?.popViewController(animated: false)
var group = Model.Group(users: chosenUsers, name: "Untitled", id: 0)
Model.createGroupChat(from: group) { [unowned self] (id) in
let vc = self.storyboard?.instantiateViewController(withIdentifier: dialogViewController) as! DialogViewController
group.id = id
vc.group = group
self.navigationController?.pushViewController(vc, animated: true)
}
whatToDoWithSelection?(chosenUsers)
}
}
}

View File

@ -40,7 +40,7 @@ class Model{
static let channelsDeleteURL = URL(string: "\(baseUrl)/channels/delete")!
static let channelsGetAnonURL = URL(string: "\(baseUrl)/channels/getAnonymous")!
static let complexURL = URL(string: "\(baseUrl)/complex")!
static let hashTagTreeURL = URL(string: "\(baseUrl)/tagCompletions")!
static let hashTagTreeURL = URL(string: "\(baseUrl)/tags/completions")!
static let createGroupChatURL = URL(string: "\(baseUrl)/chats/createGroupChat")!
static let chatsGetAllURL = URL(string: "\(baseUrl)/chats/getAll")!
static let getGroupChatURL = URL(string: "\(baseUrl)/chats/getGroupChat")!
@ -48,7 +48,7 @@ class Model{
static let updateGroupChatURL = URL(string: "\(baseUrl)/chats/updateGroupChat")!
static let messagesGetGroupChatURL = URL(string: "\(baseUrl)/messages/get/groupChat")! //r
static let messagesSendURL = URL(string: "\(baseUrl)/messages/send")!
static let messagesUserChatURL = URL(string: "\(baseUrl)/messages/userChat")!
static let messagesGetUserChatURL = URL(string: "\(baseUrl)/messages/get/userChat")!
struct QueryPosts<T: Codable>: Codable {
@ -559,7 +559,7 @@ class Model{
}
}
static func getChatAll(limit: Int = 10, exclusiveFrom: Int? = nil, request: [Int] = [], completion: @escaping (([Dialog])->()))
static func getChatAll(limit: Int = 10, exclusiveFrom: Int? = nil, request: [Int] = [], completion: @escaping ((([Dialog],[Int:Model.Users]))->()))
{
let req = GeneralRequest<[Int]>(limit: limit, exclusiveFrom: exclusiveFrom, request: request)
var request = URLRequest(url: chatsGetAllURL)
@ -573,8 +573,7 @@ class Model{
guard let json = response.data else { return }
let dialogs = try! decoder.decode(QueryPosts<Dialog>.self, from: json)
print(dialogs.response)
completion(dialogs.response)
completion((dialogs.response,dialogs.users))
}
}
@ -624,6 +623,12 @@ class Model{
var users: [Int: UserPermission]
var name: String
var id: Int
init(users: [Int: UserPermission] = [:], name: String = "", id: Int) {
self.id = id
self.users = users
self.name = name
}
}
struct UserPermission: Codable {
@ -734,16 +739,23 @@ class Model{
}
}
static func getMessagesForGroupChat(chat id: Int, exclusiveFrom: Int? = nil, limit l: Int = 10, direction: String = "backward", completion: @escaping (([LastMessage])->()))
static func getMessagesFor(typeOfChat: Model.Dialog, chat id: Int, exclusiveFrom: Int? = nil, limit l: Int = 10, direction: String = "backward", completion: @escaping (([LastMessage])->()))
{
let req = GeneralRequest<Int>(direction: direction, limit: l, exclusiveFrom: exclusiveFrom, request: id)
var request: URLRequest?
var request = URLRequest(url: messagesGetGroupChatURL)
request.httpMethod = "POST"
request.httpBody = try? JSONEncoder().encode(req)
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
switch typeOfChat {
case .groupChat:
request = URLRequest(url: messagesGetGroupChatURL)
case .userChat:
request = URLRequest(url: messagesGetUserChatURL)
}
AF.request(request).response { (response) in
request!.httpMethod = "POST"
request!.httpBody = try? JSONEncoder().encode(req)
request!.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
AF.request(request!).response { (response) in
isValidTocken?(response.response?.statusCode ?? 498)
@ -753,4 +765,32 @@ class Model{
completion(messages)
}
}
static func leaveGroupChat(id: Int, completion: @escaping (()->()))
{
var request = URLRequest(url: leaveGroupChatURL)
request.httpMethod = "POST"
request.httpBody = "\(id)".data(using: .utf8)
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
AF.request(request).response { (response) in
isValidTocken?(response.response?.statusCode ?? 498)
}
completion()
}
static func updateGroupChat(with group: Model.Group)
{
var request = URLRequest(url: updateGroupChatURL)
request.httpMethod = "POST"
request.httpBody = try? JSONEncoder().encode(group)
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
AF.request(request).response { (response) in
isValidTocken?(response.response?.statusCode ?? 498)
}
// completion()
}
}