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

[NEW] Menu for changing push notification settings #1396

Merged
merged 68 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
d68a768
create request for settings and add an option for Notifications in Pr…
Mar 5, 2018
d485edf
notifications preferences view model and cells
Mar 5, 2018
739260a
Merge branch 'develop' into feature/288-notifications-preferences
artur-ios-dev Mar 10, 2018
4da50c6
prepare view models for notifications preferences
artur-ios-dev Mar 10, 2018
2a5e6a6
add resources
Mar 12, 2018
c18145d
update notifications preferences view model
Mar 26, 2018
daff2a8
Merge branch 'develop' into feature/288-notifications-preferences
Mar 26, 2018
de4f7ac
Merge branch 'develop' into feature/288-notifications-preferences
artur-ios-dev Apr 7, 2018
dda0e6d
Merge branch 'feature/288-notifications-preferences' of https://githu…
artur-ios-dev Apr 7, 2018
7192594
Merge branch 'develop' into feature/288-notifications-preferences
artur-ios-dev Apr 14, 2018
103d0f1
Move notifications settings view controller to separate storyboard
artur-ios-dev Apr 14, 2018
3ec1281
pass channel's info (subscription) to notifications settings view con…
artur-ios-dev Apr 14, 2018
bb2d2dc
fix testNumberOfRowsInSection in Preferences
artur-ios-dev Apr 14, 2018
523e339
fix testNumberOfRowsInSection in Preferences
artur-ios-dev Apr 14, 2018
3c26372
prepare models for notifications settings
artur-ios-dev Apr 14, 2018
8a4554a
make switch cell to have dynamic bool value, remove required value fo…
artur-ios-dev Apr 14, 2018
24b5f34
get one subscription API
artur-ios-dev Apr 14, 2018
57f167f
map default values for subscription notifications preferences
artur-ios-dev Apr 15, 2018
478704b
commend out get `one subscription` for now
artur-ios-dev Apr 15, 2018
6534e62
drop down menu
artur-ios-dev Apr 15, 2018
9a79363
revert changes in preferences controller
artur-ios-dev Apr 15, 2018
27b4935
add extension to get all enum cases as array
artur-ios-dev Apr 15, 2018
9e311af
implement parentView and rect for drop-down menu
Apr 16, 2018
8ed5588
saveNotifications POST
Apr 16, 2018
c2ba2db
comment out getOne subscription request
Apr 16, 2018
d675628
add test for saveNotification POST
Apr 16, 2018
6012496
add tests for get one subscription
Apr 16, 2018
2e6660d
add notification preferences view model tests
Apr 16, 2018
d73f935
refactor notification preferences cells' models
artur-ios-dev Apr 16, 2018
45d461e
fix position of drop-down menu when it's at the very bottom of screen
artur-ios-dev Apr 16, 2018
d55fa3f
re-enable opening_brace rule
artur-ios-dev Apr 16, 2018
8b25bff
localizing notifications preferences
Apr 17, 2018
ede6545
add missing localization
Apr 17, 2018
607d02c
remove commented code
Apr 18, 2018
957c1ee
Merge branch 'develop' into feature/288-notifications-preferences
Apr 18, 2018
f9879c3
fix new requests after merge changes
Apr 18, 2018
3581127
fix tableview reloading
Apr 18, 2018
918513f
implement tests, clean up the code
Apr 18, 2018
0cdf2a6
Merge branch 'develop' into feature/288-notifications-preferences
rafaelks Apr 19, 2018
5171559
Merge branch 'develop' into feature/288-notifications-preferences
artur-ios-dev Jul 14, 2018
0ccf751
Merge branch 'develop' into feature/288-notifications-preferences
artur-ios-dev Jul 15, 2018
abe2928
replace drop down menu with uipickerview
artur-ios-dev Jul 15, 2018
9565db7
Theme picker view and remove unused drop down menu
Jul 16, 2018
206cc17
toggle picker view visibility
Jul 16, 2018
662e681
hide picker when cell tapped while it's already showing
Jul 16, 2018
59c8aca
select currently selected option in picker view
Jul 16, 2018
bad4c28
fixed colors in black theme for notifications preferences
Jul 16, 2018
aa152b9
add notification's settings icon
Jul 19, 2018
5602dad
Merge branch 'develop' into feature/288-notifications-preferences
Jul 19, 2018
39eae20
Merge branch 'develop' into feature/288-notifications-preferences
Sameesunkaria Jul 22, 2018
f88fac6
Modify the Choose Cell layout to better suit iOS
Sameesunkaria Jul 22, 2018
568e0ce
Render notifications icon as a template
Sameesunkaria Jul 22, 2018
3096be0
Only use a single label for Switch Cell
Sameesunkaria Jul 22, 2018
7504893
Update localization
Sameesunkaria Jul 22, 2018
777682b
Fix theming for UIPickerView separators
Sameesunkaria Jul 23, 2018
1b782af
Improve code indentation
Sameesunkaria Jul 23, 2018
0b9e50f
Add footers
Sameesunkaria Jul 23, 2018
47b64b1
Arrange options and add footers
Sameesunkaria Jul 23, 2018
04bb5cf
Synchronize localization
Sameesunkaria Jul 23, 2018
1df0d89
Add a hyphen to inapp
Sameesunkaria Jul 23, 2018
3098c1c
Merge pull request #1 from Sameesunkaria/feature/288-notifications-pr…
artur-ios-dev Jul 24, 2018
1add2be
Increase font size for picker view
Sameesunkaria Jul 24, 2018
8694fe2
Merge remote-tracking branch 'artrmz/feature/288-notifications-prefer…
Sameesunkaria Jul 24, 2018
2060325
Shorten title for successful save
Sameesunkaria Jul 25, 2018
33327a3
Fix typo
Sameesunkaria Jul 25, 2018
d435a55
enable/disable save button on notifications preferences
Jul 25, 2018
f424dc1
check if save button should be enabled according to current preferenc…
Jul 26, 2018
893aa77
Table view now animates
Sameesunkaria Jul 26, 2018
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
72 changes: 40 additions & 32 deletions Rocket.Chat.xcodeproj/project.pbxproj

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
}
}
9 changes: 9 additions & 0 deletions Rocket.Chat/Controllers/Chat/ChannelInfoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ChannelInfoViewController: BaseViewController {
ChannelInfoDetailCellData(title: localized("chat.info.item.members"), detail: "", action: showMembersList),
ChannelInfoDetailCellData(title: localized("chat.info.item.pinned"), detail: "", action: showPinnedList),
ChannelInfoDetailCellData(title: localized("chat.info.item.starred"), detail: "", action: showStarredList),
ChannelInfoDetailCellData(title: localized("chat.info.item.notifications"), detail: "", action: showNotificationsPreferences),
shouldListMentions ? ChannelInfoDetailCellData(title: localized("chat.info.item.mentions"), detail: "", action: showMentionsList) : nil
].compactMap({$0})

Expand Down Expand Up @@ -114,6 +115,10 @@ class ChannelInfoViewController: BaseViewController {
self.performSegue(withIdentifier: "toMessagesList", sender: data)
}

private func showNotificationsPreferences() {
performSegue(withIdentifier: "toNotificationsSettings", sender: self)
}

func showMentionsList() {
let data = ListSegueData(
title: localized("chat.messages.mentions.list.title"),
Expand All @@ -140,6 +145,10 @@ class ChannelInfoViewController: BaseViewController {
messagesList.data.isListingMentions = segueData.isListingMentions
}
}

if let notificationsSettings = segue.destination as? NotificationsPreferencesViewController {
notificationsSettings.subscription = subscription
}
}

// MARK: IBAction
Expand Down
14 changes: 13 additions & 1 deletion Rocket.Chat/Controllers/Settings/PreferencesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ final class PreferencesViewController: UITableViewController {
}
}

@IBOutlet weak var labelNotifications: UILabel! {
didSet {
labelNotifications.text = viewModel.notifications
}
}

@IBOutlet weak var labelLicense: UILabel! {
didSet {
labelLicense.text = viewModel.license
Expand Down Expand Up @@ -107,6 +113,10 @@ final class PreferencesViewController: UITableViewController {
present(controller, animated: true, completion: nil)
}

private func cellNotificationsDidPressed() {
performSegue(withIdentifier: "Notifications", sender: nil)
}

// MARK: Navigation

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
Expand All @@ -132,8 +142,10 @@ final class PreferencesViewController: UITableViewController {
if indexPath.row == 0 {
cellContactDidPressed()
} else if indexPath.row == 1 {
cellLanguageDidPressed()
cellNotificationsDidPressed()
} else if indexPath.row == 2 {
cellLanguageDidPressed()
} else if indexPath.row == 3 {
cellAppIconDidPressed()
}
} else if indexPath.section == kSectionInformation {
Expand Down
6 changes: 5 additions & 1 deletion Rocket.Chat/Controllers/Settings/PreferencesViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ final class PreferencesViewModel {
return localized("myaccount.settings.contactus")
}

internal var notifications: String {
return localized("myaccount.settings.notifications")
}

internal var license: String {
return localized("myaccount.settings.license")
}
Expand Down Expand Up @@ -98,7 +102,7 @@ final class PreferencesViewModel {
internal func numberOfRowsInSection(_ section: Int) -> Int {
switch section {
case 0: return 1
case 1: return (canChangeAppIcon ? 4 : 3)
case 1: return (canChangeAppIcon ? 5 : 4)
case 2: return 2
case 3: return (canOpenFLEX ? 1 : 0)
default: return 0
Expand Down
4 changes: 4 additions & 0 deletions Rocket.Chat/Extensions/StringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@ extension String {
let params = components.dropFirst().joined(separator: " ")
return (command: command, params: params)
}

var boolValue: Bool {
return NSString(string: self).boolValue
}
}
33 changes: 33 additions & 0 deletions Rocket.Chat/Models/Dynamic.swift
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
}
}
9 changes: 9 additions & 0 deletions Rocket.Chat/Models/Mapping/SubscriptionModelMapping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ extension Subscription: ModelMappeable {
if let lastSeen = values["ls"]["$date"].double {
self.lastSeen = Date.dateFromInterval(lastSeen)
}

self.disableNotifications = values["disableNotifications"].bool ?? false
self.emailNotifications = values["emailNotifications"].string
self.audioNotificationValue = values["audioNotificationValue"].string
if let duration = values["desktopNotificationDuration"].int {
self.desktopNotificationDuration = duration
}
self.audioNotifications = values["audioNotifications"].stringValue
self.mobilePushNotifications = values["mobilePushNotifications"].stringValue
}

func mapRoom(_ values: JSON) {
Expand Down
7 changes: 7 additions & 0 deletions Rocket.Chat/Models/Subscription/Subscription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class Subscription: BaseModel {
@objc dynamic var roomOwnerId: String?
@objc dynamic var otherUserId: String?

@objc dynamic var disableNotifications = false
@objc dynamic var emailNotifications: String?
@objc dynamic var audioNotificationValue: String?
@objc dynamic var desktopNotificationDuration = 0
@objc dynamic var audioNotifications: String?
@objc dynamic var mobilePushNotifications: String?

let messages = LinkingObjects(fromType: Message.self, property: "subscription")
}

Expand Down
13 changes: 13 additions & 0 deletions Rocket.Chat/NotificationsCellProtocol.swift
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 }
}
40 changes: 40 additions & 0 deletions Rocket.Chat/NotificationsChooseCell.swift
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
}
}
}
}
84 changes: 84 additions & 0 deletions Rocket.Chat/NotificationsPreferencesViewController.swift
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: ???

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)

// self.viewModel.desktopAlertsModel.value.value // TODO: ???

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)

// self.viewModel.desktopAudioModel.value.value // TODO: ???

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)

// self.viewModel.desktopSoundModel.value.value // TODO: ???

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)

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

Choose a reason for hiding this comment

The 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]
}
}
Loading