git.iko.soy/dashared/GDproject
on master help sign in
Added validation of status codes to messages and new post.
commit9a307ababb5342417dc87f4858f1a3b03b911d1b authorDarya Rednikina <rednikina.com@yandex.ru> dateTue 14 May 2019, 15:08 (7 years ago) parent46b3bdf
4 files changed+40−18
GDproject/Base.lproj/Main.storyboard+2−9 GDproject/Controller/ News and channels/NewPostViewController.swift+16−4 GDproject/Controller/Messages/Dialog/DialogViewController.swift+7−2 GDproject/Simple model/Model.swift+15−3
GDproject/Base.lproj/Main.storyboard+2−9
@@ -846,7 +846,7 @@
846846 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
847847 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
848848 <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">
850850 <rect key="frame" x="0.0" y="28" width="375" height="44"/>
851851 <autoresizingMask key="autoresizingMask"/>
852852 <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 @@
854854 <autoresizingMask key="autoresizingMask"/>
855855 <subviews>
856856 <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"/>
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"/>
857+ <rect key="frame" x="16" y="0.0" width="343" height="43.5"/>
865858 <autoresizingMask key="autoresizingMask"/>
866859 <fontDescription key="fontDescription" type="system" pointSize="17"/>
867860 <nil key="textColor"/>
GDproject/Controller/ News and channels/NewPostViewController.swift+16−4
@@ -232,13 +232,25 @@ class NewPostViewController: UIViewController, UITextViewDelegate, TagsReceiver
232232 var indexOfPost = 0
233233 // MARK:- new post
234234 @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+ }
236248
237− NewPostViewController.draft = ""
238− NewPostViewController.hashTagsDraft = []
249+ // NewPostViewController.draft = ""
250+ // NewPostViewController.hashTagsDraft = []
239251 // adding row to uiTableView after adding new post
240252 // myProtocol?.addPost(post: p)
241− moveBackToParentVC?()
253+ // moveBackToParentVC?()
242254 // somewhere here i will be sending server notifications about new post arrival
243255 }
244256
GDproject/Controller/Messages/Dialog/DialogViewController.swift+7−2
@@ -132,8 +132,13 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
132132 {
133133 Model.sendMessage(message: Model.SendMessage(body: Model.Attachments(markdown: messageTextView.text), destination: destination)) { [unowned self] in
134134
135− self.getMessagesNew(for: self.dialog!)
136− self.messageTextView.text = ""
135+ switch $0 {
136+ case .success, .success1:
137+ self.getMessagesNew(for: self.dialog!)
138+ self.messageTextView.text = ""
139+ default:
140+ self.showAlertOn(result: $0)
141+ }
137142 }
138143
139144 prevLast = -1
GDproject/Simple model/Model.swift+15−3
@@ -427,7 +427,7 @@ class Model{
427427 }
428428
429429
430− static func createAndPublish(body: [Attachments], tags: [String]){
430+ static func createAndPublish(body: [Attachments], tags: [String], completion: @escaping ((ResultR)->())){
431431 let jsonUpd = CreatedPost(body: body, tags: tags)
432432 var request = URLRequest(url: postsPublishURL)
433433
@@ -445,6 +445,14 @@ class Model{
445445 if let code = response.response?.statusCode, code == 498 {
446446 return
447447 }
448+
449+ if let code = response.response?.statusCode,
450+ let result = ResultR(rawValue: code)
451+ {
452+ completion(result)
453+ } else {
454+ completion(.internalServerError)
455+ }
448456 }
449457 }
450458
@@ -1048,7 +1056,7 @@ class Model{
10481056 }
10491057 }
10501058
1051− static func sendMessage(message: SendMessage, completion: @escaping (()->())){
1059+ static func sendMessage(message: SendMessage, completion: @escaping ((ResultR)->())){
10521060
10531061 var request = URLRequest(url: messagesSendURL)
10541062 request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
@@ -1062,7 +1070,11 @@ class Model{
10621070 return
10631071 }
10641072
1065− completion()
1073+ if let result = ResultR(rawValue: response.response!.statusCode){
1074+ completion(result)
1075+ } else {
1076+ completion(.internalServerError)
1077+ }
10661078 }
10671079 }
10681080