diff --git a/Stepic/AppDelegate.swift b/Stepic/AppDelegate.swift index 2778352803..d3b47903e1 100644 --- a/Stepic/AppDelegate.swift +++ b/Stepic/AppDelegate.swift @@ -50,7 +50,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { RemoteConfig.shared.setup() SVProgressHUD.setMinimumDismissTimeInterval(0.5) - SVProgressHUD.setGraceTimeInterval(0.1) SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.clear) SVProgressHUD.setHapticsEnabled(true) diff --git a/Stepic/Discussions/Comment.swift b/Stepic/Discussions/Comment.swift index c4ea13cb10..a23f43b071 100644 --- a/Stepic/Discussions/Comment.swift +++ b/Stepic/Discussions/Comment.swift @@ -33,15 +33,21 @@ final class Comment: JSONSerializable { var abuseCount: Int = 0 var actions: [Action] = [] var submissionID: Submission.IdType? + var thread: String = DiscussionThread.ThreadType.default.rawValue var userInfo: UserInfo! var vote: Vote! var submission: Submission? + var threadType: DiscussionThread.ThreadType? { + DiscussionThread.ThreadType(rawValue: self.thread) + } + var json: JSON { var dict: JSON = [ JSONKey.target.rawValue: self.targetID, - JSONKey.text.rawValue: self.text + JSONKey.text.rawValue: self.text, + JSONKey.thread.rawValue: self.thread ] if let parentID = self.parentID { @@ -55,8 +61,7 @@ final class Comment: JSONSerializable { if let submissionID = self.submissionID { try? dict.merge( with: [ - JSONKey.submission.rawValue: submissionID, - JSONKey.thread.rawValue: DiscussionThread.ThreadType.solutions.rawValue + JSONKey.submission.rawValue: submissionID ] ) } @@ -72,12 +77,14 @@ final class Comment: JSONSerializable { targetID: Step.IdType, text: String, parentID: IdType? = nil, - submissionID: Submission.IdType? = nil + submissionID: Submission.IdType? = nil, + threadType: DiscussionThread.ThreadType = .default ) { self.targetID = targetID self.text = text self.parentID = parentID self.submissionID = submissionID + self.thread = threadType.rawValue } func update(json: JSON) { @@ -97,6 +104,7 @@ final class Comment: JSONSerializable { self.epicCount = json[JSONKey.epicCount.rawValue].intValue self.abuseCount = json[JSONKey.abuseCount.rawValue].intValue self.submissionID = json[JSONKey.submission.rawValue].int + self.thread = json[JSONKey.thread.rawValue].string ?? DiscussionThread.ThreadType.default.rawValue self.actions.removeAll(keepingCapacity: true) for (actionKey, value) in json[JSONKey.actions.rawValue].dictionaryValue { @@ -168,7 +176,8 @@ extension Comment: CustomDebugStringConvertible { submissionID: \(submissionID ??? "nil"), \ userInfo: \(userInfo ??? "nil"), \ vote: \(vote ??? "nil"), \ - submission: \(submission ??? "nil")) + submission: \(submission ??? "nil")) \ + thread: \(thread)) """ } } diff --git a/Stepic/Sources/Modules/Discussions/DiscussionsInteractor.swift b/Stepic/Sources/Modules/Discussions/DiscussionsInteractor.swift index 1b9b862422..8aec18455d 100644 --- a/Stepic/Sources/Modules/Discussions/DiscussionsInteractor.swift +++ b/Stepic/Sources/Modules/Discussions/DiscussionsInteractor.swift @@ -234,7 +234,9 @@ final class DiscussionsInteractor: DiscussionsInteractorProtocol { self.currentDiscussions.remove(at: discussionIndex) self.currentReplies[commentID] = nil - self.provider.decrementStepDiscussionsCount(stepID: self.stepID).cauterize() + if self.discussionThreadType == .default { + self.provider.decrementStepDiscussionsCount(stepID: self.stepID).cauterize() + } } else { for (discussionID, replies) in self.currentReplies { guard let replyIndex = replies.firstIndex(where: { $0.id == commentID }) else { @@ -748,7 +750,9 @@ extension DiscussionsInteractor: WriteCommentOutputProtocol { self.presenter.presentCommentCreate(response: .init(result: self.makeDiscussionsData())) }.cauterize() - self.provider.incrementStepDiscussionsCount(stepID: self.stepID).cauterize() + if self.discussionThreadType == .default { + self.provider.incrementStepDiscussionsCount(stepID: self.stepID).cauterize() + } } } diff --git a/Stepic/Sources/Modules/Discussions/DiscussionsViewController.swift b/Stepic/Sources/Modules/Discussions/DiscussionsViewController.swift index d183ba75f7..b56d4a0e3e 100644 --- a/Stepic/Sources/Modules/Discussions/DiscussionsViewController.swift +++ b/Stepic/Sources/Modules/Discussions/DiscussionsViewController.swift @@ -503,19 +503,17 @@ extension DiscussionsViewController: DiscussionsTableViewDataSourceDelegate { ) ) - if viewModel.solution == nil { - alert.addAction( - UIAlertAction( - title: NSLocalizedString("Reply", comment: ""), - style: .default, - handler: { [weak self] _ in - self?.interactor.doWriteCommentPresentation( - request: .init(commentID: viewModel.id, presentationContext: .create) - ) - } - ) + alert.addAction( + UIAlertAction( + title: NSLocalizedString("Reply", comment: ""), + style: .default, + handler: { [weak self] _ in + self?.interactor.doWriteCommentPresentation( + request: .init(commentID: viewModel.id, presentationContext: .create) + ) + } ) - } + ) if viewModel.canEdit { alert.addAction( diff --git a/Stepic/Sources/Modules/Discussions/Views/Cell/DiscussionsCellView.swift b/Stepic/Sources/Modules/Discussions/Views/Cell/DiscussionsCellView.swift index 4770daf583..7794bbb6e8 100644 --- a/Stepic/Sources/Modules/Discussions/Views/Cell/DiscussionsCellView.swift +++ b/Stepic/Sources/Modules/Discussions/Views/Cell/DiscussionsCellView.swift @@ -321,8 +321,6 @@ final class DiscussionsCellView: UIView { } else { self.solutionContainerView.isHidden = true } - - self.replyButton.isHidden = viewModel.solution != nil } func calculateContentHeight(maxPreferredWidth: CGFloat) -> CGFloat { diff --git a/Stepic/Sources/Modules/WriteComment/WriteCommentDataFlow.swift b/Stepic/Sources/Modules/WriteComment/WriteCommentDataFlow.swift index a8a800fc8b..d96e32c662 100644 --- a/Stepic/Sources/Modules/WriteComment/WriteCommentDataFlow.swift +++ b/Stepic/Sources/Modules/WriteComment/WriteCommentDataFlow.swift @@ -10,6 +10,7 @@ enum WriteComment { struct CommentData { let text: String + let parentID: WriteComment.ParentIDType? let comment: Comment? let submission: Submission? let discussionThreadType: DiscussionThread.ThreadType diff --git a/Stepic/Sources/Modules/WriteComment/WriteCommentInteractor.swift b/Stepic/Sources/Modules/WriteComment/WriteCommentInteractor.swift index 54b8ff2c6a..e274f5e918 100644 --- a/Stepic/Sources/Modules/WriteComment/WriteCommentInteractor.swift +++ b/Stepic/Sources/Modules/WriteComment/WriteCommentInteractor.swift @@ -67,7 +67,8 @@ final class WriteCommentInteractor: WriteCommentInteractorProtocol { targetID: self.targetID, text: htmlText, parentID: self.parentID, - submissionID: self.submission?.id + submissionID: self.submission?.id, + threadType: self.discussionThreadType ) var actionPromise: Promise @@ -126,6 +127,7 @@ final class WriteCommentInteractor: WriteCommentInteractorProtocol { private func makeCommentData() -> WriteComment.CommentData { .init( text: self.currentText, + parentID: self.parentID, comment: self.comment, submission: self.submission, discussionThreadType: self.discussionThreadType diff --git a/Stepic/Sources/Modules/WriteComment/WriteCommentPresenter.swift b/Stepic/Sources/Modules/WriteComment/WriteCommentPresenter.swift index 9948d8bf98..6c4b2fee9a 100644 --- a/Stepic/Sources/Modules/WriteComment/WriteCommentPresenter.swift +++ b/Stepic/Sources/Modules/WriteComment/WriteCommentPresenter.swift @@ -91,18 +91,22 @@ final class WriteCommentPresenter: WriteCommentPresenterProtocol { return NSLocalizedString("WriteCommentSelectSolutionTitle", comment: "") }() + let isReply = data.parentID != nil + let isFilled: Bool = { - if data.discussionThreadType == .solutions { + if !isReply && data.discussionThreadType == .solutions { return !data.text.isEmpty && data.submission != nil } return !data.text.isEmpty }() + let isSolutionHidden = isReply || data.discussionThreadType != .solutions + return .init( text: data.text, doneButtonTitle: doneButtonTitle, isFilled: isFilled, - isSolutionHidden: data.discussionThreadType != .solutions, + isSolutionHidden: isSolutionHidden, isSolutionSelected: data.submission != nil, isSolutionCorrect: data.submission?.isCorrect ?? false, solutionTitle: solutionTitle