-
Notifications
You must be signed in to change notification settings - Fork 437
[NEW] Menu for changing push notification settings #1396
Changes from 17 commits
d68a768
d485edf
739260a
4da50c6
2a5e6a6
c18145d
daff2a8
de4f7ac
dda0e6d
7192594
103d0f1
3ec1281
bb2d2dc
523e339
3c26372
8a4554a
24b5f34
57f167f
478704b
6534e62
9a79363
27b4935
9e311af
8ed5588
c2ba2db
d675628
6012496
2e6660d
d73f935
45d461e
d55fa3f
8b25bff
ede6545
607d02c
957c1ee
f9879c3
3581127
918513f
0cdf2a6
5171559
0ccf751
abe2928
9565db7
206cc17
662e681
59c8aca
bad4c28
aa152b9
5602dad
39eae20
f88fac6
568e0ce
3096be0
7504893
777682b
1b782af
0b9e50f
47b64b1
04bb5cf
1df0d89
3098c1c
1add2be
8694fe2
2060325
33327a3
d435a55
f424dc1
893aa77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// SubscriptionGetOneRequest.swift | ||
// Rocket.Chat | ||
// | ||
// Created by Artur Rymarz on 14.04.2018. | ||
// Copyright © 2018 Rocket.Chat. All rights reserved. | ||
// | ||
|
||
import SwiftyJSON | ||
|
||
typealias SubscriptionGetOneResult = APIResult<SubscriptionGetOneRequest> | ||
|
||
class SubscriptionGetOneRequest: APIRequest { | ||
let path = "/api/v1/subscriptions.getOne" | ||
|
||
let query: String? | ||
|
||
let roomId: String? | ||
|
||
init(roomId: String) { | ||
self.roomId = roomId | ||
self.query = "roomId=\(roomId)" | ||
} | ||
} | ||
|
||
extension APIResult where T == SubscriptionGetOneRequest { | ||
var subscription: Subscription? { | ||
guard let raw = raw?["subscription"] else { return nil } | ||
|
||
let subscription = Subscription() | ||
subscription.map(raw, realm: nil) | ||
return subscription | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// Dynamic.swift | ||
// Rocket.Chat | ||
// | ||
// Created by Artur Rymarz on 14.04.2018. | ||
// Copyright © 2018 Rocket.Chat. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
class Dynamic<T> { | ||
typealias Listener = (T) -> Void | ||
var listener: Listener? | ||
|
||
func bind(_ listener: Listener?) { | ||
self.listener = listener | ||
} | ||
|
||
func bindAndFire(_ listener: Listener?) { | ||
self.listener = listener | ||
listener?(value) | ||
} | ||
|
||
var value: T { | ||
didSet { | ||
listener?(value) | ||
} | ||
} | ||
|
||
init(_ value: T) { | ||
self.value = value | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// NotificationsCellProtocol.swift | ||
// Rocket.Chat | ||
// | ||
// Created by Artur Rymarz on 10.03.2018. | ||
// Copyright © 2018 Rocket.Chat. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol NotificationsCellProtocol where Self: UITableViewCell { | ||
var cellModel: NotificationSettingModel? { get set } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// NotificationsChooseCell.swift | ||
// Rocket.Chat | ||
// | ||
// Created by Artur Rymarz on 05.03.2018. | ||
// Copyright © 2018 Rocket.Chat. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
final class NotificationsChooseCell: UITableViewCell, NotificationsCellProtocol { | ||
struct SettingModel: NotificationSettingModel { | ||
let value: Dynamic<String> | ||
var type: NotificationCellType | ||
let title: String | ||
|
||
init(value: Dynamic<String>, type: NotificationCellType, title: String) { | ||
self.value = value | ||
self.type = type | ||
self.title = title | ||
} | ||
} | ||
|
||
@IBOutlet weak var resetLabel: UILabel! | ||
@IBOutlet weak var titleLabel: UILabel! | ||
@IBOutlet weak var valueLabel: UILabel! | ||
|
||
var cellModel: NotificationSettingModel? { | ||
didSet { | ||
guard let model = cellModel as? SettingModel else { | ||
return | ||
} | ||
|
||
titleLabel.text = model.title | ||
model.value.bindAndFire { [unowned self] value in | ||
self.valueLabel.text = value | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// | ||
// NotificationsPreferencesViewController.swift | ||
// Rocket.Chat | ||
// | ||
// Created by Artur Rymarz on 05.03.2018. | ||
// Copyright © 2018 Rocket.Chat. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
final class NotificationsPreferencesViewController: UITableViewController { | ||
private let viewModel = NotificationsPreferencesViewModel() | ||
var subscription: Subscription? | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
title = viewModel.title | ||
viewModel.enableModel.value.bind { [unowned self] _ in | ||
DispatchQueue.main.async { | ||
self.tableView.reloadData() | ||
} | ||
} | ||
} | ||
|
||
override func viewWillAppear(_ animated: Bool) { | ||
super.viewWillAppear(animated) | ||
|
||
guard let subscription = subscription else { | ||
return | ||
} | ||
|
||
let request = SubscriptionGetOneRequest(roomId: subscription.rid) | ||
API.current()?.fetch(request, succeeded: { result in | ||
guard let subscription = result.subscription else { | ||
return | ||
} | ||
|
||
self.viewModel.enableModel.value.value = !subscription.disableNotifications | ||
self.viewModel.counterModel.value.value = false // TODO: ??? | ||
// self.viewModel.desktopAlertsModel.value.value // TODO: ??? | ||
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. Todo Violation: TODOs should be resolved (???). (todo) |
||
// self.viewModel.desktopAudioModel.value.value // TODO: ??? | ||
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. Todo Violation: TODOs should be resolved (???). (todo) |
||
// self.viewModel.desktopSoundModel.value.value // TODO: ??? | ||
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. Todo Violation: TODOs should be resolved (???). (todo) |
||
self.viewModel.desktopDurationModel.value.value = String(subscription.desktopNotificationDuration) | ||
self.viewModel.mobileAlertsModel.value.value = subscription.mobilePushNotifications ?? "placeholder" | ||
self.viewModel.mailAlertsModel.value.value = subscription.emailNotifications ?? "placeholder" | ||
|
||
}, errored: { error in | ||
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. Unused Closure Parameter Violation: Unused parameter "error" in a closure should be replaced with _. (unused_closure_parameter) |
||
Alert.defaultError.present() | ||
}) | ||
} | ||
} | ||
|
||
extension NotificationsPreferencesViewController { | ||
override func numberOfSections(in tableView: UITableView) -> Int { | ||
return viewModel.settingsCells.count | ||
} | ||
|
||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
return viewModel.settingsCells[section].elements.count | ||
} | ||
|
||
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { | ||
return viewModel.settingsCells[section].title | ||
} | ||
|
||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
let settingModel = viewModel.settingsCells[indexPath.section].elements[indexPath.row] | ||
|
||
guard var cell = tableView.dequeueReusableCell(withIdentifier: settingModel.type.rawValue, for: indexPath) as? UITableViewCell & NotificationsCellProtocol else { | ||
fatalError("Could not dequeue reusable cell with type \(settingModel.type.rawValue)") | ||
} | ||
|
||
cell.cellModel = settingModel | ||
|
||
return cell | ||
} | ||
} | ||
|
||
extension NotificationsPreferencesViewController { | ||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | ||
let settingModel = viewModel.settingsCells[indexPath.section].elements[indexPath.row] | ||
} | ||
} |
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.
Todo Violation: TODOs should be resolved (???). (todo)