Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.

Commit 6b08a18

Browse files
authored
Merge pull request #1998 from RocketChat/develop
[RELEASE] Merge DEVELOP into BETA
2 parents ec607e9 + 99a2253 commit 6b08a18

12 files changed

Lines changed: 90 additions & 26 deletions

File tree

Rocket.Chat.xcodeproj/project.pbxproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,6 @@
492492
807371A21F96968C00D53ADF /* LoginServiceModelMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 807371A11F96968C00D53ADF /* LoginServiceModelMapping.swift */; };
493493
807371A61F96A4FF00D53ADF /* LoginServiceModelHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 807371A51F96A4FF00D53ADF /* LoginServiceModelHandler.swift */; };
494494
8076FD9A20484A6000114F28 /* SEStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8076FD9920484A6000114F28 /* SEStore.swift */; };
495-
8076FD9B20484DBF00114F28 /* DatabaseManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 412F8DD81F599EF100AF7786 /* DatabaseManager.swift */; };
496495
8076FD9D2048510100114F28 /* AuthSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41A87BAC1DA66E700000EE80 /* AuthSettings.swift */; };
497496
8076FD9E2048510C00114F28 /* AuthManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41552F651D30308C0081438D /* AuthManager.swift */; };
498497
8076FDA02048519D00114F28 /* AuthManagerSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8076FD9F2048519D00114F28 /* AuthManagerSocket.swift */; };
@@ -714,6 +713,8 @@
714713
999483EB20644CC4004F61CA /* WebBrowserViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 999483EA20644CC4004F61CA /* WebBrowserViewModel.swift */; };
715714
999F25B5207EEB0C002E0F68 /* FileModelMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 999F25B4207EEB0C002E0F68 /* FileModelMapping.swift */; };
716715
99B060CE1FB1225200F471C2 /* DraftMessageManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 99B060CD1FB1225200F471C2 /* DraftMessageManager.swift */; };
716+
99B15BCD20FD4589005A528F /* DatabaseManagerAuthSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 99B15BCC20FD4589005A528F /* DatabaseManagerAuthSettings.swift */; };
717+
99B15BCF20FD4681005A528F /* DatabaseManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 412F8DD81F599EF100AF7786 /* DatabaseManager.swift */; };
717718
99B802ED20BC3BD400230109 /* ImageManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 99B802EC20BC3BD400230109 /* ImageManager.swift */; };
718719
99B802EE20BC3EF700230109 /* ImageManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 99B802EC20BC3BD400230109 /* ImageManager.swift */; };
719720
99B802EF20BC3F0800230109 /* StringExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4174CB1E1D2DB3350086DAC8 /* StringExtensions.swift */; };
@@ -1517,6 +1518,7 @@
15171518
999483EA20644CC4004F61CA /* WebBrowserViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebBrowserViewModel.swift; sourceTree = "<group>"; };
15181519
999F25B4207EEB0C002E0F68 /* FileModelMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileModelMapping.swift; sourceTree = "<group>"; };
15191520
99B060CD1FB1225200F471C2 /* DraftMessageManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DraftMessageManager.swift; sourceTree = "<group>"; };
1521+
99B15BCC20FD4589005A528F /* DatabaseManagerAuthSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseManagerAuthSettings.swift; sourceTree = "<group>"; };
15201522
99B802EC20BC3BD400230109 /* ImageManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageManager.swift; sourceTree = "<group>"; };
15211523
99C577ED207E4F1500CE9B4D /* File.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = File.swift; sourceTree = "<group>"; };
15221524
99D77C6A20E474BF008F2438 /* AnalyticsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsManager.swift; sourceTree = "<group>"; };
@@ -2195,6 +2197,7 @@
21952197
411EDECE1E30F2D700BC7BE3 /* Uploader */,
21962198
4101BF001F8D0A1700F67E89 /* AppManager.swift */,
21972199
412F8DD81F599EF100AF7786 /* DatabaseManager.swift */,
2200+
99B15BCC20FD4589005A528F /* DatabaseManagerAuthSettings.swift */,
21982201
419ECCA31F3CA21A005F224B /* DownloadManager.swift */,
21992202
99B060CD1FB1225200F471C2 /* DraftMessageManager.swift */,
22002203
4174CB1B1D2DB2080086DAC8 /* LogManager.swift */,
@@ -4174,6 +4177,7 @@
41744177
995F710E20C7837300B7535F /* AuthSeparatorTableViewCell.swift in Sources */,
41754178
41B554C51FBF0C71000510B7 /* UIWindowExtensions.swift in Sources */,
41764179
8062E33520A5ECF50044F407 /* APIRequestOption.swift in Sources */,
4180+
99B15BCD20FD4589005A528F /* DatabaseManagerAuthSettings.swift in Sources */,
41774181
807C7C0620751ED2006B600E /* SpotlightClient.swift in Sources */,
41784182
8039441120AF1334002F317A /* RoomKickRequest.swift in Sources */,
41794183
33383509207926DE006E1D0A /* TransparentToTouchesWindow.swift in Sources */,
@@ -4711,12 +4715,12 @@
47114715
4100B2842087779D00E2883A /* LogManager.swift in Sources */,
47124716
80D0CE62205023710056B17F /* SECell.swift in Sources */,
47134717
80FA90702056A33A0069038F /* SEComposeViewModel.swift in Sources */,
4714-
8076FD9B20484DBF00114F28 /* DatabaseManager.swift in Sources */,
47154718
80977AB2204EE21F00C41435 /* SendMessageRequest.swift in Sources */,
47164719
41D51B0720A62DD60073E8E7 /* Role.swift in Sources */,
47174720
80977AB6204EEF1E00C41435 /* SelectServer.swift in Sources */,
47184721
807FB55B2046E7DD00E21429 /* SERoomsViewController.swift in Sources */,
47194722
80977AC4204FEEA700C41435 /* SEComposeHeaderViewModel.swift in Sources */,
4723+
99B15BCF20FD4681005A528F /* DatabaseManager.swift in Sources */,
47204724
804273E2204EBD51006DF420 /* APIResponse.swift in Sources */,
47214725
8029B2F22059B6F60067157B /* VideoInfo.swift in Sources */,
47224726
80D0CE6620503C860056B17F /* SERoomCell.swift in Sources */,

Rocket.Chat/API/Requests/Room/RoomsRequest.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ struct RoomsRequest: APIRequest {
1515

1616
var query: String? {
1717
if let updatedSince = updatedSince {
18-
let dateFormatter = DateFormatter()
19-
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
20-
return "updatedSince=\(dateFormatter.string(from: updatedSince))"
18+
let dateFormatter = ISO8601DateFormatter()
19+
let dateString = dateFormatter.string(from: updatedSince)
20+
21+
if let encodedString = dateString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
22+
return "updatedSince=\(encodedString)"
23+
}
24+
25+
return ""
2126
}
2227

2328
return nil

Rocket.Chat/API/Requests/Subscription/SubscriptionsRequest.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ struct SubscriptionsRequest: APIRequest {
1616

1717
var query: String? {
1818
if let updatedSince = updatedSince {
19-
let dateFormatter = DateFormatter()
20-
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
21-
return "updatedSince=\(dateFormatter.string(from: updatedSince))"
19+
let dateFormatter = ISO8601DateFormatter()
20+
let dateString = dateFormatter.string(from: updatedSince)
21+
22+
if let encodedString = dateString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
23+
return "updatedSince=\(encodedString)"
24+
}
25+
26+
return ""
2227
}
2328

2429
return nil

Rocket.Chat/Managers/AppManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ extension AppManager {
119119

120120
static func changeSelectedServer(index: Int) {
121121
guard index != DatabaseManager.selectedIndex else {
122+
DatabaseManager.changeDatabaseInstance(index: index)
122123
reloadApp()
123124
return
124125
}

Rocket.Chat/Managers/DatabaseManager.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,6 @@ struct DatabaseManager {
159159
return index
160160
}
161161

162-
/**
163-
This method is responsible to get the server
164-
information that's stored locally on device and
165-
use it to change the database configuration being
166-
used by the currently instance.
167-
168-
- parameter index: If the index you want to use isn't stored
169-
into the UserDefaults.group, you can for the index
170-
using this parameter.
171-
*/
172-
static func changeDatabaseInstance(index: Int? = nil) {
173-
realmConfiguration = databaseConfiguration(index: index)
174-
}
175-
176162
/**
177163
This method gets the realm associated with this server
178164
*/
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// DatabaseManagerServers.swift
3+
// Rocket.Chat
4+
//
5+
// Created by Filipe Alvarenga on 16/07/18.
6+
// Copyright © 2018 Rocket.Chat. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
extension DatabaseManager {
12+
/**
13+
This method is responsible to get the server
14+
information that's stored locally on device and
15+
use it to change the database configuration being
16+
used by the currently instance.
17+
18+
- parameter index: If the index you want to use isn't stored
19+
into the UserDefaults.group, you can for the index
20+
using this parameter.
21+
*/
22+
static func changeDatabaseInstance(index: Int? = nil) {
23+
AuthSettingsManager.shared.clearCachedSettings()
24+
realmConfiguration = databaseConfiguration(index: index)
25+
}
26+
}

Rocket.Chat/Managers/Model/SubscriptionManager/SubscriptionManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ struct SubscriptionManager {
2828
realm?.refresh()
2929

3030
let client = API.current(realm: realm)?.client(SubscriptionsClient.self)
31-
let lastUpdateSubscriptions = auth.lastSubscriptionFetchWithLastMessage
32-
let lastUpdateRooms = auth.lastRoomFetchWithLastMessage
31+
let lastUpdateSubscriptions = auth.lastSubscriptionFetchWithLastMessage?.addingTimeInterval(-100000)
32+
let lastUpdateRooms = auth.lastRoomFetchWithLastMessage?.addingTimeInterval(-100000)
3333

3434
// The call needs to be nested because at the first time the user
3535
// opens the app we don't have the Subscriptions and the Room object

Rocket.Chat/Managers/Socket/Response/SocketError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension SocketError {
1515

1616
init(rawValue: String) {
1717
switch rawValue {
18-
case "403":
18+
case "403", "401":
1919
self = .invalidSession
2020
default:
2121
self = .other(rawValue)

Rocket.Chat/Managers/Socket/Response/SocketHandlers.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,41 @@ extension SocketManager {
5353

5454
fileprivate func handleError(_ result: SocketResponse, socket: WebSocket) {
5555
let error = SocketError(json: result.result["error"])
56+
switch error.error {
57+
case .invalidSession:
58+
guard !isPresentingInvalidSessionAlert else {
59+
return
60+
}
61+
62+
let invalidSessionAlert = UIAlertController(
63+
title: localized("alert.socket_error.invalid_user.title"),
64+
message: localized("alert.socket_error.invalid_user.message"),
65+
preferredStyle: .alert
66+
)
67+
68+
invalidSessionAlert.addAction(UIAlertAction(title: localized("global.ok"), style: .default, handler: { _ in
69+
self.isPresentingInvalidSessionAlert = false
70+
AppManager.reloadApp()
71+
}))
72+
73+
func present() {
74+
isPresentingInvalidSessionAlert = true
75+
76+
let alertWindow = UIWindow.topWindow
77+
alertWindow.windowLevel = UIWindowLevelAlert + 1
78+
alertWindow.rootViewController?.present(invalidSessionAlert, animated: true)
79+
}
80+
81+
API.current()?.client(PushClient.self).deletePushToken()
82+
83+
AuthManager.logout {
84+
AuthManager.recoverAuthIfNeeded()
85+
DispatchQueue.main.async(execute: present)
86+
}
87+
default:
88+
break
89+
}
90+
5691
Log.debug("[ERROR][SocketManager]: \(error.message)")
5792
}
5893

Rocket.Chat/Managers/Socket/SocketManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ final class SocketManager {
5555

5656
internal var internalConnectionHandler: SocketCompletion?
5757
internal var connectionHandlers = NSMapTable<NSString, AnyObject>(keyOptions: .strongMemory, valueOptions: .weakMemory)
58+
internal var isPresentingInvalidSessionAlert = false
5859

5960
// MARK: Connection
6061

0 commit comments

Comments
 (0)