git.iko.soy/dashared/GDproject
on master help sign in
Added validation of status codes to messages and new post.
9a307abDarya Rednikina
GDproject/Base.lproj/Main.storyboard+2−9
@@ -846,7 +846,7 @@
846 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
846 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
847 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
847 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
848 <prototypes>
848 <prototypes>
849− <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">
850 <rect key="frame" x="0.0" y="28" width="375" height="44"/>
850 <rect key="frame" x="0.0" y="28" width="375" height="44"/>
851 <autoresizingMask key="autoresizingMask"/>
851 <autoresizingMask key="autoresizingMask"/>
852 <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="5ue-Sf-Blf" id="8Dr-YE-x7M">
852 <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="5ue-Sf-Blf" id="8Dr-YE-x7M">
@@ -854,14 +854,7 @@
854 <autoresizingMask key="autoresizingMask"/>
854 <autoresizingMask key="autoresizingMask"/>
855 <subviews>
855 <subviews>
856 <label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="e4H-yo-W57">
856 <label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="e4H-yo-W57">
857− <rect key="frame" x="16" y="12" width="33.5" height="20.5"/>
857+ <rect key="frame" x="16" y="0.0" width="343" height="43.5"/>
858− <autoresizingMask key="autoresizingMask"/>
859− <fontDescription key="fontDescription" type="system" pointSize="17"/>
860− <nil key="textColor"/>
861− <nil key="highlightedColor"/>
862− </label>
863− <label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="QSb-Bd-4gu">
864− <rect key="frame" x="315" y="12" width="44" height="20.5"/>
865 <autoresizingMask key="autoresizingMask"/>
858 <autoresizingMask key="autoresizingMask"/>
866 <fontDescription key="fontDescription" type="system" pointSize="17"/>
859 <fontDescription key="fontDescription" type="system" pointSize="17"/>
867 <nil key="textColor"/>
860 <nil key="textColor"/>
GDproject/Controller/ News and channels/NewPostViewController.swift+16−4
@@ -232,13 +232,25 @@ class NewPostViewController: UIViewController, UITextViewDelegate, TagsReceiver
232 var indexOfPost = 0
232 var indexOfPost = 0
233 // MARK:- new post
233 // MARK:- new post
234 @objc func newPost(){
234 @objc func newPost(){
235− Model.createAndPublish(body: [Model.Attachments(markdown: textView!.text)], tags: currentTags)
235+ Model.createAndPublish(body: [Model.Attachments(markdown: textView!.text)], tags: currentTags) {
236+ [weak self] in
237+
238+ switch $0 {
239+ case .success1, .success:
240+ NewPostViewController.draft = ""
241+ NewPostViewController.hashTagsDraft = []
242+ self?.moveBackToParentVC?()
243+ default:
244+ // self?.actionSaveDraft()
245+ self?.showAlertOn(result: $0)
246+ }
247+ }
236
248
237− NewPostViewController.draft = ""
249+ // NewPostViewController.draft = ""
238− NewPostViewController.hashTagsDraft = []
250+ // NewPostViewController.hashTagsDraft = []
239 // adding row to uiTableView after adding new post
251 // adding row to uiTableView after adding new post
240 // myProtocol?.addPost(post: p)
252 // myProtocol?.addPost(post: p)
241− moveBackToParentVC?()
253+ // moveBackToParentVC?()
242 // somewhere here i will be sending server notifications about new post arrival
254 // somewhere here i will be sending server notifications about new post arrival
243 }
255 }
244
256
GDproject/Controller/Messages/Dialog/DialogViewController.swift+7−2
@@ -132,8 +132,13 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
132 {
132 {
133 Model.sendMessage(message: Model.SendMessage(body: Model.Attachments(markdown: messageTextView.text), destination: destination)) { [unowned self] in
133 Model.sendMessage(message: Model.SendMessage(body: Model.Attachments(markdown: messageTextView.text), destination: destination)) { [unowned self] in
134
134
135+ switch $0 {
136+ case .success, .success1:
135− self.getMessagesNew(for: self.dialog!)
137+ self.getMessagesNew(for: self.dialog!)
136− self.messageTextView.text = ""
138+ self.messageTextView.text = ""
139+ default:
140+ self.showAlertOn(result: $0)
141+ }
137 }
142 }
138
143
139 prevLast = -1
144 prevLast = -1
GDproject/Simple model/Model.swift+15−3
@@ -427,7 +427,7 @@ class Model{
427 }
427 }
428
428
429
429
430− static func createAndPublish(body: [Attachments], tags: [String]){
430+ static func createAndPublish(body: [Attachments], tags: [String], completion: @escaping ((ResultR)->())){
431 let jsonUpd = CreatedPost(body: body, tags: tags)
431 let jsonUpd = CreatedPost(body: body, tags: tags)
432 var request = URLRequest(url: postsPublishURL)
432 var request = URLRequest(url: postsPublishURL)
433
433
@@ -445,6 +445,14 @@ class Model{
445 if let code = response.response?.statusCode, code == 498 {
445 if let code = response.response?.statusCode, code == 498 {
446 return
446 return
447 }
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+ }
448 }
456 }
449 }
457 }
450
458
@@ -1048,7 +1056,7 @@ class Model{
1048 }
1056 }
1049 }
1057 }
1050
1058
1051− static func sendMessage(message: SendMessage, completion: @escaping (()->())){
1059+ static func sendMessage(message: SendMessage, completion: @escaping ((ResultR)->())){
1052
1060
1053 var request = URLRequest(url: messagesSendURL)
1061 var request = URLRequest(url: messagesSendURL)
1054 request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
1062 request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
@@ -1062,7 +1070,11 @@ class Model{
1062 return
1070 return
1063 }
1071 }
1064
1072
1073+ if let result = ResultR(rawValue: response.response!.statusCode){
1074+ completion(result)
1075+ } else {
1065− completion()
1076+ completion(.internalServerError)
1077+ }
1066 }
1078 }
1067 }
1079 }
1068
1080