Skip to content

Commit db0591c

Browse files
NMC 1935 - Notification screen customisation changes
1 parent ed45a17 commit db0591c

1 file changed

Lines changed: 45 additions & 52 deletions

File tree

iOSClient/Notification/NCNotification.swift

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
3030
let utilityFileSystem = NCUtilityFileSystem()
3131
let utility = NCUtility()
3232
var notifications: [NKNotifications] = []
33+
var dataSourceTask: URLSessionTask?
3334
var session: NCSession.Session!
3435
private let appDelegate = (UIApplication.shared.delegate as? AppDelegate)!
3536
var emptyDataSet: NCEmptyDataSet?
@@ -105,7 +106,7 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
105106

106107
// MARK: - NotificationCenter
107108
@objc func initialize() {
108-
getNetwokingNotification(nil)
109+
getNetwokingNotification()
109110
}
110111

111112
// MARK: - Empty
@@ -175,7 +176,8 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
175176
}
176177

177178
if let image = image {
178-
cell.icon.image = image.withTintColor(NCBrandColor.shared.iconColor, renderingMode: .alwaysOriginal)
179+
cell.icon.image = image.withTintColor(NCBrandColor.shared.brandElement, renderingMode: .alwaysOriginal)
180+
// cell.icon.image = image.withTintColor(NCBrandColor.shared.getElement(account: session.account), renderingMode: .alwaysOriginal)
179181
} else {
180182
cell.icon.image = utility.loadImage(named: "bell", colors: [NCBrandColor.shared.iconColor])
181183
}
@@ -206,7 +208,7 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
206208

207209
cell.date.text = DateFormatter.localizedString(from: notification.date as Date, dateStyle: .medium, timeStyle: .medium)
208210
cell.notification = notification
209-
cell.date.text = utility.dateDiff(notification.date as Date)
211+
cell.date.text = utility.getRelativeDateTitle(notification.date as Date)
210212
cell.date.textColor = .gray
211213
cell.subject.text = notification.subject
212214
cell.subject.textColor = NCBrandColor.shared.textColor
@@ -290,15 +292,9 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
290292

291293
// MARK: - tap Action
292294

293-
func tapRemove(with notification: NKNotifications, sender: Any?) {
294-
NextcloudKit.shared.setNotification(serverUrl: nil, idNotification: notification.idNotification, method: "DELETE", account: session.account) { task in
295-
Task {
296-
let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(account: self.session.account,
297-
path: "\(notification.idNotification)",
298-
name: "setNotification")
299-
await NCNetworking.shared.networkingTasks.track(identifier: identifier, task: task)
300-
}
301-
} completion: { _, _, error in
295+
func tapRemove(with notification: NKNotifications) {
296+
297+
NextcloudKit.shared.setNotification(serverUrl: nil, idNotification: notification.idNotification, method: "DELETE", account: session.account) { _, _, error in
302298
if error == .success {
303299
if let index = self.notifications
304300
.firstIndex(where: { $0.idNotification == notification.idNotification }) {
@@ -315,38 +311,36 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
315311
}
316312
}
317313

318-
func tapAction(with notification: NKNotifications, label: String, sender: Any?) {
319-
guard let actions = notification.actions,
320-
let jsonActions = JSON(actions).array,
321-
let action = jsonActions.first(where: { $0["label"].string == label })
322-
else { return }
323-
324-
let serverUrl = action["link"].stringValue
325-
let method = action["type"].stringValue
326-
327-
if method == "WEB", var url = action["link"].url {
328-
if notification.app == NCGlobal.shared.spreedName,
329-
let roomToken = notification.objectId.split(separator: "/").first,
330-
let talkUrl = URL(string: "nextcloudtalk://open-conversation?server=\(session.urlBase)&user=\(session.userId)&withRoomToken=\(roomToken)"),
331-
UIApplication.shared.canOpenURL(talkUrl) {
332-
333-
url = talkUrl
314+
func tapAction(with notification: NKNotifications, label: String) {
315+
if notification.app == NCGlobal.shared.spreedName,
316+
let roomToken = notification.objectId.split(separator: "/").first,
317+
let talkUrl = URL(string: "nextcloudtalk://open-conversation?server=\(session.urlBase)&user=\(session.userId)&withRoomToken=\(roomToken)"),
318+
UIApplication.shared.canOpenURL(talkUrl) {
319+
UIApplication.shared.open(talkUrl)
320+
} else if let actions = notification.actions,
321+
let jsonActions = JSON(actions).array,
322+
let action = jsonActions.first(where: { $0["label"].string == label }) {
323+
let serverUrl = action["link"].stringValue
324+
let method = action["type"].stringValue
325+
326+
if method == "WEB", let url = action["link"].url {
327+
UIApplication.shared.open(url, options: [:], completionHandler: nil)
328+
return
334329
}
335330

336-
UIApplication.shared.open(url)
337-
return
338-
}
339-
340-
NextcloudKit.shared.setNotification(serverUrl: serverUrl, idNotification: 0, method: method, account: session.account) { task in
341-
Task {
342-
let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(account: self.session.account,
343-
name: "setNotification")
344-
await NCNetworking.shared.networkingTasks.track(identifier: identifier, task: task)
345-
}
346-
} completion: { _, _, error in
347-
if error == .success {
348-
if let index = self.notifications.firstIndex(where: { $0.idNotification == notification.idNotification }) {
349-
self.notifications.remove(at: index)
331+
NextcloudKit.shared.setNotification(serverUrl: serverUrl, idNotification: 0, method: method, account: session.account) { _, _, error in
332+
if error == .success {
333+
if let index = self.notifications.firstIndex(where: { $0.idNotification == notification.idNotification }) {
334+
self.notifications.remove(at: index)
335+
}
336+
self.tableView.reloadData()
337+
if self.navigationController?.presentingViewController != nil, notification.app == NCGlobal.shared.twoFactorNotificatioName {
338+
self.dismiss(animated: true)
339+
}
340+
} else if error != .success {
341+
NCContentPresenter().showError(error: error)
342+
} else {
343+
print("[Error] The user has been changed during networking process.")
350344
}
351345
self.tableView.reloadData()
352346
if self.navigationController?.presentingViewController != nil, notification.app == NCGlobal.shared.twoFactorNotificatioName {
@@ -359,17 +353,16 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
359353
} else {
360354
print("[Error] The user has been changed during networking process.")
361355
}
362-
}
356+
} // else: Action not found
357+
}
358+
359+
func tapMore(with notification: NKNotifications) {
360+
toggleMenu(notification: notification)
363361
}
364362

365363
// MARK: - Load notification networking
366364

367-
@MainActor
368-
func getNetwokingNotification() async {
369-
// If is already in-flight, do nothing
370-
if await NCNetworking.shared.networkingTasks.isReading(identifier: "NCNotification") {
371-
return
372-
}
365+
@objc func getNetwokingNotification() {
373366

374367
self.tableView.reloadData()
375368

@@ -421,23 +414,23 @@ class NCNotificationCell: UITableViewCell {
421414

422415
@IBAction func touchUpInsideRemove(_ sender: Any) {
423416
guard let notification = notification else { return }
424-
delegate?.tapRemove(with: notification, sender: sender)
417+
delegate?.tapRemove(with: notification)
425418
}
426419

427420
@IBAction func touchUpInsidePrimary(_ sender: Any) {
428421
guard let notification = notification,
429422
let button = sender as? UIButton,
430423
let label = button.titleLabel?.text
431424
else { return }
432-
delegate?.tapAction(with: notification, label: label, sender: sender)
425+
delegate?.tapAction(with: notification, label: label)
433426
}
434427

435428
@IBAction func touchUpInsideSecondary(_ sender: Any) {
436429
guard let notification = notification,
437430
let button = sender as? UIButton,
438431
let label = button.titleLabel?.text
439432
else { return }
440-
delegate?.tapAction(with: notification, label: label, sender: sender)
433+
delegate?.tapAction(with: notification, label: label)
441434
}
442435
}
443436

0 commit comments

Comments
 (0)