Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Rocket.Chat/API/Clients/MessagesClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ struct MessagesClient: APIClient {
return true
}

// swiftlint:disable function_body_length
@discardableResult
func reactMessage(_ message: Message, emoji: String, user: User? = AuthManager.currentUser(), realm: Realm? = Realm.current) -> Bool {
guard let id = message.identifier, let username = user?.username else {
Expand Down
3 changes: 2 additions & 1 deletion Rocket.Chat/API/Clients/SpotlightClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ struct SpotlightClient: APIClient {
var subscriptions: [Subscription] = []

resource.rooms.forEach { object in
// Important note: On this API "_id" means "rid"
if let roomIdentifier = object["_id"].string {
if let subscription = Subscription.find(rid: roomIdentifier, realm: realm) {
subscription.map(object, realm: realm)
subscription.mapRoom(object, realm: realm)
subscriptions.append(subscription)
} else {
let subscription = Subscription()
subscription.identifier = String.random()
subscription.identifier = roomIdentifier
subscription.rid = roomIdentifier
subscription.name = object["name"].string ?? ""

Expand Down
34 changes: 27 additions & 7 deletions Rocket.Chat/API/Clients/SubscriptionsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,40 @@ struct SubscriptionsClient: APIClient {
guard let auth = AuthManager.isAuthenticated(realm: realm) else { return }

func queueSubscriptionForUpdate(_ object: JSON) {
let subscription = Subscription.getOrCreate(realm: realm, values: object, updates: nil)
subscription.auth = auth
subscriptions.append(subscription)
var subscription: Subscription?

if let rid = object["rid"].string {
subscription = Subscription.find(rid: rid, realm: realm) ??
Subscription.getOrCreate(realm: realm, values: object, updates: nil)
} else {
subscription = Subscription.getOrCreate(realm: realm, values: object, updates: nil)
}

if let subscription = subscription {
subscription.auth = auth
subscription.map(object, realm: realm)
subscription.mapRoom(object, realm: realm)
subscriptions.append(subscription)
}
}

resource.list?.forEach(queueSubscriptionForUpdate)
resource.update?.forEach(queueSubscriptionForUpdate)

resource.remove?.forEach { object in
let subscription = Subscription.getOrCreate(realm: realm, values: object, updates: { (obj) in
obj?.auth = nil
})
var subscription: Subscription?

subscriptions.append(subscription)
if let rid = object["rid"].string {
subscription = Subscription.find(rid: rid, realm: realm) ??
Subscription.getOrCreate(realm: realm, values: object, updates: nil)
} else {
subscription = Subscription.getOrCreate(realm: realm, values: object, updates: nil)
}

if let subscription = subscription {
subscription.auth = nil
subscriptions.append(subscription)
}
}

auth.lastSubscriptionFetchWithLastMessage = Date.serverDate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import MobilePlayer
import FLAnimatedImage
import SimpleImageViewer

// swiftlint:disable type_body_length
final class MessageSection: ChatSection {
var object: AnyDifferentiable
weak var controllerContext: UIViewController?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extension MessagesViewController: ChatPreviewModeViewProtocol {

Realm.executeOnMainThread({ realm in
subscription.auth = auth
subscription.open = true
realm.add(subscription, update: true)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ struct SubscriptionManager {
return
}

let subscription = Subscription.getOrCreate(realm: realm, values: object, updates: nil)
let subscription = Subscription.find(rid: rid, realm: realm) ??
Subscription.getOrCreate(realm: realm, values: object, updates: nil)

if msg == "removed" {
realm.delete(subscription)
} else {
subscription.auth = auth
realm.add(subscription, update: true)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extension SubscriptionManager {
"msg": "method",
"method": "joinRoom",
"params": [rid]
] as [String: Any]
] as [String: Any]

SocketManager.send(request) { (response) in
guard !response.isError() else { return Log.debug(response.result.string) }
Expand Down
1 change: 1 addition & 0 deletions Rocket.Chat/Managers/Socket/Response/ResponseMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum ResponseMessage: String {
case ping
case changed
case added
case inserted
case updated
case removed
case unknown
Expand Down
4 changes: 2 additions & 2 deletions Rocket.Chat/Managers/Socket/Response/SocketHandlers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ extension SocketManager {
return self.handleConnectionMessage(result, socket: socket)
case .ping:
return self.handlePingMessage(result, socket: socket)
case .changed, .added, .removed:
case .changed, .added, .inserted, .updated, .removed:
return self.handleModelUpdates(result, socket: socket)
case .updated, .unknown:
case .unknown:
break
case .error:
self.handleError(result, socket: socket)
Expand Down
2 changes: 1 addition & 1 deletion Rocket.Chat/Models/Base/ModelHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extension ModelHandler where Self: BaseModel {
}

switch msg {
case .added:
case .added, .inserted:
object.add(values, realm: realm)
case .changed:
object.update(values, realm: realm)
Expand Down
1 change: 1 addition & 0 deletions Rocket.Chat/Models/Mapping/SubscriptionModelMapping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ extension Subscription: ModelMappeable {
func mapNotifications(_ values: JSON) {
self.disableNotifications = values["disableNotifications"].bool ?? false
self.hideUnreadStatus = values["hideUnreadStatus"].bool ?? false

if let desktopNotificationsString = values["desktopNotifications"].string {
self.desktopNotifications = SubscriptionNotificationsStatus(rawValue: desktopNotificationsString) ?? .default
}
Expand Down
2 changes: 2 additions & 0 deletions Rocket.Chat/Models/Message/UnmanagedMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ extension UnmanagedMessage {
}

extension UnmanagedMessage {

// swiftlint:disable function_body_length
init?(_ message: Message) {
guard
let messageIdentifier = message.identifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class SubscriptionCell: BaseSubscriptionCell {
override func updateSubscriptionInformation() {
guard let subscription = subscription?.managedObject else { return }

labelLastMessage.text = subscription.roomLastMessageText
labelLastMessage.text = subscription.roomLastMessageText ?? localized("subscriptions.list.no_message")

if let roomLastMessage = subscription.roomLastMessage?.createdAt {
labelDate.text = dateFormatted(date: roomLastMessage)
Expand Down
2 changes: 2 additions & 0 deletions Rocket.ChatTests/API/Clients/SubscriptionsClientSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import RealmSwift

@testable import Rocket_Chat

// swiftlint:disable type_body_length
class SubscriptionsClientSpec: XCTestCase {

override func setUp() {
Expand Down Expand Up @@ -236,6 +237,7 @@ class SubscriptionsClientSpec: XCTestCase {
XCTAssertEqual(user2Object.rolesInSubscription(subscriptionObject).count, 1)
}

// swiftlint:disable function_body_length
func testLoadHistory() {
let api = MockAPI()
let client = SubscriptionsClient(api: api)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class RoomHistoryRequestSpec: APITestCase {
XCTAssertNil(request.httpBody, "body is nil")
}

// swiftlint:disable function_body_length
func testResult() {
let mockResult = JSON([
"messages": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class NSAttributedStringExtensionsSpec: XCTestCase {
assert(attributedString, has: (NSAttributedString.Key.backgroundColor, color), in: wordRange, "setBackgroundColor will work")
}

// swiftlint:disable function_body_length
func testMentionParsing() {
let string = "Hi @rafael.kellermann, how are you doing? " +
"Is everyone @here having a great day? How about you @filipe.alvarenga? Wish you @all a happy Christmas :) from @matheus.cardoso"
Expand Down Expand Up @@ -91,7 +92,7 @@ class NSAttributedStringExtensionsSpec: XCTestCase {
let range0 = nsString.range(of: "Hi ")
let attributes0 = result.attributes(at: range0.location, longestEffectiveRange: nil, in: range0)
XCTAssertEqual(attributes0.count, 0, "Will have no attributes")

let range1 = nsString.range(of: "\u{00a0}rafael.kellermann\u{00a0}")
let attributes1 = result.attributes(at: range1.location, longestEffectiveRange: nil, in: range1)
XCTAssertEqual(attributes1.count, 4, "Will have 4 attributes")
Expand Down