mirror of
https://github.com/dashared/GDproject.git
synced 2024-11-29 02:54:30 +03:00
Added validation of status codes to messages and new post.
This commit is contained in:
parent
46b3bdf1cf
commit
9a307ababb
@ -846,7 +846,7 @@
|
||||
<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" reuseIdentifier="peopleToWriteCell" textLabel="e4H-yo-W57" detailTextLabel="QSb-Bd-4gu" style="IBUITableViewCellStyleValue1" id="5ue-Sf-Blf">
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="peopleToWriteCell" textLabel="e4H-yo-W57" style="IBUITableViewCellStyleDefault" id="5ue-Sf-Blf">
|
||||
<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="5ue-Sf-Blf" id="8Dr-YE-x7M">
|
||||
@ -854,14 +854,7 @@
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="e4H-yo-W57">
|
||||
<rect key="frame" x="16" y="12" 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="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="QSb-Bd-4gu">
|
||||
<rect key="frame" x="315" y="12" width="44" height="20.5"/>
|
||||
<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"/>
|
||||
|
@ -232,13 +232,25 @@ class NewPostViewController: UIViewController, UITextViewDelegate, TagsReceiver
|
||||
var indexOfPost = 0
|
||||
// MARK:- new post
|
||||
@objc func newPost(){
|
||||
Model.createAndPublish(body: [Model.Attachments(markdown: textView!.text)], tags: currentTags)
|
||||
Model.createAndPublish(body: [Model.Attachments(markdown: textView!.text)], tags: currentTags) {
|
||||
[weak self] in
|
||||
|
||||
switch $0 {
|
||||
case .success1, .success:
|
||||
NewPostViewController.draft = ""
|
||||
NewPostViewController.hashTagsDraft = []
|
||||
self?.moveBackToParentVC?()
|
||||
default:
|
||||
// self?.actionSaveDraft()
|
||||
self?.showAlertOn(result: $0)
|
||||
}
|
||||
}
|
||||
|
||||
NewPostViewController.draft = ""
|
||||
NewPostViewController.hashTagsDraft = []
|
||||
// NewPostViewController.draft = ""
|
||||
// NewPostViewController.hashTagsDraft = []
|
||||
// adding row to uiTableView after adding new post
|
||||
// myProtocol?.addPost(post: p)
|
||||
moveBackToParentVC?()
|
||||
// moveBackToParentVC?()
|
||||
// somewhere here i will be sending server notifications about new post arrival
|
||||
}
|
||||
|
||||
|
@ -132,8 +132,13 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
|
||||
{
|
||||
Model.sendMessage(message: Model.SendMessage(body: Model.Attachments(markdown: messageTextView.text), destination: destination)) { [unowned self] in
|
||||
|
||||
self.getMessagesNew(for: self.dialog!)
|
||||
self.messageTextView.text = ""
|
||||
switch $0 {
|
||||
case .success, .success1:
|
||||
self.getMessagesNew(for: self.dialog!)
|
||||
self.messageTextView.text = ""
|
||||
default:
|
||||
self.showAlertOn(result: $0)
|
||||
}
|
||||
}
|
||||
|
||||
prevLast = -1
|
||||
|
@ -427,7 +427,7 @@ class Model{
|
||||
}
|
||||
|
||||
|
||||
static func createAndPublish(body: [Attachments], tags: [String]){
|
||||
static func createAndPublish(body: [Attachments], tags: [String], completion: @escaping ((ResultR)->())){
|
||||
let jsonUpd = CreatedPost(body: body, tags: tags)
|
||||
var request = URLRequest(url: postsPublishURL)
|
||||
|
||||
@ -445,6 +445,14 @@ class Model{
|
||||
if let code = response.response?.statusCode, code == 498 {
|
||||
return
|
||||
}
|
||||
|
||||
if let code = response.response?.statusCode,
|
||||
let result = ResultR(rawValue: code)
|
||||
{
|
||||
completion(result)
|
||||
} else {
|
||||
completion(.internalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1048,7 +1056,7 @@ class Model{
|
||||
}
|
||||
}
|
||||
|
||||
static func sendMessage(message: SendMessage, completion: @escaping (()->())){
|
||||
static func sendMessage(message: SendMessage, completion: @escaping ((ResultR)->())){
|
||||
|
||||
var request = URLRequest(url: messagesSendURL)
|
||||
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
|
||||
@ -1062,7 +1070,11 @@ class Model{
|
||||
return
|
||||
}
|
||||
|
||||
completion()
|
||||
if let result = ResultR(rawValue: response.response!.statusCode){
|
||||
completion(result)
|
||||
} else {
|
||||
completion(.internalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user