@@ -10,22 +10,6 @@ import Foundation
10import UIKit
10import UIKit
11import Alamofire
11import Alamofire
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
23− case tooMuchToAdd = 406
29class Model{
13class Model{
31 static let invalidTocken = 498
15 static let invalidTocken = 498
@@ -33,7 +17,7 @@ class Model{
33 static var hashTagTree: CompletionTree?
17 static var hashTagTree: CompletionTree?
35 private static var isValidTocken: ((Int)->())? = { responce in
19 private static var isValidTocken: ((Int)->())? = { responce in
37 if responce == invalidTocken {
21 if responce == invalidTocken {
39 DataStorage.standard.setIsLoggedIn(value: false, with: 0)
23 DataStorage.standard.setIsLoggedIn(value: false, with: 0)
@@ -49,7 +33,6 @@ class Model{
49 static let decoder = JSONDecoder()
33 static let decoder = JSONDecoder()
51 static let authMeURL = URL(string: "\(baseUrl)/authentication/me")!
35 static let authMeURL = URL(string: "\(baseUrl)/authentication/me")!
52− static let deactivateURL = URL(string: "\(baseUrl)/deactivateAll")!
53 static let registerMeURL = URL(string: "\(baseUrl)/authentication/register")!
36 static let registerMeURL = URL(string: "\(baseUrl)/authentication/register")!
54 static let authVerifyURL = URL(string: "\(baseUrl)/authentication/verify")!
37 static let authVerifyURL = URL(string: "\(baseUrl)/authentication/verify")!
55 static let authenticationURL = URL(string:"\(baseUrl)/authentication/login")!
38 static let authenticationURL = URL(string:"\(baseUrl)/authentication/login")!
@@ -59,7 +42,6 @@ class Model{
59 static let postsPublishURL = URL(string:"\(baseUrl)/posts/publish")!
42 static let postsPublishURL = URL(string:"\(baseUrl)/posts/publish")!
60 static let usersURL = URL(string:"\(baseUrl)/users")!
43 static let usersURL = URL(string:"\(baseUrl)/users")!
61 static let usersAllURL = URL(string:"\(baseUrl)/users/all")!
44 static let usersAllURL = URL(string:"\(baseUrl)/users/all")!
62− static let usersUpdateURL = URL(string:"\(baseUrl)/users/update")!
63 static let channelsGetURL = URL(string: "\(baseUrl)/channels/get")!
45 static let channelsGetURL = URL(string: "\(baseUrl)/channels/get")!
64 static let channelsUpdateURL = URL(string: "\(baseUrl)/channels/update")!
46 static let channelsUpdateURL = URL(string: "\(baseUrl)/channels/update")!
65 static let channelsListURL = URL(string: "\(baseUrl)/channels")!
47 static let channelsListURL = URL(string: "\(baseUrl)/channels")!
@@ -269,13 +251,15 @@ class Model{
271 if code == 204 {
253 if code == 204 {
273 let fields = responce.response?.allHeaderFields as? [String :String]
254 let fields = responce.response?.allHeaderFields as? [String :String]
274 let cookies = HTTPCookie.cookies(withResponseHeaderFields: fields!, for: responce.response!.url!)
256 let cookies = HTTPCookie.cookies(withResponseHeaderFields: fields!, for: responce.response!.url!)
275 HTTPCookieStorage.shared.setCookie(cookies[0])
258 HTTPCookieStorage.shared.setCookie(cookies[0])
277 completion()
260 completion()
@@ -427,7 +411,7 @@ class Model{
430− static func createAndPublish(body: [Attachments], tags: [String], completion: @escaping ((ResultR)->())){
414+ static func createAndPublish(body: [Attachments], tags: [String]){
431 let jsonUpd = CreatedPost(body: body, tags: tags)
415 let jsonUpd = CreatedPost(body: body, tags: tags)
432 var request = URLRequest(url: postsPublishURL)
416 var request = URLRequest(url: postsPublishURL)
@@ -445,14 +429,6 @@ class Model{
445 if let code = response.response?.statusCode, code == 498 {
429 if let code = response.response?.statusCode, code == 498 {
449− if let code = response.response?.statusCode,
450− let result = ResultR(rawValue: code)
454− completion(.internalServerError)
@@ -494,7 +470,7 @@ class Model{
495 static func getUsers(for ids: [Int], completion: @escaping (([Int:Users])->())){
471 static func getUsers(for ids: [Int], completion: @escaping (([Int:Users])->())){
496 let json = "\(Set(ids))"
472 let json = "\(Set(ids))"
498 var request = URLRequest(url: usersURL)
474 var request = URLRequest(url: usersURL)
500 request.httpMethod = "POST"
476 request.httpMethod = "POST"
@@ -558,7 +534,7 @@ class Model{
561− static func createChannel(with channel: Channels, completion: @escaping ((ResultR)->())) {
537+ static func createChannel(with channel: Channels) {
563 var request = URLRequest(url: channelsCreateURL)
539 var request = URLRequest(url: channelsCreateURL)
564 request.httpMethod = "POST"
540 request.httpMethod = "POST"
@@ -569,13 +545,9 @@ class Model{
569 (response) in
545 (response) in
571 isValidTocken?(response.response?.statusCode ?? 498)
547 isValidTocken?(response.response?.statusCode ?? 498)
573− if let code = response.response?.statusCode, let result = ResultR(rawValue: code) {
548+ if let code = response.response?.statusCode, code == 498 {
578− completion(ResultR.internalServerError)
@@ -737,6 +709,8 @@ class Model{
737 guard let json = response.data else { return }
709 guard let json = response.data else { return }
739 guard let newQueery = try? decoder.decode(QueryPosts<Posts>.self, from: json) else { return }
711 guard let newQueery = try? decoder.decode(QueryPosts<Posts>.self, from: json) else { return }
713+ print("\(anonymousChannel) \(newQueery)")
740 completion((newQueery.users, newQueery.response))
714 completion((newQueery.users, newQueery.response))
@@ -953,7 +927,7 @@ class Model{
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])->()))
958 let req = GeneralRequest<Int>(direction: direction, limit: l, exclusiveFrom: exclusiveFrom, request: id)
932 let req = GeneralRequest<Int>(direction: direction, limit: l, exclusiveFrom: exclusiveFrom, request: id)
959 var request: URLRequest?
933 var request: URLRequest?
@@ -1056,7 +1030,7 @@ class Model{
1059− static func sendMessage(message: SendMessage, completion: @escaping ((ResultR)->())){
1033+ static func sendMessage(message: SendMessage, completion: @escaping (()->())){
1061 var request = URLRequest(url: messagesSendURL)
1035 var request = URLRequest(url: messagesSendURL)
1062 request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
1036 request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
@@ -1070,11 +1044,7 @@ class Model{
1073− if let result = ResultR(rawValue: response.response!.statusCode){
1076− completion(.internalServerError)
1047+ completion()
@@ -1111,40 +1081,4 @@ class Model{
1111 completion(faculties)
1081 completion(faculties)
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)
1121− AF.request(request).response { (response) in
1122− isValidTocken?(response.response?.statusCode ?? 498)
1124− if let code = response.response?.statusCode, code == 498 {
1128− if let code = response.response?.statusCode, code != 204{
1136− static func deactivateAll(completion: @escaping (()->())){
1137− var request = URLRequest(url: deactivateURL)
1138− request.httpMethod = "DELETE"
1140− AF.request(request).response { (responce) in
1141− isValidTocken?(responce.response?.statusCode ?? 498)
1143− if let code = responce.response?.statusCode, code == 498 {