Skip to content

Commit b8f184b

Browse files
authored
Remove NoteBlockCommentTableViewCell and related code (#24184)
* Fix formatting * Remove NoteBlockCommentTableViewCell * Remove LongPressGestureLabel * Remove NoteBlockCommentTableViewCell usages * Remove replyTextView
1 parent 6a1f355 commit b8f184b

6 files changed

+27
-508
lines changed

WordPress/Classes/Extensions/UIAlertController+Helpers.swift

-13
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,4 @@ extension UIAlertController {
3333
alertController.addCancelActionWithTitle(NSLocalizedString("Cancel", comment: "Cancel copying link to comment button title"))
3434
return alertController
3535
}
36-
37-
/// This method is will present an alert controller (action sheet style) that
38-
/// provides a copy action to allow copying the url parameter to the clip board.
39-
/// Once copied, a notice will be posted using the dispacher so the user will know
40-
/// the url was copied.
41-
@objc static func presentAlertAndCopyCommentURLToClipboard(url: URL) {
42-
let noticeTitle = NSLocalizedString("Link Copied to Clipboard", comment: "Link copied to clipboard notice title")
43-
44-
let copyAlertController = UIAlertController.copyCommentURLAlertController(url) {
45-
ActionDispatcher.dispatch(NoticeAction.post(Notice(title: noticeTitle)))
46-
}
47-
copyAlertController?.presentFromRootViewController()
48-
}
4936
}

WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift

+7-127
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ class NotificationDetailsViewController: UIViewController, NoResultsViewHost {
4848
///
4949
@IBOutlet var badgeCenterLayoutConstraint: NSLayoutConstraint!
5050

51-
/// RelpyTextView
52-
///
53-
@IBOutlet var replyTextView: CommentLargeButton!
54-
5551
/// Embedded Media Downloader
5652
///
5753
fileprivate var mediaDownloader = NotificationMediaDownloader()
@@ -139,7 +135,6 @@ class NotificationDetailsViewController: UIViewController, NoResultsViewHost {
139135
setupTableView()
140136
setupTableViewCells()
141137
setupTableDelegates()
142-
setupReplyTextView()
143138
}
144139

145140
override func viewWillAppear(_ animated: Bool) {
@@ -201,7 +196,6 @@ class NotificationDetailsViewController: UIViewController, NoResultsViewHost {
201196
fileprivate func refreshInterface() {
202197
formatter.resetCache()
203198
tableView.reloadData()
204-
attachReplyViewIfNeeded()
205199
adjustLayoutConstraintsIfNeeded()
206200
refreshNavigationBar()
207201
}
@@ -358,7 +352,6 @@ extension NotificationDetailsViewController {
358352
let cellClassNames: [NoteBlockTableViewCell.Type] = [
359353
NoteBlockHeaderTableViewCell.self,
360354
NoteBlockTextTableViewCell.self,
361-
NoteBlockCommentTableViewCell.self,
362355
NoteBlockImageTableViewCell.self,
363356
NoteBlockUserTableViewCell.self,
364357
NoteBlockButtonTableViewCell.self
@@ -395,22 +388,6 @@ extension NotificationDetailsViewController {
395388
}
396389
}
397390

398-
func setupReplyTextView() {
399-
let replyTextView = CommentLargeButton()
400-
401-
replyTextView.placeholder = NSLocalizedString("Write a reply", comment: "Placeholder text for inline compose view")
402-
replyTextView.accessibilityLabel = NSLocalizedString("Reply Text", comment: "Notifications Reply Accessibility Identifier")
403-
404-
replyTextView.onTap = {
405-
// TODO: (kean) remove the remaining .comment-related code
406-
wpAssertionFailure("Notifications have been using NotificationCommentDetailViewController since 2023")
407-
}
408-
409-
replyTextView.setContentCompressionResistancePriority(.required, for: .vertical)
410-
411-
self.replyTextView = replyTextView
412-
}
413-
414391
func setupNotificationListeners() {
415392
let nc = NotificationCenter.default
416393
nc.addObserver(self, selector: #selector(notificationWasUpdated), name: .NSManagedObjectContextObjectsDidChange, object: note.managedObjectContext)
@@ -422,28 +399,6 @@ extension NotificationDetailsViewController {
422399
}
423400
}
424401

425-
// MARK: - Reply View Helpers
426-
//
427-
extension NotificationDetailsViewController {
428-
func attachReplyViewIfNeeded() {
429-
guard shouldAttachReplyView else {
430-
replyTextView.removeFromSuperview()
431-
return
432-
}
433-
434-
stackView.addArrangedSubview(replyTextView)
435-
}
436-
437-
var shouldAttachReplyView: Bool {
438-
// Attach the Reply component only if the notification has a comment, and it can be replied to.
439-
//
440-
guard let block: FormattableCommentContent = note.contentGroup(ofKind: .comment)?.blockOfKind(.comment) else {
441-
return false
442-
}
443-
return block.action(id: ReplyToCommentAction.actionIdentifier())?.on ?? false
444-
}
445-
}
446-
447402
// MARK: - Layout Helpers
448403
//
449404
private extension NotificationDetailsViewController {
@@ -479,16 +434,14 @@ private extension NotificationDetailsViewController {
479434
fallthrough
480435
case .text:
481436
return NoteBlockTextTableViewCell.reuseIdentifier()
482-
case .comment:
483-
return NoteBlockCommentTableViewCell.reuseIdentifier()
484437
case .image:
485438
return NoteBlockImageTableViewCell.reuseIdentifier()
486439
case .user:
487440
return NoteBlockUserTableViewCell.reuseIdentifier()
488441
case .button:
489442
return NoteBlockButtonTableViewCell.reuseIdentifier()
490443
default:
491-
assertionFailure("Unmanaged group kind: \(blockGroup.kind)")
444+
wpAssertionFailure("Unmanaged group kind", userInfo: ["kind": "\(blockGroup.kind)"])
492445
return NoteBlockTextTableViewCell.reuseIdentifier()
493446
}
494447
}
@@ -512,8 +465,6 @@ private extension NotificationDetailsViewController {
512465
setupFooterCell(cell, blockGroup: blockGroup)
513466
case let cell as NoteBlockUserTableViewCell:
514467
setupUserCell(cell, blockGroup: blockGroup)
515-
case let cell as NoteBlockCommentTableViewCell:
516-
setupCommentCell(cell, blockGroup: blockGroup, at: indexPath)
517468
case let cell as NoteBlockImageTableViewCell:
518469
setupImageCell(cell, blockGroup: blockGroup)
519470
case let cell as NoteBlockTextTableViewCell:
@@ -587,76 +538,6 @@ private extension NotificationDetailsViewController {
587538
cell.downloadGravatarWithURL(mediaURL)
588539
}
589540

590-
func setupCommentCell(_ cell: NoteBlockCommentTableViewCell, blockGroup: FormattableContentGroup, at indexPath: IndexPath) {
591-
// Note:
592-
// The main reason why it's a very good idea *not* to reuse NoteBlockHeaderTableViewCell, just to display the
593-
// gravatar, is because we're implementing a custom behavior whenever the user approves/ unapproves the comment.
594-
//
595-
// - Font colors are updated.
596-
// - A left separator is displayed.
597-
//
598-
guard let commentBlock: FormattableCommentContent = blockGroup.blockOfKind(.comment) else {
599-
assertionFailure("Missing Comment Block for Notification [\(note.notificationId)]")
600-
return
601-
}
602-
603-
guard let userBlock: FormattableUserContent = blockGroup.blockOfKind(.user) else {
604-
assertionFailure("Missing User Block for Notification [\(note.notificationId)]")
605-
return
606-
}
607-
608-
// Merge the Attachments with their ranges: [NSRange: UIImage]
609-
let mediaMap = mediaDownloader.imagesForUrls(commentBlock.imageUrls)
610-
let mediaRanges = commentBlock.buildRangesToImagesMap(mediaMap)
611-
612-
let styles = RichTextContentStyles(key: "RichText-\(indexPath)")
613-
let text = formatter.render(content: commentBlock, with: styles).stringByEmbeddingImageAttachments(mediaRanges)
614-
615-
// Setup: Properties
616-
cell.name = userBlock.text
617-
cell.timestamp = (note.timestampAsDate as NSDate).mediumString()
618-
cell.site = userBlock.metaTitlesHome ?? userBlock.metaLinksHome?.host
619-
cell.attributedCommentText = text.trimNewlines()
620-
cell.isApproved = commentBlock.isCommentApproved
621-
622-
// Add comment author's name to Reply placeholder.
623-
let placeholderFormat = NSLocalizedString("Reply to %1$@",
624-
comment: "Placeholder text for replying to a comment. %1$@ is a placeholder for the comment author's name.")
625-
replyTextView.placeholder = String(format: placeholderFormat, cell.name ?? String())
626-
627-
// Setup: Callbacks
628-
cell.onUserClick = { [weak self] in
629-
guard let homeURL = userBlock.metaLinksHome else {
630-
return
631-
}
632-
633-
self?.displayURL(homeURL)
634-
}
635-
636-
cell.onUrlClick = { [weak self] url in
637-
self?.displayURL(url as URL)
638-
}
639-
640-
cell.onAttachmentClick = { [weak self] attachment in
641-
guard let image = attachment.image else {
642-
return
643-
}
644-
self?.router.routeTo(image)
645-
}
646-
647-
cell.onTimeStampLongPress = { [weak self] in
648-
guard let urlString = self?.note.url,
649-
let url = URL(string: urlString) else {
650-
return
651-
}
652-
UIAlertController.presentAlertAndCopyCommentURLToClipboard(url: url)
653-
}
654-
655-
// Download the Gravatar
656-
let mediaURL = userBlock.media.first?.mediaURL
657-
cell.downloadGravatarWithURL(mediaURL)
658-
}
659-
660541
func setupImageCell(_ cell: NoteBlockImageTableViewCell, blockGroup: FormattableContentGroup) {
661542
guard let imageBlock = blockGroup.blocks.first as? NotificationTextContent else {
662543
assertionFailure("Missing Image Block for Notification [\(note.notificationId)")
@@ -974,19 +855,19 @@ private extension NotificationDetailsViewController {
974855
}
975856

976857
enum ContentMedia {
977-
static let richBlockTypes = Set(arrayLiteral: FormattableContentKind.text, FormattableContentKind.comment)
978-
static let duration = TimeInterval(0.25)
979-
static let delay = TimeInterval(0)
858+
static let richBlockTypes = Set(arrayLiteral: FormattableContentKind.text, FormattableContentKind.comment)
859+
static let duration = TimeInterval(0.25)
860+
static let delay = TimeInterval(0)
980861
static let options: UIView.AnimationOptions = [.overrideInheritedDuration, .beginFromCurrentState]
981862
}
982863

983864
enum Settings {
984-
static let numberOfSections = 1
985-
static let estimatedRowHeight = CGFloat(44)
865+
static let numberOfSections = 1
866+
static let estimatedRowHeight = CGFloat(44)
986867
}
987868

988869
enum Assets {
989-
static let confettiBackground = "notifications-confetti-background"
870+
static let confettiBackground = "notifications-confetti-background"
990871
}
991872
}
992873

@@ -1003,5 +884,4 @@ extension NotificationDetailsViewController {
1003884
//
1004885
private extension String {
1005886
static let notificationDetailsTableAccessibilityId = "notifications-details-table"
1006-
static let replyTextViewAccessibilityId = "reply-text-view"
1007887
}

WordPress/Classes/ViewRelated/Notifications/Style/WPStyleGuide+Notifications.swift

+20-55
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ extension WPStyleGuide {
1313
public static let unreadIndicatorColor = UIAppColor.primaryLight
1414

1515
// Notification cells
16-
public static let noticonFont = UIFont(name: "Noticons", size: 16)
17-
public static let noticonReadColor = UIColor.systemGray
16+
public static let noticonFont = UIFont(name: "Noticons", size: 16)
17+
public static let noticonReadColor = UIColor.systemGray
1818

1919
// Notification undo overlay
20-
public static let noteUndoBackgroundColor = UIAppColor.error
21-
public static let noteUndoTextColor = UIColor.white
22-
public static let noteUndoTextFont = subjectRegularFont
20+
public static let noteUndoBackgroundColor = UIAppColor.error
21+
public static let noteUndoTextColor = UIColor.white
22+
public static let noteUndoTextFont = subjectRegularFont
2323

2424
// Subject Text
2525
public static var subjectRegularStyle: [NSAttributedString.Key: Any] {
@@ -64,11 +64,11 @@ extension WPStyleGuide {
6464
//
6565

6666
// Header
67-
public static let headerTitleColor = blockTextColor
68-
public static let headerTitleBoldFont = blockBoldFont
67+
public static let headerTitleColor = blockTextColor
68+
public static let headerTitleBoldFont = blockBoldFont
6969

70-
public static let headerDetailsColor = UIAppColor.primary
71-
public static let headerDetailsRegularFont = blockRegularFont
70+
public static let headerDetailsColor = UIAppColor.primary
71+
public static let headerDetailsRegularFont = blockRegularFont
7272

7373
public static var headerTitleRegularStyle: [NSAttributedString.Key: Any] {
7474
return [.font: headerTitleRegularFont,
@@ -132,27 +132,17 @@ extension WPStyleGuide {
132132
}
133133

134134
// Blocks
135-
public static let contentBlockRegularFont = WPFontManager.notoRegularFont(ofSize: blockFontSize)
136-
public static let contentBlockBoldFont = WPFontManager.notoBoldFont(ofSize: blockFontSize)
137-
public static let contentBlockItalicFont = WPFontManager.notoItalicFont(ofSize: blockFontSize)
138-
public static let blockRegularFont = WPFontManager.systemRegularFont(ofSize: blockFontSize)
139-
public static let blockBoldFont = WPFontManager.systemSemiBoldFont(ofSize: blockFontSize)
140-
141-
public static let blockTextColor = UIColor.label
142-
public static let blockQuotedColor = UIAppColor.neutral
143-
public static let blockBackgroundColor = UIColor.secondarySystemGroupedBackground
144-
public static let blockLinkColor = UIAppColor.primary
145-
public static let blockSeparatorColor = UIColor.separator
146-
147-
public static let blockApprovedBgColor = UIColor.clear
148-
149-
public static let blockUnapprovedSideColor = UIAppColor.warning(.shade60)
150-
public static let blockUnapprovedBgColor = UIColor(
151-
light: UIAppColor.warning(.shade0),
152-
dark: UIAppColor.warning(.shade90)
153-
)
154-
public static let blockUnapprovedTextColor = UIColor.label
155-
public static let blockUnapprovedLinkColor = UIAppColor.primary
135+
public static let contentBlockRegularFont = WPFontManager.notoRegularFont(ofSize: blockFontSize)
136+
public static let contentBlockBoldFont = WPFontManager.notoBoldFont(ofSize: blockFontSize)
137+
public static let contentBlockItalicFont = WPFontManager.notoItalicFont(ofSize: blockFontSize)
138+
public static let blockRegularFont = WPFontManager.systemRegularFont(ofSize: blockFontSize)
139+
public static let blockBoldFont = WPFontManager.systemSemiBoldFont(ofSize: blockFontSize)
140+
141+
public static let blockTextColor = UIColor.label
142+
public static let blockQuotedColor = UIAppColor.neutral
143+
public static let blockBackgroundColor = UIColor.secondarySystemGroupedBackground
144+
public static let blockLinkColor = UIAppColor.primary
145+
public static let blockSeparatorColor = UIColor.separator
156146

157147
public static var contentBlockRegularStyle: [NSAttributedString.Key: Any] {
158148
return [.paragraphStyle: contentBlockParagraph,
@@ -195,31 +185,6 @@ extension WPStyleGuide {
195185
return isBadge ? badgeBackgroundColor : blockBackgroundColor
196186
}
197187

198-
// Comment Helpers
199-
public static func blockGravatarPlaceholderImage(isApproved approved: Bool) -> UIImage {
200-
return approved ? .gravatarPlaceholderImage : .gravatarUnapprovedImage
201-
}
202-
203-
public static func blockSeparatorColorForComment(isApproved approved: Bool) -> UIColor {
204-
return (approved ? blockSeparatorColor : blockUnapprovedSideColor)
205-
}
206-
207-
public static func blockBackgroundColorForComment(isApproved approved: Bool) -> UIColor {
208-
return approved ? blockApprovedBgColor : blockUnapprovedBgColor
209-
}
210-
211-
public static func blockTitleColorForComment(isApproved approved: Bool) -> UIColor {
212-
return (approved ? blockTextColor : blockUnapprovedTextColor)
213-
}
214-
215-
public static func blockDetailsColorForComment(isApproved approved: Bool) -> UIColor {
216-
return approved ? blockQuotedColor : blockUnapprovedSideColor
217-
}
218-
219-
public static func blockLinkColorForComment(isApproved approved: Bool) -> UIColor {
220-
return (approved ? blockLinkColor : blockUnapprovedLinkColor)
221-
}
222-
223188
// User Cell Helpers
224189
public static func configureFollowButton(_ button: UIButton) {
225190
// General

WordPress/Classes/ViewRelated/Notifications/Views/LongPressGestureLabel.swift

-28
This file was deleted.

0 commit comments

Comments
 (0)