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

Commit 2226e12

Browse files
committed
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.iOS into feat/hw_keyboard_shortcuts
2 parents c40f402 + d6c014c commit 2226e12

63 files changed

Lines changed: 1562 additions & 178 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Podfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ def ui_pods
1313
pod 'MBProgressHUD', '~> 1.1.0'
1414
end
1515

16+
def diff_pods
17+
pod 'DifferenceKit'
18+
end
19+
1620
def shared_pods
1721
# Analytics
1822
pod 'Firebase/Core'
@@ -28,6 +32,7 @@ def shared_pods
2832
pod 'SlackTextViewController', :git => 'https://github.com/rafaelks/SlackTextViewController.git'
2933
pod 'MobilePlayer', :git => 'https://github.com/RocketChat/RCiOSMobilePlayer'
3034
pod 'SimpleImageViewer', :git => 'https://github.com/cardoso/SimpleImageViewer.git'
35+
pod 'SwipeCellKit'
3136
ui_pods
3237

3338
# Text Processing
@@ -49,12 +54,16 @@ def shared_pods
4954
# Debugging
5055
pod 'SwiftLint', :configurations => ['Debug']
5156
pod 'FLEX', '~> 2.0', :configurations => ['Debug', 'Beta']
57+
58+
# Diffing
59+
diff_pods
5260
end
5361

5462
target 'Rocket.Chat.ShareExtension' do
5563
pod 'Nuke-FLAnimatedImage-Plugin'
5664
database_pods
5765
ui_pods
66+
diff_pods
5867
end
5968

6069
target 'Rocket.Chat' do
@@ -68,7 +77,7 @@ target 'Rocket.ChatTests' do
6877
end
6978

7079
post_install do |installer|
71-
swift4Targets = ['OAuthSwift', 'TagListView', 'SearchTextField', 'Nuke', 'Nuke-FLAnimatedImage-Plugin']
80+
swift4Targets = ['OAuthSwift', 'TagListView', 'SearchTextField', 'Nuke', 'Nuke-FLAnimatedImage-Plugin', 'DifferenceKit', 'SwipeCellKit']
7281
installer.pods_project.targets.each do |target|
7382
target.build_configurations.each do |config|
7483
config.build_settings['SWIFT_VERSION'] = '3.1'

Podfile.lock

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ PODS:
22
- 1PasswordExtension (1.8.5)
33
- Crashlytics (3.10.5):
44
- Fabric (~> 1.7.9)
5+
- DifferenceKit (0.5.2):
6+
- DifferenceKit/Core (= 0.5.2)
7+
- DifferenceKit/UIExtensions (= 0.5.2)
8+
- DifferenceKit/Core (0.5.2)
9+
- DifferenceKit/UIExtensions (0.5.2):
10+
- DifferenceKit/Core
511
- Fabric (1.7.9)
612
- Firebase/Core (5.4.1):
713
- Firebase/CoreOnly
@@ -48,10 +54,12 @@ PODS:
4854
- Starscream (2.1.1)
4955
- SwiftLint (0.26.0)
5056
- SwiftyJSON (4.1.0)
57+
- SwipeCellKit (2.4.3)
5158

5259
DEPENDENCIES:
5360
- 1PasswordExtension
5461
- Crashlytics
62+
- DifferenceKit
5563
- Fabric
5664
- Firebase/Core
5765
- FLEX (~> 2.0)
@@ -69,11 +77,13 @@ DEPENDENCIES:
6977
- Starscream (~> 2)
7078
- SwiftLint
7179
- SwiftyJSON
80+
- SwipeCellKit
7281

7382
SPEC REPOS:
7483
https://github.com/cocoapods/specs.git:
7584
- 1PasswordExtension
7685
- Crashlytics
86+
- DifferenceKit
7787
- Fabric
7888
- Firebase
7989
- FirebaseAnalytics
@@ -94,6 +104,7 @@ SPEC REPOS:
94104
- Starscream
95105
- SwiftLint
96106
- SwiftyJSON
107+
- SwipeCellKit
97108

98109
EXTERNAL SOURCES:
99110
MobilePlayer:
@@ -122,6 +133,7 @@ CHECKOUT OPTIONS:
122133
SPEC CHECKSUMS:
123134
1PasswordExtension: 0e95bdea64ec8ff2f4f693be5467a09fac42a83d
124135
Crashlytics: 7f2e38d302d9da96475b3d64d86fb29e31a542b7
136+
DifferenceKit: 3999ddee5146dbd12d7418e2b907c6f5e2673805
125137
Fabric: a2917d3895e4c1569b9c3170de7320ea1b1e6661
126138
Firebase: 355bd535bfdacaa82a7fe8d9784115edefd6fc03
127139
FirebaseAnalytics: b3628aea54c50464c32c393fb2ea032566e7ecc2
@@ -146,7 +158,8 @@ SPEC CHECKSUMS:
146158
Starscream: 142bd8ef24592d985daee9fa48c936070b85b15f
147159
SwiftLint: f6b83e8d95ee1e91e11932d843af4fdcbf3fc764
148160
SwiftyJSON: c29297daf073d2aa016295d5809cdd68045c39b3
161+
SwipeCellKit: cee9906e6d3a36e22ad1a852fba7f8fa0839d113
149162

150-
PODFILE CHECKSUM: e30b11fd34e7043eec6c9d2d0550e6e147670e19
163+
PODFILE CHECKSUM: 6702db159e15966472657eea05905247ba9622d9
151164

152165
COCOAPODS: 1.5.3

Rocket.Chat.xcodeproj/project.pbxproj

Lines changed: 48 additions & 0 deletions
Large diffs are not rendered by default.

Rocket.Chat/API/Clients/MessagesClient.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,18 @@ struct MessagesClient: APIClient {
171171
return false
172172
}
173173

174+
// optimistic UI update
175+
176+
let message = Message(value: message)
177+
try? realm?.write {
178+
message.updatedAt = Date()
179+
message.temporary = true
180+
message.text = text
181+
realm?.add(message, update: true)
182+
}
183+
184+
// send request
185+
174186
let request = UpdateMessageRequest(roomId: message.rid, msgId: id, text: text)
175187

176188
api.fetch(request) { response in

Rocket.Chat/API/Clients/SubscriptionsClient.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,42 @@ extension SubscriptionsClient {
308308
}
309309
}
310310
}
311+
312+
// MARK: Subsctiption actions
313+
314+
extension SubscriptionsClient {
315+
func favoriteSubscription(subscription: Subscription) {
316+
SubscriptionManager.toggleFavorite(subscription) { (response) in
317+
DispatchQueue.main.async {
318+
if response.isError() {
319+
subscription.updateFavorite(!subscription.favorite)
320+
}
321+
}
322+
}
323+
324+
subscription.updateFavorite(!subscription.favorite)
325+
}
326+
327+
func hideSubscription(subscription: Subscription) {
328+
let hideRequest = SubscriptionHideRequest(rid: subscription.rid, subscriptionType: subscription.type)
329+
api.fetch(hideRequest, completion: nil)
330+
331+
Realm.executeOnMainThread { realm in
332+
realm.delete(subscription)
333+
}
334+
}
335+
336+
func markRead(subscription: Subscription) {
337+
api.fetch(SubscriptionReadRequest(rid: subscription.rid), completion: nil)
338+
Realm.executeOnMainThread { _ in
339+
subscription.alert = false
340+
}
341+
}
342+
343+
func markUnread(subscription: Subscription) {
344+
api.fetch(SubscriptionUnreadRequest(rid: subscription.rid), completion: nil)
345+
Realm.executeOnMainThread { _ in
346+
subscription.alert = true
347+
}
348+
}
349+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// SubscriptionHideRequest.swift
3+
// Rocket.Chat
4+
//
5+
// Created by Filipe Alvarenga on 27/07/18.
6+
// Copyright © 2018 Rocket.Chat. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import SwiftyJSON
11+
12+
fileprivate extension SubscriptionType {
13+
var path: String {
14+
switch self {
15+
case .channel:
16+
return "/api/v1/channels.close"
17+
case .group:
18+
return "/api/v1/groups.close"
19+
case .directMessage:
20+
return "/api/v1/im.close"
21+
}
22+
}
23+
}
24+
25+
final class SubscriptionHideRequest: APIRequest {
26+
typealias APIResourceType = SubscriptionHideResource
27+
28+
let requiredVersion = Version(0, 48, 0)
29+
30+
let method: HTTPMethod = .post
31+
var path: String {
32+
return type.path
33+
}
34+
35+
let rid: String
36+
let type: SubscriptionType
37+
38+
init(rid: String, subscriptionType: SubscriptionType) {
39+
self.rid = rid
40+
self.type = subscriptionType
41+
}
42+
43+
func body() -> Data? {
44+
let body = JSON([
45+
"roomId": rid
46+
])
47+
48+
return body.rawString()?.data(using: .utf8)
49+
}
50+
}
51+
52+
final class SubscriptionHideResource: APIResource {
53+
var success: Bool? {
54+
return raw?["success"].boolValue
55+
}
56+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// SubscriptionLeaveRequest.swift
3+
// Rocket.Chat
4+
//
5+
// Created by Filipe Alvarenga on 27/07/18.
6+
// Copyright © 2018 Rocket.Chat. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import SwiftyJSON
11+
12+
fileprivate extension SubscriptionType {
13+
var path: String {
14+
switch self {
15+
case .channel:
16+
return "/api/v1/channels.leave"
17+
case .group:
18+
return "/api/v1/groups.leave"
19+
default:
20+
return "/api/v1/channels.leave"
21+
}
22+
}
23+
}
24+
25+
final class SubscriptionLeaveRequest: APIRequest {
26+
typealias APIResourceType = SubscriptionLeaveResource
27+
28+
let requiredVersion = Version(0, 48, 0)
29+
30+
let method: HTTPMethod = .post
31+
var path: String {
32+
return type.path
33+
}
34+
35+
let rid: String
36+
let type: SubscriptionType
37+
38+
init(rid: String, subscriptionType: SubscriptionType) {
39+
self.rid = rid
40+
self.type = subscriptionType
41+
}
42+
43+
func body() -> Data? {
44+
let body = JSON([
45+
"roomId": rid
46+
])
47+
48+
return body.rawString()?.data(using: .utf8)
49+
}
50+
}
51+
52+
final class SubscriptionLeaveResource: APIResource {
53+
var success: Bool? {
54+
return raw?["success"].boolValue
55+
}
56+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// SubscriptionUnreadRequest.swift
3+
// Rocket.Chat
4+
//
5+
// Created by Filipe Alvarenga on 26/07/18.
6+
// Copyright © 2018 Rocket.Chat. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import SwiftyJSON
11+
12+
final class SubscriptionUnreadRequest: APIRequest {
13+
typealias APIResourceType = SubscriptionUnreadResource
14+
15+
let requiredVersion = Version(0, 65, 0)
16+
17+
let method: HTTPMethod = .post
18+
let path = "/api/v1/subscriptions.unread"
19+
20+
let rid: String
21+
22+
init(rid: String) {
23+
self.rid = rid
24+
}
25+
26+
func body() -> Data? {
27+
let body = JSON([
28+
"roomId": rid
29+
])
30+
31+
return body.rawString()?.data(using: .utf8)
32+
}
33+
}
34+
35+
final class SubscriptionUnreadResource: APIResource {
36+
var success: Bool? {
37+
return raw?["success"].boolValue
38+
}
39+
}

Rocket.Chat/Controllers/Chat/ChannelActionsViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ChannelActionsViewController: BaseViewController {
2727

2828
var subscription: Subscription? {
2929
didSet {
30-
guard let subscription = self.subscription else { return }
30+
guard let subscription = self.subscription?.validated() else { return }
3131

3232
let isDirectMessage = subscription.type == .directMessage
3333

@@ -142,7 +142,7 @@ extension ChannelActionsViewController {
142142
}
143143

144144
@objc func buttonFavoriteDidPressed(_ sender: Any) {
145-
guard let subscription = self.subscription else { return }
145+
guard let subscription = self.subscription?.validated() else { return }
146146

147147
SubscriptionManager.toggleFavorite(subscription) { [unowned self] (response) in
148148
DispatchQueue.main.async {
@@ -223,7 +223,7 @@ extension ChannelActionsViewController {
223223
}
224224

225225
func shareRoom() {
226-
guard let url = subscription?.externalURL() else { return }
226+
guard let url = subscription?.validated()?.externalURL() else { return }
227227
let controller = UIActivityViewController(activityItems: [url], applicationActivities: nil)
228228

229229
if shareRoomCell != nil && UIDevice.current.userInterfaceIdiom == .pad {

Rocket.Chat/Controllers/Chat/ChatDataController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ final class ChatDataController {
4040
var data: [ChatData] = [] {
4141
didSet {
4242
messagesUsernames.removeAll()
43-
messagesUsernames.formUnion(data.compactMap { $0.message?.user?.username })
43+
messagesUsernames.formUnion(data.compactMap { $0.message?.validated()?.user?.validated()?.username })
4444
}
4545
}
4646

0 commit comments

Comments
 (0)