git.iko.soy/dashared/GDproject
on master help sign in
27 files changed+742−165
since splitsnapshots
unifiedsplit
GDproject.xcodeproj/project.pbxproj+4 GDproject/Base.lproj/Main.storyboard+44−27 GDproject/Controller/ News and channels/ChannelController.swift+1−1 GDproject/Controller/ News and channels/ChannelListController.swift+2−2 GDproject/Controller/ News and channels/ChannelViewController.swift+8−3 GDproject/Controller/ News and channels/FullPostController.swift+1−18 GDproject/Controller/ News and channels/NewPostViewController.swift+26−8 GDproject/Controller/ News and channels/NewsController.swift+3−1 GDproject/Controller/ News and channels/NewsVC.swift+3−1 GDproject/Controller/ News and channels/PostViewCell.swift+2−1 GDproject/Controller/Coordinators/LogInCoordinator.swift+2−1 GDproject/Controller/Coordinators/ProfileCoordinator.swift+15−13 GDproject/Controller/Log In/CodeViewController.swift+47−8 GDproject/Controller/Log In/FacultyTableViewController.swift+1 GDproject/Controller/Log In/LogInViewController.swift+26−1 GDproject/Controller/Log In/RegisterTableViewController.swift+60−7 GDproject/Controller/Messages/ChatInfoViewController.swift+25−4 GDproject/Controller/Messages/Dialog/DialogViewController.swift+17−7 GDproject/Controller/Messages/MessageViewCell.swift+38 GDproject/Controller/Messages/MessagesViewController.swift+107−12 GDproject/Controller/Messages/PeopleToWriteViewController.swift−1 GDproject/Controller/Profile/BasicInfoController.swift+16−11 GDproject/Controller/Profile/InfoCell.swift+2−1 GDproject/Controller/Profile/ProfileViewController.swift+88−23 GDproject/DataStorage.swift+8 GDproject/Extentions.swift+30 GDproject/Simple model/Model.swift+166−14
GDproject.xcodeproj/project.pbxproj+4
@@ -10,6 +10,7 @@
1010 1210A0BB223940310080686D /* SimplifiedChannelsList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1210A0BA223940310080686D /* SimplifiedChannelsList.swift */; };
1111 121A8972226B1EAC005EE599 /* TagsSuggestionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 121A8971226B1EAC005EE599 /* TagsSuggestionController.swift */; };
1212 1220FF94227C41270092C6BC /* TaggsSelectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1220FF93227C41270092C6BC /* TaggsSelectionViewController.swift */; };
13+ 123589FD22899339002F8028 /* MessageViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123589FC22899339002F8028 /* MessageViewCell.swift */; };
1314 123E37A5221F1B3200F6E42A /* LogInViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123E37A4221F1B3200F6E42A /* LogInViewController.swift */; };
1415 123E37A7221F1DD700F6E42A /* MainController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123E37A6221F1DD700F6E42A /* MainController.swift */; };
1516 124CC7032221C00C009DF531 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 124CC7022221C00C009DF531 /* Model.swift */; };
@@ -108,6 +109,7 @@
108109 1210A0BA223940310080686D /* SimplifiedChannelsList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimplifiedChannelsList.swift; sourceTree = "<group>"; };
109110 121A8971226B1EAC005EE599 /* TagsSuggestionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagsSuggestionController.swift; sourceTree = "<group>"; };
110111 1220FF93227C41270092C6BC /* TaggsSelectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggsSelectionViewController.swift; sourceTree = "<group>"; };
112+ 123589FC22899339002F8028 /* MessageViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageViewCell.swift; sourceTree = "<group>"; };
111113 123E37A4221F1B3200F6E42A /* LogInViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogInViewController.swift; sourceTree = "<group>"; };
112114 123E37A6221F1DD700F6E42A /* MainController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainController.swift; sourceTree = "<group>"; };
113115 124CC7022221C00C009DF531 /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = "<group>"; };
@@ -238,6 +240,7 @@
238240 129320082279C3B50035C7B3 /* PeopleToWriteViewController.swift */,
239241 1298810C227F138C0032ACA3 /* Dialog */,
240242 129320032279B4270035C7B3 /* MessagesViewController.swift */,
243+ 123589FC22899339002F8028 /* MessageViewCell.swift */,
241244 );
242245 path = Messages;
243246 sourceTree = "<group>";
@@ -451,6 +454,7 @@
451454 1298810B227F13840032ACA3 /* DialogCell.swift in Sources */,
452455 125A9A922286100800513E2A /* FacultyTableViewController.swift in Sources */,
453456 125A9A8E2286068A00513E2A /* RegisterTableViewController.swift in Sources */,
457+ 123589FD22899339002F8028 /* MessageViewCell.swift in Sources */,
454458 12E36DCC22144725006FCDD7 /* PostViewCell.swift in Sources */,
455459 123E37A5221F1B3200F6E42A /* LogInViewController.swift in Sources */,
456460 125BD57F22171D73008A3575 /* Extentions.swift in Sources */,
GDproject/Base.lproj/Main.storyboard+44−27
@@ -248,37 +248,37 @@
248248 <stackView opaque="NO" contentMode="scaleToFill" spacing="12" translatesAutoresizingMaskIntoConstraints="NO" id="2Gj-pC-RZ2">
249249 <rect key="frame" x="37.5" y="99" width="300" height="58"/>
250250 <subviews>
251− <textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="_" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="744-t1-YNn">
251+ <textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="_" textAlignment="center" adjustsFontSizeToFit="NO" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="744-t1-YNn">
252252 <rect key="frame" x="0.0" y="0.0" width="40" height="58"/>
253253 <nil key="textColor"/>
254254 <fontDescription key="fontDescription" type="system" pointSize="45"/>
255255 <textInputTraits key="textInputTraits" keyboardType="numberPad"/>
256256 </textField>
257− <textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="_" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="jcR-jp-s7a">
257+ <textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="_" textAlignment="center" adjustsFontSizeToFit="NO" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="jcR-jp-s7a">
258258 <rect key="frame" x="52" y="0.0" width="40" height="58"/>
259259 <nil key="textColor"/>
260260 <fontDescription key="fontDescription" type="system" pointSize="45"/>
261261 <textInputTraits key="textInputTraits" keyboardType="numberPad"/>
262262 </textField>
263− <textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="_" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="YKO-0M-KD8">
263+ <textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="_" textAlignment="center" adjustsFontSizeToFit="NO" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="YKO-0M-KD8">
264264 <rect key="frame" x="104" y="0.0" width="40" height="58"/>
265265 <nil key="textColor"/>
266266 <fontDescription key="fontDescription" type="system" pointSize="45"/>
267267 <textInputTraits key="textInputTraits" keyboardType="numberPad"/>
268268 </textField>
269− <textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="_" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="SmG-Ae-oOs">
269+ <textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="_" textAlignment="center" adjustsFontSizeToFit="NO" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="SmG-Ae-oOs">
270270 <rect key="frame" x="156" y="0.0" width="40" height="58"/>
271271 <nil key="textColor"/>
272272 <fontDescription key="fontDescription" type="system" pointSize="45"/>
273273 <textInputTraits key="textInputTraits" keyboardType="numberPad"/>
274274 </textField>
275− <textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="_" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="vaP-rO-NZW">
275+ <textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="_" textAlignment="center" adjustsFontSizeToFit="NO" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="vaP-rO-NZW">
276276 <rect key="frame" x="208" y="0.0" width="40" height="58"/>
277277 <nil key="textColor"/>
278278 <fontDescription key="fontDescription" type="system" pointSize="45"/>
279279 <textInputTraits key="textInputTraits" keyboardType="numberPad"/>
280280 </textField>
281− <textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="_" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="qDh-32-HSn">
281+ <textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="_" textAlignment="center" adjustsFontSizeToFit="NO" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="qDh-32-HSn">
282282 <rect key="frame" x="260" y="0.0" width="40" height="58"/>
283283 <nil key="textColor"/>
284284 <fontDescription key="fontDescription" type="system" pointSize="45"/>
@@ -778,29 +778,53 @@
778778 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
779779 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
780780 <prototypes>
781− <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="MessagesCell" textLabel="9br-gb-mg8" detailTextLabel="Jxd-We-VyC" style="IBUITableViewCellStyleSubtitle" id="67C-fT-WEV">
782− <rect key="frame" x="0.0" y="28" width="375" height="44"/>
781+ <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="MessageViewCell" rowHeight="78" id="67C-fT-WEV" customClass="MessageViewCell" customModule="GDproject" customModuleProvider="target">
782+ <rect key="frame" x="0.0" y="28" width="375" height="78"/>
783783 <autoresizingMask key="autoresizingMask"/>
784784 <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="67C-fT-WEV" id="O3b-Xv-UNk">
785− <rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
785+ <rect key="frame" x="0.0" y="0.0" width="375" height="77.5"/>
786786 <autoresizingMask key="autoresizingMask"/>
787787 <subviews>
788− <label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="9br-gb-mg8">
789− <rect key="frame" x="16" y="5" width="33.5" height="20.5"/>
790− <autoresizingMask key="autoresizingMask"/>
791− <fontDescription key="fontDescription" type="system" pointSize="17"/>
788+ <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="xAY-IF-RpX">
789+ <rect key="frame" x="229" y="11" width="130" height="15"/>
790+ <constraints>
791+ <constraint firstAttribute="width" relation="greaterThanOrEqual" constant="130" id="f99-ZF-f8h"/>
792+ </constraints>
793+ <fontDescription key="fontDescription" type="system" pointSize="12"/>
794+ <color key="textColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
795+ <nil key="highlightedColor"/>
796+ </label>
797+ <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="FG3-gU-0r1">
798+ <rect key="frame" x="16" y="11" width="46" height="22"/>
799+ <fontDescription key="fontDescription" type="system" weight="semibold" pointSize="18"/>
792800 <nil key="textColor"/>
793801 <nil key="highlightedColor"/>
794802 </label>
795− <label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Detail" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Jxd-We-VyC">
796− <rect key="frame" x="16" y="25.5" width="33" height="14.5"/>
797− <autoresizingMask key="autoresizingMask"/>
798− <fontDescription key="fontDescription" type="system" pointSize="12"/>
803+ <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="nTy-rK-XTr">
804+ <rect key="frame" x="16" y="49" width="343" height="18"/>
805+ <fontDescription key="fontDescription" type="system" pointSize="15"/>
799806 <nil key="textColor"/>
800807 <nil key="highlightedColor"/>
801808 </label>
802809 </subviews>
810+ <constraints>
811+ <constraint firstItem="nTy-rK-XTr" firstAttribute="top" secondItem="xAY-IF-RpX" secondAttribute="bottom" constant="23" id="09Y-aK-nD9"/>
812+ <constraint firstItem="FG3-gU-0r1" firstAttribute="top" secondItem="O3b-Xv-UNk" secondAttribute="topMargin" id="4Hp-d5-9An"/>
813+ <constraint firstItem="xAY-IF-RpX" firstAttribute="top" secondItem="O3b-Xv-UNk" secondAttribute="topMargin" id="G4f-oJ-7ud"/>
814+ <constraint firstItem="nTy-rK-XTr" firstAttribute="trailing" secondItem="O3b-Xv-UNk" secondAttribute="trailingMargin" id="MaE-VM-KhL"/>
815+ <constraint firstItem="nTy-rK-XTr" firstAttribute="leading" secondItem="O3b-Xv-UNk" secondAttribute="leadingMargin" id="OIX-rY-Leo"/>
816+ <constraint firstItem="nTy-rK-XTr" firstAttribute="top" secondItem="FG3-gU-0r1" secondAttribute="bottom" constant="16" id="Qdj-s3-t60"/>
817+ <constraint firstItem="nTy-rK-XTr" firstAttribute="bottom" secondItem="O3b-Xv-UNk" secondAttribute="bottomMargin" id="Rv3-Mz-Aed"/>
818+ <constraint firstItem="FG3-gU-0r1" firstAttribute="leading" secondItem="O3b-Xv-UNk" secondAttribute="leadingMargin" id="iN1-KG-dYn"/>
819+ <constraint firstItem="xAY-IF-RpX" firstAttribute="trailing" secondItem="O3b-Xv-UNk" secondAttribute="trailingMargin" id="opV-4x-VCk"/>
820+ <constraint firstItem="xAY-IF-RpX" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="FG3-gU-0r1" secondAttribute="trailing" constant="4" id="x9r-sM-t4x"/>
821+ </constraints>
803822 </tableViewCellContentView>
823+ <connections>
824+ <outlet property="dateLabel" destination="xAY-IF-RpX" id="fcz-re-BXk"/>
825+ <outlet property="dialogName" destination="FG3-gU-0r1" id="gd7-ND-wCi"/>
826+ <outlet property="lastMessagePreview" destination="nTy-rK-XTr" id="Cmo-IJ-2r0"/>
827+ </connections>
804828 </tableViewCell>
805829 </prototypes>
806830 <connections>
@@ -811,7 +835,7 @@
811835 </tableViewController>
812836 <placeholder placeholderIdentifier="IBFirstResponder" id="fu3-z4-EY7" userLabel="First Responder" sceneMemberID="firstResponder"/>
813837 </objects>
814− <point key="canvasLocation" x="2798" y="932"/>
838+ <point key="canvasLocation" x="2681" y="918"/>
815839 </scene>
816840 <!--People To Write View Controller-->
817841 <scene sceneID="6Td-bq-Ebf">
@@ -822,7 +846,7 @@
822846 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
823847 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
824848 <prototypes>
825− <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="peopleToWriteCell" textLabel="e4H-yo-W57" detailTextLabel="QSb-Bd-4gu" style="IBUITableViewCellStyleValue1" id="5ue-Sf-Blf">
849+ <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="peopleToWriteCell" textLabel="e4H-yo-W57" style="IBUITableViewCellStyleDefault" id="5ue-Sf-Blf">
826850 <rect key="frame" x="0.0" y="28" width="375" height="44"/>
827851 <autoresizingMask key="autoresizingMask"/>
828852 <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="5ue-Sf-Blf" id="8Dr-YE-x7M">
@@ -830,14 +854,7 @@
830854 <autoresizingMask key="autoresizingMask"/>
831855 <subviews>
832856 <label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="e4H-yo-W57">
833− <rect key="frame" x="16" y="12" width="33.5" height="20.5"/>
834− <autoresizingMask key="autoresizingMask"/>
835− <fontDescription key="fontDescription" type="system" pointSize="17"/>
836− <nil key="textColor"/>
837− <nil key="highlightedColor"/>
838− </label>
839− <label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="QSb-Bd-4gu">
840− <rect key="frame" x="315" y="12" width="44" height="20.5"/>
857+ <rect key="frame" x="16" y="0.0" width="343" height="43.5"/>
841858 <autoresizingMask key="autoresizingMask"/>
842859 <fontDescription key="fontDescription" type="system" pointSize="17"/>
843860 <nil key="textColor"/>
GDproject/Controller/ News and channels/ChannelController.swift+1−1
@@ -73,7 +73,7 @@ class ChannelController: UIViewController, UITableViewDelegate, UITableViewDataS
7373 if let _ = channel?.id { print("update")
7474 Model.updateChannel(with: channel!)
7575 } else { print("create")
76− Model.createChannel(with: channel!)
76+ //Model.createChannel(with: channel!)
7777 }
7878 return
7979 }
GDproject/Controller/ News and channels/ChannelListController.swift+2−2
@@ -30,7 +30,7 @@ class ChannelListController: UITableViewController {
3030 var displayingChannel: Model.Channels?
3131
3232 var toReload: Bool = false {
33− didSet{
33+ didSet {
3434 tableView.reloadData()
3535 }
3636 }
@@ -100,7 +100,7 @@ class ChannelListController: UITableViewController {
100100 @objc func addChannel()
101101 {
102102 // editing mode is on automatically
103− onEditingModeBegins?(Model.Channels(people: [], name: "Untitled", tags: []),IndexPath(row: 1, section: 0))
103+ onEditingModeBegins?(Model.Channels(people: [], name: "Untitled", id: 0, tags: []),IndexPath(row: 1, section: 0))
104104 }
105105
106106 static let generalChannel = Model.Channels(people: [], name: "General", id: -1, tags: [])
GDproject/Controller/ News and channels/ChannelViewController.swift+8−3
@@ -60,12 +60,17 @@ class ChannelViewController: UITableViewController, UpdatableName, UpdatableChan
6060 super.viewWillDisappear(animated)
6161 }
6262
63− guard let _ = self.navigationController?.viewControllers.lastIndex(of: self) else {
64− if let _ = channel?.id
63+ guard let _ = self.navigationController?.viewControllers.lastIndex(of: self) else
64+ {
65+ if let id = channel?.id, id != 0
6566 {
6667 Model.updateChannel(with: channel!)
6768 } else {
68− Model.createChannel(with: channel!)
69+ Model.createChannel(with: channel!) {
70+ [weak self] in
71+ self?.showAlertOn(result: $0)
72+ return
73+ }
6974 }
7075 return
7176 }
GDproject/Controller/ News and channels/FullPostController.swift+1−18
@@ -26,26 +26,9 @@ class FullPostController: UITableViewController {
2626 func setUpNavigationBar(){
2727 navigationItem.largeTitleDisplayMode = .never
2828 navigationItem.title = "Post"
29− navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(self.options))]
3029 }
3130
32− @objc func options(){
33− // drafts
34− // saved
35−
36− let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
37− let editAction = UIAlertAction(title: "Send via message", style: .default)
38− let shareAction = UIAlertAction(title: "Send via project", style: .default)
39− let settingsAction = UIAlertAction(title: "Copy link", style: .default)
40− let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
41−
42− optionMenu.addAction(editAction)
43− optionMenu.addAction(shareAction)
44− optionMenu.addAction(settingsAction)
45− optionMenu.addAction(cancelAction)
46−
47− self.present(optionMenu, animated: true, completion: nil)
48− }
31+
4932 // MARK: - Table view data source
5033
5134 override func numberOfSections(in tableView: UITableView) -> Int {
GDproject/Controller/ News and channels/NewPostViewController.swift+26−8
@@ -41,7 +41,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate, TagsReceiver
4141 let textStorage = MarklightTextStorage()
4242
4343 static var draft: String = ""
44− static var hashTagsDraft: [String] = ["tt"]
44+ static var hashTagsDraft: [String] = [ ]
4545
4646 var textView: UITextView!
4747
@@ -72,7 +72,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate, TagsReceiver
7272
7373 setUpMD()
7474 setUpTextView()
75− setUpAccessoryView()
75+ // setUpAccessoryView()
7676 //setUpTagsView()
7777 }
7878
@@ -109,7 +109,8 @@ class NewPostViewController: UIViewController, UITextViewDelegate, TagsReceiver
109109 override func viewWillAppear(_ animated: Bool) {
110110 super.viewWillAppear(animated)
111111
112− navigationController?.navigationBar.prefersLargeTitles = false
112+ //navigationController?.navigationBar.prefersLargeTitles = false
113+ navigationItem.largeTitleDisplayMode = .never
113114 navigationItem.title = "New post"
114115 textView.text = NewPostViewController.draft
115116 // tagsField.addTags(NewPostViewController.hashTagsDraft)
@@ -140,7 +141,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate, TagsReceiver
140141 func setUpTextView(){
141142 view.addConstraint(bottomTextViewConstraint)
142143 view1.addSubview(textView)
143− textView.edgesToSuperview(insets: .top(8) + .left(8) + .bottom(40+8) + .right(8))
144+ textView.edgesToSuperview(insets: .top(8) + .left(8) + .bottom(8) + .right(8))
144145
145146 if #available(iOS 11.0, *) {
146147 textView.smartDashesType = .no
@@ -209,7 +210,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate, TagsReceiver
209210 }
210211
211212 func setUpMD(){
212− textStorage.marklightTextProcessor.codeColor = UIColor.orange
213+ textStorage.marklightTextProcessor.codeColor = UIColor.gray
213214 textStorage.marklightTextProcessor.quoteColor = UIColor.darkGray
214215 textStorage.marklightTextProcessor.syntaxColor = UIColor.blue
215216 textStorage.marklightTextProcessor.codeFontName = "Courier"
@@ -231,10 +232,27 @@ class NewPostViewController: UIViewController, UITextViewDelegate, TagsReceiver
231232 var indexOfPost = 0
232233 // MARK:- new post
233234 @objc func newPost(){
234− Model.createAndPublish(body: [Model.Attachments(markdown: textView!.text)], tags: currentTags)
235+ self.navigationItem.title = "Sending..."
236+ Model.createAndPublish(body: [Model.Attachments(markdown: textView!.text)], tags: currentTags) {
237+ [weak self] in
238+
239+ switch $0 {
240+ case .success1, .success:
241+ NewPostViewController.draft = ""
242+ NewPostViewController.hashTagsDraft = []
243+ self?.moveBackToParentVC?()
244+ default:
245+ self?.showAlertOn(result: $0)
246+ self?.navigationItem.title = "New post"
247+ }
248+
249+ }
250+
251+ // NewPostViewController.draft = ""
252+ // NewPostViewController.hashTagsDraft = []
235253 // adding row to uiTableView after adding new post
236254 // myProtocol?.addPost(post: p)
237− moveBackToParentVC?()
255+ // moveBackToParentVC?()
238256 // somewhere here i will be sending server notifications about new post arrival
239257 }
240258
@@ -246,7 +264,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate, TagsReceiver
246264 [weak self]
247265 _ in
248266 NewPostViewController.draft = self?.textView.text ?? ""
249− NewPostViewController.hashTagsDraft = /*self?.tagsField.tags.map { $0.text } ??*/ []
267+ NewPostViewController.hashTagsDraft = self?.currentTags ?? []
250268 self?.moveBackToParentVC?()
251269 }
252270
GDproject/Controller/ News and channels/NewsController.swift+3−1
@@ -52,6 +52,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, UpdateableWi
5252 let updater = TagsSuggestionController()
5353 updater.delegate = self
5454 searchController = UISearchController(searchResultsController: updater)
55+ navigationItem.largeTitleDisplayMode = .always
5556
5657 navigationController?.navigationBar.prefersLargeTitles = true
5758 navigationItem.title = "Loading ..."
@@ -81,7 +82,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, UpdateableWi
8182 searchController?.searchBar.placeholder = "Search tags"
8283 }
8384
84− @objc func refreshPostsData( _ ff: UIRefreshControl){
85+ @objc func refreshPostsData( _ ff: UIRefreshControl) {
8586 decideWhatChannelDisplay()
8687 }
8788
@@ -121,6 +122,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, UpdateableWi
121122 }
122123 }
123124 default:
125+ refreshContr.endRefreshing()
124126 break
125127 }
126128
GDproject/Controller/ News and channels/NewsVC.swift+3−1
@@ -19,7 +19,9 @@ struct PostCellData{
1919
2020 let markdownParser = MarkdownParser(font: UIFont.systemFont(ofSize: 16))
2121 markdownParser.enabledElements = .disabledAutomaticLink
22− markdownParser.code.textBackgroundColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
22+ markdownParser.code.font = UIFont(name: "Menlo", size: 16)
23+ markdownParser.code.textBackgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
24+ markdownParser.code.color = #colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1)
2325
2426 return markdownParser.parse(markdown)
2527 }
GDproject/Controller/ News and channels/PostViewCell.swift+2−1
@@ -42,6 +42,7 @@ class PostViewCell: UITableViewCell
4242
4343 let shareButton: UIButton = {
4444 let button = UIButton(type: UIButton.ButtonType.detailDisclosure)
45+ button.isHidden = true
4546 return button
4647 }()
4748
@@ -86,7 +87,7 @@ class PostViewCell: UITableViewCell
8687 nameLabel.setTitle("\(post.user?.firstName ?? "") \(post.user?.lastName ?? "")", for: .normal)
8788 nameLabel.addTarget(self, action: #selector(displayProfile), for: .touchUpInside)
8889 if let user = post.user{
89− fullNameLabel.text = "\(user.firstName) \(user.middleName) \(user.lastName)"
90+ fullNameLabel.text = "\(user.faculty.name)"
9091 }
9192 else {
9293 fullNameLabel.text = "\(post.authorId)"
GDproject/Controller/Coordinators/LogInCoordinator.swift+2−1
@@ -26,13 +26,14 @@ class LogInCoordinator: BaseCoordinator {
2626 let logInVC = LogInViewController()
2727 logInVC.authenticate = { [weak self, weak logInVC] (email) in
2828
29+ DataStorage.standard.setEmail(email: email)
2930 Model.authenticate(with: email) { [weak self]
3031 (authStatus) in
3132
3233 print(authStatus.userStatus)
3334
3435 if (authStatus.userStatus == "invalid") {
35− logInVC?.mailTextField.text = "invalid"
36+ logInVC?.presentAlertInvalidCode()
3637 }
3738 else if (authStatus.userStatus == "canRegister") { // register form
3839 self?.presentRegisterVC()
GDproject/Controller/Coordinators/ProfileCoordinator.swift+15−13
@@ -36,23 +36,25 @@ class ProfileCoordinator: BaseCoordinator {
3636 }
3737 }
3838
39− profile.onSettings = { [weak self, weak storyboard] in
40− let vc = storyboard?.instantiateViewController(withIdentifier: "SettingsViewController") as! SettingsViewController
41− self?.navigationController?.pushViewController(vc, animated: true)
39+ profile.deleteAllSessions = {
40+ Model.deactivateAll() {
41+ [weak self] in
42+
43+ DataStorage.standard.setIsLoggedIn(value: false, with: 0)
44+ self?.didEndSession?()
45+ }
4246 }
4347
44− profile.onChannelsListToAddAPerson = { [weak self, weak storyboard] (user) in
45− let vc = storyboard?.instantiateViewController(withIdentifier: simplifiedChannelsList) as! SimplifiedChannelsList
46− vc.user = user
48+ profile.onSettings = { [weak self, weak storyboard, weak profile] in
49+
50+ let vc = storyboard?.instantiateViewController(withIdentifier: "RegisterTableViewController") as! RegisterTableViewController
51+ vc.delegate = profile
52+ vc.userActive = profile?.user
4753
48− let transition = CATransition()
49− transition.duration = 0.5
50− transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
51− transition.type = CATransitionType.moveIn
52− transition.subtype = CATransitionSubtype.fromTop
53− self?.navigationController?.view.layer.add(transition, forKey: nil)
54− self?.navigationController?.pushViewController(vc, animated: false)
54+ self?.navigationController?.pushViewController(vc, animated: true)
5555 }
56+
57+
5658 navigationController?.setViewControllers([profile], animated: false)
5759 }
5860}
GDproject/Controller/Log In/CodeViewController.swift+47−8
@@ -7,6 +7,7 @@
77//
88
99import UIKit
10+import TinyConstraints
1011
1112class CodeViewController: UIViewController {
1213
@@ -17,12 +18,16 @@ class CodeViewController: UIViewController {
1718 @IBOutlet weak var f5: UITextField!
1819 @IBOutlet weak var f6: UITextField!
1920
21+ var loading = UIActivityIndicatorView(style: .gray)
22+
2023 var onSuccessLogIn: (()->())?
2124
2225 override func viewDidLoad() {
2326 super.viewDidLoad()
2427 setUpConstraint()
2528
29+ navigationItem.title = DataStorage.standard.getEmail()
30+
2631 f1.addTarget(self, action: #selector(textFiledDidChange(textField:)), for: .editingChanged)
2732 f2.addTarget(self, action: #selector(textFiledDidChange(textField:)), for: .editingChanged)
2833 f3.addTarget(self, action: #selector(textFiledDidChange(textField:)), for: .editingChanged)
@@ -31,6 +36,12 @@ class CodeViewController: UIViewController {
3136 f6.addTarget(self, action: #selector(textFiledDidChange(textField:)), for: .editingChanged)
3237 }
3338
39+ override func viewWillDisappear(_ animated: Bool) {
40+ super.viewWillDisappear(animated)
41+
42+ loading.stopAnimating()
43+ }
44+
3445 override func viewWillAppear(_ animated: Bool) {
3546 super.viewWillAppear(animated)
3647
@@ -62,28 +73,56 @@ class CodeViewController: UIViewController {
6273 }
6374
6475
76+ func presentAlertInvalidData(with text: String)
77+ {
78+ let alert = UIAlertController(title: "Invalid code", message: text, preferredStyle: .alert)
79+ alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
80+ self.present(alert, animated: true, completion: nil)
81+
82+ loading.stopAnimating()
83+ }
84+
6585 @IBOutlet weak var bottomConstraint: NSLayoutConstraint!
6686
6787 @IBAction func whereToGoNext(_ sender: UIButton)
6888 {
89+ guard let f1t = f1.text, let f2t = f2.text, let f3t = f3.text, let f4t = f4.text, let f5t = f5.text, let f6t = f6.text else {
90+ presentAlertInvalidData(with: "Some fields are missing");
91+ return
92+ }
93+
94+ if f1t.isEmpty || f2t.isEmpty || f3t.isEmpty || f4t.isEmpty || f5t.isEmpty || f6t.isEmpty {
95+ presentAlertInvalidData(with: "Some fields are missing");
96+ return
97+ }
98+
6999 let code = "\(f1.text!)\(f2.text!)\(f3.text!)\(f4.text!)\(f5.text!)\(f6.text!)"
70100 if let codeToInt = Int(code)
71101 {
72− Model.verify(with: codeToInt) { _ in
102+ loading.startAnimating()
103+ Model.verify(with: codeToInt) { [weak self] in
73104 // if everything is okay we can authemticicate
74− // Model.authemticiateMe
75− Model.authenticateMe { [weak self] (res) in
76− if res {
77− self?.onSuccessLogIn?()
78− } else {
79− print("sosi")
105+ if !$0 {
106+ self?.presentAlertInvalidData(with: "Wrong code. Try again!")
107+ self?.loading.stopAnimating()
108+ return
109+ } else {
110+ // Model.authemticiateMe
111+ Model.authenticateMe { [weak self] (res) in
112+ if res {
113+ self?.onSuccessLogIn?()
114+ }
80115 }
116+ return
81117 }
82118 }
83119 }
84120 }
85121
86− func setUpConstraint(){
122+ func setUpConstraint()
123+ {
124+ self.view.addSubview(loading)
125+ loading.centerInSuperview()
87126 // for keyboard notifications
88127 NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotifications), name: UIResponder.keyboardWillShowNotification, object: nil)
89128
GDproject/Controller/Log In/FacultyTableViewController.swift+1
@@ -81,6 +81,7 @@ class FacultyTableViewController: UITableViewController {
8181
8282 override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
8383 delegate?.onChooseFaculty(faculty: currentFaculties[indexPath.row])
84+ searchController.dismiss(animated: true, completion: nil)
8485 self.navigationController?.popViewController(animated: true)
8586 }
8687
GDproject/Controller/Log In/LogInViewController.swift+26−1
@@ -14,8 +14,25 @@ import Result
1414
1515class LogInViewController: UIViewController {
1616
17+ var loading = UIActivityIndicatorView(style: .gray)
18+
1719 var authenticate: ((String)->())?
1820
21+ func presentAlertInvalidCode()
22+ {
23+ let alert = UIAlertController(title: "Invalid email", message: "Try again. Use @hse.ru mail.", preferredStyle: .alert)
24+ alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
25+ self.present(alert, animated: true, completion: nil)
26+ mailTextField.text = ""
27+ loading.stopAnimating()
28+ }
29+
30+ override func viewWillDisappear(_ animated: Bool) {
31+ super.viewWillDisappear(animated)
32+
33+ loading.stopAnimating()
34+ }
35+
1936 let logInLabel: UILabel = {
2037 let label = UILabel()
2138 label.text = "Log In"
@@ -30,6 +47,8 @@ class LogInViewController: UIViewController {
3047 textField.placeholder = "Mail"
3148 textField.borderStyle = .roundedRect
3249 textField.textColor = .black
50+ textField.autocorrectionType = UITextAutocorrectionType.no
51+ textField.autocapitalizationType = UITextAutocapitalizationType.none
3352 textField.clearButtonMode = .always
3453 return textField
3554 }()
@@ -45,6 +64,7 @@ class LogInViewController: UIViewController {
4564 }()
4665
4766 @objc func handleTap(){
67+ loading.startAnimating()
4868 authenticate?(mailTextField.text!)
4969 }
5070
@@ -55,6 +75,10 @@ class LogInViewController: UIViewController {
5575 func setUpView(){
5676 // logIn stack with textField and label
5777 view.addSubview(contentView)
78+ view.addSubview(loading)
79+
80+ loading.centerInSuperview()
81+
5882 contentView.edgesToSuperview(excluding: .bottom, insets: .left(16) + .right(16) + .top(80), usingSafeArea: true)
5983 let views = [logInLabel, mailTextField]
6084 contentView.stack(views, axis: .vertical, spacing: 10)
@@ -62,6 +86,7 @@ class LogInViewController: UIViewController {
6286
6387 func configureKeyboard(){
6488
89+ mailTextField.keyboardType = .emailAddress
6590 // configure keyboardBar setUp
6691 view.addSubview(keyboardBar)
6792 keyboardBar.height(50)
@@ -79,7 +104,7 @@ class LogInViewController: UIViewController {
79104 func logicOfLogInInputValidation() -> ((String?)->()) {
80105
81106 let logic: ((String?)->()) = { [weak self] (someText) in
82− if let text = someText, !text.isEmpty {
107+ if let text = someText, !text.isEmpty, text.contains("@") {
83108 self?.logInButton.isEnabled = true
84109 } else {
85110 self?.logInButton.isEnabled = false
GDproject/Controller/Log In/RegisterTableViewController.swift+60−7
@@ -11,38 +11,91 @@ import UIKit
1111class RegisterTableViewController: UITableViewController, ChosenFactulty
1212{
1313
14+ func presentAlertInvalidData(message: String)
15+ {
16+ let alert = UIAlertController(title: "Invalid data", message: message, preferredStyle: .alert)
17+ alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
18+ self.present(alert, animated: true, completion: nil)
19+ }
20+
1421 func onChooseFaculty(faculty: Model.Faculty) {
1522 self.faculty = faculty
1623 tableView.reloadData()
1724 }
1825
19−
26+ weak var delegate: UpdateUser?
27+
2028 var onRegistration: (()->())?
2129
2230 var faculty: Model.Faculty?
23− var user: Model.NewRegistration = Model.NewRegistration(email: "dyurednikina@edu.hse.ru", firstName: nil, middleName: nil, lastName: nil, faculty: nil)
31+ var user: Model.NewRegistration = Model.NewRegistration(email: DataStorage.standard.getEmail()!, firstName: nil, middleName: nil, lastName: nil, faculty: nil)
32+
33+ var userActive: Model.Users? {
34+ didSet {
35+ if let userA = userActive {
36+ user.firstName = userA.firstName
37+ user.middleName = userA.middleName
38+ user.lastName = userA.lastName
39+
40+ faculty = userA.faculty
41+ self.updateUserIfCan = true
42+ tableView.reloadData()
43+ }
44+ }
45+ }
46+
47+ var updateUserIfCan: Bool = false
2448
2549 override func viewDidLoad()
2650 {
2751 super.viewDidLoad()
2852
53+ navigationItem.largeTitleDisplayMode = .never
2954 tableView.keyboardDismissMode = .interactive
3055 navigationItem.title = user.email
3156 navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(endRegistration))
3257 }
3358
59+
3460 @objc func endRegistration()
3561 {
62+ let fieldsMissing = "Some fields are missing. Add more information"
3663 updateUser()
37− guard let faculty = faculty else { return }
64+ guard let faculty = faculty else { presentAlertInvalidData(message: fieldsMissing); return }
3865
3966 user.faculty = faculty.url
4067
41− Model.register(object: user)
42− { [weak self] in
43− self?.onRegistration?()
44− }
68+ guard let name = user.firstName else { presentAlertInvalidData(message: fieldsMissing); return }
69+ guard let middle = user.middleName else { presentAlertInvalidData(message: fieldsMissing); return }
70+ guard let last = user.lastName else { presentAlertInvalidData(message: fieldsMissing); return }
4571
72+ if updateUserIfCan {
73+ guard let delegate = delegate else { return }
74+ guard var userA = userActive else { return }
75+
76+ // updating current
77+ userA.firstName = name
78+ userA.faculty = faculty
79+ userA.middleName = middle
80+ userA.lastName = last
81+
82+ Model.userUpdate(with: user) { [weak self] in
83+
84+ if $0 {
85+ delegate.updateUserObj(with: userA)
86+ self?.navigationController?.popViewController(animated: true)
87+ } else {
88+ self?.presentAlertInvalidData(message: "Something went wrong! Try again")
89+ }
90+
91+ }
92+ } else {
93+
94+ Model.register(object: user)
95+ { [weak self] in
96+ self?.onRegistration?()
97+ }
98+ }
4699 }
47100 // MARK: - Table view data source
48101
GDproject/Controller/Messages/ChatInfoViewController.swift+25−4
@@ -91,10 +91,12 @@ class ChatInfoViewController: UITableViewController {
9191 switch indexPath.section {
9292 case 0:
9393 cell.textLabel?.text = groupChat!.name
94+ cell.selectionStyle = .none
9495 return cell
9596 case 1:
9697 cell.textLabel?.text = "Leave chat"
9798 cell.textLabel?.textColor = #colorLiteral(red: 1, green: 0.1491314173, blue: 0, alpha: 1)
99+ cell.selectionStyle = .none
98100 return cell
99101 default:
100102 switch myPermissions{
@@ -104,6 +106,7 @@ class ChatInfoViewController: UITableViewController {
104106 case .ordinary:
105107 cell.textLabel?.text = name(for: users[usersArray[indexPath.row]])
106108 }
109+ cell.selectionStyle = .none
107110 return cell
108111 }
109112 }
@@ -114,7 +117,7 @@ class ChatInfoViewController: UITableViewController {
114117 case .ordinary:
115118 cell.textLabel?.text = name(for: users[usersArray[indexPath.row]])
116119 }
117−
120+ cell.selectionStyle = .none
118121 return cell
119122 }
120123
@@ -143,9 +146,9 @@ class ChatInfoViewController: UITableViewController {
143146
144147
145148 func editName(for cell: UITableViewCell){
146− let alert = UIAlertController(title: "Вы уверены?", message: "Название:", preferredStyle: .alert)
149+ let alert = UIAlertController(title: "Are you sure?", message: "Title:", preferredStyle: .alert)
147150
148− let action1 = UIAlertAction(title: "Oтмена", style: .cancel, handler: nil)
151+ let action1 = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
149152
150153 alert.addTextField { [weak self] (tf) in
151154 tf.textColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
@@ -194,10 +197,28 @@ class ChatInfoViewController: UITableViewController {
194197 case .admin:
195198 showUserChoiceVC()
196199 default:
197− break
200+ showParticipantPage(with: usersArray[indexPath.row])
198201 }
199202 }
200203 }
204+
205+
206+ if indexPath.section == 2 && indexPath.row != 0 {
207+ switch myPermissions{
208+ case .admin:
209+ showParticipantPage(with: usersArray[indexPath.row-1])
210+ default:
211+ showParticipantPage(with: usersArray[indexPath.row])
212+ }
213+ }
214+ }
215+
216+ var onUserDiplay: ((Int)->())?
217+
218+ func showParticipantPage(with user: Int?) {
219+ if let user = user {
220+ onUserDiplay?(user)
221+ }
201222 }
202223
203224 func showUserChoiceVC()
GDproject/Controller/Messages/Dialog/DialogViewController.swift+17−7
@@ -61,7 +61,9 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
6161
6262 self.tableView.delegate = self
6363 self.tableView.dataSource = self
64−
64+
65+ tableView.setContentOffset(CGPoint(x: 0, y: 50), animated: false)
66+
6567 navigationItem.largeTitleDisplayMode = .never
6668
6769 tableView.keyboardDismissMode = .onDrag
@@ -114,6 +116,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
114116 let button = UIButton()
115117 button.setTitle("Send", for: .normal)
116118 button.setTitleColor(.blue, for: .normal)
119+ button.titleLabel?.font = UIFont.systemFont(ofSize: 17, weight: .semibold)
117120 button.addTarget(self, action: #selector(sendMessage), for: .touchUpInside)
118121 return button
119122 }()
@@ -132,8 +135,13 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
132135 {
133136 Model.sendMessage(message: Model.SendMessage(body: Model.Attachments(markdown: messageTextView.text), destination: destination)) { [unowned self] in
134137
135− self.getMessagesNew(for: self.dialog!)
136− self.messageTextView.text = ""
138+ switch $0 {
139+ case .success, .success1:
140+ self.getMessagesNew(for: self.dialog!)
141+ self.messageTextView.text = ""
142+ default:
143+ self.showAlertOn(result: $0)
144+ }
137145 }
138146
139147 prevLast = -1
@@ -158,7 +166,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
158166
159167 messageSendView.edgesToSuperview(excluding: [.top,.bottom])
160168
161− bottomConstraint = NSLayoutConstraint(item: messageSendView, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1, constant: 0)
169+ bottomConstraint = NSLayoutConstraint(item: messageSendView, attribute: .bottom, relatedBy: .equal, toItem: self.view.safeAreaLayoutGuide, attribute: .bottom, multiplier: 1, constant: 0)
162170 view.addConstraint(bottomConstraint)
163171
164172 messageSendView.height(60)
@@ -191,7 +199,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
191199
192200 let keyBoardFrame = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
193201
194− bottomConstraint.constant = notification.name == UIResponder.keyboardWillShowNotification ? -(keyBoardFrame.height) : 0
202+ bottomConstraint.constant = notification.name == UIResponder.keyboardWillShowNotification ? -(keyBoardFrame.height) + self.view.safeAreaInsets.bottom : 0
195203
196204 UIView.animate(withDuration: 0, delay: 0, options: .curveEaseOut, animations: {
197205 self.view.layoutIfNeeded()
@@ -223,6 +231,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
223231
224232 vc.delegate = self
225233 vc.users = users!
234+ vc.onUserDiplay = onUserDisplay
226235
227236 if let groupChat = groupChat {
228237 vc.groupChat = groupChat.group
@@ -248,7 +257,8 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
248257 return cellData.count
249258 }
250259
251− override func viewWillAppear(_ animated: Bool) {
260+ override func viewWillAppear(_ animated: Bool)
261+ {
252262 super.viewWillAppear(animated)
253263 tabBarController?.tabBar.isHidden = true
254264
@@ -313,7 +323,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
313323 var canBePaginated = false
314324 func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
315325 {
316− if indexPath.row == cellData.count - 1 && prevLast != indexPath.row && canBePaginated
326+ if indexPath.row == cellData.count - 1 && prevLast != indexPath.row && canBePaginated && cellData.count >= 24
317327 {
318328 print("exclusiveFrom \(currentMessagesInChat.last?.id ?? 0)")
319329 if let dialog = dialog
GDproject/Controller/Messages/MessageViewCell.swiftnew file+38
@@ -0,0 +1,38 @@
1+//
2+// MessageViewCell.swift
3+// GDproject
4+//
5+// Created by cstore on 13/05/2019.
6+// Copyright © 2019 drHSE. All rights reserved.
7+//
8+
9+import UIKit
10+
11+class MessageViewCell: UITableViewCell {
12+
13+ @IBOutlet weak var dialogName: UILabel!
14+
15+ @IBOutlet weak var lastMessagePreview: UILabel!
16+
17+ @IBOutlet weak var dateLabel: UILabel!
18+
19+ override func awakeFromNib() {
20+ super.awakeFromNib()
21+ // Initialization code
22+ }
23+
24+ func fill(with dialog: Model.Dialog, user: Model.Users? = nil)
25+ {
26+ switch dialog {
27+
28+ case .groupChat(let group):
29+ dialogName.text = group.group.name
30+ lastMessagePreview.text = group.lastMessage?.body.markdown
31+ dateLabel.text = group.lastMessage?.time.getDate()
32+ case .userChat(let userChat):
33+ dialogName.text = "👤 \(user!.fullName())"
34+ lastMessagePreview.text = userChat.lastMessage?.body.markdown
35+ dateLabel.text = userChat.lastMessage?.time.getDate()
36+ }
37+ }
38+}
GDproject/Controller/Messages/MessagesViewController.swift+107−12
@@ -8,8 +8,44 @@
88
99import UIKit
1010
11−class MessagesViewController: UITableViewController {
11+protocol SelectableDialog: class {
12+ func openDialog(with dialog: Model.Dialog)
13+}
1214
15+class MessagesViewController: UITableViewController, UISearchControllerDelegate, UISearchResultsUpdating, SelectableDialog {
16+
17+ func openDialog(with dialog: Model.Dialog) {
18+ onDialogDisplay?((dialog, users))
19+ }
20+
21+ func updateSearchResults(for searchController: UISearchController) {
22+
23+ let filteredData = currentActiveDialogs
24+ let inputText = searchController.searchBar.text ?? ""
25+
26+ let filteredResults = filteredData.filter {
27+
28+ switch $0 {
29+ case .groupChat(let gropuChat):
30+ return gropuChat.group.name.contains(inputText)
31+
32+ case .userChat(let userChat):
33+ let user = users[userChat.user]
34+ guard let u = user else { return false }
35+ return u.fullName().contains(inputText)
36+
37+ }
38+
39+ }
40+
41+ // Apply the filtered results to the search results table.
42+ if let resultsController = searchController.searchResultsController as? SuggestedDialogsTableViewController {
43+ resultsController.users = users
44+ resultsController.currentDialogs = filteredResults
45+ resultsController.tableView.reloadData()
46+ }
47+ }
48+
1349 // curreent Active which can be displayed
1450 var currentActiveDialogs: [Model.Dialog] = [] {
1551 didSet {
@@ -17,6 +53,17 @@ class MessagesViewController: UITableViewController {
1753 }
1854 }
1955
56+ func setUpSearchContr(){
57+
58+ searchController?.delegate = self
59+ searchController?.obscuresBackgroundDuringPresentation = true
60+ navigationItem.searchController = searchController
61+ definesPresentationContext = true
62+ searchController?.searchResultsUpdater = self
63+ searchController?.searchBar.placeholder = "Search dialogs"
64+
65+ }
66+
2067 // curreent users
2168 var users: [Int: Model.Users] = [:]
2269
@@ -24,17 +71,22 @@ class MessagesViewController: UITableViewController {
2471
2572 var onDialogDisplay: (((dialog: Model.Dialog, users: [Int:Model.Users]))->())?
2673
27− let searchC = UISearchController(searchResultsController: nil)
74+ var searchController: UISearchController?
2875
2976 override func viewDidLoad() {
3077 super.viewDidLoad()
31−
78+
79+ let updater = SuggestedDialogsTableViewController()
80+
81+ updater.delegate = self
82+ searchController = UISearchController(searchResultsController: updater)
83+
3284 // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
3385 self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Write", style: .plain, target: self, action: #selector(choosePerson))
3486
3587 self.navigationItem.title = "Messages"
3688 // self.navigationItem.largeTitleDisplayMode = .always
37− self.navigationItem.searchController = searchC
89+ setUpSearchContr()
3890 navigationController?.navigationBar.prefersLargeTitles = true
3991 self.navigationItem.hidesSearchBarWhenScrolling = false
4092 }
@@ -64,18 +116,15 @@ class MessagesViewController: UITableViewController {
64116
65117 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
66118 {
67− let cell = tableView.dequeueReusableCell(withIdentifier: "MessagesCell", for: indexPath)
119+ let cell = tableView.dequeueReusableCell(withIdentifier: "MessageViewCell", for: indexPath) as! MessageViewCell
68120
69121 switch currentActiveDialogs[indexPath.row].self {
70−
71− case .groupChat(let group):
72− cell.textLabel?.text = group.group.name
73− cell.detailTextLabel?.text = group.lastMessage!.body.markdown
122+ case .groupChat:
123+ cell.fill(with: currentActiveDialogs[indexPath.row])
74124 case .userChat(let userChat):
75− cell.textLabel?.text = "👤 \(users[userChat.user]!.fullName())"
76− cell.detailTextLabel?.text = userChat.lastMessage!.body.markdown
125+ cell.fill(with: currentActiveDialogs[indexPath.row], user: users[userChat.user])
77126 }
78−
127+
79128 return cell
80129 }
81130
@@ -84,3 +133,49 @@ class MessagesViewController: UITableViewController {
84133 onDialogDisplay?(tuple)
85134 }
86135}
136+
137+
138+class SuggestedDialogsTableViewController: UITableViewController {
139+
140+ var idCell = "cell"
141+
142+ var users: [Int: Model.Users] = [:]
143+
144+ weak var delegate: SelectableDialog?
145+
146+ var currentDialogs: [Model.Dialog] = []
147+
148+ override func viewDidLoad() {
149+ super.viewDidLoad()
150+ tableView.register(UITableViewCell.self, forCellReuseIdentifier: idCell)
151+ tableView.reloadData()
152+ }
153+
154+ override func numberOfSections(in tableView: UITableView) -> Int {
155+ return 1
156+ }
157+
158+ override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
159+ return currentDialogs.count
160+ }
161+
162+ override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
163+ {
164+ let cell = tableView.dequeueReusableCell(withIdentifier: idCell, for: indexPath)
165+
166+ switch currentDialogs[indexPath.row] {
167+ case .groupChat(let groupChat):
168+ cell.textLabel?.text = groupChat.group.name
169+ case .userChat(let userChat):
170+ cell.textLabel?.text = users[userChat.user]?.fullName()
171+ }
172+
173+ cell.accessoryType = .disclosureIndicator
174+ return cell
175+ }
176+
177+ override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
178+ delegate?.openDialog(with: currentDialogs[indexPath.row])
179+ // self.dismiss(animated: true)
180+ }
181+}
GDproject/Controller/Messages/PeopleToWriteViewController.swift−1
@@ -53,7 +53,6 @@ class PeopleToWriteViewController: UITableViewController {
5353 let cell = tableView.dequeueReusableCell(withIdentifier: "peopleToWriteCell", for: indexPath)
5454
5555 cell.textLabel?.text = users[indexPath.row].fullName()
56− cell.detailTextLabel?.text = "\(users[indexPath.row].id)"
5756
5857 return cell
5958 }
GDproject/Controller/Profile/BasicInfoController.swift+16−11
@@ -16,17 +16,20 @@ struct CellData{
1616
1717class BasicInfoController: UIViewController, UITableViewDelegate, UITableViewDataSource {
1818
19− var dataSourse: [CellData] = [
20− CellData(opened: false, title: "Phone", sectionData: ["+7 901 733 01 79"]),
21− CellData(opened: false, title: "Mail", sectionData: ["vbogomazova@edu.hse.ru"]),
22− CellData(opened: false, title: "Research ID", sectionData: ["4567834336789456737"]),
23− CellData(opened: false, title: "Published", sectionData: ["Это будет очень длинное название книги 1, чтобы сделать проверку", "Книга 2", "Книга 3"]),
24− CellData(opened: false, title: "Courses", sectionData: ["Курс 1", "Курс 2"]),
25− CellData(opened: false, title: "Link", sectionData: ["https://wwww.hse.ru"])
26− ]
19+ var userInfo: Model.Users? {
20+ didSet {
21+ if let userInfo = userInfo {
22+ dataSourse = [CellData(opened: false, title: "Contacts", sectionData: [userInfo.email, userInfo.faculty.address]),
23+ CellData(opened: false, title: "Faculty", sectionData: [userInfo.faculty.campusName, userInfo.faculty.name, userInfo.faculty.address, userInfo.faculty.path]),
24+ CellData(opened: false, title: "Interests", sectionData: userInfo.faculty.tags)]
25+ }
26+ }
27+ }
28+
29+ var dataSourse: [CellData] = [ ]
2730
2831 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
29− if (dataSourse[section].opened){
32+ if (dataSourse[section].opened) {
3033 return dataSourse[section].sectionData.count + 1
3134 } else {
3235 return 1
@@ -45,8 +48,10 @@ class BasicInfoController: UIViewController, UITableViewDelegate, UITableViewDat
4548 cell.selectionStyle = .none
4649 return cell
4750 } else {
48− let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
49− cell.textLabel?.text = dataSourse[indexPath.section].sectionData[indexPath.row - 1]
51+ let cell = tableView.dequeueReusableCell(withIdentifier: infoCellId, for: indexPath) as! InfoCell
52+ cell.fill(title: dataSourse[indexPath.section].sectionData[indexPath.row - 1])
53+ cell.accessoryType = .none
54+ cell.selectionStyle = .none
5055 return cell
5156 }
5257 }
GDproject/Controller/Profile/InfoCell.swift+2−1
@@ -16,8 +16,9 @@ class InfoCell: UITableViewCell{
1616 label.font = UIFont.systemFont(ofSize: 16)
1717 label.sizeToFit()
1818 label.isScrollEnabled = false
19− label.isUserInteractionEnabled = false
19+ // label.isUserInteractionEnabled = false
2020 label.isEditable = false
21+ label.dataDetectorTypes = .all
2122 label.textColor = .black
2223 return label
2324 }()
GDproject/Controller/Profile/ProfileViewController.swift+88−23
@@ -9,8 +9,17 @@
99import UIKit
1010import TinyConstraints
1111
12−class ProfileViewController: UIViewController
12+protocol UpdateUser: class {
13+ func updateUserObj(with user: Model.Users)
14+}
15+
16+class ProfileViewController: UIViewController, UpdateUser
1317{
18+ func updateUserObj(with user: Model.Users)
19+ {
20+ self.user = user
21+ Model.Channels.fullPeopleDict[user.id] = user
22+ }
1423
1524 @IBOutlet weak var segmentedControl: UISegmentedControl!
1625
@@ -32,6 +41,8 @@ class ProfileViewController: UIViewController
3241
3342 var logOut: (()->())?
3443
44+ var deleteAllSessions: (()->())?
45+
3546 var onSettings: (()->())?
3647
3748 @IBAction func sendMessage(_ sender: UIButton)
@@ -46,8 +57,6 @@ class ProfileViewController: UIViewController
4657 }
4758 }
4859
49− var onChannelsListToAddAPerson: ((Model.Users)->())?
50−
5160 var protoDictionary: [String: UIImage] = ["135213": #imageLiteral(resourceName: "9"), "135288": #imageLiteral(resourceName: "5051"), "22723" : #imageLiteral(resourceName: "69"), "135083": #imageLiteral(resourceName: "42")]
5261
5362 func fill(with user: Model.Users)
@@ -56,7 +65,7 @@ class ProfileViewController: UIViewController
5665 self.nameLabel.text = "\(user.firstName) \(user.middleName)"
5766 self.surnameLabel.text = "\(user.lastName)"
5867 self.profileImageView.image = protoDictionary[user.faculty.campusCode]?.roundedImage
59− self.placeLabel.text = "📍\(user.faculty.campusName)"
68+ self.placeLabel.text = "📍\(user.faculty.address)"
6069 if user.id == DataStorage.standard.getUserId() {
6170 newMessageButton.isHidden = true
6271 } else {
@@ -106,6 +115,15 @@ class ProfileViewController: UIViewController
106115 posts.type = .NONE
107116 posts.currChannel = channel
108117
118+ posts.onFullPost = {
119+ [weak self] (type,post) in
120+
121+ let vc = self?.storyboard?.instantiateViewController(withIdentifier: fullPostControllerId) as! FullPostController
122+ vc.type = type
123+ vc.post = post
124+ self?.navigationController!.pushViewController(vc, animated: true)
125+ }
126+
109127 tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
110128
111129 tableView.register(PostViewCell.self, forCellReuseIdentifier: postCellId)
@@ -141,7 +159,7 @@ class ProfileViewController: UIViewController
141159 }
142160
143161 func setUpNavigarionBar(){
144− navigationController?.navigationBar.prefersLargeTitles = true
162+ // navigationController?.navigationBar.prefersLargeTitles = true
145163 let uibarbutton = UIBarButtonItem(title: "More", style: .plain, target: self, action: #selector(showInformation))
146164 navigationItem.rightBarButtonItems = [uibarbutton]
147165 navigationItem.largeTitleDisplayMode = .always
@@ -151,29 +169,75 @@ class ProfileViewController: UIViewController
151169
152170 let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
153171
154− let channelAction = UIAlertAction(title: "Add to a channel", style: .default){
155− [weak self] (_) in
156− self?.onChannelsListToAddAPerson?(self!.user!)
157− }
158−
159− let settingsAction = UIAlertAction(title: "Setting", style: .default)
160− { [weak self] (_) in
161− self?.onSettings?()
162− }
163−
172+
164173 let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
165174
166− let logoutAction = UIAlertAction(title: "Log out", style: .destructive)
167− { [weak self]
168− (_) in
169− self?.logOut?()
175+
176+ if idProfile == DataStorage.standard.getUserId() {
177+ let logoutAction = UIAlertAction(title: "Log out", style: .destructive)
178+ { [weak self] (_) in
179+
180+ if let logOut = self?.logOut {
181+ logOut()
182+ } else {
183+ Model.logout() {
184+ DataStorage.standard.setIsLoggedIn(value: false, with: 0)
185+ (UIApplication.shared.delegate as! AppDelegate).relaunch()
186+ }
187+ }
188+ }
189+
190+ let deleetAllSessionsAction = UIAlertAction(title: "Delete all sessions", style: .destructive)
191+ { [weak self] _ in
192+
193+ if let delete = self?.deleteAllSessions {
194+ delete()
195+ } else {
196+ Model.deactivateAll() {
197+ DataStorage.standard.setIsLoggedIn(value: false, with: 0)
198+ (UIApplication.shared.delegate as! AppDelegate).relaunch()
199+ }
200+ }
201+ }
202+
203+ let settingsAction = UIAlertAction(title: "Edit profile", style: .default)
204+ { [weak self] (_) in
205+
206+ if let settings = self?.onSettings{
207+ settings()
208+ } else {
209+ let vc = self?.storyboard?.instantiateViewController(withIdentifier: "RegisterTableViewController") as! RegisterTableViewController
210+ vc.delegate = self
211+ vc.userActive = self?.user
212+
213+ self?.navigationController?.pushViewController(vc, animated: true)
214+ }
215+ }
216+
217+ optionMenu.addAction(settingsAction)
218+ optionMenu.addAction(logoutAction)
219+ optionMenu.addAction(deleetAllSessionsAction)
220+ } else {
221+ let channelAction = UIAlertAction(title: "Add to a channel", style: .default)
222+ {
223+ [weak self] (_) in
224+
225+ let vc = self?.storyboard?.instantiateViewController(withIdentifier: simplifiedChannelsList) as! SimplifiedChannelsList
226+ vc.user = self?.user
227+
228+ let transition = CATransition()
229+ transition.duration = 0.5
230+ transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
231+ transition.type = CATransitionType.moveIn
232+ transition.subtype = CATransitionSubtype.fromTop
233+ self?.navigationController?.view.layer.add(transition, forKey: nil)
234+ self?.navigationController?.pushViewController(vc, animated: false)
235+ }
236+
237+ optionMenu.addAction(channelAction)
170238 }
171239
172− optionMenu.addAction(channelAction)
173− optionMenu.addAction(settingsAction)
174− optionMenu.addAction(logoutAction)
175240 optionMenu.addAction(cancelAction)
176−
177241 self.present(optionMenu, animated: true, completion: nil)
178242 }
179243
@@ -203,6 +267,7 @@ class ProfileViewController: UIViewController
203267 func changeToBasicInfo(){
204268 tableView.delegate = basicInfo
205269 tableView.dataSource = basicInfo
270+ basicInfo.userInfo = self.user
206271 tableView.reloadData()
207272 }
208273}
GDproject/DataStorage.swift+8
@@ -37,6 +37,13 @@ class DataStorage{
3737 return UserDefaults.standard.integer(forKey: UserDefaultsKeys.id.rawValue)
3838 }
3939
40+ func setEmail(email: String) {
41+ UserDefaults.standard.set(email, forKey: UserDefaultsKeys.email.rawValue)
42+ }
43+
44+ func getEmail() -> String? {
45+ return UserDefaults.standard.string(forKey: UserDefaultsKeys.email.rawValue)
46+ }
4047 /**
4148 Function to determine is user logged in already or not
4249 */
@@ -49,4 +56,5 @@ class DataStorage{
4956enum UserDefaultsKeys: String{
5057 case loggedIn
5158 case id
59+ case email
5260}
GDproject/Extentions.swift+30
@@ -77,3 +77,33 @@ extension String {
7777 return timeStamp
7878 }
7979}
80+
81+extension UIViewController {
82+ func showAlertOn(result: ResultR) {
83+
84+ let message: String
85+
86+ switch result {
87+ case .impossibleContent:
88+ message = "Impossible content"
89+ case .exceededContent:
90+ message = "The content exceeded"
91+ case .longContent:
92+ message = "The content is too long"
93+ case .badAccess:
94+ message = "Try reloading the page again"
95+ case .alreadyRegistered:
96+ message = "User is already registered"
97+ case .tooMuchToAdd:
98+ message = "Limit of channels exceeded"
99+ case .success, .success1:
100+ return
101+ default:
102+ message = "Something went wrong"
103+ }
104+
105+ let alert = UIAlertController(title: "Error", message: message, preferredStyle: .alert)
106+ alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
107+ self.present(alert, animated: true, completion: nil)
108+ }
109+}
GDproject/Simple model/Model.swift+166−14
@@ -10,6 +10,22 @@ import Foundation
1010import UIKit
1111import Alamofire
1212
13+enum ResultR: Int {
14+ case internalServerError = 500
15+ case exceededContent = 470
16+ case longContent = 471
17+ case incorrectContent = 472
18+ case impossibleContent = 473
19+ case invalidTocken = 498
20+ case alreadyRegistered = 409
21+ case invalidCode = 403
22+ case badAccess = 400
23+ case tooMuchToAdd = 406
24+ case notFound = 404
25+ case success1 = 204
26+ case success = 200
27+}
28+
1329class Model{
1430
1531 static let invalidTocken = 498
@@ -19,10 +35,12 @@ class Model{
1935 private static var isValidTocken: ((Int)->())? = { responce in
2036 print(responce)
2137 if responce == invalidTocken {
38+
39+ DataStorage.standard.setIsLoggedIn(value: false, with: 0)
40+ (UIApplication.shared.delegate as! AppDelegate).relaunch()
41+
2242 Model.logout {
2343 print("Logout Is Successful")
24− DataStorage.standard.setIsLoggedIn(value: false, with: 0)
25− (UIApplication.shared.delegate as! AppDelegate).relaunch()
2644 }
2745 }
2846 }
@@ -31,6 +49,7 @@ class Model{
3149 static let decoder = JSONDecoder()
3250
3351 static let authMeURL = URL(string: "\(baseUrl)/authentication/me")!
52+ static let deactivateURL = URL(string: "\(baseUrl)/deactivateAll")!
3453 static let registerMeURL = URL(string: "\(baseUrl)/authentication/register")!
3554 static let authVerifyURL = URL(string: "\(baseUrl)/authentication/verify")!
3655 static let authenticationURL = URL(string:"\(baseUrl)/authentication/login")!
@@ -40,6 +59,7 @@ class Model{
4059 static let postsPublishURL = URL(string:"\(baseUrl)/posts/publish")!
4160 static let usersURL = URL(string:"\(baseUrl)/users")!
4261 static let usersAllURL = URL(string:"\(baseUrl)/users/all")!
62+ static let usersUpdateURL = URL(string:"\(baseUrl)/users/update")!
4363 static let channelsGetURL = URL(string: "\(baseUrl)/channels/get")!
4464 static let channelsUpdateURL = URL(string: "\(baseUrl)/channels/update")!
4565 static let channelsListURL = URL(string: "\(baseUrl)/channels")!
@@ -208,6 +228,10 @@ class Model{
208228 AF.request(request).response { (responce) in
209229 isValidTocken?(responce.response?.statusCode ?? 498)
210230
231+ if let code = responce.response?.statusCode, code == 498 {
232+ return
233+ }
234+
211235 completion()
212236 }
213237 }
@@ -240,11 +264,14 @@ class Model{
240264 guard let code = responce.response?.statusCode else { return }
241265 isValidTocken?(code)
242266
267+ if let code = responce.response?.statusCode, code == 498 {
268+ return
269+ }
270+
243271 if code == 204 {
244− let fields = responce.response?.allHeaderFields as? [String :String]
245272
273+ let fields = responce.response?.allHeaderFields as? [String :String]
246274 let cookies = HTTPCookie.cookies(withResponseHeaderFields: fields!, for: responce.response!.url!)
247−
248275 HTTPCookieStorage.shared.setCookie(cookies[0])
249276
250277 completion()
@@ -264,12 +291,16 @@ class Model{
264291 guard let statusCode = responce.response?.statusCode else { completion(false); return }
265292 isValidTocken?(statusCode)
266293
294+ if let code = responce.response?.statusCode, code == 498 {
295+ return
296+ }
297+
267298 if statusCode == 204 {
268299 // at this point cookies are set
269300 completion(true)
301+ } else {
302+ completion(false)
270303 }
271−
272− completion(false)
273304 }
274305 }
275306
@@ -283,6 +314,10 @@ class Model{
283314 guard let statusCode = responce.response?.statusCode else { completion(false); return }
284315 isValidTocken?(statusCode)
285316
317+ if let code = responce.response?.statusCode, code == 498 {
318+ return
319+ }
320+
286321 guard let json = responce.data else { return }
287322 guard let personId = Int(String(data: json, encoding: String.Encoding.utf8)!) else {
288323 completion(false)
@@ -377,6 +412,10 @@ class Model{
377412
378413 isValidTocken?(response.response?.statusCode ?? 498)
379414
415+ if let code = response.response?.statusCode, code == 498 {
416+ return
417+ }
418+
380419 guard let json = response.data else { return }
381420
382421 guard let newQueery = try? decoder.decode(QueryPosts<Posts>.self, from: json) else { print("no")
@@ -388,7 +427,7 @@ class Model{
388427 }
389428
390429
391− static func createAndPublish(body: [Attachments], tags: [String]){
430+ static func createAndPublish(body: [Attachments], tags: [String], completion: @escaping ((ResultR)->())){
392431 let jsonUpd = CreatedPost(body: body, tags: tags)
393432 var request = URLRequest(url: postsPublishURL)
394433
@@ -402,6 +441,18 @@ class Model{
402441 (response) in
403442
404443 isValidTocken?(response.response?.statusCode ?? 498)
444+
445+ if let code = response.response?.statusCode, code == 498 {
446+ return
447+ }
448+
449+ if let code = response.response?.statusCode,
450+ let result = ResultR(rawValue: code)
451+ {
452+ completion(result)
453+ } else {
454+ completion(.internalServerError)
455+ }
405456 }
406457 }
407458
@@ -427,6 +478,10 @@ class Model{
427478
428479 isValidTocken?(response.response?.statusCode ?? 498)
429480
481+ if let code = response.response?.statusCode, code == 498 {
482+ return
483+ }
484+
430485 guard let json = response.data else { return }
431486
432487 guard let newPost = try? decoder.decode(QueryPosts<Posts>.self, from: json) else { return }
@@ -439,7 +494,7 @@ class Model{
439494
440495 static func getUsers(for ids: [Int], completion: @escaping (([Int:Users])->())){
441496 let json = "\(Set(ids))"
442− print(json)
497+
443498 var request = URLRequest(url: usersURL)
444499
445500 request.httpMethod = "POST"
@@ -453,6 +508,10 @@ class Model{
453508
454509 isValidTocken?(response.response?.statusCode ?? 498)
455510
511+ if let code = response.response?.statusCode, code == 498 {
512+ return
513+ }
514+
456515 guard let json = response.data else { return }
457516
458517 guard let users = try? decoder.decode([Users].self, from: json) else { return }
@@ -485,6 +544,9 @@ class Model{
485544
486545 isValidTocken?(response.response?.statusCode ?? 498)
487546
547+ if let code = response.response?.statusCode, code == 498 {
548+ return
549+ }
488550
489551 guard let json = response.data else { return }
490552
@@ -496,7 +558,7 @@ class Model{
496558 }
497559
498560
499− static func createChannel(with channel: Channels) {
561+ static func createChannel(with channel: Channels, completion: @escaping ((ResultR)->())) {
500562
501563 var request = URLRequest(url: channelsCreateURL)
502564 request.httpMethod = "POST"
@@ -507,6 +569,13 @@ class Model{
507569 (response) in
508570
509571 isValidTocken?(response.response?.statusCode ?? 498)
572+
573+ if let code = response.response?.statusCode, let result = ResultR(rawValue: code) {
574+ completion(result)
575+ return
576+ }
577+
578+ completion(ResultR.internalServerError)
510579 }
511580
512581 }
@@ -519,6 +588,9 @@ class Model{
519588 AF.request(request).responseJSON { (response) in
520589
521590 isValidTocken?(response.response?.statusCode ?? 498)
591+ if let code = response.response?.statusCode, code == 498 {
592+ return
593+ }
522594
523595 guard let json = response.data else { return }
524596
@@ -537,6 +609,9 @@ class Model{
537609
538610 AF.request(request).response { (response) in
539611 isValidTocken?(response.response?.statusCode ?? 498)
612+ if let code = response.response?.statusCode, code == 498 {
613+ return
614+ }
540615 }
541616 completion()
542617 }
@@ -552,6 +627,9 @@ class Model{
552627 (response) in
553628
554629 isValidTocken?(response.response?.statusCode ?? 498)
630+ if let code = response.response?.statusCode, code == 498 {
631+ return
632+ }
555633 }
556634 }
557635
@@ -574,6 +652,9 @@ class Model{
574652 }
575653
576654 isValidTocken?(response.response?.statusCode ?? 498)
655+ if let code = response.response?.statusCode, code == 498 {
656+ return
657+ }
577658 }
578659 }
579660
@@ -649,12 +730,13 @@ class Model{
649730 (response) in
650731
651732 isValidTocken?(response.response?.statusCode ?? 498)
733+ if let code = response.response?.statusCode, code == 498 {
734+ return
735+ }
652736
653737 guard let json = response.data else { return }
654738
655739 guard let newQueery = try? decoder.decode(QueryPosts<Posts>.self, from: json) else { return }
656−
657− print("\(anonymousChannel) \(newQueery)")
658740 completion((newQueery.users, newQueery.response))
659741 }
660742 }
@@ -664,6 +746,9 @@ class Model{
664746 AF.request(URLRequest(url: hashTagTreeURL)).responseJSON {
665747 (response) in
666748 isValidTocken?(response.response?.statusCode ?? 498)
749+ if let code = response.response?.statusCode, code == 498 {
750+ return
751+ }
667752 guard let json = response.data else { return }
668753 guard let tree = try? decoder.decode(CompletionTree.self, from: json) else { return }
669754 completion(tree)
@@ -681,6 +766,10 @@ class Model{
681766 AF.request(request).responseJSON { response in
682767 isValidTocken?(response.response?.statusCode ?? 498)
683768
769+ if let code = response.response?.statusCode, code == 498 {
770+ return
771+ }
772+
684773 guard let json = response.data else { return }
685774 let dialogs = try! decoder.decode(QueryPosts<Dialog>.self, from: json)
686775
@@ -852,6 +941,9 @@ class Model{
852941 AF.request(request).response { (response) in
853942
854943 isValidTocken?(response.response?.statusCode ?? 498)
944+ if let code = response.response?.statusCode, code == 498 {
945+ return
946+ }
855947
856948 guard let json = response.data else { return }
857949 let stringInt = String.init(data: json, encoding: String.Encoding.utf8)
@@ -861,7 +953,7 @@ class Model{
861953 }
862954 }
863955
864− static func getMessagesFor(typeOfChat: Model.Dialog, chat id: Int, exclusiveFrom: Int? = nil, limit l: Int = 10, direction: String = "backward", completion: @escaping (([LastMessage])->()))
956+ static func getMessagesFor(typeOfChat: Model.Dialog, chat id: Int, exclusiveFrom: Int? = nil, limit l: Int = 25, direction: String = "backward", completion: @escaping (([LastMessage])->()))
865957 {
866958 let req = GeneralRequest<Int>(direction: direction, limit: l, exclusiveFrom: exclusiveFrom, request: id)
867959 var request: URLRequest?
@@ -880,6 +972,9 @@ class Model{
880972 AF.request(request!).response { (response) in
881973
882974 isValidTocken?(response.response?.statusCode ?? 498)
975+ if let code = response.response?.statusCode, code == 498 {
976+ return
977+ }
883978
884979 guard let json = response.data else { return }
885980 guard let messages = try? decoder.decode([LastMessage].self, from: json) else { return }
@@ -897,6 +992,10 @@ class Model{
897992
898993 AF.request(request).response { (response) in
899994 isValidTocken?(response.response?.statusCode ?? 498)
995+
996+ if let code = response.response?.statusCode, code == 498 {
997+ return
998+ }
900999 }
9011000
9021001 completion()
@@ -911,6 +1010,10 @@ class Model{
9111010
9121011 AF.request(request).response { (response) in
9131012 isValidTocken?(response.response?.statusCode ?? 498)
1013+
1014+ if let code = response.response?.statusCode, code == 498 {
1015+ return
1016+ }
9141017 }
9151018
9161019 // completion()
@@ -953,7 +1056,7 @@ class Model{
9531056 }
9541057 }
9551058
956− static func sendMessage(message: SendMessage, completion: @escaping (()->())){
1059+ static func sendMessage(message: SendMessage, completion: @escaping ((ResultR)->())){
9571060
9581061 var request = URLRequest(url: messagesSendURL)
9591062 request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
@@ -963,7 +1066,15 @@ class Model{
9631066 AF.request(request).response { (response) in
9641067 isValidTocken?(response.response?.statusCode ?? 498)
9651068
966− completion()
1069+ if let code = response.response?.statusCode, code == 498 {
1070+ return
1071+ }
1072+
1073+ if let result = ResultR(rawValue: response.response!.statusCode){
1074+ completion(result)
1075+ } else {
1076+ completion(.internalServerError)
1077+ }
9671078 }
9681079 }
9691080
@@ -976,6 +1087,7 @@ class Model{
9761087 var campusCode: String
9771088 var name: String
9781089 var tags: [String]
1090+ var address: String
9791091
9801092 }
9811093
@@ -989,10 +1101,50 @@ class Model{
9891101 AF.request(request).response { (response) in
9901102 isValidTocken?(response.response?.statusCode ?? 498)
9911103
1104+ if let code = response.response?.statusCode, code == 498 {
1105+ return
1106+ }
1107+
9921108 guard let json = response.data else { return }
9931109 guard let faculties = try? decoder.decode([Faculty].self, from: json) else { return }
9941110
9951111 completion(faculties)
9961112 }
9971113 }
1114+
1115+ static func userUpdate(with newUser: NewRegistration, completion: @escaping ((Bool)->())) {
1116+ var request = URLRequest(url: usersUpdateURL)
1117+ request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
1118+ request.httpMethod = "POST"
1119+ request.httpBody = try? JSONEncoder().encode(newUser)
1120+
1121+ AF.request(request).response { (response) in
1122+ isValidTocken?(response.response?.statusCode ?? 498)
1123+
1124+ if let code = response.response?.statusCode, code == 498 {
1125+ return
1126+ }
1127+
1128+ if let code = response.response?.statusCode, code != 204{
1129+ completion (false)
1130+ } else {
1131+ completion(true)
1132+ }
1133+ }
1134+ }
1135+
1136+ static func deactivateAll(completion: @escaping (()->())){
1137+ var request = URLRequest(url: deactivateURL)
1138+ request.httpMethod = "DELETE"
1139+
1140+ AF.request(request).response { (responce) in
1141+ isValidTocken?(responce.response?.statusCode ?? 498)
1142+
1143+ if let code = responce.response?.statusCode, code == 498 {
1144+ return
1145+ }
1146+
1147+ completion()
1148+ }
1149+ }
9981150}