This repository was archived by the owner on Jun 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 437
[NEW] Add support to Broadcast rooms #1657
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6d1a3eb
Map broadcasting on the Subscription object
rafaelks ea8312b
Write some tests for the false & empty values
rafaelks 92515ba
Add "Reply" button to each message on Broadcasting
rafaelks 32b54a6
Call the delegate on pressing the button
rafaelks 108b6f3
Let the user open the DM with the reply
rafaelks 82d9733
Only show reply button when required
rafaelks c331e04
Write some tests and improve performance check for message broadcast
rafaelks 6108437
Write some tests for broadcasting
rafaelks 57554db
Fixed a bug & increase top spacing of the button
rafaelks 756fa46
Only allow certain users to view members & depending on the kind of room
rafaelks c27abf1
Request the roles of channels & groups, persist it on Realm & check f…
rafaelks 700504b
Add minimum version for the API
rafaelks 9f22a0d
Write some tests to the new request
rafaelks 2e731eb
Add more tests
rafaelks 1a51b2e
Do not update roles for DMs
rafaelks 0f31226
Revert change on private
rafaelks bfdf72c
Dont show alert on failing
rafaelks e4cea21
Merge branch 'develop' into feature/broadcasts.1654
rafaelks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
Rocket.Chat/API/Requests/Subscription/SubscriptionRolesRequest.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // | ||
| // SubscriptionRolesRequest.swift | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| // Rocket.Chat | ||
| // | ||
| // Created by Rafael Kellermann Streit on 11/05/18. | ||
| // Copyright © 2018 Rocket.Chat. All rights reserved. | ||
| // | ||
|
|
||
| import SwiftyJSON | ||
| import RealmSwift | ||
|
|
||
| fileprivate extension SubscriptionType { | ||
| var path: String { | ||
| switch self { | ||
| case .channel: | ||
| return "/api/v1/channels.roles" | ||
| case .group: | ||
| return "/api/v1/groups.roles" | ||
| case .directMessage: | ||
| return "" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| final class SubscriptionRolesRequest: APIRequest { | ||
| typealias APIResourceType = SubscriptionRolesResource | ||
|
|
||
| let requiredVersion = Version(0, 64, 2) | ||
|
|
||
| var path: String { | ||
| return type.path | ||
| } | ||
|
|
||
| var query: String? | ||
| let roomName: String? | ||
| let type: SubscriptionType | ||
|
|
||
| init(roomName: String, subscriptionType: SubscriptionType) { | ||
| self.type = subscriptionType | ||
| self.roomName = roomName | ||
| self.query = "roomName=\(roomName)" | ||
| } | ||
| } | ||
|
|
||
| final class SubscriptionRolesResource: APIResource { | ||
| var subscriptionRoles: [SubscriptionRoles]? { | ||
| guard let realm = Realm.current else { return nil } | ||
| return raw?["roles"].arrayValue.map { | ||
| let object = SubscriptionRoles() | ||
| object.user = User.getOrCreate(realm: realm, values: $0["u"], updates: nil) | ||
| object.roles.append(contentsOf: $0["roles"].arrayValue.compactMap({ $0.string })) | ||
| return object | ||
| } | ||
| } | ||
|
|
||
| var success: Bool { | ||
| return raw?["success"].bool ?? false | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,15 +11,17 @@ import Foundation | |
| extension AuthViewController { | ||
| internal func handleAuthenticationResponse(_ response: LoginResponse) { | ||
| if case let .resource(resource) = response, let error = resource.error { | ||
| stopLoading() | ||
| DispatchQueue.main.async { [weak self] in | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| self?.stopLoading() | ||
|
|
||
| switch error.lowercased() { | ||
| case "totp-required": | ||
| return performSegue(withIdentifier: "TwoFactor", sender: nil) | ||
| case "unauthorized": | ||
| return Alert(key: "error.login_unauthorized").present() | ||
| default: | ||
| return Alert(key: "error.login").present() | ||
| switch error.lowercased() { | ||
| case "totp-required": | ||
| self?.performSegue(withIdentifier: "TwoFactor", sender: nil) | ||
| case "unauthorized": | ||
| Alert(key: "error.login_unauthorized").present() | ||
| default: | ||
| Alert(key: "error.login").present() | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
Rocket.Chat/Controllers/Chat/ChatControllerRolesController.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // | ||
| // ChatControllerRolesController.swift | ||
| // Rocket.Chat | ||
| // | ||
| // Created by Rafael Kellermann Streit on 11/05/18. | ||
| // Copyright © 2018 Rocket.Chat. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
| import RealmSwift | ||
|
|
||
| extension ChatViewController { | ||
|
|
||
| func updateSubscriptionRoles() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this would be a good method for SubscriptionsClient, with realm and subscription as parameters, instead of being in the ViewController. This would make it more testable and reusable. I can do it in another PR if you want. |
||
| guard | ||
| let subscription = subscription, | ||
| subscription.type != .directMessage | ||
| else { | ||
| return | ||
| } | ||
|
|
||
| let rid = subscription.rid | ||
| let rolesRequest = SubscriptionRolesRequest(roomName: subscription.name, subscriptionType: subscription.type) | ||
| API.current()?.fetch(rolesRequest, completion: { result in | ||
| switch result { | ||
| case .resource(let resource): | ||
| if let subscription = Subscription.find(rid: rid) { | ||
| Realm.executeOnMainThread({ (realm) in | ||
| subscription.usersRoles.removeAll() | ||
| resource.subscriptionRoles?.forEach({ (role) in | ||
| subscription.usersRoles.append(role) | ||
| }) | ||
|
|
||
| realm.add(subscription, update: true) | ||
| }) | ||
| } | ||
|
|
||
| // Fail silently | ||
| default: break | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍