@@ -10,22 +10,6 @@ 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−
2913class Model{
3014
3115 static let invalidTocken = 498
@@ -33,7 +17,7 @@ class Model{
3317 static var hashTagTree: CompletionTree?
3418
3519 private static var isValidTocken: ((Int)->())? = { responce in
36− print(responce)
20+
3721 if responce == invalidTocken {
3822
3923 DataStorage.standard.setIsLoggedIn(value: false, with: 0)
@@ -49,7 +33,6 @@ class Model{
4933 static let decoder = JSONDecoder()
5034
5135 static let authMeURL = URL(string: "\(baseUrl)/authentication/me")!
52− static let deactivateURL = URL(string: "\(baseUrl)/deactivateAll")!
5336 static let registerMeURL = URL(string: "\(baseUrl)/authentication/register")!
5437 static let authVerifyURL = URL(string: "\(baseUrl)/authentication/verify")!
5538 static let authenticationURL = URL(string:"\(baseUrl)/authentication/login")!
@@ -59,7 +42,6 @@ class Model{
5942 static let postsPublishURL = URL(string:"\(baseUrl)/posts/publish")!
6043 static let usersURL = URL(string:"\(baseUrl)/users")!
6144 static let usersAllURL = URL(string:"\(baseUrl)/users/all")!
62− static let usersUpdateURL = URL(string:"\(baseUrl)/users/update")!
6345 static let channelsGetURL = URL(string: "\(baseUrl)/channels/get")!
6446 static let channelsUpdateURL = URL(string: "\(baseUrl)/channels/update")!
6547 static let channelsListURL = URL(string: "\(baseUrl)/channels")!
@@ -269,13 +251,15 @@ class Model{
269251 }
270252
271253 if code == 204 {
272−
273254 let fields = responce.response?.allHeaderFields as? [String :String]
255+
274256 let cookies = HTTPCookie.cookies(withResponseHeaderFields: fields!, for: responce.response!.url!)
257+
275258 HTTPCookieStorage.shared.setCookie(cookies[0])
276259
277260 completion()
278261 }
262+
279263 }
280264 }
281265
@@ -427,7 +411,7 @@ class Model{
427411 }
428412
429413
430− static func createAndPublish(body: [Attachments], tags: [String], completion: @escaping ((ResultR)->())){
414+ static func createAndPublish(body: [Attachments], tags: [String]){
431415 let jsonUpd = CreatedPost(body: body, tags: tags)
432416 var request = URLRequest(url: postsPublishURL)
433417
@@ -445,14 +429,6 @@ class Model{
445429 if let code = response.response?.statusCode, code == 498 {
446430 return
447431 }
448−
449− if let code = response.response?.statusCode,
450− let result = ResultR(rawValue: code)
451− {
452− completion(result)
453− } else {
454− completion(.internalServerError)
455− }
456432 }
457433 }
458434
@@ -494,7 +470,7 @@ class Model{
494470
495471 static func getUsers(for ids: [Int], completion: @escaping (([Int:Users])->())){
496472 let json = "\(Set(ids))"
497−
473+ print(json)
498474 var request = URLRequest(url: usersURL)
499475
500476 request.httpMethod = "POST"
@@ -558,7 +534,7 @@ class Model{
558534 }
559535
560536
561− static func createChannel(with channel: Channels, completion: @escaping ((ResultR)->())) {
537+ static func createChannel(with channel: Channels) {
562538
563539 var request = URLRequest(url: channelsCreateURL)
564540 request.httpMethod = "POST"
@@ -569,13 +545,9 @@ class Model{
569545 (response) in
570546
571547 isValidTocken?(response.response?.statusCode ?? 498)
572−
573− if let code = response.response?.statusCode, let result = ResultR(rawValue: code) {
574− completion(result)
548+ if let code = response.response?.statusCode, code == 498 {
575549 return
576550 }
577−
578− completion(ResultR.internalServerError)
579551 }
580552
581553 }
@@ -737,6 +709,8 @@ class Model{
737709 guard let json = response.data else { return }
738710
739711 guard let newQueery = try? decoder.decode(QueryPosts<Posts>.self, from: json) else { return }
712+
713+ print("\(anonymousChannel) \(newQueery)")
740714 completion((newQueery.users, newQueery.response))
741715 }
742716 }
@@ -953,7 +927,7 @@ class Model{
953927 }
954928 }
955929
956− static func getMessagesFor(typeOfChat: Model.Dialog, chat id: Int, exclusiveFrom: Int? = nil, limit l: Int = 25, direction: String = "backward", completion: @escaping (([LastMessage])->()))
930+ static func getMessagesFor(typeOfChat: Model.Dialog, chat id: Int, exclusiveFrom: Int? = nil, limit l: Int = 10, direction: String = "backward", completion: @escaping (([LastMessage])->()))
957931 {
958932 let req = GeneralRequest<Int>(direction: direction, limit: l, exclusiveFrom: exclusiveFrom, request: id)
959933 var request: URLRequest?
@@ -1056,7 +1030,7 @@ class Model{
10561030 }
10571031 }
10581032
1059− static func sendMessage(message: SendMessage, completion: @escaping ((ResultR)->())){
1033+ static func sendMessage(message: SendMessage, completion: @escaping (()->())){
10601034
10611035 var request = URLRequest(url: messagesSendURL)
10621036 request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
@@ -1070,11 +1044,7 @@ class Model{
10701044 return
10711045 }
10721046
1073− if let result = ResultR(rawValue: response.response!.statusCode){
1074− completion(result)
1075− } else {
1076− completion(.internalServerError)
1077− }
1047+ completion()
10781048 }
10791049 }
10801050
@@ -1111,40 +1081,4 @@ class Model{
11111081 completion(faculties)
11121082 }
11131083 }
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− }
11501084}