NCActivity.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. //
  2. // NCActivity.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 17/01/2019.
  6. // Copyright © 2019 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. // Author Henrik Storch <henrik.storch@nextcloud.com>
  10. //
  11. // This program is free software: you can redistribute it and/or modify
  12. // it under the terms of the GNU General Public License as published by
  13. // the Free Software Foundation, either version 3 of the License, or
  14. // (at your option) any later version.
  15. //
  16. // This program is distributed in the hope that it will be useful,
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. // GNU General Public License for more details.
  20. //
  21. // You should have received a copy of the GNU General Public License
  22. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. //
  24. import UIKit
  25. import SwiftRichString
  26. import NextcloudKit
  27. import SVGKit
  28. class NCActivity: UIViewController, NCSharePagingContent {
  29. @IBOutlet weak var viewContainerConstraint: NSLayoutConstraint!
  30. @IBOutlet weak var tableView: UITableView!
  31. var commentView: NCActivityCommentView?
  32. var textField: UIView? { commentView?.newCommentField }
  33. var height: CGFloat = 0
  34. var metadata: tableMetadata?
  35. var showComments: Bool = false
  36. let utilityFileSystem = NCUtilityFileSystem()
  37. let utility = NCUtility()
  38. let database = NCManageDatabase.shared
  39. var allItems: [DateCompareable] = []
  40. var sectionDates: [Date] = []
  41. var dataSourceTask: URLSessionTask?
  42. var insets = UIEdgeInsets(top: 8, left: 0, bottom: 0, right: 0)
  43. var didSelectItemEnable: Bool = true
  44. var objectType: String?
  45. var account: String = ""
  46. var isFetchingActivity = false
  47. var hasActivityToLoad = true {
  48. didSet { tableView.tableFooterView?.isHidden = hasActivityToLoad }
  49. }
  50. var dateAutomaticFetch: Date?
  51. var session: NCSession.Session {
  52. if account.isEmpty {
  53. NCSession.shared.getSession(controller: tabBarController)
  54. } else {
  55. NCSession.shared.getSession(account: account)
  56. }
  57. }
  58. // MARK: - View Life Cycle
  59. override func viewDidLoad() {
  60. super.viewDidLoad()
  61. self.navigationController?.navigationBar.prefersLargeTitles = true
  62. view.backgroundColor = .systemBackground
  63. self.title = NSLocalizedString("_activity_", comment: "")
  64. tableView.allowsSelection = false
  65. tableView.separatorColor = UIColor.clear
  66. tableView.contentInset = insets
  67. tableView.backgroundColor = .systemBackground
  68. if showComments {
  69. setupComments()
  70. }
  71. }
  72. func setupComments() {
  73. // Display Name & Quota
  74. guard let metadata else { return }
  75. tableView.register(UINib(nibName: "NCShareCommentsCell", bundle: nil), forCellReuseIdentifier: "cell")
  76. commentView = Bundle.main.loadNibNamed("NCActivityCommentView", owner: self, options: nil)?.first as? NCActivityCommentView
  77. commentView?.setup(account: metadata.account) { newComment in
  78. guard let newComment = newComment, !newComment.isEmpty, let metadata = self.metadata else { return }
  79. NextcloudKit.shared.putComments(fileId: metadata.fileId, message: newComment, account: metadata.account) { _, _, error in
  80. if error == .success {
  81. self.commentView?.newCommentField.text?.removeAll()
  82. self.loadComments()
  83. } else {
  84. NCContentPresenter().showError(error: error)
  85. }
  86. }
  87. }
  88. }
  89. override func viewWillAppear(_ animated: Bool) {
  90. super.viewWillAppear(animated)
  91. navigationController?.setNavigationBarAppearance()
  92. fetchAll(isInitial: true)
  93. }
  94. override func viewWillDisappear(_ animated: Bool) {
  95. super.viewWillDisappear(animated)
  96. // Cancel Queue & Retrieves Properties
  97. NCNetworking.shared.downloadThumbnailActivityQueue.cancelAll()
  98. dataSourceTask?.cancel()
  99. }
  100. override func viewWillLayoutSubviews() {
  101. super.viewWillLayoutSubviews()
  102. tableView.tableFooterView = makeTableFooterView()
  103. tableView.tableHeaderView = commentView
  104. commentView?.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
  105. commentView?.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
  106. viewContainerConstraint.constant = height - 10
  107. }
  108. func makeTableFooterView() -> UIView {
  109. let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 100))
  110. view.backgroundColor = .clear
  111. view.isHidden = self.hasActivityToLoad
  112. let label = UILabel()
  113. label.font = UIFont.systemFont(ofSize: 15)
  114. label.textColor = NCBrandColor.shared.textColor2
  115. label.textAlignment = .center
  116. label.text = NSLocalizedString("_no_activity_footer_", comment: "")
  117. view.addSubview(label)
  118. label.translatesAutoresizingMaskIntoConstraints = false
  119. label.topAnchor.constraint(equalTo: view.topAnchor, constant: 20).isActive = true
  120. label.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
  121. label.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
  122. return view
  123. }
  124. }
  125. // MARK: - Table View
  126. extension NCActivity: UITableViewDelegate {
  127. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  128. return 50
  129. }
  130. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  131. return 80.0
  132. }
  133. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  134. let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 50))
  135. view.backgroundColor = .clear
  136. let label = UILabel()
  137. label.font = UIFont.boldSystemFont(ofSize: 13)
  138. label.textColor = NCBrandColor.shared.textColor
  139. label.text = utility.getTitleFromDate(sectionDates[section])
  140. label.textAlignment = .center
  141. let blur = UIBlurEffect(style: .systemMaterial)
  142. let blurredEffectView = UIVisualEffectView(effect: blur)
  143. blurredEffectView.layer.cornerRadius = 11
  144. blurredEffectView.layer.masksToBounds = true
  145. view.addSubview(blurredEffectView)
  146. view.addSubview(label)
  147. blurredEffectView.translatesAutoresizingMaskIntoConstraints = false
  148. label.translatesAutoresizingMaskIntoConstraints = false
  149. NSLayoutConstraint.activate([
  150. blurredEffectView.topAnchor.constraint(equalTo: view.topAnchor),
  151. blurredEffectView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
  152. blurredEffectView.widthAnchor.constraint(equalToConstant: label.intrinsicContentSize.width + 30),
  153. blurredEffectView.heightAnchor.constraint(equalToConstant: 22),
  154. label.topAnchor.constraint(equalTo: view.topAnchor),
  155. label.centerXAnchor.constraint(equalTo: view.centerXAnchor),
  156. label.centerYAnchor.constraint(equalTo: blurredEffectView.centerYAnchor)
  157. ])
  158. return view
  159. }
  160. }
  161. extension NCActivity: UITableViewDataSource {
  162. func numberOfSections(in tableView: UITableView) -> Int {
  163. return sectionDates.count
  164. }
  165. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  166. let date = sectionDates[section]
  167. return allItems.filter({ Calendar.current.isDate($0.dateKey, inSameDayAs: date) }).count
  168. }
  169. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  170. let date = sectionDates[indexPath.section]
  171. let sectionItems = allItems
  172. .filter({ Calendar.current.isDate($0.dateKey, inSameDayAs: date) })
  173. let cellData = sectionItems[indexPath.row]
  174. if let activityData = cellData as? tableActivity {
  175. return makeActivityCell(activityData, for: indexPath)
  176. } else if let commentData = cellData as? tableComments {
  177. return makeCommentCell(commentData, for: indexPath)
  178. } else {
  179. return UITableViewCell()
  180. }
  181. }
  182. func makeCommentCell(_ comment: tableComments, for indexPath: IndexPath) -> UITableViewCell {
  183. guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? NCShareCommentsCell,
  184. let metadata else {
  185. return UITableViewCell()
  186. }
  187. cell.indexPath = indexPath
  188. cell.tableComments = comment
  189. cell.delegate = self
  190. // Avatar
  191. let fileName = NCSession.shared.getFileName(urlBase: metadata.urlBase, user: comment.actorId)
  192. let results = NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName)
  193. if results.image == nil {
  194. cell.fileAvatarImageView?.image = utility.loadUserImage(for: comment.actorId, displayName: comment.actorDisplayName, urlBase: NCSession.shared.getSession(account: account).urlBase)
  195. } else {
  196. cell.fileAvatarImageView?.image = results.image
  197. }
  198. if let tableAvatar = results.tableAvatar,
  199. !tableAvatar.loaded,
  200. NCNetworking.shared.downloadAvatarQueue.operations.filter({ ($0 as? NCOperationDownloadAvatar)?.fileName == fileName }).isEmpty {
  201. NCNetworking.shared.downloadAvatarQueue.addOperation(NCOperationDownloadAvatar(user: comment.actorId, fileName: fileName, account: account, view: tableView))
  202. }
  203. // Username
  204. cell.labelUser.text = comment.actorDisplayName
  205. cell.labelUser.textColor = NCBrandColor.shared.textColor
  206. // Date
  207. cell.labelDate.text = utility.dateDiff(comment.creationDateTime as Date)
  208. cell.labelDate.textColor = .lightGray
  209. // Message
  210. cell.labelMessage.text = comment.message
  211. cell.labelMessage.textColor = NCBrandColor.shared.textColor
  212. // Button Menu
  213. if comment.actorId == metadata.userId {
  214. cell.buttonMenu.isHidden = false
  215. } else {
  216. cell.buttonMenu.isHidden = true
  217. }
  218. cell.sizeToFit()
  219. return cell
  220. }
  221. func makeActivityCell(_ activity: tableActivity, for indexPath: IndexPath) -> UITableViewCell {
  222. guard let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath) as? NCActivityTableViewCell else {
  223. return UITableViewCell()
  224. }
  225. var orderKeysId: [String] = []
  226. cell.idActivity = activity.idActivity
  227. cell.account = activity.account
  228. cell.indexPath = indexPath
  229. cell.avatar.image = nil
  230. cell.avatar.isHidden = true
  231. cell.didSelectItemEnable = self.didSelectItemEnable
  232. cell.subject.textColor = NCBrandColor.shared.textColor
  233. cell.viewController = self
  234. // icon
  235. if !activity.icon.isEmpty {
  236. activity.icon = activity.icon.replacingOccurrences(of: ".png", with: ".svg")
  237. let fileNameIcon = (activity.icon as NSString).lastPathComponent
  238. let fileNameLocalPath = utilityFileSystem.directoryUserData + "/" + fileNameIcon
  239. if FileManager.default.fileExists(atPath: fileNameLocalPath) {
  240. let image = fileNameIcon.contains(".svg") ? SVGKImage(contentsOfFile: fileNameLocalPath)?.uiImage : UIImage(contentsOfFile: fileNameLocalPath)
  241. if let image {
  242. cell.icon.image = image.withTintColor(NCBrandColor.shared.textColor, renderingMode: .alwaysOriginal)
  243. }
  244. } else {
  245. NextcloudKit.shared.downloadContent(serverUrl: activity.icon, account: activity.account) { _, responseData, error in
  246. if error == .success, let data = responseData?.data {
  247. do {
  248. try data.write(to: NSURL(fileURLWithPath: fileNameLocalPath) as URL, options: .atomic)
  249. self.tableView.reloadData()
  250. } catch { return }
  251. }
  252. }
  253. }
  254. }
  255. // avatar
  256. if !activity.user.isEmpty && activity.user != session.userId {
  257. cell.avatar.isHidden = false
  258. cell.fileUser = activity.user
  259. cell.subjectLeadingConstraint.constant = 15
  260. let fileName = NCSession.shared.getFileName(urlBase: session.urlBase, user: activity.user)
  261. let results = NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName)
  262. if results.image == nil {
  263. cell.fileAvatarImageView?.image = utility.loadUserImage(for: activity.user, displayName: nil, urlBase: session.urlBase)
  264. } else {
  265. cell.fileAvatarImageView?.image = results.image
  266. }
  267. if !(results.tableAvatar?.loaded ?? false),
  268. NCNetworking.shared.downloadAvatarQueue.operations.filter({ ($0 as? NCOperationDownloadAvatar)?.fileName == fileName }).isEmpty {
  269. NCNetworking.shared.downloadAvatarQueue.addOperation(NCOperationDownloadAvatar(user: activity.user, fileName: fileName, account: session.account, view: tableView))
  270. }
  271. } else {
  272. cell.subjectLeadingConstraint.constant = -30
  273. }
  274. // subject
  275. cell.subject.text = activity.subject
  276. if !activity.subjectRich.isEmpty {
  277. var subject = activity.subjectRich
  278. var keys: [String] = []
  279. if let regex = try? NSRegularExpression(pattern: "\\{[a-z0-9]+\\}", options: .caseInsensitive) {
  280. let string = subject as NSString
  281. keys = regex.matches(in: subject, options: [], range: NSRange(location: 0, length: string.length)).map {
  282. string.substring(with: $0.range).replacingOccurrences(of: "[\\{\\}]", with: "", options: .regularExpression)
  283. }
  284. }
  285. for key in keys {
  286. if let result = database.getActivitySubjectRich(account: session.account, idActivity: activity.idActivity, key: key) {
  287. orderKeysId.append(result.id)
  288. subject = subject.replacingOccurrences(of: "{\(key)}", with: "<bold>" + result.name + "</bold>")
  289. }
  290. }
  291. let normal = Style {
  292. $0.font = UIFont.systemFont(ofSize: cell.subject.font.pointSize)
  293. $0.lineSpacing = 1.5
  294. }
  295. let bold = Style { $0.font = UIFont.systemFont(ofSize: cell.subject.font.pointSize, weight: .bold) }
  296. let date = Style { $0.font = UIFont.systemFont(ofSize: cell.subject.font.pointSize - 3)
  297. $0.color = UIColor.lightGray
  298. }
  299. subject += "\n" + "<date>" + utility.dateDiff(activity.date as Date) + "</date>"
  300. cell.subject.attributedText = subject.set(style: StyleGroup(base: normal, ["bold": bold, "date": date]))
  301. }
  302. return cell
  303. }
  304. }
  305. // MARK: - ScrollView
  306. extension NCActivity: UIScrollViewDelegate {
  307. func scrollViewDidScroll(_ scrollView: UIScrollView) {
  308. guard
  309. scrollView.contentOffset.y > 50,
  310. scrollView.contentSize.height - scrollView.frame.height - scrollView.contentOffset.y < -50
  311. else { return }
  312. fetchAll(isInitial: false)
  313. }
  314. }
  315. // MARK: - NC API & Algorithm
  316. extension NCActivity {
  317. func fetchAll(isInitial: Bool) {
  318. guard !isFetchingActivity else { return }
  319. self.isFetchingActivity = true
  320. var bottom: CGFloat = 0
  321. if let mainTabBar = self.tabBarController?.tabBar as? NCMainTabBar {
  322. bottom = -mainTabBar.getHeight()
  323. }
  324. NCActivityIndicator.shared.start(backgroundView: self.view, bottom: bottom - 35, style: .medium)
  325. let dispatchGroup = DispatchGroup()
  326. loadComments(disptachGroup: dispatchGroup)
  327. if !isInitial, let activity = allItems.compactMap({ $0 as? tableActivity }).last {
  328. loadActivity(idActivity: activity.idActivity, disptachGroup: dispatchGroup)
  329. } else {
  330. checkRecentActivity(disptachGroup: dispatchGroup)
  331. }
  332. dispatchGroup.notify(queue: .main) {
  333. self.loadDataSource()
  334. NCActivityIndicator.shared.stop()
  335. // otherwise is triggered again
  336. DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
  337. self.isFetchingActivity = false
  338. }
  339. }
  340. }
  341. func loadDataSource() {
  342. var newItems = [DateCompareable]()
  343. if showComments, let metadata {
  344. let comments = database.getComments(account: metadata.account, objectId: metadata.fileId)
  345. newItems += comments
  346. }
  347. let activities = database.getActivity(
  348. predicate: NSPredicate(format: "account == %@", session.account),
  349. filterFileId: metadata?.fileId)
  350. newItems += activities.filter
  351. self.allItems = newItems.sorted(by: { $0.dateKey > $1.dateKey })
  352. self.sectionDates = self.allItems.reduce(into: Set<Date>()) { partialResult, next in
  353. let newDay = Calendar.current.startOfDay(for: next.dateKey)
  354. partialResult.insert(newDay)
  355. }.sorted(by: >)
  356. self.tableView.reloadData()
  357. }
  358. func loadComments(disptachGroup: DispatchGroup? = nil) {
  359. guard showComments, let metadata = metadata else { return }
  360. disptachGroup?.enter()
  361. NextcloudKit.shared.getComments(fileId: metadata.fileId, account: metadata.account) { _, comments, _, error in
  362. if error == .success, let comments = comments {
  363. self.database.addComments(comments, account: metadata.account, objectId: metadata.fileId)
  364. } else if error.errorCode != NCGlobal.shared.errorResourceNotFound {
  365. NCContentPresenter().showError(error: error)
  366. }
  367. if let disptachGroup = disptachGroup {
  368. disptachGroup.leave()
  369. } else {
  370. self.loadDataSource()
  371. }
  372. }
  373. }
  374. /// Check if most recent activivities are loaded, if not trigger reload
  375. func checkRecentActivity(disptachGroup: DispatchGroup) {
  376. guard let result = database.getLatestActivityId(account: session.account), metadata == nil, hasActivityToLoad else {
  377. return self.loadActivity(idActivity: 0, disptachGroup: disptachGroup)
  378. }
  379. let resultActivityId = max(result.activityFirstKnown, result.activityLastGiven)
  380. disptachGroup.enter()
  381. NextcloudKit.shared.getActivity(
  382. since: 0,
  383. limit: 1,
  384. objectId: nil,
  385. objectType: objectType,
  386. previews: true,
  387. account: session.account) { task in
  388. self.dataSourceTask = task
  389. } completion: { account, _, activityFirstKnown, activityLastGiven, _, error in
  390. defer { disptachGroup.leave() }
  391. let largestActivityId = max(activityFirstKnown, activityLastGiven)
  392. guard error == .success,
  393. account == self.session.account,
  394. largestActivityId > resultActivityId
  395. else {
  396. self.hasActivityToLoad = error.errorCode == NCGlobal.shared.errorNotModified ? false : self.hasActivityToLoad
  397. return
  398. }
  399. self.loadActivity(idActivity: 0, limit: largestActivityId - resultActivityId, disptachGroup: disptachGroup)
  400. }
  401. }
  402. func loadActivity(idActivity: Int, limit: Int = 200, disptachGroup: DispatchGroup) {
  403. guard hasActivityToLoad else { return }
  404. var resultActivityId = 0
  405. disptachGroup.enter()
  406. NextcloudKit.shared.getActivity(
  407. since: idActivity,
  408. limit: min(limit, 200),
  409. objectId: metadata?.fileId,
  410. objectType: objectType,
  411. previews: true,
  412. account: session.account) { task in
  413. self.dataSourceTask = task
  414. } completion: { account, activities, activityFirstKnown, activityLastGiven, _, error in
  415. defer { disptachGroup.leave() }
  416. guard error == .success,
  417. account == self.session.account,
  418. !activities.isEmpty
  419. else {
  420. self.hasActivityToLoad = error.errorCode == NCGlobal.shared.errorNotModified ? false : self.hasActivityToLoad
  421. return
  422. }
  423. self.database.addActivity(activities, account: account)
  424. // update most recently loaded activity only when all activities are loaded (not filtered)
  425. let largestActivityId = max(activityFirstKnown, activityLastGiven)
  426. if let result = self.database.getLatestActivityId(account: self.session.account) {
  427. resultActivityId = max(result.activityFirstKnown, result.activityLastGiven)
  428. }
  429. if self.metadata == nil, largestActivityId > resultActivityId {
  430. self.database.updateLatestActivityId(activityFirstKnown: activityFirstKnown, activityLastGiven: activityLastGiven, account: account)
  431. }
  432. }
  433. }
  434. }
  435. extension NCActivity: NCShareCommentsCellDelegate {
  436. func showProfile(with tableComment: tableComments?, sender: Any) {
  437. guard let tableComment = tableComment else {
  438. return
  439. }
  440. self.showProfileMenu(userId: tableComment.actorId, session: session)
  441. }
  442. func tapMenu(with tableComments: tableComments?, sender: Any) {
  443. toggleMenu(with: tableComments)
  444. }
  445. func toggleMenu(with tableComments: tableComments?) {
  446. var actions = [NCMenuAction]()
  447. actions.append(
  448. NCMenuAction(
  449. title: NSLocalizedString("_edit_comment_", comment: ""),
  450. icon: utility.loadImage(named: "pencil", colors: [NCBrandColor.shared.iconImageColor]),
  451. action: { _ in
  452. guard let metadata = self.metadata, let tableComments = tableComments else { return }
  453. let alert = UIAlertController(title: NSLocalizedString("_edit_comment_", comment: ""), message: nil, preferredStyle: .alert)
  454. alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil))
  455. alert.addTextField(configurationHandler: { textField in
  456. textField.placeholder = NSLocalizedString("_new_comment_", comment: "")
  457. })
  458. alert.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in
  459. guard let message = alert.textFields?.first?.text, !message.isEmpty else { return }
  460. NextcloudKit.shared.updateComments(fileId: metadata.fileId, messageId: tableComments.messageId, message: message, account: metadata.account) { _, _, error in
  461. if error == .success {
  462. self.loadComments()
  463. } else {
  464. NCContentPresenter().showError(error: error)
  465. }
  466. }
  467. }))
  468. self.present(alert, animated: true)
  469. }
  470. )
  471. )
  472. actions.append(
  473. NCMenuAction(
  474. title: NSLocalizedString("_delete_comment_", comment: ""),
  475. destructive: true,
  476. icon: utility.loadImage(named: "trash", colors: [.red]),
  477. action: { _ in
  478. guard let metadata = self.metadata, let tableComments = tableComments else { return }
  479. NextcloudKit.shared.deleteComments(fileId: metadata.fileId, messageId: tableComments.messageId, account: metadata.account) { _, _, error in
  480. if error == .success {
  481. self.loadComments()
  482. } else {
  483. NCContentPresenter().showError(error: error)
  484. }
  485. }
  486. }
  487. )
  488. )
  489. presentMenu(with: actions)
  490. }
  491. }