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

Commit 37bdd1e

Browse files
authored
Merge pull request #1709 from RocketChat/beta
[RELEASE] Merge beta into master
2 parents 38ac1f1 + 4482665 commit 37bdd1e

File tree

17 files changed

+91
-83
lines changed

17 files changed

+91
-83
lines changed

Rocket.Chat.ShareExtension/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
<key>CFBundlePackageType</key>
1818
<string>XPC!</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>2.4.0</string>
20+
<string>2.4.1</string>
2121
<key>CFBundleVersion</key>
22-
<string>171</string>
22+
<string>176</string>
2323
<key>ITSEncryptionExportComplianceCode</key>
2424
<string></string>
2525
<key>NSExtension</key>

Rocket.Chat/API/Clients/SubscriptionsClient.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ struct SubscriptionsClient: APIClient {
3030
}
3131

3232
func fetchSubscriptions(updatedSince: Date?, realm: Realm? = Realm.current, completion: (() -> Void)? = nil) {
33-
let req = SubscriptionsRequest(updatedSince: updatedSince)
33+
let req = SubscriptionsRequest()
3434

3535
let currentRealm = realm
3636

3737
api.fetch(req, options: [.retryOnError(count: 3)]) { response in
3838
switch response {
3939
case .resource(let resource):
40-
guard resource.success == true else { return }
40+
guard resource.success == true else {
41+
completion?()
42+
return
43+
}
4144

4245
let subscriptions = List<Subscription>()
4346

@@ -67,21 +70,24 @@ struct SubscriptionsClient: APIClient {
6770
case .version:
6871
self.fetchSubscriptionsFallback(updatedSince: updatedSince, realm: realm, completion: completion)
6972
default:
70-
break
73+
completion?()
7174
}
7275
}
7376
}
7477
}
7578

7679
func fetchRooms(updatedSince: Date?, realm: Realm? = Realm.current, completion: (() -> Void)? = nil) {
77-
let req = RoomsRequest(updatedSince: updatedSince)
80+
let req = RoomsRequest()
7881

7982
let currentRealm = realm
8083

8184
api.fetch(req, options: [.retryOnError(count: 3)]) { response in
8285
switch response {
8386
case .resource(let resource):
84-
guard resource.success == true else { return }
87+
guard resource.success == true else {
88+
completion?()
89+
return
90+
}
8591

8692
currentRealm?.execute({ realm in
8793
guard let auth = AuthManager.isAuthenticated(realm: realm) else { return }
@@ -113,7 +119,7 @@ struct SubscriptionsClient: APIClient {
113119
case .version:
114120
self.fetchRoomsFallback(updatedSince: updatedSince, realm: realm, completion: completion)
115121
default:
116-
break
122+
completion?()
117123
}
118124
}
119125
}

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,6 @@ struct RoomsRequest: APIRequest {
1212
typealias APIResourceType = RoomsResource
1313
let path = "/api/v1/rooms.get"
1414
let requiredVersion = Version(0, 62, 0)
15-
16-
var query: String? {
17-
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))"
21-
}
22-
23-
return nil
24-
}
25-
26-
let updatedSince: Date?
27-
28-
init(updatedSince: Date? = nil) {
29-
self.updatedSince = updatedSince
30-
}
3115
}
3216

3317
final class RoomsResource: APIResource {

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,6 @@ struct SubscriptionsRequest: APIRequest {
1313
typealias APIResourceType = SubscriptionsResource
1414
let path = "/api/v1/subscriptions.get"
1515
let requiredVersion = Version(0, 60, 0)
16-
17-
var query: String? {
18-
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))"
22-
}
23-
24-
return nil
25-
}
26-
27-
let updatedSince: Date?
28-
29-
init(updatedSince: Date? = nil) {
30-
self.updatedSince = updatedSince
31-
}
3216
}
3317

3418
final class SubscriptionsResource: APIResource {

Rocket.Chat/Controllers/Auth/AuthViewController.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ final class AuthViewController: BaseViewController {
247247
return
248248
}
249249

250+
if loginService.service == "gitlab", let url = serverPublicSettings?.gitlabUrl {
251+
try? realm.write {
252+
loginService.serverUrl = url
253+
}
254+
}
255+
250256
switch loginService.type {
251257
case .cas:
252258
presentCASViewController(for: loginService)

Rocket.Chat/Controllers/Subscriptions/FilesListViewController.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,23 @@ class FilesListViewData {
5656
}
5757

5858
private func handle(result: SubscriptionFilesResource, completion: (() -> Void)? = nil) {
59-
self.showing += result.count ?? 0
60-
self.total = result.total ?? 0
61-
62-
if let files = result.files {
63-
guard !files.isEmpty else {
64-
self.isLoadingMoreFiles = false
65-
completion?()
66-
return
67-
}
68-
69-
self.cells.append(contentsOf: files)
59+
self.showing += result.count ?? 0
60+
self.total = result.total ?? 0
61+
62+
if let files = result.files {
63+
guard !files.isEmpty else {
64+
self.isLoadingMoreFiles = false
65+
completion?()
66+
return
7067
}
7168

72-
self.currentPage += 1
69+
self.cells.append(contentsOf: files)
70+
}
71+
72+
self.currentPage += 1
7373

74-
self.isLoadingMoreFiles = false
75-
completion?()
74+
self.isLoadingMoreFiles = false
75+
completion?()
7676
}
7777
}
7878

Rocket.Chat/Extensions/URLExtension.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ extension URL {
2626
}
2727

2828
init?(string: String, scheme: String) {
29+
var string = string
30+
if !string.contains("://") {
31+
string = "https://\(string)"
32+
}
33+
2934
guard let url = URL(string: string) else {
3035
return nil
3136
}

Rocket.Chat/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@
206206
<key>CFBundlePackageType</key>
207207
<string>APPL</string>
208208
<key>CFBundleShortVersionString</key>
209-
<string>2.4.0</string>
209+
<string>2.4.1</string>
210210
<key>CFBundleSignature</key>
211211
<string>????</string>
212212
<key>CFBundleURLTypes</key>
@@ -222,7 +222,7 @@
222222
</dict>
223223
</array>
224224
<key>CFBundleVersion</key>
225-
<string>171</string>
225+
<string>176</string>
226226
<key>Fabric</key>
227227
<dict>
228228
<key>APIKey</key>

Rocket.Chat/Managers/NotificationManager.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,15 @@ final class NotificationManager {
3232
return
3333
}
3434

35+
let formattedBody = NSMutableAttributedString(string: notification.body)
36+
.transformMarkdown().string
37+
.components(separatedBy: .newlines)
38+
.joined(separator: " ")
39+
.replacingOccurrences(of: "^\\s+", with: "", options: .regularExpression)
40+
3541
NotificationViewController.shared.displayNotification(
3642
title: notification.title,
37-
body: notification.body.trimmingCharacters(in: .newlines),
43+
body: formattedBody,
3844
username: notification.payload.sender.username
3945
)
4046

Rocket.Chat/Managers/OAuthManager.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ final class OAuthManager {
8181
return nil
8282
}
8383

84-
return URL(string: "https://\(host)/_oauth/\(callbackPath)")
84+
var portString = ""
85+
if let port = server.port {
86+
portString = ":\(port)"
87+
}
88+
89+
return URL(string: "https://\(host)\(portString)/_oauth/\(callbackPath)")
8590
}
8691

8792
static func state() -> String? {

Rocket.Chat/Models/Mapping/SubscriptionModelMapping.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ extension Subscription: ModelMappeable {
2929
}
3030

3131
if self.type == .directMessage {
32-
let userId = values["u"]["_id"].stringValue
33-
self.otherUserId = self.rid.replacingOccurrences(of: userId, with: "")
32+
if let userId = values["u"]["_id"].string {
33+
if let range = self.rid.ranges(of: userId).first {
34+
self.otherUserId = self.rid.replacingCharacters(in: range, with: "")
35+
}
36+
}
3437
}
3538

3639
if let createdAt = values["ts"]["$date"].double {

Rocket.Chat/Models/User/UserQueries.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension User {
1919
let realm = realm,
2020
let user = realm.objects(User.self).filter("username = %@", username).first
2121
else {
22-
return nil
22+
return nil
2323
}
2424

2525
return user

Rocket.Chat/Views/Cells/Chat/ChatDirectMessageHeaderCell.swift

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,11 @@ final class ChatDirectMessageHeaderCell: UICollectionViewCell {
1515

1616
var subscription: Subscription? {
1717
didSet {
18-
guard let user = subscription?.directMessageUser else {
18+
guard subscription?.directMessageUser != nil else {
1919
return fetchUser()
2020
}
2121

22-
labelUser.text = user.displayName()
23-
avatarView.user = user
24-
25-
let startText = localized("chat.dm.start_conversation")
26-
labelStartConversation.text = String(format: startText, user.displayName())
22+
updateUser()
2723
}
2824
}
2925

@@ -55,13 +51,31 @@ final class ChatDirectMessageHeaderCell: UICollectionViewCell {
5551
labelStartConversation.text = ""
5652
}
5753

54+
func updateUser() {
55+
guard let user = subscription?.directMessageUser else {
56+
labelUser.text = ""
57+
labelStartConversation.text = ""
58+
return
59+
}
60+
61+
labelUser.text = user.displayName()
62+
avatarView.user = user
63+
64+
let startText = localized("chat.dm.start_conversation")
65+
labelStartConversation.text = String(format: startText, user.displayName())
66+
}
67+
5868
func fetchUser() {
59-
guard let userId = subscription?.otherUserId else { return }
69+
guard
70+
let userId = subscription?.otherUserId,
71+
!userId.isEmpty
72+
else {
73+
updateUser()
74+
return
75+
}
6076

6177
User.fetch(by: .userId(userId), completion: { _ in
62-
DispatchQueue.main.async { [weak self] in
63-
self?.subscription = self?.subscription
64-
}
78+
self.updateUser()
6579
})
6680
}
6781

Rocket.Chat/Views/Cells/Chat/Info/MemberCell.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,16 @@ final class MemberCell: UITableViewCell {
9191
extension MemberCell: ReactorPresenter {
9292
var reactor: String {
9393
set {
94+
guard !newValue.isEmpty else { return }
95+
9496
if let user = User.find(username: newValue) {
9597
data = MemberCellData(member: user)
9698
return
9799
}
98100

99101
User.fetch(by: .username(newValue), completion: { user in
100102
guard let user = user else { return }
101-
102-
DispatchQueue.main.async {
103-
self.data = MemberCellData(member: user)
104-
}
103+
self.data = MemberCellData(member: user)
105104
})
106105
}
107106

Rocket.ChatTests/API/Requests/Room/RoomsRequestSpec.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@ class RoomsRequestSpec: APITestCase {
2626
}
2727

2828
func testRequestWithUpdatedSince() {
29-
let date = Date.dateFromString("2015-03-25T12:00:00.000+0000")
30-
31-
let roomsRequest = RoomsRequest(updatedSince: date)
29+
let roomsRequest = RoomsRequest()
3230

3331
guard let request = roomsRequest.request(for: api) else {
3432
return XCTFail("request is not nil")
3533
}
3634

3735
XCTAssertEqual(request.url?.path, "/api/v1/rooms.get", "path is correct")
38-
XCTAssert(request.url?.query?.contains("updatedSince=") == true, "has updatedSince query parameter")
3936
XCTAssertEqual(request.httpMethod, "GET", "http method is correct")
4037
XCTAssertEqual(request.value(forHTTPHeaderField: "Content-Type"), "application/json", "content type is correct")
4138
}

Rocket.ChatTests/API/Requests/Subscription/SubscriptionsRequestSpec.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@ class SubscriptionsRequestSpec: APITestCase {
2626
}
2727

2828
func testRequestWithUpdatedSince() {
29-
let date = Date.dateFromString("2015-03-25T12:00:00.000+0000")
30-
31-
let subscriptionsRequest = SubscriptionsRequest(updatedSince: date)
29+
let subscriptionsRequest = SubscriptionsRequest()
3230

3331
guard let request = subscriptionsRequest.request(for: api) else {
3432
return XCTFail("request is not nil")
3533
}
3634

3735
XCTAssertEqual(request.url?.path, "/api/v1/subscriptions.get", "path is correct")
38-
XCTAssert(request.url?.query?.contains("updatedSince=") == true, "has updatedSince query parameter")
3936
XCTAssertEqual(request.httpMethod, "GET", "http method is correct")
4037
XCTAssertEqual(request.value(forHTTPHeaderField: "Content-Type"), "application/json", "content type is correct")
4138
}

Rocket.ChatTests/Extensions/URLExtensionSpec.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class URLExtensionSpec: XCTestCase {
3333

3434
func testInitWithStringAndScheme() {
3535
XCTAssertEqual(URL(string: "open.rocket.chat", scheme: "https")?.absoluteString, "https://open.rocket.chat", "will add scheme")
36+
XCTAssertEqual(URL(string: "open.rocket.chat:3000", scheme: "https")?.absoluteString, "https://open.rocket.chat:3000", "will add scheme & keep port")
3637
XCTAssertEqual(URL(string: "https://open.rocket.chat", scheme: "https")?.absoluteString, "https://open.rocket.chat", "will return correct url")
38+
XCTAssertEqual(URL(string: "https://open.rocket.chat:3000", scheme: "https")?.absoluteString, "https://open.rocket.chat:3000", "will return correct url & port")
3739
XCTAssertEqual(URL(string: "http://open.rocket.chat", scheme: "https")?.absoluteString, "https://open.rocket.chat", "will force https scheme")
3840
XCTAssertEqual(URL(string: "https://open.rocket.chat", scheme: "wss")?.absoluteString, "wss://open.rocket.chat", "will force wss scheme")
3941
XCTAssertEqual(URL(string: "http://open.rocket.chat/path", scheme: "https")?.absoluteString, "https://open.rocket.chat/path", "will keep path")

0 commit comments

Comments
 (0)